akhauriyash/Code-Regression huggingface dataset:
///              B I S M I L L A H I R  R A H M A N I R  R A H I M

#include<bits/stdc++.h>
using namespace std;
typedef bool                   boo;
typedef int                    li;
typedef long                   il;
typedef unsigned long          ul;
typedef long long int          ll;
typedef unsigned long long     ull;
typedef double                 dd;
typedef string                 str;
#define vli                    vector<li>
#define vll                    vector<ll>
#define sli                    set<li>
#define sll                    set<ll>
#define pli                    pair<li>
#define pll                    pair<ll>
#define vpi                    vector<pair<li, li>>
#define vpl                    vector<pair<ll, ll>>
#define mpl                    map<ll, ll>
#define wt                     ll t; cin>>t; while(t--)
#define input(a,n)             for(int i=0;i<n;i++) cin>>a[i];
#define lp(a, i, b)            for(ll i=a; i<b; i++)
#define rlp(a, i, b)           for(ll i=a; i>=b; i--)
#define sz(x)                  x.size()
#define len(z)                 z.begin(), z.end()
#define co(x)                  cout<<x nl
#define mem(z, l)              memset(z, l, sizeof(z))
#define MP                     make_pair
#define pb                     push_back
#define F                      first
#define S                      second
#define nl                     <<endl
#define nll                    cout<<endl
#define sp                     <<" "<<
#define sl                     <<" "
#define cy                     cout<<"YES"
#define cn                     cout<<"NO"
#define rn                     return
#define good_bye               return 0
#define PI                     3.1415926536
#define gcd(a,b)               __gcd(a,b)
#define lcm(a,b)               (a*(b/gcd(a,b)))
#define faster                 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define input_txt()            freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
const double eps=              1e-9;
const int inf=                 2000000000;
const ll infLL=                9000000000000000000;
//ll Pow(ll P, ll Q)           { ll R=1; for(ll I=1; I<=Q; I++) R*=P; rn R; }
//void dfs(ll K)               { vis[K]=true; for(auto J: v[K]) { if(!vis[J]) dfs(J); } }
//void seive(ll MX)            { S.pb(2); for(ll I=3; i<=MX; i+=2) { if(!vis[I]) { S.pb(I); for(ll J=I*I; j<=MX; J+=(2*I)) vis[J]=false; } } }
//bool isPrime(ll n)           { if(n%2==0) rn false; for(ll i=3; i*i<=n; i+=2) { if(n%i==0) rn false; } rn true; }
//----------------------------------------LET'S BEGIN-----------------------------------------------------------------------
const int mX = 2e5+123;
ll n, k, a[mX], dp[mX];

ll soln(ll m)
{

    if(dp[m]!=-1) rn dp[m]; if(m==n) rn 0;
    ll s = inf;
    for(ll i=1; i<=k; i++) if(m+i<=n) s = min(s, abs(a[m] - a[m+i]) + soln(m+i));
    rn dp[m] = s;
}

void case_i()
{
    cin>>n>>k;
    lp(1, i, n+1) cin>>a[i];
    mem(dp, -1);
    cout<<soln(1) nl;
}

int main()
{
    faster;
//    input_txt();
//    wt
      case_i();
    good_bye;
}
///           _5_4_8_8_1_9_                ///



Measured memory_bytes: 12140
/* AUTHOR :  SHIVANK JAIN */

#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false)
#define itt cin.tie(0)
#define now cout.tie(0)

using namespace std;

#define ll long long
#define li long int

#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)
#define reprev(i,n,a) for(int i=n;i>=a;i--)
#define endl "\n"

#define vi vector<int>
#define vll vector<ll>
#define vpi vector< pair<int , int> >
#define mapi map<int , int>
#define mapll map<ll ,ll >
#define seti set<int> 

#define fr first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mp make_pair
#define sort(v) sort(v.begin() , v.end())

#define BIG 1000000007
int gcd(int a, int b) 
{ // builtin function __gcd(a,b)
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
int main(){

     fast;itt;now;
 
     ll n ;  cin>>n;
     string s;  cin>>s;
     ll r(0) , g(0) , b(0);
     rep(i,0,n){
     	if(s[i] == 'R')
     	++r;
     	if(s[i] == 'B')
     	++b;
     	if(s[i] == 'G')
     	++g;
	 }
	 
	 ll ans = r*g*b;
	 
	 rep(i,0,n){
	 	rep(j,i+1,n){
	 		int k = 2*j - i;
	 		
	 		if(k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i])
	 		 --ans;
		 }
	 }
	 cout<<ans<<endl;
}

	 

Measured memory_bytes: 3640
H, W = map(int,input().split())
S = [list(input()) for _ in range(H)]



for h in range(H):
  for w in range(W):

    if S[h][w] == ".":
      cnt = 0

      for h1 in range(max(0,h-1),min(H,h+2)):
        for w1 in range(max(0,w-1),min(W,w+2)):
          if S[h1][w1] =="#":
            cnt += 1
      S[h][w] = cnt
    
for h in range(H):
  print("".join(map(str,S[h])))

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

int main() {
	int n; cin >> n;
	vector<int> flag(101);

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

	int ans = 0;
	for (int i = 0; i < flag.size(); i++) {
		ans += flag[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
int main(){
    int N;
    string S;
    cin >> N;
    cin >> S;
    int ans = 0;
    for(int i=1; i<N; i++){
        int cnt = 0;
        for(char c = 'a'; c <= 'z'; c++){
            bool left=false, right=false;
            for(int j=0; j<i; j++){
                if(S[j] == c) left=true;
            }
            for(int j=i; j<N; j++){
                if(S[j] == c) right=true;
            }
            if(left&&right) cnt++;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

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


void solve(long long a, long long b){
    ll n = b-a;
    cout << n*(n+1)/2 - b << endl;
}

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	/*
	 * 問題文 整数  n  に対して， n  
	 * を十進法で表したときの各桁の和を  
	 * S ( n )  で表すことにします． 
	 * たとえば， S ( 101 ) = 1 + 0 + 1 = 2  です．  
	 * 整数Nが与えられたとき， N  が  S ( N )  
	 * で割り切れるかどうかを判定してください．
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int input = sc.nextInt();
		int temp = input;
		int digitSum = 0;
		while(temp != 0) {
			digitSum += temp%10;
			temp /= 10;
		}
		if(input%digitSum == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}

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

main(){
  
  ll n;
  cin>>n;
  vector<ll> a(n);
  for(auto& ai:a)cin>>ai;
  
  map<ll,ll> ecnt,ocnt;
  rep(i,n){
    if(i&1)ocnt[a[i]]++;
    else ecnt[a[i]]++;
  }
  vector<pair<ll,ll>> x,y;
  for(const auto& elm:ecnt)x.emplace_back(elm);
  for(const auto& elm:ocnt)y.emplace_back(elm);
  sort(x.begin(),x.end(), [&](auto a,auto b){return a.second > b.second;} );
  sort(y.begin(),y.end(), [&](auto a,auto b){return a.second > b.second;} );
  x.emplace_back(0,0);
  y.emplace_back(0,0);
  if(x[0].first==y[0].first){
    ll s=x[0].second+y[1].second;
    ll t=y[0].second+x[1].second;
    cout<<(n-max(s,t))<<endl;
  }
  else{
    cout<<(n-x[0].second-y[0].second)<<endl;
  }


}


Measured memory_bytes: 9592
#include<bits/stdc++.h>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 998244353;
const ll mod1 = 1e16 + 7;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
// freopen("in.txt", "r", stdin);
const int N = 2e5 + 5;
int t;
ll a[N], b[N],pa[N],pb[N];
int main()
{
	ll n, m,k,x;
	while (cin >> n >> m >> k)
	{
		f(i, 1, n)
		{
			scanf("%lld", &a[i]);
			pa[i] = pa[i-1] + a[i];
		}
		f(i, 1, m)
		{
			scanf("%lld", &b[i]);
			pb[i] = pb[i-1] + b[i];
		}
		int idx = upper_bound(pa + 1, pa + n + 1, k) - pa;
		idx--;
		ll ans = 0;
		f(i, 0, idx)
		{
			ll re = k - pa[i];
			//debug(re);
			int nowid = upper_bound(pb + 1, pb + 1 + m, re) - pb;
			//debug(nowid);
			nowid--;
			ans = max(ans, (ll)i + nowid);
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 10012
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, K = LI()
    A = LI()
    freq = collections.defaultdict(int)
    num = [0] * (N+1)
    for a in A:
        num[a] += 1
    num = sorted(num)[::-1]
    print(sum(num[K:]))

main()



Measured memory_bytes: 100680
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

ll calc_digit_sum(ll num) {
    ll sum = 0;
    while (num > 0) {
        sum += num % 10;
        num /= 10;
    }
    return sum;
}
int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    ll total = 0;
    REP(i, n + 1) {
        ll sum = calc_digit_sum(i);
        if (sum >= a && sum <= b) {
            total += i;
        }
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;
int a[200000];
int dif[200000];

int main()
{
	int n;
	int b;
	ll ans=0;
	
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		a[i]-=(i+1);
	}
	sort(a,a+n);
	b=a[n/2];
	for(int i=0;i<n;i++)
	{
		ans+=abs(a[i]-b);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
import math
N,M = list(map(int, input().split()))


def combinations_count(n, r):
    if n==1 or n==0:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

print(combinations_count(N,2)+combinations_count(M,2))

Measured memory_bytes: 3060
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x, a;
	cin >> x >> a;
	if (x < a)cout << 0 << endl;
	else cout << 10 << endl;
}

Measured memory_bytes: 256
N = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
cnt = 0
history = Array.new(N+2,0)
a.each do |n|
	if n>100000
		next
	end
	history[n] += 1
	if history[n] == n
		cnt += n
	end
end
p N-cnt

Measured memory_bytes: 10500
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if(s[1]=='R')
	{
		if(s[0]=='R'&&s[2]=='R')
			cout<<3;
		else if(s[0]=='R'||s[2]=='R')
			cout<<2;
		else
			cout<<1;
	}
	else
	{
		if(s[0]=='R'||s[2]=='R')
			cout<<1;
		else
			cout<<0;
	}
	return 0;
}

Measured memory_bytes: 3612
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FScanner sc = new FScanner();
		int r = sc.nextInt();
		System.out.println(r * r);
	}

}

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

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 22612
"""
分割統治法
総当たり

長さnの数列Aと整数mに対して、Aの中のいくつかの要素を足し合わせてmが作れるかどうか
n < 20
2^20 < 10^7なので、全部やる
"""

n = int(input())
As = list(map(int, input().split()))
q = int(input())
ms = list(map(int, input().split()))

import sys
sys.setrecursionlimit(100000)
# たかだか2000個なので、sum可能なデータの結果を全部持っておくと、再計算の必要がない
check_values = [False]*2016
flg = False
def dfs(i,sum):
    global flg
    if sum > 2000:
        return 0
    if i+1 == n:
        check_values[sum] = True
        return 0 
    for loop in [0,1]:
        dfs(i+1,sum+As[i+1]*loop)

dfs(-1,0)
for m in ms:
    flg = check_values[m]
    if flg:
        print("yes")
    else:
        print("no")


Measured memory_bytes: 5644
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



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

  int ans = 0;
  REP(i, s.size()){
    if(s[i]== '+') ++ans;
    else --ans;
  }

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


Measured memory_bytes: 3580
ans=0
for i in range(int(input())+1):
	if 0 < i < 10:
		ans+=1
	elif 100 <= i < 1000:
		ans+=1
	elif 10000 <= i < 100000:
		ans+=1
	elif 1000000 <= i < 10000000:
		ans+=1
print(ans)

Measured memory_bytes: 39024
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <cassert>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)
#define RRANGE(i, m, n) for(ll i = (m); i >= (n); --i)
#define POSITIVE(x) (x)=((x) < 0) ? 0 : (x)

ll power(ll x, ll y) {
    ll ret = 1;
    while(y-- > 0) ret *= x;
    return ret;
}

ll gcd(ll a, ll b) {
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll extgcd(ll a, ll b, ll& x, ll& y) {
    x = 1; y = 0;
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    ll X, Y;
    auto d = extgcd(b, a % b, X, Y);
    x = Y;
    y = X - (a / b) * Y;
    return d;
}

int run(istream& in, ostream& out) {
    ll A, B;
    in >> A >> B;
    ll ans = 0;

    bool found = false;
    RANGE(x, 1, 1100) {
        if(100* A <= 8*x && 8*x < 100*A + 100 && 100*B <= 10*x && 10*x < 100*B+100) {
            ans = x;
            found = true;
            break;
        }
    }
    if (!found) ans = -1;
    out << ans << endl;
    return 0;
}

int run2(istream& in, ostream& out) {
    ll N, M, R;
    in >> N >> M >> R;
    vector<ll> r{};
    REP(i, R) {
        ll x;
        in >> x;
        r.emplace_back(x);
    }
    vector<tuple<ll,ll,ll>> v{};
    REP(i, M) {
        ll a,b,c;
        in >> a >> b >> c;
        v.emplace_back(make_tuple(a,b,c));
    }

    ll ans = 0;

    // solution here

    out << ans << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 256
#include <stdio.h>

void trace(int A[], int N){
	int i;
	for (i = 0; i < N; i++){
		if (i > 0) printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
}


void insertionSort(int A[], int N){
	int j, i, v;
    for (i = 1; i < N; i++){
    	v = A[i];
    	j = i - 1;
    	while(j >= 0 && A[j] > v){
    		A[j+1] = A[j];
    		j--;
    	}
    	A[j+1] = v;
    	trace(A,N);
    }
}


int main(void){
    int A[100];
    int N, i, j;

    scanf("%d", &N);
    for (i=0; i < N; i++) scanf("%d", &A[i]);

    trace(A,N);
    insertionSort(A,N);

    return 0;
}

Measured memory_bytes: 604
#pragma GCC optimize("trapv")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
const int maxn = 3e5 + 33, mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define left dsafjalsjfsk
int n;
vi g[maxn], lst[2];
int  col[maxn];
void dfs(int v = 1, int p = 1, int h = 0) {
	lst[h&1].pb(v);
	for(auto i : g[v]) {
		if(i!=p) dfs(i, v, h^1);
	}
}
set<int> left;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int f, t, i = 1; i < n; i++) {
		cin >> f >> t;
		g[f].pb(t);
		g[t].pb(f);
	}
	for(int i = 1; i <= n; i++) left.insert(i);
	dfs();
	if(lst[0].size() > lst[1].size()) swap(lst[0], lst[1]);
	if(lst[0].size() <= n/3) {
		int k = 3;
		for(auto i : lst[0]) col[i] = k, left.erase(k), k+=3;
	} else {
		int k = 3;
		while(k <= n) {
			if(lst[0].size()>lst[1].size()) col[lst[0].back()] = k, lst[0].pop_back();
			else col[lst[1].back()] = k, lst[1].pop_back();
			left.erase(k), k += 3;
		}
		if(lst[0].size() > lst[1].size()) swap(lst[0], lst[1]);
		k = 2;
		while(k <= n) {
			col[lst[0].back()] = k;
			lst[0].pop_back();
			left.erase(k), k += 3;
		}
		k = 1;
		while(k <= n) {
			col[lst[1].back()] = k;
			lst[1].pop_back();
			left.erase(k), k += 3;
		}
	}
	for(int i = 1; i <= n; i++) {
		if(!col[i]) col[i] = *left.begin(), left.erase(left.begin());
		cout << col[i] << " " ;
	}
}



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

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

  string str = to_string(N);
  
  int size = str.size();
  for (int i = 0; i < size; i++) {
    char c = str[i];
    total += (('0' <= c && c <= '9') ? (c - '0') : -1);
  }
  
  cout << ((N % total == 0) ? "Yes" : "No") << endl;
}


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

ll mod = 1e9+7;
#define NMAX 200010
ll fac[NMAX];
ll inv[NMAX];

ll mod_pow(ll a, ll n, ll mod){
    ll ret = 1;
    while(n > 0){
        if(n & 1) ret = (ret*(a % mod))%mod;
        a = ((a%mod)*(a%mod)) % mod;
        n = n >> 1;
    }
    return ret;
}

ll mod_inv(ll a, ll mod){
    return mod_pow(a, mod-2, mod);
}

void mae_nck(){
    fac[1] = 1;
    inv[1] = 1;
    for(ll i = 2; i < NMAX; i++){
        fac[i] = (fac[i-1] * i)%mod;
        inv[i] = (inv[i-1] * mod_inv(i, mod))%mod;
    }
}

ll mod_nck(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    if(k == 0 || k == n) return 1;
    ll ret = ((fac[n] * inv[k])%mod * inv[n-k])%mod;
    return ret;
}

int main(){
    ll N, K;
    cin >> N >> K;
    cerr << "BP1" << endl;
    mae_nck();
    cerr << "BP2" << endl;
    ll ans = 0;
    rep(m, 0, N){
        if(m > K) break;
        ans += (mod_nck(N, m) * mod_nck(N-1, N-m-1)) % mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3328
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
using namespace std;
typedef long long LL;
stack<char> q;
int main(){
	string s,a;
	cin >> s;
	for(int i = 0;i < s.size();i++){
		if(s[i]=='B'){
			if(q.empty());
			else q.pop();
			}
		else q.push(s[i]);
		}
		while(!q.empty()){
			a += q.top();
			q.pop();
			}
		for(int i = a.size() - 1;i >= 0;i--) cout << a[i];
			cout << endl;
		return 0;
	}//

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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 (b<a) { a=b; return 1; } return 0; }

bool solve(LL &t, VLL a, LL &n, LL &m, LL &v, LL &p) {
    a[t] += m;
    LL rem = m * (v-1);
    REP(i,0,p-1) {
        a[n-1-i] += m;
        rem -= m;
    }

    REP(i,0,t) {
        rem -= m;
        a[i] += m;
    }
    //if (rem <= 0) return true;
    REP(i,t+1,n-p+1) {
        if (rem <= 0) {
            while (i < n && a[i] <= a[t]) ++i;
            return n - i + 1 <= p;
        }
        LL diff = max(0LL, min(rem, a[t] - a[i]));
        //dump(diff);
        rem -= diff;
        a[i] += diff;
    }
    //dump(rem);

    return rem <= 0;
}

long long meguru_bin(VLL &a, LL &n, LL &m, LL &v, LL &p) {
    long long ok = n - p + 1;
    long long ng = -1;

    while (abs(ok - ng) > 1) {
        long long mid = ng + (ok - ng) / 2;
        //dump(mid);
        if (solve(mid,a,n,m,v,p)) ok = mid;
        else ng = mid;
    }
    //dump(ok);
    return ok;
}

void solve() {
    LL n,m,v,p;
    cin >> n >> m >> v >> p;
    VLL a(n);
    REP(i,0,n) cin >> a[i];
    sort(all(a));

    cout << n - meguru_bin(a,n,m,v,p) << endl;
}

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

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.Linq;
using System.Numerics;
using System.Text.RegularExpressions;

class Program
{
    static long[] ReadLongs()
        => Console.ReadLine()
            .Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
            .Select(s => long.Parse(s))
            .ToArray();

    static void Main(string[] args)
    {
        string s = Console.ReadLine();
        if (s.EndsWith("s"))
        {
            Console.WriteLine(s + "es");
        }
        else
        {
            Console.WriteLine(s + "s");
        }
    }
}

Measured memory_bytes: 26224
a,b,c = map(int, input().split())
ans = 0
while(a%2==0 and b%2==0 and c%2==0):
    if(a==b and b==c and c==a):
        ans = -1
        break
    else:
        a1 = b+c
        b1 = a+c
        c1 = b+a
        a = a1/2
        b = b1/2
        c = c1/2
        ans+=1
    
print(ans)

Measured memory_bytes: 3316
#! python3
#  solve_133C.py

L,R = map(int,input().split())

ans = 3000

for i in range(L,min(R,L+2019)):
    for j in range(i+1,min(R+1,L+2019)):
        ans = min(ans,i*j%2019)
        
print(ans)

Measured memory_bytes: 9152
#include <iostream>
#include <string>
#include <stdlib.h>
#include <cstdlib>
using namespace std;


int main(){
	string S, T;
	int max_match = 0;
	cin >> S >> T;
	
	for(unsigned i=0; i<(S.size()-T.size()+1); i++){
		int match = 0;
		for(unsigned j=0; j<T.size(); j++){
			if(S[i+j] == T[j]){
				match++;
			}
		}
		if(max_match < match) max_match = match;
	}
	
	cout << (T.size() - max_match) << endl;
	return 0;
}


Measured memory_bytes: 3576
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
	int n;
	cin>>n;
	int *A = new int[n+1];
	int *B = new int[n];
	for(int i = 0; i < n+1; i++){
		cin>>A[i];
	}
	for(int i = 0; i < n; i++){
		cin>>B[i];
	}
	long long int sum = 0;
	for(int i = 0; i < n; i++){
		if( A[i] >= B[i]){
			sum += B[i];
		}else{
			sum += A[i];
			B[i] -= A[i];
			if( A[i+1] >= B[i]){
				A[i+1] -= B[i];
				sum += B[i];
			}else{
				sum += A[i+1];
				A[i+1] = 0;
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

int main(){
	string S;
	while(getline(cin,S)){
		priority_queue<int,vector<int>,greater<int> > pq[2]; pq[0].push(0);
		int cnt = 0;
		for(int i=0;i<S.size();i++){
			if(i==0 || S[i]==' '){
				int n = stoi(&S[i]);
				if(n==0) return 0;
				while(!pq[cnt&1].empty()){
					int pq_c = pq[cnt&1].top(); pq[cnt&1].pop();
					if(pq_c>21) continue;
					if(n==1) pq[(cnt+1)&1].push(pq_c+1), pq[(cnt+1)&1].push(pq_c+11);
					else if(n<10) pq[(cnt+1)&1].push(pq_c+n);
					else pq[(cnt+1)&1].push(pq_c+10);
				}
				cnt++;
			}
		}
		int ans = 0;
		while(!pq[cnt&1].empty()){
			if(pq[cnt&1].top()<=21) ans = max(ans,pq[cnt&1].top());
			pq[cnt&1].pop();
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const ld eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int N;
	const int M = 256;
	while (cin >> N, N) {
		vector<int> I(N); cin >> I;
		int as = -1, aa = -1, ac = -1;
		ld ans = linf;
		REP(S, 16) REP(A, 16) REP(C, 16) {
			vector<int> R(N+1, S);
			FOR(i, 1, N+1) R[i] = (A * R[i-1] + C) % M;
			vector<int> O(N);
			REP(i,N) O[i] = (I[i] + R[i+1]) % M;
			map<int, int> m;
			REP(i,N) m[O[i]]++;
			ld H = 0;
			EACH(p,m) {
				ld per = (ld)p.second/N;
				H -= per * log(per);
			}
			if (S == 1 && A == 7 && C == 12) {
//				cout << m.size() << " " << O << " " << H << " " << ans << endl;
			}
			if (S == 8 && A == 7 && C == 14) {
//				cout << m.size() << " " << O << " " << H << " " << ans << endl;
			}
			if (H < ans-eps) {
				ans = H;
				as = S, aa = A, ac = C;
			}
		}
		cout << as << " " << aa << " " << ac << endl;
	}
}

Measured memory_bytes: 3256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    string s;
    cin >> s;
    rep(i, s.size()-8)cout << s[i];
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define sc second
using namespace std;
typedef long long ll;
const int maxn=2e5+50;
ll dp[maxn][2][2];
ll a[maxn];
int main(){
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	dp[1][1][1]=a[1];dp[1][0][1]=-1e18;dp[1][1][0]=-1e18;
	for(int i=2;i<=n;i++){ 
		if(i%2){
			dp[i][0][0]=max(dp[i-1][1][1],dp[i-1][0][1]);dp[i][0][1]=-1e18;dp[i][1][0]=dp[i-1][0][0]+a[i];dp[i][1][1]=dp[i-2][1][1]+a[i];
		}else{
			if(n%2){
				dp[i][1][0]=-1e18;dp[i][1][1]=max(dp[i-2][0][1],dp[i-2][1][1])+a[i];dp[i][0][1]=dp[i-1][1][1];dp[i][0][0]=max(dp[i-1][0][0],dp[i-1][1][0]);
			}else{
				dp[i][0][0]=dp[i][0][1]=dp[i-1][1][1];dp[i][1][0]=dp[i][1][1]=max(dp[i-2][1][0],dp[i-2][0][0])+a[i];
			}
		}
	}printf("%lld\n",max(dp[n][0][0],dp[n][1][0]));
}

Measured memory_bytes: 11632
#include<bits/stdc++.h>
  using namespace std;
  template<typename T, typename V>
  void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
  template<typename T>
  void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
  void _print() {cout << "]\n";}
  template <typename T, typename... V>
  void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
  #ifndef ONLINE_JUDGE
  #define debug(x...) cout << "[" << #x << "] = ["; _print(x)
  #else
  #define debug(x...)
  #endif
  #define int long long int 
  #define fi first
  #define se second
  #define FIO {ios::sycnt2_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
  #define pb push_back
  #define all(x) (x).begin(), (x).end()
  #define rall(x) (x).rbegin(), (x).rend()
  #define forn(i, n) for (int i = 0; i < (int)(n); ++i)
  #define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
  #define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
  #define all(x) (x).begin(), (x).end()
  #define pow10(n) stoll("1"+string(n,'0'))
  //fill(all(arr),1)
  //if(map.count(key)){}
  //bitset<20> b(n);
  //int num=b.count();
  //int mini=min({a,b,c,d,e});
  #define int long long int
  typedef pair<int, int> pii;
  typedef vector<int> vi;
  typedef vector<pii> vpi;
  typedef vector<vi> vvi;
  typedef long long ll;
  typedef vector<ll> vll;
  typedef vector<vll> vvll;
  typedef long double ld;
  int32_t main()
  {
  int x;
  cin>>x;
  cout<<not(x);
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <map>
#include <algorithm>
#include <math.h>
#include <iostream>     // std::cout, std::fixed
#include <iomanip>
#include<queue>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <iostream>
#include <sstream>
typedef long long ll;
using namespace std;

int main () {
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> c(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
        cin>>b[i];
    for(int i=0;i<n;i++)
        cin>>c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    vector<ll> ezerb(n,0);
    int j=n-1;
    ll count=0;
    for(int i=n-1;i>=0;i--)
    {
        ll cur=b[i];
        
        
        for(;j>=0;j--)
        {
            if(cur<c[j])
                count++;
            else
                break;
        }
        ezerb[i]=count;
    }
    ll ans=0;
    count=0;
    j=n-1;
    for(int i=n-1;i>=0;i--)
    {
        ll cur=a[i];
        
        
        for(;j>=0;j--)
        {
            if(cur<b[j])
                count+=ezerb[j];
            else
                break;
        }
        ans+=count;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3456
mass = gets.chomp.split(" ").map(&:to_i)
height = mass[0]
width = mass[1]
grid = []
(0..height-1).each do
    grid.push(gets.chomp.split(""))
end

can = true
(0..height-1).each do |h|
    (0..width-1).each do |w|
        next if grid[h][w] == "." #白なら無視
        #周囲のマスに黒があるか確認
        next if h > 0 && grid[h-1][w] == "#" #上のマス
        next if h < height-1 && grid[h+1][w] == "#" #下のマス
        next if w > 0 && grid[h][w-1] == "#" #左のマス
        next if w < width-1 && grid[h][w+1] == "#" #右のマス
        can = false
    end
    
end

if can
    puts "Yes"
else
    puts "No"
end

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

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

using namespace std;

int main(){

    int N; cin >> N;
    string res = "No";

    rep(i, 10){
        if(N%i==0 && N/i<=9){
            res = "Yes";
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define rap(i,j,k) for(int i=j;i>=k;--i)
using namespace std;
int read()
{
	int num=0,f=1;char c=getchar();
	for(;c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
	for(;c>='0'&&c<='9';c=getchar())num=(num<<1)+(num<<3)+c-48;
	return num*f;
}
const int mn=100010;
int n,m,t,len,ans,a[mn],b[mn],c[mn],mx=-1,my=-1,t1;
void fre()
{
	freopen("test.in","r",stdin);
	freopen("test.out","w",stdout);
}
void init()
{
	n=read();
	rep(i,1,n)
	{
		a[i]=read();
	}
}
void bf_work()
{
	
}
void work()
{
	for(int i=1;i<=n;i+=2)
	{
		b[a[i]]++;
	}
	for(int i=2;i<=n;i+=2)
	{
		c[a[i]]++;
	}
	for(int i=1;i<=100000;++i)
	{
		if(mx<b[i])
		t1=i;
		mx=max(mx,b[i]);
	}
	for(int i=1;i<=100000;++i)
	{
		if(t1!=i)
		{
			my=max(my,c[i]);
		}
	}
	ans=n-mx-my;
	mx=-1;my=-1;
	for(int i=1;i<=100000;++i)
	{
		if(mx<c[i])
		t1=i;
		mx=max(mx,c[i]);
	}
	for(int i=1;i<=100000;++i)
	{
		if(t1!=i)
		{
			my=max(my,b[i]);
		}
	}
	ans=min(ans,n-mx-my);
	printf("%d",ans);
}
void re_zero()
{
	ans=0;
}
int main()
{
//	fre();
		init();
		bf_work();
		work();
		re_zero();
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 30) - 1;
struct Node
{
    int y, x, cost;
    Node () {}
    Node (int y, int x, int cost) : y(y), x(x), cost(cost) {}
    bool operator < (const Node &d) const { return (cost > d.cost); }
};

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int R;
int W[2], H[2], X[2], Y[2];
int mas[2][505][505];
int mc[2][505][505];
vector < int > D[2];
void Dijkstra(int p, int sx, int sy)
{
    priority_queue < Node > pq;
    pq.push(Node(sy, sx, 1));
    mc[p][sy][sx] = 1;
    while(!pq.empty()) {
        Node d = pq.top(); pq.pop();
        if(d.cost > mc[p][d.y][d.x]) continue;
        D[p].push_back(d.cost);
        for(int i = 0; i < 4; i++) {
            int ny = d.y + dy[i], nx = d.x + dx[i], w = max(d.cost, mas[p][ny][nx]);
            if(ny < H[p] && nx < W[p] && ny >= 0 && nx >= 0 && mc[p][ny][nx] > w) {
                mc[p][ny][nx] = w;
                pq.push(Node(ny, nx, w));
            }
        }
    }
}

int main()
{
    while(cin >> R, R) {
        D[0].push_back(0); D[1].push_back(0);
        fill_n(**mc, 2 * 505 * 505, INF);
        for(int p = 0; p < 2; p++) {
            cin >> W[p] >> H[p] >> X[p] >> Y[p]; --X[p], --Y[p];
            for(int i = 0; i < H[p]; i++) {
                for(int j = 0; j < W[p]; j++) {
                    cin >> mas[p][i][j];
                }
            }
            Dijkstra(p, X[p], Y[p]);
        }
        int minv = INF;
        for(int i = 0; i <= R; i++) {
            if(i < D[0].size() && R - i < D[1].size()) {
                minv = min(minv, D[0][i] + D[1][R - i]);
            }
        }
        cout << minv << endl;
        while(!D[0].empty()) D[0].pop_back();
        while(!D[1].empty()) D[1].pop_back();
    }
    return (0);
}


Measured memory_bytes: 9704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;

int main(void){
    int n;
    cin>>n;
    int ans=0;
    int x[100],y[100];
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<n;i++){
        cin>>y[i];
    }
    for(int i=0;i<n;i++){
        if(x[i]-y[i]>0){
            ans+=x[i]-y[i];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vlll = vector<vll>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
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 (b < a) { a = b; return 1; } return 0; }
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second > secondElof.second;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod, LIS, digitDP, treeDP, Rerooting//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA, FordFulkerson//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q, T;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vl flag, D; vector<vpll> path; vll A;
//***********//
int main() {
	cin >> K;
	ll ans = 0;
	ll p = 7;
	for (i = 1; i <= 1000010; i++) {
		(ans += p) %= K;
		if (ans == 0) {
			co(i);
			exit(0);
		}
		(p *= 10) %= K;
	}
	co(-1);
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N >> K;
    vi a(N);
    cin >> a;
    REP(i, N) {
        a[i]--;
    }
    vi v;
    int x = 0;
    set<int> s;
    REP(i, 2 * N) {
        s.insert(x);
        v.push_back(x);
        x = a[x];
        if (s.find(x) != s.end()) {
            break;
        }
    }
    int ind;
    REP(i, v.size()) {
        if (v[i] == x) {
            ind = i;
        }
    }
    dump(ind, v);
    K++;
    if (K <= ind) {
        cout << v[K - 1] + 1 << endl;
    } else {
        K -= ind;
        int rot = v.size() - ind;
        K %= rot;
        if (K == 0) {
            cout << v.back() + 1 << endl;
        } else {
            cout << v[ind + K - 1] + 1 << endl;
        }
    }
}

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

inline int read(){
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}

inline void write(int x){
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
}
inline void writeln(int x){
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
     puts("");
}

int main(){
    int h1,m1,h2,m2,k;
    h1=read(),m1=read(),h2=read(),m2=read(),k=read();
    
    int ans=0;
    ans=(h2-h1)*60+(m2-m1)*1-k;
    writeln(ans);
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  int m;
  cin>>m;
  vector<int> b(m);
  for(int i=0;i<m;i++) cin>>b[i];

  vector<int> c;
  set_union(a.begin(),a.end(),b.begin(),b.end(),back_inserter(c));
  for(int x:c) cout<<x<<endl;
  return 0;
}



Measured memory_bytes: 6520
//Monsters Battle Royale

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a) vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<ll,string> p;
using g = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    nvarep(n,a);
    ll ans = gcd(a[0],a[1]);
    rep(i,1,n){
        ans=gcd(ans,a[i]);
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
typedef long long int ll;

ll min(ll x,ll y){
	if(x > y){
		return y;
	}else{
		return x;
	}
}

int main(void)
{
	ll w,h,x,y;
	
	scanf("%lld%lld%lld%lld",&w,&h,&x,&y);
	
	ll menseki = w * h;
	
	printf("%lf %lld\n",(double)menseki/2,2*x == w && 2*y == h);
	
	return 0;
	
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>

using namespace std;

void q(long long l, long long r, string a, string b) {
    long long query = (l + r)/2;
    std::cout << query << std::endl;
    string answer;
    std::cin >> answer;
    if (answer == "Vacant") {
        return;
    }
    if ((query - l)%2 == 0) {
        if (a == answer) {
            q(query, r, answer, b);
        } else {
            q(l, query, a, answer);
        }
    } else {
        if (a == answer) {
            q(l, query, a, answer);
        } else {
            q(query, r, answer, b);
        }
    }
}

void solve(long long N){
    std::cout << 0 << std::endl;
    string a;
    std::cin >> a;
    if (a == "Vacant") {
        return;
    }
    q(0, N, a, a);
}

int main(){	
    struct timeval start,end;
    long long span;
    gettimeofday(&start,NULL);

    long long N;
    cin >> N;
    solve(N);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


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

int main() {
  
  int N; cin >> N; bool flag = false;
  
  for (int i = 1; i < 10; i++) {
    for (int j = 1; j < 10; j++) {
      if (i * j == N) {
        flag = true;
      }
    }
  }
  
  if (flag) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
n = int(input());
array = [[0]*2 for i in range(n)];
for i in range(n) :
	s = input().split(" ");
	array[i][0] = int(s[0]);
	array[i][1] = int(s[1]);
array.sort(key=lambda x:x[1]);
time = 0;
can = 1;
for i in range(n) :
	time += array[i][0];
	if time > array[i][1] :
		can = 0;
if bool(can) :
	print('Yes');
else :
	print('No')

Measured memory_bytes: 38040
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int S, W;
    cin >> S >> W;
    cout << (S <= W ? "unsafe" : "safe") << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const double pi=3.1415926535;

signed main()
{
    string s,t;
    cin>>s>>t;
    bool flag=1;
    for(int i=0;i<s.length();i++){
    	if(s[i]!=t[i]){
    		flag=0;break;
		}
	}
	if(flag)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3628
def check(b):
  for i in range(n):
    for j in range(i+1,n):
      if b[i][j]!=b[j][i]:
        return False
  return True

n=int(input())
board=[list(input()) for _ in range(n)]
cnt=0
for i in range(n):
  if check(board[i:]+board[:i]):
    cnt+=1
print(cnt*n)

Measured memory_bytes: 3828