akhauriyash/Code-Regression huggingface dataset:
N,M=map(int, input().split())

import itertools
nl=[]
ml=[]
for n in range(1,N+1):
    nl.append(n)
for m in range(1,M+1):
    ml.append(m)
nnum=len(list(itertools.combinations(nl,2)))
mnum=len(list(itertools.combinations(ml,2)))
res=nnum+mnum
print(res)

Measured memory_bytes: 3444
a, b, c, x, y = map(int,input().split())
ans = 0
if((a+b)/2 > c):
    ans += min(x,y)*c*2
else:
    ans += min(x,y)*(a+b)
if(x==max(x,y)):
    ans += (x-y)*min(a,2*c)
else:
    ans += (y-x)*min(b,2*c)

print(ans)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, l, r) for(int i = (l); i <= (r); ++i)
#define REP(i, n) FOR(i, 0, (n) - 1)
#ifdef DEBUG
  template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) {
	  return out << '(' << p.first << ", " << p.second << ')';
  }
  template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
	  out << '{';
	  for(auto it = x.begin(); it != x.end(); ++it)
		  out << *it << (it == --x.end() ? "" : ", ");
	  return out << '}';
  }
  void dump() {}
  template<class T, class... Args> void dump(T &&x, Args... args) {
	  cerr << x << ";  ";
	  dump(args...);
  }
  const int seed = 1;
  struct Nl{~Nl(){cerr << '\n';}};
# define debug(x...) cerr << (#x != "" ? #x ":  " : ""), dump(x), Nl(), cerr
#else
  const int seed = chrono::system_clock::now().time_since_epoch().count();
# define debug(...) 0 && cerr
#endif
mt19937_64 rng(seed);
int rd(int l, int r) {
	return uniform_int_distribution<int>(l, r)(rng);
}
template<class T> int size(T a) { return a.size(); }

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

	int n;
	cin >> n;

	array<LL, 3> A, B;
	REP(i, 3) cin >> A[i];
	REP(i, 3) cin >> B[i];

	auto get = [&](int N)
	{
		vector<LL> dp(N + 1);
		REP(i, 3)
		{
			LL gain = B[i] - A[i];
			if(gain <= 0) continue;
			FOR(x, A[i], N)
				dp[x] = max(dp[x], dp[x - A[i]] + gain);
		}

		return N + dp[N];
	};

	n = get(n);
	swap(A, B);
	cout << get(n) << "\n";
}


Measured memory_bytes: 195712
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>

#define _USE_MATH_DEFINES

#include<math.h>

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

int main()
{
	vector<int> a, b;
	vector<char> op;
	while (true)
	{
		int ta, tb;
		char top;

		scanf("%d %c %d", &ta, &top, &tb);

		if (top == '?')
		{
			break;
		}
		else
		{
			a.push_back(ta);
			b.push_back(tb);
			op.push_back(top);
		}
	}
	for (int i = 0; i != op.size(); i++)
	{
		switch (op[i])
		{
		case '+':
			printf("%d\n", a[i] + b[i]);
			break;
		case '-':
			printf("%d\n", a[i] - b[i]);
			break;
		case '*':
			printf("%d\n", a[i] * b[i]);
			break;
		case '/':
			printf("%d\n", a[i] / b[i]);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 2760
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	long long n, n1, n2 = 1, ans = 1000000007;
	cin >> n;
	for (long long i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			int n1 = n / i;
			int n2 = i;
			string n3 = to_string(n1);
			string n4 = to_string(n2);
			if (ans > max(n3.size(), n4.size())) {
				ans = max(n3.size(), n4.size());
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector <ll> v(n);
  rep(i, n) cin >> v.at(i);
  vector <ll> res;
  vector <ll> sum(n, 0);
  for (ll i = n-1; i >= 0; i--) {
    if (sum.at(i)%2 != v.at(i)) {
      res.push_back(i+1);
      for (ll j = 1; j*j <= i+1; j++) {
        if ((i+1)%j == 0) {
          sum.at(j-1)++;
          if (j != (i+1)/j) sum.at((i+1)/j-1)++;
        }
      }
    }
  }
  sort(res.begin(), res.end());
  cout << res.size() << endl;
  rep(i, res.size()) {
    if (i) cout << ' ' << res.at(i);
    else cout << res.at(i);
    if (i == res.size()-1) cout << endl;
  }
}

Measured memory_bytes: 4980
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int h = sc.nextInt();
		
		int result = (a + b) * h / 2;
		
		System.out.println(result);
	}

}

Measured memory_bytes: 35864
c, n = map(int, input().split())
P = [list(map(int, input())) for i in range(n)]
S = [[0]*n for i in range(n)]
T = [[0]*n for i in range(n)]
dS = dT = 0
for i in range(n):
    for j in range(n//2):
        S[i][j] = P[i][j] ^ P[i][n-1-j]
        dS += S[i][j]
for j in range(n):
    for i in range(n//2):
        T[i][j] = P[i][j] ^ P[n-1-i][j]
        dT += T[i][j]
ans = +(dS == dT == 0)
for i in range(c-1):
    d = int(input())
    for j in range(d):
        r, c = map(int, input().split())
        S[r-1][min(c-1, n-c)] ^= 1
        if S[r-1][min(c-1, n-c)]:
            dS += 1
        else:
            dS -= 1
        T[min(r-1, n-r)][c-1] ^= 1
        if T[min(r-1, n-r)][c-1]:
            dT += 1
        else:
            dT -= 1
    if dS == dT == 0:
        ans += 1
print(ans)

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

signed main(){
  lint N; cin >> N;
  lint ans = 0;
  if(N % 2 != 0) ans = 0;
  else{
    N /= 10;
    while(N > 0){
      ans += N;
      N /= 5;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

bool DP[110000] = {};

int main(){
	
	int N, K;
	cin >> N >> K;
	
	int a[110] = {};
	
	for(int i = 0; i < N; i++){
		cin >> a[i];
	}
	
	for(int i = 0; i <= K; i++){
		bool flag = false;
		for(int j = 0; j < N; j++){
			if(a[j] > i){
				continue;
			}
			if(!DP[i - a[j]]){
				flag = true;
			}
		}
		DP[i] = flag;
	}
	
	if(DP[K]){
		cout << "First" << endl;
	}else{
		cout << "Second" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	
    	int N = sc.nextInt(), K = sc.nextInt(),
    		X = sc.nextInt(), Y = sc.nextInt(),
    		min = Math.min(N, K), ans = 0;
    	
    	for(int i = 0; i < min; i++)	ans += X;
    	for(int i = K; i < N; i++)	ans += Y;
    	
    	System.out.println(ans);
    }
}

Measured memory_bytes: 9044
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
#define MOD 1000000007
int main()
{
    ll N, K;
    cin >> N >> K;
    ll sum = 0;
 
    for (ll i = K; i <= N + 1; i++)
    {
        ll low = (i - 1) * i / 2;
        ll high = (2 * N + 1 - i) * i / 2;
        ll add = high - low + 1;
        sum = (sum + add) % MOD;
    }
 
    cout << sum << endl;

    return 0;
}

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

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

int main(){
    int n;cin>>n;
    int a[n],l[n],r[n];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=1;i<n;i++){
        if(i == 1){
            l[i]=a[i-1];
            r[n-1-i]=a[n-i];
        }
        else{
            l[i] = gcd(l[i-1],a[i-1]);
            r[n-1-i] = gcd(r[n-i],a[n-i]);
        }
    }
    int ans=0;
    int tmp;
    for(int i=0;i<n;i++){
        if(i==0) tmp=r[0];
        else if(i==n-1) tmp=l[n-1];
        else tmp=gcd(l[i],r[i]);
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
}

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

void swap (long int *x, long int *y);
int partition (long int array[], int left, int right);
void quick_sort (long int array[], int left, int right);

int main(void){
  int n;
  long int a[200000];
  
  scanf("%d", &n);
  
  //a = (long int*)malloc(sizeof(long int)*n);
  for(int i=0; i < n; i ++){
    scanf("%ld ", &a[i]);
  }
  
  quick_sort(a, 0, n-1);
  
  for(int i=0; i < n-1; i ++){
  	if(a[i] == a[i+1]){
      printf("NO");
      return 0;
    }
  }
  printf("YES");
  return 0;
}

void swap (long int *x, long int *y) {
  long int temp; 

  temp = *x;
  *x = *y;
  *y = temp;
}

int partition (long int array[], int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;   // 先頭要素をpivotとする

  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);

  swap(&array[pivot], &array[j]);   //pivotを更新

  return j;
}

/* クイックソート */
void quick_sort (long int array[], int left, int right) {
  int pivot;

  if (left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot-1);   // pivotを境に再帰的にクイックソート
    quick_sort(array, pivot+1, right);
  }
}


Measured memory_bytes: 1792
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	factors := Factorization(n)

	cnt := 0
	for i := 0; i < 1<<uint(len(factors)); i++ {
		lcm := 1
		f := 0
		combi := 0
		for j := i; j > 0; j >>= 1 {
			if j&1 == 1 {
				combi++
				lcm = LCM(lcm, factors[f])
			}
			f++
		}
		sign := 1
		if combi&1 == 1 {
			sign = -1
		}
		cnt += sign * (n / lcm)
	}
	fmt.Println(cnt)
}

func Factorization(n int) []int {
	a := []int{}
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			a = append(a, i)
			n /= i
			for n%i == 0 {
				n /= i
			}
		}
	}
	if n > 1 {
		a = append(a, n)
	}
	return a
}

func LCM(a, b int) int { return a * b / GCD(a, b) }

func GCD(a, b int) int {
	if b == 0 {
		return a
	}
	return GCD(b, a%b)
}



Measured memory_bytes: 1156
#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>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
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.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, Npow, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path;
//***********//
int main() {
	cin >> N;
	vll R(N);
	for (i = 0; i < N; i++) {
		ll a, b;
		cin >> a >> b;
		R[i] = { a, b, 0 };
	}
	vpll B(N);
	for (i = 0; i < N; i++) {
		ll c, d;
		cin >> c >> d;
		B[i] = make_pair(c, d);
	}
	sort(B.begin(), B.end());
	for (i = 0; i < N; i++) {
		ll match = -1;
		ll y = -1;
		for (j = 0; j < N; j++) {
			if (R[j][0] < B[i].first && R[j][2] == 0 && R[j][1] > y && R[j][1]<B[i].second) {
				y = R[j][1];
				match = j;
			}
		}
		if (match >= 0) {
			R[match][2] = 1;
			ans++;
		}
	}
	cout << ans;
}

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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;



int main(){
  ll n;
  cin>>n;
  ll ans=n*(n+1)/2;
  ll x=n/3;
  ans-=3*x*(x+1)/2;
  x=n/5;
  ans-=5*x*(x+1)/2;
  x=n/15;
  ans+=15*x*(x+1)/2;
  cout<<ans<<endl;
}


Measured memory_bytes: 3636
N, Q = (int(i) for i in input().split())
S = input()
l = []
r = []
for i in range(Q):
    a, b = (int(i) for i in input().split())
    l.append(a)
    r.append(b)

t = [0] * (N+1)
for i in range(N):
    #pre_str = S[l[i]-1:r[i]]
    #print(pre_str.count('AC'))
    t[i+1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)

for i in range(Q):
    print(t[r[i]-1] - t[l[i]-1])


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

int main(){
    multimap<string, ll, std::less<>> mp;
    ll q, c, x;
    string s, l;
    cin >> q;
    rep(i, q){
        cin >> c >> s;
        auto t = mp.find(s);
        switch(c){
            case 0:
                cin >> x;
                mp.insert(make_pair(s, x));
                break;
            case 1:
                for(auto i = mp.lower_bound(s); i!= mp.upper_bound(s); i++){
                    cout << i->second << endl;
                }
                break;
            case 2:
                if(t != mp.end()){
                    mp.erase(s);
                }
                break;
            case 3:
                cin >> l;
                for(auto i = mp.lower_bound(s); i!= mp.upper_bound(l); i++){
                    cout << i->first << " " << i->second << endl;
                }
                break;
        }
    }
    return 0;
}


Measured memory_bytes: 24824
import math

n, p = list(map(int, input().split()))
a = list(map(int, input().split()))

b = [a[i] % 2 for i in range(n)]

z = b.count(0)
o = b.count(1)

c = 0

for i in range(o+1):
  if i % 2 == 0:
    c += math.factorial(o)/(math.factorial(i)*math.factorial(o-i))

ans = int(c *( 2 **z))
    
if p == 0:
  print(ans)
else:
  print(str(2**n-ans))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	int cnt = 1, answer = 1;
	for (int i = 1; i < n; ++i) {
		if (a[i] <= a[i - 1]) {
			++cnt;
		} else {
			answer = max(answer, cnt);
			cnt = 1;
		}
	}
	answer = max(answer, cnt);
	cout << answer - 1 << '\n';
	return 0;
}


Measured memory_bytes: 640
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 1000000000000000000LL
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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

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

const int inf=100000000;

int pow(int m, int n) {
        if (n == 0) { return 1; }
        if (n % 2 == 0) { return pow(m*m, n/2); }
        return pow(m, n-1) * m;
    }

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int N,K;
    cin>>N>>K;
    long double ans=0;
    long double v=0;
    if(N>=K) {v=(long double)(N-K+1)/N;}

    vector<int> cnt;

    for(int i=1; i<=N; i++)
    {
        int j=i;
        int c=0;
        if(i<K)
        {
            while (j<K)

        {
            j=j*2;
            c++;
        }
        cnt.push_back(c);
        }
        else if(i>=K) cnt.push_back(0);
    }
    for(int i=0; i<N; i++)
    {
        if(cnt[i]!=0)
        {
        long double  vv=(long double)1/pow(2,cnt[i])/N;
        ans+=vv;
        }
    }
    ans+=v;

    cout<<setprecision(10)<<ans<<endl;

}

Measured memory_bytes: 892
private data class Cell(val row:Int, val col:Int)

fun main(args: Array<String>) {
    val (h, w) = readLine()!!.split(" ").map { it.toInt() }

    // # を起点にした幅優先探索実装

    var mat = Array<MutableList<Char>>(h) { mutableListOf() }
    for ( i in 0 until h) {
        mat[i] = readLine()!!.toCharArray().toMutableList()
    }

    var count = 0
    var queue = mutableListOf<MutableList<Cell>>()

    // 最初からすべて黒場合は 0 を出力
    var allblack = true
    var target = mutableListOf<Cell>()
    for (i in 0 until h) {
        for (j in 0 until w){
            if(mat[i][j] == "#".single()) {
                target.add(Cell(row = i, col = j))
            } else {
                allblack = false
            }
        }
    }

    if (allblack){
        print(0)
        return
    }

    // 幅優先探索で順次取り出し色を塗る, 濡れなかったところを次にenqueue
    queue.add(target)
    while(queue.size != 0) {
        target = queue.first()
        queue.removeAt(0)

        var painted_total = mutableListOf<Cell>()

        for ( c in target) {
            painted_total.addAll(paint(mat, c.row, c.col, h, w))
        }

        if (painted_total.size != 0){
            queue.add(painted_total)
            count += 1
        }
    }
    print(count)
}

private fun paint(mat: Array<MutableList<Char>>, row: Int, col: Int, h:Int, w:Int): MutableList<Cell> {
    var painted = mutableListOf<Cell>()

    if (row - 1 >= 0 && mat[row-1][col] == ".".single()){
        mat[row-1][col] = "#".single()
        painted.add(Cell(row = row-1, col = col))
    }
    if (row + 1 < h && mat[row+1][col] == ".".single()){
        mat[row+1][col] = "#".single()
        painted.add(Cell(row = row+1, col = col))
    }
    if (col - 1 >= 0 && mat[row][col-1] == ".".single()){
        mat[row][col-1] = "#".single()
        painted.add(Cell(row = row, col = col-1))
    }
    if (col + 1 < w && mat[row][col+1] == ".".single()){
        mat[row][col+1] = "#".single()
        painted.add(Cell(row = row, col = col+1))
    }

    return painted
}

Measured memory_bytes: 112168
#include <stdio.h>
#include <string.h>

int main()
{
	int n;
	char *p;
	char str[1000];
	scanf("%d\n",&n);
	while(n--){
	gets(str);
	for(p;p=strstr(str,"Hoshino");)p[6]='a';
	puts(str);
	}
	return 0;
}

Measured memory_bytes: 588
#include <bits/stdc++.h>
#define ll long long
#define maxn 200020
using namespace std;

ll ans=1,sum[27];

int l;

char s[maxn];

int main(){
	scanf("%s",s+1);
	l=strlen(s+1);
	for(int i=1;i<=l;i++) sum[s[i]-'a']++;
	for(int i=0;i<26;i++) for(int j=i+1;j<26;j++) ans+=1ll*sum[i]*sum[j];
	printf("%lld",ans);
	return 0;
}

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

int main() {
    uint N; cin >> N;
    vector<int> A(N, 0);
    for (auto &a: A) cin >> a;

    int cnt = 0;
    bool finish = false;
    while(!finish) {
        for (size_t i=0; i<A.size(); ++i) {
            if ((A[i] & 0x01) == 1) {
                finish = true;
                break;
            }
            if (i == (A.size() - 1)) ++cnt;
            A[i] = A[i] >> 1;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3616
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>

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

int main( void ){
	int n;
	if (!scanf( "%d", &n))
		return -1;
	int* array = new int[n];
	rep(i,0,n)
		if (!scanf( "%d", array+i))
			return -1;
	int max = 0, count = 0, max_pos = 0, pos = 0;
	unsigned int pre_height = 0;
	rep(i,0,n){
		if (array[i] <= pre_height)
			count++;
		else{
			if (max < count){
				max = count;
				max_pos = pos;
				pos = i;
			}
			count = 0;
		}
		pre_height = array[i];
	}
	printf("%d\n", std::max(max, count));
}


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

ll LCM(ll a, ll b)
{
    ll x = a * b, r = a % b;
    while (r != 0)
    {
        a = b;
        b = r;
        r = a % b;
    }
    return (x / b);
}

int main(void)
{
    ll a, b;

    scanf("%lld%lld", &a, &b);

    printf("%lld\n", LCM(a, b));

    return 0;
}

Measured memory_bytes: 128
n = int(input())
lst = list(map(int, input().split()))
ma = {}
mb = {}
for i in range(0, n, 2):
    lst[i] in ma
    if lst[i] in ma:
        ma[lst[i]] += 1
    else:
        ma[lst[i]] = 1
    lst[i+1] in mb
    if lst[i+1] in mb:
        mb[lst[i+1]] += 1
    else:
        mb[lst[i+1]] = 1
if max(ma, key=ma.get) != max(mb, key=mb.get):
    d = n - max(ma.values()) - max(mb.values())
else:
    ma2 = max(ma.values())
    mb2 = max(mb.values())
    ma[max(ma, key=ma.get)] = 0
    mb[max(mb, key=mb.get)] = 0
    d1 = n - ma2 - max(mb.values())
    d2 = n - max(ma.values()) - mb2
    d = min(d1, d2)
print(d)

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

using namespace std;

typedef long long ll;

int main()
{
	ll i, n, s;
	
	scanf("%lld", &n);
	
	for(i=s=0;n>=10;n/=10,i++) s += n%10;
	
	printf("%lld\n", max(s + n, n-1 + 9*i));
	
	return 0;
}

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


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int popcount(T n) { return n ? 1 + popcount(n & (n - 1)) : 0; }
#endif
#ifdef __GNUC__
template <class T> int popcount(T n);
template <> int popcount(unsigned int n) { return n ? __builtin_popcount(n) : 0; }
template <> int popcount(int n) { return n ? __builtin_popcount(n) : 0; }
template <> int popcount(unsigned long long n) { return n ? __builtin_popcountll(n) : 0; }
template <> int popcount(long long n) { return n ? __builtin_popcountll(n) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CL(arr, val) memset(arr, val, sizeof(arr))

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

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

typedef long long ll;
typedef pair<int, int> pint;

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };
bool valid_pos(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }

template <class T> void print(T a, int n, int br = 1, const string& deli = ", ") { cout << "{ "; for (int i = 0; i < n; ++i) { cout << a[i]; if (i + 1 != n) cout << deli; } cout << " }"; while (br--) cout << endl; }
template <class T> void print(const vector<T>& v, int br = 1, const string& deli = ", ") { print(v, v.size(), br, deli); }




vector<string> split(string str, const string& deli_chars)
{
	for (int i = 0; i < str.size(); ++i)
		if (deli_chars.find(str[i]) != string::npos)
			str[i] = ' ';
	stringstream ss(str);
	vector<string> res;
	for (string s; ss >> s; )
		res.push_back(s);
	return res;
}

map<string, set<string> > g;
void unfold(const string& s)
{
	vector<string> add;
	vector<string> del;
	foreach (i, g[s])
	{
		string n = *i;
		if (g.count(n))
		{
			unfold(n);
			foreach (j, g[n])
				add.push_back(*j);
			del.push_back(*i);
		}
	}
	for (int i = 0; i < del.size(); ++i)
		g[s].erase(del[i]);
	for (int i = 0; i < add.size(); ++i)
		g[s].insert(add[i]);
}
int main()
{
	int n;
	while (cin >> n, n)
	{
		g.clear();

		string f;
		for (int T = 0; T < n; ++T)
		{
			string s;
			cin >> s;
			vector<string> v = split(s.substr(0, s.size() - 1), ":,");
			for (int i = 1; i < v.size(); ++i)
				g[v[0]].insert(v[i]);
			if (T == 0)
				f = v[0];
		}
		unfold(f);
		cout << g[f].size() << endl;
	}
}

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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)

li a[10100];
li b[10100];
li n;

inline bool check() {
	cin >> n;
	li sa = 0;
	rep(i, n) {
		cin >> a[i];
		sa += a[i];
	}
	li sb = 0;
	rep(i, n) {
		cin >> b[i];
		sb += b[i];
	}
	li num = sb - sa;

	li num1 = num;
	rep(i, n) {
		if (a[i] < b[i]) {
			li cnt = (b[i] - a[i] + 1) / 2;
			a[i] += cnt * 2;
			num1 -= cnt;
		}
	}
	if (num1 < 0) {
		return false;
	}
	return true;
}

int main() {
	cout << (check() ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 384
// Problem : B - 1%
// Contest : AtCoder - AtCoder Beginner Contest 165
// URL : https://atcoder.jp/contests/abc165/tasks/abc165_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/**
 * @author dwij
 */

#include <bits/stdc++.h>

#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>

using namespace std;

//******* Debugging Class Template *******/
#define sim template <class c
#define ris return *this
#define dor > deb& operator<<
#define eni(x) \
    sim > typename enable_if<sizeof dud<c>(0) x 1, deb&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct deb {
#ifdef LOCAL
    ~deb() { cerr << endl; }
    eni(!=) cerr << boolalpha << i;
    ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
    sim dor(const c&) { ris; }
#endif
}
;
#define log(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// End of weird debugging stuff.

typedef long long ll;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;

#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<ll, ll>

#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define endl "\n"

void solution() {
    // deb() << log();
    ll n;
    cin >> n;
    ll k = 100;
    int count = 0;
    while (k < n) {
        k += (k / 100LL);
        count++;
    }

    cout << count << endl;
}

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

    int T = 1;
    // cin >> T;
    // cin.ignore(); must be there when using getline(cin, s)
    for (int tt = 1; tt <= T; tt++) {
        // cout << "Case #" << tt << ": ";
        solution();
    }

    return 0;
}


Measured memory_bytes: 3632
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, K: int, a: "List[int]"):
    a.sort(reverse=True)
    dp = [False] * K
    dp[0] = True
    ret = 0
    for i in range(N):
        for j in range(K - 1, -1, -1):
            if dp[j]:
                if j + a[i] >= K:
                    ret = i + 1
                else:
                    dp[j + a[i]] = True
    print(N - ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, a)

if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

const int MM = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 2e6 + 10;

int n, m;

void prework(){

}

void read(){

}

int L[MAXN], R[MAXN];
int a[MAXN], b[MAXN];
char s[MAXN];

vector<PII> c;

int gaol(int l, int r){
	sort(c.begin(), c.end());
	int ans = 1e9;
	int mr = 0;
	for (int i = (int)c.size() - 1; i >= 0; i--){
		// L = max(c[i].first, l), R = mr
		if (c[i].first <= l)
			ans = min(ans, 2 * mr + l);
		else
			ans = min(ans, 2 * mr + 2 * c[i].first - l);
		mr = max(mr, c[i].second);
	}
	ans = min(ans, 2 * mr + l);
	return ans;
}

int gaor(int l, int r){
	for (int i = 0; i < c.size(); i++)
		swap(c[i].first, c[i].second);
	sort(c.begin(), c.end());
	int ans = 1e9;
	int ml = 0;
	for (int i = (int)c.size() - 1; i >= 0; i--){
		if (c[i].first <= r)
			ans = min(ans, 2 * ml + r);
		else
			ans = min(ans, 2 * ml + 2 * c[i].first - r);
		ml = max(ml, c[i].second);
	}
	ans = min(ans, 2 * ml + r);
	return ans;
}

int nos(){
	int cnt = 0;
	for (int i = 0; i < n; i++)
		cnt += b[i];
	return cnt == 0;
}

void solve(int casi){
//	cout << "Case #" << casi << ": ";
	scanf("%s", s);
	n = strlen(s);
	for (int i = 0; i < n; i++)
		a[i] = (s[i] == '1');
	scanf("%s", s);
	for (int i = 0; i < n; i++)
		b[i] = (s[i] == '1');
	if (nos()){
		int cnt = 0;
		for (int i = 0; i < n; i++)
			cnt += a[i];
		if (cnt == 0)
			puts("0");
		else
			puts("-1");
		return ;
	}
	
	int pre = n - 1;
	while(b[pre] != 1) pre--;
	for (int i = 0; i < n; i++){
		if (b[i] == 1){
			pre = i;
		}
		L[i] = (i - pre + n) % n;
	}
	pre = 0;
	while(b[pre] == 0) pre++;
	for (int i = n - 1; i >= 0; i--){
		if (b[i] == 1)
			pre = i;
		R[i] = (pre - i + n) % n;
	}
	
	int ans = 1e9;
	// A[i], A[i+1], ..., A[i-1] 
	// B[0], B[1],   ..., B[n-1] 
	for (int i = 0; i < n; i++){
		c.clear();
		for (int j = 0; j < n; j++){
			if (a[(i + j) % n] != b[j])
				c.push_back(PII(L[(i + j) % n], R[(i + j) % n]));
		}
		ans = min(ans, gaol(i, 0) + (int)c.size());
		ans = min(ans, gaor(0, n - i) + (int)c.size());
	}
	printf("%d\n", ans);
}

void printans(){

}


int main(){
//	std::ios::sync_with_stdio(false);
	prework();
	int T = 1;
//	cin>>T;
	for(int i = 1; i <= T; i++){
		read();
		solve(i);
		printans();
	}
	return 0;
}



Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define INF 100000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  ll ans = 0;
  vector<bool> used(N, false);
  for (ll i = N - 1; i >= 0; --i) {
    if (used.at(i)) {
      continue;
    }
    used.at(i) = true;
    ll pow2 = 1;
    while (pow2 <= A.at(i)) {
      pow2 *= 2;
    }
    ll need = pow2 - A.at(i);
    ll l = lower_bound(A.begin(), A.end(), need) - A.begin() - 1;
    ll r = upper_bound(A.begin(), A.end(), need) - A.begin();
    r = min(r, i);
    // cout << "nned" << need << endl;
    // cout << l << ' ' << r << endl;
    if (l == r) {
      continue;
    }
    while (l + 1 != r) {
      ll m = (l + r) / 2;
      if (used.at(m)) {
        l = m;
      }
      else {
        r = m;
      }
    }
    // cout << "l" << l << "r" << r << endl;
    if (r == N) {
      continue;
    }
    if (A.at(r) != need) {
      continue;
    }
    if (used.at(r)) {
      continue;
    }
    used.at(r) = true;
    ans += 1;
    // for (ll j = l; j < r; ++j) {
    //   if (!used.at(j)) {
    //     used.at(j) = true;
    //     ans += 1;
    //     break;
    //   }
    // }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        Arrays.setAll(array, i -> sc.nextInt());
        Arrays.sort(array);
        long ans = array[n - 1];
        int maxIndex = n - 2;
        boolean isOK = true;
        for (int i = 2; i < n; i++) {
            isOK = !isOK;
            ans += array[maxIndex];
            if (isOK) {
                maxIndex--;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 61152
/* 0 -> Top
 * 1 -> S
 * 2 -> E
 * 3 -> W
 * 4 -> N
 * 5 -> Down
 */

#include <iostream>
using namespace std;

int numbers[6];

void changeDirection(char s) {
	int tmpNumber;
	if (s == 'E'){
		tmpNumber = numbers[0];
		numbers[0] = numbers[3];
		numbers[3] = numbers[5];
		numbers[5] = numbers[2];
		numbers[2] = tmpNumber;
	} 
	else if (s == 'W'){
		tmpNumber = numbers[0];
		numbers[0] = numbers[2];
		numbers[2] = numbers[5];
		numbers[5] = numbers[3];
		numbers[3] = tmpNumber;
	
	} 
	else if (s == 'S'){
		tmpNumber = numbers[0];
		numbers[0] = numbers[4];
		numbers[4] = numbers[5];
		numbers[5] = numbers[1];
		numbers[1] = tmpNumber;
	} 
	else if (s == 'N'){
		tmpNumber = numbers[0];
		numbers[0] = numbers[1];
		numbers[1] = numbers[5];
		numbers[5] = numbers[4];
		numbers[4] = tmpNumber;
	} 
}

int main(int argc, char const* argv[])
{
	string directions;

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

	cin >> directions;
	for (int i=0; i<directions.size(); i++) {
		changeDirection(directions[i]);
	}
	cout << numbers[0] << endl;

	return 0;
}


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

using namespace std;


void solve() {
    int n; cin >> n;
    map<int, int> cnt;
    for (int _ = 0; _ < n; _++) {
        int x; cin >> x;
        cnt[x]++;
    }
    int res = 0;
    for (auto& p: cnt) {
        int tmp = p.second;
        if (cnt.find(p.first-1) != cnt.end()) tmp += cnt[p.first-1];
        if (cnt.find(p.first+1) != cnt.end()) tmp += cnt[p.first+1];
        res = max(res, tmp);
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 3200
import java.util.Scanner;

public class Main{
 public static void main(String[] args) {
   Scanner kbd =new Scanner(System.in);
   long a=kbd.nextLong();
   long v=kbd.nextLong();
   long b=kbd.nextLong();
   long w=kbd.nextLong();
   long t=kbd.nextLong();
   long A=a+v*t;
   long B=b+w*t;
   long C=a-v*t;
   long D=b-w*t;
   if(a<=b){
   if(A>=B){
      System.out.println("YES");
   }else{
      System.out.println("NO");
   }
 }
 if(a>b){
   if(C<=D){
   System.out.println("YES");
}else{
  System.out.println("NO");
}
 }
}
}

Measured memory_bytes: 35764
#include<bits/stdc++.h>
#define taskname "bichromestree"
#define int long long
using namespace std;

const int MOD = 1e9 + 7;
const int maxn = 1e3;
const int maxm = 2e3;

int lab[maxn + 10];
struct edge
{
    int u, v, w;
} e[maxm + 10];
int n, m, t;
int cnt[3], p[maxm + 10];

int findset(int u)
{
    return (lab[u] < 0)? u : lab[u] = findset(lab[u]);
}

void uni(int u, int v)
{
    if (lab[u] > lab[v]) swap(u, v);
    lab[u] += lab[v];
    lab[v] = u;
}

int type(int k)
{
    for (int i = 1; i <= n; ++i) lab[i] = -1;
    uni(e[k].u, e[k].v);
    int sum = e[k].w;
    for (int i = 1; i <= m; ++i)
    {
        int u = findset(e[i].u);
        int v = findset(e[i].v);
        if (u != v)
        {
            uni(u, v);
            sum += e[i].w;
        }
    }
    if (sum < t) return 0;
    if (sum == t) return 1;
    return 2;
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);	cout.tie(nullptr);
    if (ifstream("test.inp"))
    {
        freopen("test.inp", "r", stdin);
        #ifdef CHECKING
            freopen(taskname".out", "w", stdout);
        #else
            freopen("test.out", "w", stdout);
        #endif //CHECKING
    }
    else if (ifstream(taskname".inp"))
    {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }

    cin >> n >> m >> t;
    for (int i = 1; i <= m; ++i)
        cin >> e[i].u >> e[i].v >> e[i].w;
    sort(&e[1], &e[m] + 1, [](edge a, edge b){
             return a.w < b.w;
         });
    for (int i = 1; i <= m; ++i) ++cnt[type(i)];
    p[0] = 1;
    for (int i = 1; i <= m; ++i) p[i] = p[i - 1] * 2 % MOD;
    if (cnt[0]) cnt[0] = 1;
    if (!cnt[1])
    {
        cout << 0;
        return 0;
    }
    cout << (p[cnt[0]] * p[cnt[1]] - 2 + MOD) * p[cnt[2]] % MOD;
}


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

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

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

    long long sum = 0;
    long count = 0;
    for (int i = 1; i < N+1;i++) {
        count = count + i;
        for (int j = 1; j < N + 1; j++) {
            for (int k = 1; k < N + 1; k++) {
                sum = sum + gcd(gcd(i, j), k);
                //cout << i << ',' << j << ',' << k << endl;
            }
        }

    }


    cout << sum  << endl;
    //cout << sum - count*2 << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int n,k,ans=0;
  cin>>n>>k;
  if(n%k!=0){
    ans++;
  }
  cout<<ans<<"\n";
  return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>

using namespace std;

static const int MAX = 100000;

vector<int> G[MAX];
list<int> out;
bool V[MAX];
int N;

void dfs(int u) {
  V[u] = true;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (!V[v]) {
      dfs(v);
    }
  }
  out.push_front(u);
}

int main() {
  int s, t, M;

  cin >> N >> M;

  for (int i = 0; i < N; i++) {
    V[i] = false;
  }

  for (int i = 0; i < M; i++) {
    cin >> s >> t;
    G[s].push_back(t);
  }

  for (int i = 0; i < N; i++) {
    if (!V[i]) {
      dfs(i);
    }
  }

  for (list<int>::iterator it = out.begin(); it != out.end(); it++) {
    cout << *it << endl;
  }

  return 0;
}



Measured memory_bytes: 6220
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s,t;
  cin >> s >> t;
  bool ans = false;
  for(int i = 0;i<s.size();i++){
    if( s == t){
      ans = true;
      break;
    }
    char k = s.at(0);
    s.erase(s.begin()) ;
    s.push_back(k);
    
  }
  if( ans ){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int h,w,i,j,M=1e9+7,d[1010][1010]={1};
  char s[1010][1010]={};
  scanf("%d %d",&h,&w);
  for(i=0;i<h;i++)scanf("%s",s[i]);
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(s[i][j]-'.')d[i][j]=0;//printf("%d ",d[i][j]);
      d[i+1][j]=(d[i+1][j]+d[i][j])%M;
      d[i][j+1]=(d[i][j+1]+d[i][j])%M;
    }//printf("\n");
  }
  printf("%d\n",d[h-1][w-1]);
  return 0;
}


Measured memory_bytes: 5120
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <iomanip>
#include <cmath>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;

int main()
{
    // 整数の入力
    ll A,B;
    cin >> A >> B;

    cout << max(0LL,A - 2 * B) << endl;
    return 0;
}

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

using namespace std;

int main(){
	
	int n; cin >> n;
	int a[n];
	long long ans = 0;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		if(i == 0) continue;
		ans += max(- a[i] + a[i-1], 0);
		a[i] = max(a[i-1], a[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4276
#include <iostream>

using namespace std;

char c[2][3];

int main(void)
{
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < 3; j++){
			cin >> c[i][j];
		}
	}
	
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < 3; j++){
			if(c[i][j] != c[1-i][2-j]){
				cout << "NO" << endl;
				return 0;
			}
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std; 
typedef long long ll; 
int lst[10005], to[100005], pre[100005], rev[100005], tot; 
int dep[10005], fst[10005], que[10005]; 
ll cap[100005]; 
inline void add_edge(int u, int v, ll _cap)
{
	to[tot] = v; 
	pre[tot] = lst[u]; 
	cap[tot] = _cap; 
	rev[tot] = tot + 1; 
	lst[u] = tot++; 
	to[tot] = u; 
	pre[tot] = lst[v]; 
	cap[tot] = 0; 
	rev[tot] = tot - 1; 
	lst[v] = tot++; 
}
inline bool bfs(int s, int t)
{
	int he = 0, ta = 1; 
	que[0] = s; 
	memset(dep, -1, sizeof(dep)); 
	dep[s] = 0; 
	while (he < ta)
	{
		int u = que[he++]; 
		for (int i = lst[u]; ~i; i = pre[i])
		{
			if (cap[i] && dep[to[i]] == -1)
			{
				dep[to[i]] = dep[u] + 1; 
				que[ta++] = to[i]; 
			}
		}
	}
	return dep[t] != -1; 
}
ll dfs(int u, int t, ll mx)
{
	if (u == t)
		return mx; 
	ll ans = 0; 
	for (int i = fst[u]; ~i; i = pre[i])
	{
		if (cap[i] && dep[to[i]] == dep[u] + 1)
		{
			ll res = dfs(to[i], t, min(mx - ans, cap[i])); 
			cap[i] -= res; 
			cap[rev[i]] += res; 
			if (cap[i])
				fst[u] = i; 
			ans += res; 
			if (ans == mx)
				return ans;
		}
	}
	if (!ans)
		dep[u] = -1; 
	return ans; 
}
inline ll dinic(int s, int t)
{
	ll ans = 0; 
	while (bfs(s, t))
	{
		memcpy(fst, lst, sizeof(lst)); 
		ans += dfs(s, t, 1e18); 
	}
	return ans; 
}
int main()
{
	// freopen("ARC085-E.in", "r", stdin); 
	memset(lst, -1, sizeof(lst)); 
	int n; 
	scanf("%d", &n); 
	ll sum = 0; 
	for (int i = 1; i <= n; i++)
	{
		int x; 
		scanf("%d", &x); 
		if (x < 0)
			add_edge(0, i, -x); 
		else
		{
			sum += x; 
			add_edge(i, n + 1, x); 
		}
		for (int j = 1; j < i; j++)
		{
			if (!(i % j))
				add_edge(j, i, 1e18); 
		}
	}
	printf("%lld\n", sum - dinic(0, n + 1));
	return 0; 
}


Measured memory_bytes: 384
n = int(input())
a = list(map(int,input().split()))
box = [0]*n
box_list = []

for i in range(n-1,-1,-1):
    now = i+1
    if a[i] == 0:
        if sum(box[i+now::now])%2 == 1:
            box[i] = 1
            box_list.append(i)
    else:
        if sum(box[i+now::now])%2 == 0:
            box[i] = 1
            box_list.append(i)

print(len(box_list))
for i in box_list:
    print(i+1)

Measured memory_bytes: 13240
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>
#include <string>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;

#define rep(i, n) for(int i = 0; i < n ; i++ )
#define For(i, a, b) for(int i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

int main(void){
    int A, B;

    cin >> A >> B;
    
    if (B % A == 0) cout << A + B << endl;
    else cout << B - A << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    // https:// atcoder.jp/contests/abc101/tasks/abc101_b
    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        String input = scan.next();
        char[] inputCharArray = input.toCharArray();

        int sn = 0;
        for (int i = 0; i < inputCharArray.length; i++) {
            sn = sn + (int) Character.getNumericValue(inputCharArray[i]);
        }

        String answer = (double) Integer.parseInt(input) % sn == 0 ? "Yes" : "No";

        System.out.println(answer);

        scan.close();

    }

}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

long long gcd(long long a, long long b) { return b ? gcd(b, a%b) : a;}

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

    int k;
    cin >> k;
    ll ans = 0;
    for (int a = 1; a <= k; ++a) {
        for (int b = 1; b <= k; ++b) {
            for (int c = 1; c <= k; ++c) {
                int g = gcd(a, b);
                g = gcd(g, c);
                ans += g;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3584