akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//ユークリッドの互除法
//最大公約数
ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

//最小公倍数
ll lcm(ll x, ll y){
	ll g = gcd(x,y);
	return x/g*y;
}

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

int main() {
	int n;
	int ans = 0;
	cin >> n;
	vector<int> a(n), b(n), c(n-1);
	rep(i,n){
		cin >> a[i];
	}
	rep(i,n){
		cin >> b[i];
	}
	rep(i,n-1){
		cin >> c[i];
	}
	rep(i,n){
		ans += b[a[i] - 1];
		if(i==0){
			continue;
		}
		if(a[i-1] == a[i]-1){
			ans += c[a[i-1]-1];
		}
	}
	cout << ans << endl;
}


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

int n, w, r, ans, h[200001]; string s;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cin >> n >> s, w = n; 
    for (int i = 0, j = 1; i < n; i = j++)
        h[j] = h[i] += (s[i] == 'W');
    while (r < w) {
        while (r < n and s[r] == 'R')
            ++r;
        while (w > 0 and s[w-1] == 'W')
            --w;
        if (r < w)
            ++r, --w, ++ans; }
    for (int i = 1, g = n-1-h[n]; ans > 0 and i <= n; ++i, --g)
        ans = min(ans,g+2*h[i]);
    cout << ans; }


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

int main()
{

  string s;
  cin >> s;
  int n = s.size();

  string ans;
  int now = 0;
  for (int i = 0; i < n; i++)
  {
    if (s[i] == '0')
    {
      ans += '0';
      now++;
    }
    else if (s[i] == '1')
    {
      ans += '1';
      now++;
    }
    else if (s[i] == 'B' && now != 0)
    {
      ans.erase(now - 1);
      now--;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3604
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;

void solve() {
  int N;
  cin >> N;

  int ans = 0;
  while (N--) {
    int a;
    cin >> a;
    ans += a - 1;
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;// 998244353;// ;
constexpr long long INF = numeric_limits<LL>::max() / 2;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourd; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<vector<LL>>g, rev;
vector<edge>edges;
vector<LL>v;
map<LL, LL>ma;
set<LL>st;
LL h, w, n, m, k, t, s, p, q, last, cnt, sum, ans,a[510000], b[510000], dp[50000];
string str, ss;
bool f;
char c;
int main() {
	cin >> n;
	cin >> m;
	rep(i, n)a[i] = -1;
	rep(i, m) {
		LL x, y;
		cin >> x >> y;
		x--;
		if (a[x] != -1 && a[x] != y) {
			cout << -1 << endl;
			return 0;
		}
		a[x] = y;
	}
	for (int i = pow(10, n - 1)+(n==1?-1:0); i < pow(10, n); i++) {
		LL cur = i;
		for (int j = 0; j < n; j++) {
			if (a[n - j - 1] != -1 && cur % 10 != a[n - j - 1])break;
			cur /= 10;
			if (n - 1 == j) {
				cout << i << endl;
				return 0;
			}
		}
	}
	cout << -1 << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define read freopen("in.txt", "r", stdin)
#define write freopen("out.txt", "w", stdout)
#define mem(x, n) memset(x, n, sizeof(x))
#define all(x) x.begin(), x.end()
#define endl "\n"

int main() {
	faster;
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (auto &x : a)
		cin >> x;

	ll ans = 0;
	for (ll i = 1; i < n; i++) {
		if (a[i] < a[i - 1]) {
			ans += (a[i - 1] - a[i]);
			a[i] = a[i - 1];
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4776
n,k=map(int,input().split())
h=[int(input()) for _ in range(n)]
h.sort()
min1=10**9*1
soezi=0
count=0
for i in range(n-(k-1)):
    count=h[i+(k-1)]-h[i]
    if min1>count:
        min1=count
print(min1)


Measured memory_bytes: 7384
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE Rank2Types #-}

-- Default Imports

import Control.Monad
import Control.Monad.ST
import Control.Monad.Trans.Class

import qualified Control.Monad.Reader as Reader
import Control.Monad.Reader (Reader, ReaderT, runReader, runReaderT)

import qualified Data.Array.MArray as MArray
import qualified Data.Array.ST as STArray
import Data.Array.ST (STArray, STUArray, runSTArray, runSTUArray)
import Data.Ix (Ix)

import qualified Data.Bits as Bits
import Data.Bits ((.&.), (.|.))

import qualified Data.ByteString.Char8 as BS
import Data.ByteString.Char8 (ByteString)

import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Map as Map
import Data.Map (Map)
import qualified Data.Maybe as Maybe

import qualified Data.Vector as Vector
import qualified Data.Vector.Generic as GVector
import qualified Data.Vector.Unboxed as UVector

import Numeric

import Debug.Trace
-- ----------

-- Custom Import Here


-- ----------

-- Default Definitions

type Vector = Vector.Vector
-- type GVector = GVector.Vector
type UVector = UVector.Vector

readIntToList :: ByteString -> [Int]
readIntToList = List.unfoldr (fmap (second $ BS.dropWhile Char.isSpace) . BS.readInt)

readToList :: Read a => ByteString -> [a]
readToList = List.unfoldr $ fmap (mapTaken . mapRemain) . span' (not . Char.isSpace)
	where
		mapTaken  = first $ read . BS.unpack
		mapRemain = second $ BS.dropWhile Char.isSpace
		span' pred s
			| BS.null taken = Nothing
			| otherwise     = Just (taken, remain')
			where
				(taken, remain) = BS.span pred s
				remain' = BS.dropWhile Char.isSpace remain

readToListN :: Read a => Int -> ByteString -> [a]
readToListN n = take n . readToList

readIntToUVector :: ByteString -> UVector.Vector Int
readIntToUVector = UVector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVectorN :: Int -> ByteString -> UVector.Vector Int
readIntToUVectorN n = UVector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

first :: (a -> a') -> (a, b) -> (a', b)
first f (a, b) = (f a, b)

second :: (b -> b') -> (a, b) -> (a, b')
second f (a, b) = (a, f b)

-- ----------

remain :: String -> Int
remain "SUN" = 7
remain "MON" = 6
remain "TUE" = 5
remain "WED" = 4
remain "THU" = 3
remain "FRI" = 2
remain "SAT" = 1


main :: IO ()
main = do
	s <- getLine
	print $ remain s


Measured memory_bytes: 380
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tommy6073
 */

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

class AABC333 {
public:
    void solve(std::istream& in, std::ostream& out) {
        int A, B;
        in >> A >> B;

        if ((A * B) % 2 == 0) {
            out << "No";
        } else {
            out << "Yes";
        }
    }
};


int main() {
	AABC333 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace contest_Csharp
{
    class Program
    {
        static void Main(string[] args)
        {

            var vals = Console.ReadLine().Split(' ')
                .Select(x => int.Parse(x)).ToList();
            int N = vals[0];
            //int M = vals[1];

            var A = Console.ReadLine().Split(' ')
                .Select(x => int.Parse(x)).ToList();
            List<int> buka=new List<int>(new int[N+1]);
            foreach(int x in A)
            {
                buka[x] += 1;
            }
            for (int i = 0; i < N; i++)
            {
                Console.WriteLine(buka[i+1]);
            }
            


        }
       

    }
}


Measured memory_bytes: 41152
#include <stdio.h>
#include <math.h>

int main(void){
    
    int n,t,a,h[1000],j;
    j=0;
    
    scanf("%d %d %d",&n,&t,&a);
    
    for(int i=0; i<n; i++){
        scanf("%d",&h[i]);
 
        if(fabs(a-(t-h[i]*0.006)) < fabs(a-(t-h[j]*0.006)))
          j=i;
    }
  printf("%d",j+1);
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>

using namespace std;
using ll = long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  string s; cin >> s;
  string fore, rev;
  fore = rev = s;
  reverse(rev.begin(), rev.end());
  if(fore != rev){
    cout << "No" << endl;
    return 0;
  }

  fore = rev = s.substr(0, (s.length()-1)/2);
  reverse(rev.begin(), rev.end());
  if(fore != rev){
    cout << "No" << endl;
    return 0;
  }

  rev = fore = s.substr((s.length()+3)/2-1);
  reverse(rev.begin(), rev.end());
  if(fore != rev){
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


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

int main () {
    int n;
    string card_taro, card_hanako;

    int p_taro = 0, p_hanako = 0;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> card_taro >> card_hanako;
        if ( card_taro > card_hanako ) {
            p_taro += 3;
        } else if ( card_taro < card_hanako ) {
            p_hanako += 3;
        } else if ( card_taro == card_hanako ) {
            p_taro++;
            p_hanako++;
        }
    }
    cout << p_taro << " " << p_hanako << endl;

    return 0;
}

Measured memory_bytes: 3140
# import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
# import math
mod = 10**9 + 7

# n = int(input())
# a = list(map(int, input().split()))
def fac(n):
    a = n
    t = 1
    while a > 0:
        t *= a
        t %= mod
        a -= 1
    return t


def C(n,r):
    return (fac(n) * pow(fac(r),mod-2,mod) * pow(fac(n-r),mod-2,mod) )%mod

x,y = map(int,input().split())

ans = 0

if (x+y)%3==0 and max(x,y)-min(x,y)<=min(x,y):
    diff = max(x,y)-min(x,y)
    total = (x+y)//3
    ans = C(total,(total-diff)//2)

print(ans)

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

int main()
{

    int N;
    cin >> N;

    vector<int> a(N);

    for (int i = 0; i < N; i++)
    {
        cin >> a.at(i);
    }

    vector<bool> b(N);
    b.at(0) = true;

    int ans = 0;
    int next_light = a.at(0) - 1;
    while (true)
    {
        ans++;
        if (next_light == 1)
        {
            break;
        }
        next_light = a.at(next_light) - 1;
        if (b.at(next_light))
        {
            ans = -1;
            break;
        }
        b.at(next_light) = true;
    }

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

Measured memory_bytes: 3784
N,K=map(int,input().split())
if K>((N-1)*(N-2))//2:
    print(-1)
else:
    edge=[]
    for i in range(2,N+1):
        edge.append([1,i])
    addedge=((N-1)*(N-2))//2-K
    for i in range(2,N):
        for j in range(i+1,N+1):
            if addedge!=0:
                edge.append([i,j])
                addedge-=1
            else:
                break

    print(len(edge))
    for i in range(0,len(edge)):
        print(*edge[i])

Measured memory_bytes: 43504
# N = int(input())
# A = [int(x) for x in input().split()]
# from collections import defaultdict
# dd = defaultdict(lambda: 0)

N = int(input())

S = []
bStart = 0
aEnd = 0
ba = 0
abSum = 0
for i in range(N):
    s = input()
    abSum += s.count('AB')

    if s[0] == 'B' and s[-1] == 'A':
        ba += 1
    elif s[0] == 'B':
        bStart += 1
    elif s[-1] == 'A':
        aEnd += 1

ret = 0

if ba > 0:
    ba -= 1
    if aEnd > 0:
        ba += 1
        aEnd -= 1
    if bStart > 0:
        ba += 1
        bStart -= 1

print(abSum + ba + min(bStart, aEnd))


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

using namespace std;

int n,m;
vector<string> v[100010];

int main() {
    cin >> n >> m;

    for (int i = 0; i < m; ++i) {
        int x;
        string s;
        cin >> x >> s;
        if(s == "AC") {
            if((int)v[x].size() and v[x].back() == "AC") {}
            else v[x].push_back(s);
        } else {
            if((int)v[x].size() and v[x].back() == "AC") {}
            else v[x].push_back(s);
        }
    }

    int a = 0, b = 0;
    for (int i = 1; i <= n; ++i) {
        if((int)v[i].size() != 0 and v[i].back() == "AC") {
            a++;
            b += v[i].size() - 1;
        }
    }
    cout << a << " " << b << "\n";
    return 0;
}


Measured memory_bytes: 10368
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	long long n, i, j, k, MOD = 1000000007, x, ans;
	cin >> n;
	map<int, int> ct;
	for (i = 0; i < n; i++) {
		cin >> x;
		ct[x] ++;
	}

	vector<long long> f(n + 1);
	f[0] = 1;
	for (i = 1; i <= n; i++) f[i] = (f[i - 1] * i) % MOD;

	bool valid = true;
	if (n % 2 == 0) {
		for (i = 1; i <= n; i += 2) {
			if (ct[i] != 2) valid = false;
		}
	}
	else {
		if (ct[0] != 1) valid = false;
		for (i = 2; i < n; i += 2) {
			if (ct[i] != 2) valid = false;
		}
	}

	ans = 1;
	for (auto p : ct) {
		ans = (ans * f[p.second]) % MOD;
	}

	if (!valid) ans = 0;
	cout << ans << "\n";

	return 0;
}



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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF 1e15

#define MAX_N 1000

int r,c;
int n;
vector<P> G[222222];
bool vis[222222];
ll w[222222];
ll rmin, cmin;

void dfs(int v,ll h){
	vis[v]=true;
	w[v]=h;
	rep(i,G[v].size()){
		int nv=G[v][i].fi,cost=G[v][i].se;
		if(!vis[nv]){
			dfs(nv,cost-h);
		}
	}
}

bool check(int v){
	vis[v]=true;
	if(v<r) minch(rmin,w[v]);
	else minch(cmin,w[v]);
	rep(i,G[v].size()){
		int nv=G[v][i].fi,cost=G[v][i].se;
		if(w[v]+w[nv]!=cost)return false;
	}
	rep(i,G[v].size()){
		int nv=G[v][i].fi;
		if(!vis[nv]){
			if(!check(nv))return false;
		}
	}
	return true;
}

int main(){
	cin.sync_with_stdio(false);
	cin>>r>>c;
	cin>>n;
	rep(i,n){
		int rr,cc,a;
		cin>>rr>>cc>>a;
		rr--; cc--;
		G[rr].pb(P(r+cc,a)); G[r+cc].pb(P(rr,a));
	}
	rep(i,r+c){
		vis[i]=false;
	}
	rep(i,r+c){
		if(!vis[i])dfs(i,0);
	}
	bool res=true;
	rep(i,r+c){
		vis[i]=false;
	}
	rep(i,r+c){
		if(!vis[i]){
			rmin=INF,cmin=INF;
			if(!check(i))res=false;
			if(rmin+cmin<0)res=false;
		}
	}
	if(res)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


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

#define int long long int
#define mp make_pair
using namespace std;

int32_t main() {
    int n,a,b;
    scanf("%lld", &n);
    scanf("%lld", &a);
    scanf("%lld", &b);
    int mini = min(a,b);
    int maxi = max(a,b);
    int ans1 = mini;
    if(maxi - (n-mini) <= 0){
        printf("%lld 0",ans1);
        return 0;
    }
    printf("%lld %lld",ans1,maxi - (n-mini));
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	cin >> a;
	cin >> b;
	cin >> c;
	int ab,bc,ca;
	ab=(a-b==0 ? 0 : 1);
	bc=(b-c==0 ? 0 : 1);
	ca=(c-a==0 ? 0 : 1);
	if(ab+bc+ca==0||ab+bc+ca==3){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
	return 0;
}





Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

typedef long long ll;
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define rerepi(i, a, b) for(int i = int(a)-1; i >= b; --i)
#define rerep(i, n) rerepi(i, n, 0)

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; }
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) {o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

// 降順ソート
// std::sort(data.begin(),data.end(),std::greater<int>());
// 昇順ソート
// std::sort(data.begin(),data.end());

const long long INF = 1LL << 60;

// ここから開始だよ！
ll X;

int main() {
	// 呪文エリア
	cin.tie(0);
	ios::sync_with_stdio(false);
	// 詠唱完了

	cin >> X;
	if (X == 7 || X == 5 || X == 3) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<functional>
using namespace std;
#define ll long long int
#define ld long double
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,
tree_order_statistics_node_update> in_set;
#define rep(n) for(ll i=0;i<(n);i++)
#define jrep(n) for(ll j=0;j<(n);j++)
#define krep(n) for(ll ki=0;ki<(n);ki++)
#define all(a) (a).begin(), (a).end()
#define dpp(a) cout<<(a).first<<" "<<(a).second<<endl;
#define append push_back
#define mod 1000000007
#define ff first
#define ss second
#define ffast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fast ios::sync_with_stdio(0);
ll pw(ll x,ll y,ll p=mod){ll r=1; x=x%p;while(y>0){ if(y&1)r=(r*x)%p;
y=y>>1;x=(x*x)%p;} return r; } vector<ll> uniq(vector<ll> arr)
{vector<ll>brr;sort(all(arr));brr.append(arr[0]);
for(auto i:arr)if(brr.back()!=i)brr.append(i);return brr;}
 


vector<vector<ll>> arr;  ll h,w,k;
vector<ll> bin(ll a){
    vector<ll> ret(h-1);
    rep(h-1){ if(a&((ll)1<<i)) ret[i]=1; else ret[i]=0; }
    return ret;
}
void solve(){
    ll mc=mod; cin>>h>>w>>k;  arr.resize(h);
    rep(h){ arr[i].resize(w,0); string s; cin>>s; jrep(w){ if(s[j]=='1') arr[i][j]=1; } }
    //rep(h){ jrep(w) cout<<arr[i][j]<<" "; cout<<endl; }
    vector<ll> vs(11,0);
    vector<ll> cuts;
    rep((ll)1<<(h-1)){
        cuts = bin(i);
        //cout<<"HERE  "<<cuts.size()<<endl;
        //for(auto ia:cuts){ cout<<"PRINTING "; cout<<ia<<" "; } cout<<endl;
        //jrep(cuts.size()){ cout<<"PRINTING "<<j<<" "; cout<<cuts[i]<<" "; } 
        //cout<<" DONE \n";
        //cout<<"HERE\n";
        ll tc=0;
        ll tot = 0;
        jrep(cuts.size()) tot+=cuts[j];
        jrep(tot+1) vs[j]=0;
        jrep(w){
            if(*max_element(all(vs))>k){ tc=mod; break; }
            ll ts=0; ll vi=0;
            krep(h){
                vs[vi]+=arr[ki][j]; if(ki+1<h&&cuts[ki]==1) vi++;
            }
            if(*max_element(all(vs))>k){
                tc++; vi=0; vs[vi]=0;
                krep(h){
                    vs[vi]+=arr[ki][j]; if(ki+1<h&&cuts[ki]==1){ vi++; vs[vi]=0; }
                }
            }
        }
        ll ctot = tc + accumulate(all(cuts),(ll)0);
        if(ctot<mc) mc=ctot;
    }
    cout<<mc<<endl;
}
 
int main(){
    ffast
    ll t=1;
    //cin>>t;
    rep(t) solve();
}
 
 
// *p.find_by_order(n) : nth value (0 indexed)
// p.order_of_key(7): index of 7 (0 indexed)


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

#define in freopen("input.txt", "r" ,stdin)
#define out freopen("fenceplan.out", "w" ,stdout)
#define ll long long
#define pb push_back
#define fr first
#define sc second
const int mod = 1e9+7;
using namespace std;
ll n;
ll a[200005];
int main (){
    //in;
    //out;
    //ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
    }

    ll cnt = 0;
    ll x = 1;
    for (int i = 1; i  <= n; i++) {
        if (a[i] != x) cnt++;
        else x++;
    }
    if (x == 1) cout << -1;
    else cout << cnt;
}


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

using namespace std;

using ll = long long;

int main(){
    string s;
    cin >> s;
    if(s[0] != 'A'){
        cout << "WA";
        return 0;
    }
    ll cnt = 0;
    for(ll i = 2; i < s.length() - 1; ++i){
        if(s[i] == 'C'){
            cnt++;
        }
    }
    if(cnt != 1){
        cout << "WA";
        return 0;
    }
    ll upper = 0;
    for(ll i = 0; i < s.length(); ++i){
        if(s[i] >= 'A' && s[i] <= 'Z') upper++;
    }
    if(upper != 2){
        cout << "WA";
        return 0;
    }
    cout << "AC";
    return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

//-----------------------------------------------------------------------------

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

	int ans;
	cin>>ans;
	while(true) {
		char ch;
		cin>>ch;
		if(ch=='=') break;
		int n;
		cin>>n;
		if(ch=='+') ans+=n;
		else if(ch=='-') ans-=n;
		else if(ch=='*') ans*=n;
		else ans/=n;
	}
	cout<<ans<<endl;

	return 0;
}



Measured memory_bytes: 3092
arr=Array.new(10){Array.new(10,0)}
while gets
    x,y,s=$_.chomp.split(',').map(&:to_i)
    if s>=1
        arr[y][x]+=1
        arr[y][x+1]+=1 if x+1<10
        arr[y][x-1]+=1 if x-1>=0
        arr[y+1][x]+=1 if y+1<10
        arr[y-1][x]+=1 if y-1>=0
    end
    if s>1
        arr[y-1][x-1]+=1 if y-1>=0 && x-1>=0
        arr[y-1][x+1]+=1 if y-1>=0 && x+1<10
        arr[y+1][x-1]+=1 if y+1<10 && x-1>=0
        arr[y+1][x+1]+=1 if y+1<10 && x+1<10
    end
    if s>2
        arr[y-2][x]+=1 if y-2>=0
        arr[y+2][x]+=1 if y+2<10
        arr[y][x-2]+=1 if x-2>=0
        arr[y][x+2]+=1 if x+2<10
    end
end
arr.flatten!.sort!
p arr.find_all{|item|item==0}.size
p arr[-1]

Measured memory_bytes: 6140
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

int solve(int n, vector< vector< pair<int,int> > > &G){
  vector<bool> connected(n,false);
  priority_queue< pair<int,int> > wait;
  vector<int> costs;
  wait.emplace(0,0);
  while(!wait.empty()){
    int c = -wait.top().first, v = wait.top().second;
    wait.pop();
    if(connected[v]) continue;
    connected[v] = true;
    costs.push_back(c);
    for(int i = 0; i < G[v].size(); ++i){
      int v_ = G[v][i].first, c_ = G[v][i].second;
      if(!connected[v_]){
        wait.emplace(-c_,v_);
      }
    }
  }
  sort(costs.begin(),costs.end());
  return costs[n/2];
}

int main(){
  int n, m;
  while(cin >> n >> m, n){
    vector< vector< pair<int,int> > > G(n);
    int s, t, c;
    for(int i = 0; i < m; ++i){
      cin >> s >> t >> c;
      --s;--t;
      G[s].emplace_back(t,c);
      G[t].emplace_back(s,c);
    }

    cout << solve(n,G) << endl;
  }
  return 0;
}

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


int main()
{
	int  n,k;
	cin>>n>>k;
	int wt[n+1],v[n+1];
	long long dp[n+2][k+2];
	for( int i=1;i<=n;i++)
		cin>>wt[i]>>v[i];
	//cout<<"P";
	for(int i=0;i<=n;i++)
	{
		for( int w=0;w<=k;w++)
		{
			if(i==0 || w==0)
			{
				dp[i][w]=0;
			}
			else if(w>=wt[i])
			{
				dp[i][w]=max(dp[i-1][w-wt[i]]+v[i],dp[i-1][w]);
			}
			else
				dp[i][w]=dp[i-1][w];
		}
	}
	cout<<dp[n][k]<<endl;
}

Measured memory_bytes: 82436
#include <iostream>
#include <algorithm>
#include<vector>
#include <queue>
using namespace std;
int main()
{
	int n, d, x, a;
     cin >> n >> d >> x; 
	 int ans = 0;
	 for (int i = 1; i <= n; i++) {
		 cin >> a;
		 ans += (d-1)/a+1;
	 }
	 cout << ans +x<< endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>
#include<complex>

using namespace std;

typedef long long            ll;
typedef unsigned             ui;
typedef unsigned long long   ull;
typedef pair<int,int>        i_i;
typedef pair<ll,int>         ll_i;
typedef pair<ll,ll>          ll_ll;
typedef pair<double,int>     d_i;
typedef pair<double,double>  d_d;
typedef vector<int>          vi;
typedef vector<vector<int> > vii;

#ifdef DEBUG
#define dprintf      printf
#define dputs        puts
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)  {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dputs        (1)?0:puts
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(int i=0){}else
#define drep(i,n)    if(int i=0){}else
#define dstop()
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__)
#define array(T,id,n) T id[(n)]; for(int i=0;i<(n);i++)cin>>id[i]
#define putv(n)     cout<<(n)<<endl

//#define int long long
#ifndef int
#define INF __INT32_MAX__
#else
#define INF __INT64_MAX__
#endif

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

signed main(void)
{
  in(int,n);
  int i;
  rep(i,n){
    in(char,s);
    if(s=='Y'){
      puts("Four");
      return 0;
    }
  }
  puts("Three");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b;
    
    cin >> a >> b;
    int coin = 0;
    
    for(int i = 0; i < 2; ++i){
        
        if (a <= b){
            coin+=b;
            --b;
        }else{
            coin+=a;
            --a;
        }
    }
    
    printf("%d", coin);
    
    
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int N = 305;
const int inf = 1e9 + 9;
int n;
int graph[N][N];
vector < pair < int , pair < int , int > > > v;
unsigned dp[N][N];
long long ans;
int main(){
	scanf("%d" , &n);
	for(int i = 1 ; i <= n ; ++i){
		for(int j = 1 ; j <= n ; ++j){
			scanf("%d" , &graph[i][j]);
			if(j > i){
				v.push_back({graph[i][j] , {i , j}});
			}
			dp[i][j] = inf;
		}
		dp[i][i] = 0;
	}
	sort(v.begin() , v.end());
	for(auto it : v){
		int a = it.second.first;
		int b = it.second.second;
		int c = it.first;
		int val = inf;
		for(int i = 1 ; i <= n ; ++i){
			if(i == a || i == b){
				continue;
			}
			val = min(val , graph[a][i] + graph[i][b]);
		}
		if(val < c){
			printf("-1\n");
			return 0;
		}
		if(val == c){
			continue;
		}
		ans += c;
	}
	printf("%lld\n" , ans);
}

Measured memory_bytes: 1656
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()
p = list(map(int, input().split()))

if x not in p:
    print(x)
    exit()

s = 1
while True:
    if x - s not in p :
        print(x-s)
        exit()
    elif x + s not in p:
        print(x+s)
        exit()
    else:
        s += 1

Measured memory_bytes: 9196
#include<stdio.h>
main(){
	int W,H,x,y,r;
	int left,right,top,bottom;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

	left = x - r;
	right = x + r;
	top = y + r;
	bottom = y - r;

	if(left >= 0 && right <= W && top <= H && bottom >= 0){
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1012
#include <stdio.h>
#include <list>
#include <set>

using namespace std;

typedef struct {
  int *ks;
  int length;
} node;

node *nodes;


int dikstra(int s, int e, int deep){
  int c=0;

  list<int> que;
  set<int> done;
  set<int> done2;
  que.push_back(s);
  done.insert(s);

  while(1){
    c++;
    if(c >= deep) return -1;

    done2.clear();

    int len = que.size();
    for(int i=0;i<len;i++){

      int v = que.front();
      que.pop_front();

      for(int j=0;j<nodes[v].length;j++){
        if(nodes[v].ks[j]==e){
          return c+1;
        }else{
          int k = nodes[v].ks[j];
          if(done.find(k) == done.end()){
            que.push_back(k);
            done2.insert(k);
          }
        }
      }
    }
    done.insert(done2.begin(), done2.end());
  }
}

int main(){
  int n;
  scanf("%d", &n);

  nodes = new node[n];

  int i,j;
  int t,u,v;
  for(i=0;i<n;i++){
    scanf("%d%d", &t,&u);
    nodes[t-1].ks = new int[u];
    nodes[t-1].length = u;
    for(j=0;j<u;j++){
      scanf("%d", &v);
      nodes[t-1].ks[j] = v-1;
    }
  }

  int m;
  scanf("%d", &m);
  for(i=0;i<m;i++){
    scanf("%d%d%d", &t, &u, &v);
    int r;
    if((r=dikstra(t-1, u-1,v)) != -1) printf("%d\n", r);
    else puts("NA");
  }
}
    

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main(){
	int n,m;
	int a[101][101];
	int i,j;
	int b[101];
	int ans=0;
	cin>>n>>m;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cin>>a[i][j];
		}
	}
	for(i=0;i<m;i++){
		cin>>b[i];
	}
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			ans+=a[i][j]*b[j];
		}
		cout<<ans<<endl;
		ans=0;
	}
	return 0;
}

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

using namespace std;

#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int N, X;
int x[100000];

int gcd(int x, int y) {
	return y == 0 ? x : gcd(y, x % y);
}

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

    cin >> N >> X;
    rep(i, N) {
        cin >> x[i];
        x[i] = abs(X - x[i]);
    }
    int res = x[0];
    rep(i, N - 1) {
        res = gcd(res, x[i + 1]);
    } 
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    d = {}
    for a in A:
        for i in [-1, 0, 1]:
            if not a+i in d:
                d[a+i] = 1
            else:
                d[a+i] += 1
    print(max(d.values()))

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 62124
n , yen = [int(i) for i in input().split()]

x, y, z = 0, 0, 0
ans = False
for i in range(n+1):
    for j in range(n+1):
        tmp = i*10000 + j*5000 + (n-i-j)*1000
        if(yen == tmp and (n-i-j) >= 0):
            print("{} {} {}".format(i, j, (n-i-j)))
            ans = True
            break
    if(ans):
        break
        
if(not ans):
    print("-1 -1 -1")

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

signed main(){
	int a,b;
	cin>>a>>b;
	int k;
	cin>>k;
	r(i,k){
		if(i%2==0){
		if(a%2){
			a--;
		}
		b+=a/2;
		a/=2;}
		else{
		if(b%2){
			b--;
		}
			a+=b/2;
			b/=2;
		}
	}
	cout<<a<<' '<<b<<endl;
}

Measured memory_bytes: 256
from collections import Counter

n = int(raw_input())
li = list()
for i in range(0,n):
    li.append(raw_input())
count = Counter(li)
m = int(raw_input())
for i in range(0,m):
    s = raw_input()
    if count[s] != 0:
        count[s] -= 1
print count.most_common(1)[0][1]

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





int main() {
  string s,t;
  cin>>s>>t;
  
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  
  if (s<t){
    cout<<"Yes"<<endl;
  }
  
  else {
    cout<<"No"<<endl;
  }
  
    
      
  
}

  













Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int min, max, a, b, c, h;

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

    min = a;
    max = a;
    
    if(min>b){
        min = b;
        if(min>c){
            max = a;
            h = b;
            min = c;
            }
        else if(max<c){
            max = c;
            h = a;
            min = b;
        }
        else{
            max = a;
            h = c;
            min = b;
        }
    }
    else if(max<b){
        max = b;
        if(max<c){
            max = c;
            h = b;
            min = a;
            }
        else if(min<c){
            max = b;
            h = c;
            min = a;
        }
        else{
            max = b;
            h = a;
            min = c;
        }
    }
    
    printf("%d %d %d\n", min, h, max);
    
    return 0;
}


Measured memory_bytes: 2052
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int p[202020];
int main()
{
	int n,x,ans=0,now=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		p[x]=i;
	}
	now=1;
	for(int i=2;i<=n;i++)
	{
		if(p[i]>p[i-1])
			now++;
		else
		{
			ans=max(now,ans);
			now=1;
		}
	}
	ans=max(now,ans);
	printf("%d\n",n-ans);
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#define B 4
#define F 3
#define R 10

int main(void){
	
	int A[B][F][R], i, j, k, n, b, f, r, v;
	
	for(i = 0; i < B; i++){
		for(j = 0; j < F; j++){
			for(k = 0; k < R; k++){
				A[i][j][k] = 0;
			}
		}
	}
	
	scanf("%d", &n);
	
	for(i = 0; i < n; i++){
		scanf("%d %d %d %d", &b, &f, &r, &v);
		A[b - 1][f - 1][r - 1] += v;
	}

	for(i = 0; i < B; i++){
		for(j = 0; j < F; j++){
			for(k = 0; k < R; k++){
				printf(" %d", A[i][j][k]);
			}
			printf("\n");
		}
		if(i != B - 1){
			printf("####################\n");
		}
	}

	return 0;
}

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

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

const int N = 110;
int dist[N][N];

int main(void){
  int n, m;
  cin >> n >> m;
  const int inf = 1e8;
  REP(i, 0, N) {
    REP(j, 0, N) {
      dist[i][j] = inf;
    }
    dist[i][i] = 0;
  }
  int cnt = 0;
  typedef pair<int, PI> PIII;
  vector<PIII> edges;
  REP(i, 0, m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    edges.push_back(PIII(c, PI(a, b)));
  }
  sort(edges.begin(), edges.end());
  REP(i, 0, m) {
    // update
    PIII t = edges[i];
    int a = t.second.first;
    int b = t.second.second;
    int c = t.first;
    if (dist[a][b] < c) {
      cnt++;
    } else {
      dist[a][b] = c;
      dist[b][a] = c;
      REP(j, 0, n) {
	REP(k, 0, n) {
	  dist[j][k] = min(dist[j][k], dist[j][a] + dist[a][k]);
	}
      }
      REP(j, 0, n) {
	REP(k, 0, n) {
	  dist[j][k] = min(dist[j][k], dist[j][b] + dist[b][k]);
	}
      }
    }
    if (0) {
      cerr << "dist:" << endl;
      REP(j, 0, n) {
	cerr << "[" << j << "]";
	REP(k, 0, n) {
	  cerr << " " << dist[j][k];
	}
	cerr << endl;
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,m,q,val[20],res;
struct quar{
	int a,b,c,d;
	void read(){
		scanf("%d%d%d%d",&a,&b,&c,&d);
	}
}p[100];
void dfs(int pos,int lim){
	if(pos>n){
		int tot=0;
		for(int i=1;i<=q;i++)if(val[p[i].b]-val[p[i].a]==p[i].c)tot+=p[i].d;
		res=max(res,tot);
		return;
	}
	for(int i=lim;i<=m;i++)val[pos]=i,dfs(pos+1,i);
}
int main(){
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=q;i++)p[i].read();
	dfs(1,1);
	printf("%d\n",res);
	return 0;
}

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

int GCD(int a, int b) {
    while (b != 0) {
        int t = a % b;
        a = b;
        b = t;
    }
    return a;
}

int main() {
    int n, x, t, res;
    cin >> n >> x >> t;
    res = abs(t - x);
    for (int i = 1; i < n; i++) {
        cin >> x;
        res = GCD(res, abs(x - t));
        t = x;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

int dfs_visit(int u)
{
    int v;
    color[u] = GRAY;
    d[u] = ++tt;
    for (int v = 0; v < n; v++)
    {
        if (M[u][v] == 0)
        {
            continue;
        }
        if (color[v] == WHITE)
        {
            dfs_visit(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++tt;
}

int dfs()
{
    int u;
    for (int u = 0; u < n; u++)
    {
        color[u] = WHITE;
    }
    tt = 0;
    for (int u = 0; u < n; u++)
    {
        if (color[u] == WHITE)
        {
            dfs_visit(u);
        }
    }
    for (int u = 0; u < n; u++)
    {
        cout << u + 1 << " " << d[u] << " " << f[u] << endl;
    }
}

int main()
{
    int u, v, k, i, j;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            M[i][j] = 0;
        }
    }

    for (int i = 0; i < n; i++)
    {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++)
        {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    dfs();
    return 0;
}


Measured memory_bytes: 3140
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007

int main(){
	int n;
	scanf("%d", &n);
	int answer = (n-1)/2;
	
	printf("%d\n", answer);

	return 0;
}

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

using ll = long long;

ll solve(int N, int x, vector<int> costs)
{
    costs.insert(end(costs), begin(costs), end(costs));

    auto result = numeric_limits<ll>::max();

    auto shift_cost = 0LL;
    for (auto shifts = 0; shifts < N; shifts++, shift_cost += x)
    {
        auto options = multiset<int>();
        for (auto i = 0; i <= shifts; i++) options.insert(costs[i]);

        auto total_cost = shift_cost;
        for (auto i = shifts; i < shifts+N; i++)
        {
            total_cost += *begin(options);
            options.erase(options.find(costs[i-shifts]));
            options.insert(costs[i+1]);
        }

        result = min(result, total_cost);
    }

    return result;
}

int main()
{
    int N, x; cin >> N >> x;

    auto costs = vector<int>(N);
    for (auto& x : costs) cin >> x;

    cout << solve(N, x, costs) << endl;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007; 
    return res; } 
 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n,x;
        cin>>n;
        ll A[n],B[n]={0},C[n]={0};
        for(ll i=0;i<n;i++)
        {
            cin>>A[i];
        }
        if(n%2==0)
        x=n/2;
        else
        x=n/2+1;
        for(ll i=0;i<x;i++)
        {
            cout<<A[n-1-i*2]<<" ";
        }
        for(ll i=0;i<n/2;i++)
        {
            if(n%2!=0)
            {
                cout<<A[i*2+1]<<" ";
            }
            else
            {
                cout<<A[i*2]<<" ";
            }
        }
        return 0;
    }    
}


Measured memory_bytes: 8204
n,k,q = map(int,input().split())
A = [int(input()) for i in range(q)]
Point = [0 for i in range(n)]
for i in range(q):
    Point[A[i]-1] += 1
for i in range(n):
    if k-q+Point[i]>0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 8640
n, l = map(int, input().split())

taste = 0

# 味が0のりんごがある場合
if l <= 0 and 0 < n + l:
  for i in range(n):
    taste += l + i
# すべて負値の場合
elif l <= 0:
  for i in range(n -1):
    taste += l + i
# すべて正値の場合
else:
  for i in range(1, n):
    taste += l + i

print(taste)

Measured memory_bytes: 39728
#include<bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define ff first
#define ss second
#define vll vector<ll>
#define FOR(i,l,r) for(int i = l; i < r; ++i)
#define MAX 800000
using namespace std;

void solve(){
	string s;
	cin>>s;
	if (s[0] == 'R' and s[1] == 'R' and s[2] == 'R')
	{
		cout<<3;
	}
	else if ((s[0] == 'R' and s[1] == 'R' and s[2] == 'S') or (s[0] == 'S' and s[1] == 'R' and s[2] == 'R'))
	{
		cout<<2;
	}
	else if ((s[0] == 'R' and s[1] == 'S' and s[2] == 'R') or (s[0] == 'R' and s[1] == 'S' and s[2] == 'S') or (s[0] == 'S' and s[1] == 'S' and s[2] == 'R') or (s[0] == 'S' and s[1] == 'R' and s[2] == 'S'))
	{
		cout<<1;
	}
	else{
		cout<<0;
	}
}
  
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	cerr<<"Timpe elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " mps\n" ;
	return 0;
}

Measured memory_bytes: 3760
#include <iostream>
#include<set>
#include<vector>
#include<string>
#include<iterator>
#include<iomanip>
#include<cmath>
#include<map>
#include<string.h>
#include<algorithm>

using namespace std;
void ll(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(0);
}

int main() {

	ll();
	int a, b;
	cin >> a >> b;
	int r, c;
	cout << (a - 1)*(b - 1) << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int n, a, b;
      cin >> n >>a >> b;
      
      if( a*n > b){
        cout << b << endl;
      }
      
      else {
        cout << a*n << endl;
      }
      // ここにプログラムを追記
    }

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args)
	{
		Scanner sc =new Scanner(System.in);
		int n=sc.nextInt();	//個数
		int k=sc.nextInt();	//ペンキの種類

		int num=k;	//塗り方の個数

		for(int i=0;i<n-1;i++) num*=(k-1);

		//答えを出力
		System.out.println(num);
	}
} 

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
using namespace std;
int main(){
    int a[10];
    for(int i = 0; i < 5; i++) cin >> a[i];
    int min = 200;
    int t = 0;
    int total = 0;
    for(int i = 0; i < 5; i++){
        if(a[i]%10 < min && a[i]%10 != 0){
            min = a[i]%10;
            t = a[i];
        }

        if(a[i]%10 == 0) total += a[i];
        else total += (a[i]/10 + 1)*10;
    }

    if(t%10 != 0) cout << total + t -(t/10 + 1)*10 << endl;
    else cout << total << endl;
}

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repd(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define forr(i,a,b) for(ll i=(a);i<=(b);i++)
#define ford(i,a,b) for(ll i=(a);i>=(b);i--)
#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 INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)



int main(void) {
    long int N,i,j;
    cin >> N;
    long int n[201000];
    long int m[201000];
    for(i=0;i<N-1;++i){
       cin >> n[i];
      
    }
     for(i=0;i<N-1;++i){
     
       m[n[i]-1]++;
    }
    for (j=0;j<N;++j){
        
         cout << m[j] << "\n";
    

    }   
    
  return 0;
}

Measured memory_bytes: 6772
r,c = gets.chomp.split(" ").map &:to_i

rows = Array.new()
r.times {
    data = gets.chomp.split(" ").map &:to_i
    data << data.inject(:+)
    rows << data
}

total = Array.new(c+1, 0)

rows.each { |rw|
    rw.length.times { |i|
        total[i] += rw[i]
        print " " if i != 0
        print "#{rw[i]}"
    }
    puts
}

total.length.times { |i|
    print " " if i != 0
    print "#{total[i]}"
}
puts

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

int main(){
    int n;
    cin >> n;
    long long ans = 0;
    for(int i = 1; i <= n; i++){
        long long y = n/i;
        ans += y*(y+1)/2 * i;
    }
    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 3504
N = int(input())
A = sorted([int(n) for n in input().split()], reverse=True)
M = 10**18
ans = A[0]
for i in range(1, len(A)):
    if A[-1] == 0:
        ans = 0
        break
    ans *= A[i]
    if M < ans:
        ans = -1
        break 
print(ans)


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

using namespace std;

int main(){
	int ans=0;
	string w,t;
	cin>>w;
	for(int i=0;i<w.size();i++) if('A'<=w[i]&&w[i]<='Z') w[i]-=('A'-'a');
	while(1){
		cin>>t;
		if(t=="END_OF_TEXT") break;
		for(int i=0;i<t.size();i++) if('A'<=t[i]&&t[i]<='Z') t[i]-=('A'-'a');
		if(w==t) ans++;
	}
	cout<<ans<<endl;;
	return 0;
}



Measured memory_bytes: 3144