akhauriyash/Code-Regression huggingface dataset:
/* include */
#include <bits/stdc++.h>

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

/* template */
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;
}

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) \
    sort(all(x));  \
    (x).erase(unique(all(x)), (x).end())
#define int long long
#define mp make_pair

/* function */
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

/* const */
const int inf = 1e9 + 7;
const int dxl[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dyl[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dxs[4] = {1, 0, -1, 0};
const int dys[4] = {0, 1, 0, -1};

/* main */
signed main(void)
{
    int n, tmp, sum = 0;
    cin >> n;
    tmp = n;
    while (n != 0)
    {
        sum += n % 10;
        n /= 10;
    }
    cout << ((tmp % sum == 0) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
from math import log, floor
L = int(input())
n = floor(log(L, 3))
l = [(L // (3**(n + 1 - i))) % 3 for i in range(1, n + 2)]
N = n + 2
uvws = [(i, i + 1, j * 3**(n + 1 - i)) 
                for i in range(2, n + 2)
                for j in range(3)] + \
             [(1, i, j * 3**(n + 2 - i)  + sum(l[k - 1] * 3**(n + 1 - k) for k in range(1, i - 1)))
                for i in range(2, n + 3)
                for j in range(l[i - 2])]
M = len(uvws)
print('{} {}'.format(N, M))
for uvw in uvws:
  print('{} {} {}'.format(*uvw))

Measured memory_bytes: 3316
n, m = gets.chomp.split(" ").map(&:to_i)

ans = 0
if n.times.to_a.length >= 2
  ans += n.times.to_a.combination(2).to_a.length
end
if m.times.to_a.length >= 2
  ans += m.times.to_a.combination(2).to_a.length
end
print "#{ans}\n"

Measured memory_bytes: 2172
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
  
  	if(input[0] >= 3200){
        console.log(input[1]);
    } else {
        console.log('red');
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  cout << setprecision(8);
  int no_of_input;
  cin >> no_of_input;
  if(no_of_input%2==1){
    cout << (double)((double)(no_of_input/2+1))/(double)no_of_input;
  }
  else{
    cout << 0.5;
  }
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;
import java.util.Arrays;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long h = sc.nextLong()/2;


    long count = 1;
    long k = 1;
    while (h > 0) {
      k *= 2;
      count += k;
      h /= 2;
    }

    System.out.println(count);


  }

}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    int res = 0;
    while (n >= 10) {
      auto s = to_string(n);
      int m = s.size(), mx = -1;
      for (int i = 1; i < m; ++i) {
        mx = max(mx, stoi(s.substr(0, i)) * stoi(s.substr(i)));
      }
      n = mx;
      ++res;
    }
    cout << res << '\n';
  }
}



Measured memory_bytes: 3292
#define N 100
#include<stdio.h>


int main(){
  /*スワップ数*/
int count=0;
int A[N];
 int i,j,n,temp;
 /*入力数*/
  scanf("%d",&n);
  /*配列格納*/
  for(i=0;i<n;i++)

    scanf("%d",&A[i]);
  /*Bubble Sort*/
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(A[j-1]>A[j]){
	temp=A[j-1];
	A[j-1]=A[j];
	A[j]=temp;
	count++;
      }}

  }
  /*カウント数と配列出力*/
  for(i=0;i<n-1;i++)
    printf("%d ",A[i]);
  printf("%d\n",A[n-1]);
  printf("%d\n",count);
  return 0;


}





Measured memory_bytes: 2728
#include <stdio.h>

int main(){
	int H,W,i,j;
	while(1){
		scanf("%d %d",&H,&W);
		if(H==0 && W==0)break;
		for(i=1;i<=H;i++){
			for(j=1;j<=W;j++){
				if(i%2==0){
					if(j%2==0){
						printf("#");
					}else{
						printf(".");
					}
				}else{
					if(j%2==0){
						printf(".");
					}else{
						printf("#");
					}
				}
			}
			puts("");
		}
		puts("");
	}
return 0;
}


Measured memory_bytes: 2052
import bisect
from collections import deque
N = int(input())

arr = deque([int(input())])
for _ in range(N-1):
    a = int(input())
    x = bisect.bisect_left(arr, a)
    if x == 0:
        arr.appendleft(a)
    else:
        arr[x-1] = a


print(len(arr))


Measured memory_bytes: 7284
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "YES" : "NO") << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))

//vector<string> split(string,string);

//template<typename T>
//void swap(T*,T*);
//char ToUpper (char cX) { return toupper(cX); }

int main()
{
    int N;
    cin >> N;
    int disc = N / 15;
    cout << N * 800 - disc * 200;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if(a == 1) a += 20;
  if(b == 1) b+= 20;
  if(a> b){
    cout << "Alice" << endl;
  }else if(b > a){
    cout << "Bob" << endl;
  }else {
    cout << "Draw" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

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

    char s[n];
    scanf("%s", s);

    int res = 1;
    for (int i = 0; i < n - 1; i++)
    {
        if (s[i] != s[i + 1])
        {
            res++;
        }
    }

    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 256
MOD = 10**9+7

n,a,b = map(int,input().split())

Sn = pow(2,n,MOD) - 1
a = min(a, n-a)
b = min(b, n-b)
if a > b:
    a,b = b,a
Xa, Xb = 1,1
Ya, Yb = 1,1
for i in range(b):
    if i < a:
        Xa = ( Xa * (n-i) ) % MOD
        Ya = ( Ya * pow((a-i),MOD-2, MOD)) % MOD
    Xb = ( Xb * (n-i) ) % MOD
    Yb = ( Yb * pow((b-i),MOD-2, MOD)) % MOD

ans = Sn - Xa*Ya % MOD - Xb*Yb % MOD
while ans < 0:
    ans += MOD
    
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	string s,ans="";
	cin>>s;
	rep(i,s.size()-8)ans+=s[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;

#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

ll n, k, m, M = 1e9 + 7;

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

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

    vl b(m);
    rep(i, m) cin >> b[i];

    vvl a(n, vl(m));
    rep(i, n) rep(j, m) cin >> a[i][j];

    int num = 0;
    rep(i, n) {
        int sum = 0;
        rep(j, m) sum += a[i][j] * b[j];
        if(sum + c > 0) num++;
    }

    cout << num << endl;
}

Measured memory_bytes: 3640
<?php
fscanf(STDIN,"%d%d",$n,$k);
fscanf(STDIN,"%d%d%d",$r,$s,$p);
fscanf(STDIN,"%s",$t);

$points['r'] = $p;
$points['s'] = $r;
$points['p'] = $s;
$sum = 0;
for($i=0;$i<$n;$i++){
  //echo "i k".$i-$k."\n";
//  echo $t[$i-$k];
  $index = $i-$k;
  if($index>=0 && $t[$i]==$t[$i-$k]){
    $t[$i] = '?';
  }else{
   /// echo $t[$i]." ".$t[$i-$k]."\n";
    $sum += $points[$t[$i]];
  }

}

//echo $t."\n";


echo $sum;
    

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

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

  const int A = 1e6+1;

  vector<int> a(n);
  vector<int> c(A);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    c.at(a.at(i))++;
  }

  bool pairwise = true;
  // ### 計算量
  //
  //     A
  // O(sigma(A/i))
  //    i=1
  //
  //         A
  // O(A * sigma(1/i))
  //        i=1
  //
  //         A
  // O(A * sigma(1/i))
  //        i=1
  //
  // 右辺が調和級数である
  // 右辺の数列を展開すると以下になる。
  //
  //   a = 1 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6 + 1/7 + 1/8 + ...
  //
  // これを上から押さえると a < b となる。
  //
  //   b = 1 + (1/2 + 1/2) + (1/4 + 1/4 + 1/4 + 1/4) + (1/8 + ...) + ...
  //
  // A = 16 と仮定すると a, b は以下となる
  //
  //   a = 1 + 1/2 + 1/3 + ... + 1/15 + 1/16
  //   b = 1 + (1/2 + 1/2) + ... (1/8 + ... + 1/8) + 1/16
  //     = 1 + 1 + 1 + 1 + 1/16
  //
  // これらより、a の計算量の最大値は log2(A) + 1/A より小さい
  //
  //   b = log2(A) + 1/A
  //   a < log2(A) + 1/A
  //
  // 最初の数列より
  //
  //         A
  // O(A * sigma(1/i))
  //        i=1
  //
  // = O(A * (log2(A) + 1/A))
  // = O(A log2(A) + 1)
  // = O(A log2(A))
  //
  for (int i = 2; i < A; i++) {
    int cnt = 0;
    // ### 例: A = { 6, 10, 15 } の場合
    //
    // * c[6] = 1
    // * c[10] = 1
    // * c[15] = 1
    //
    // 2〜A までの数について、倍数の登場回数をカウントする
    //
    // * i=2 の場合
    //   * cnt = 2 (6, 10)
    //   * つまり素因数として 2 を持つ数が、集合の中に2件以上存在する
    // * i=3 の場合
    //   * cnt = 2 (6, 15)
    // * i=5 の場合
    //   * cnt = 2 (10, 15)
    //
    for (int j = i; j < A; j=j+i) {
      cnt = cnt + c.at(j);
    }
    // ### cnt > 1 を満たすケース
    // i = 2 を例とすると gcd(6, 10) = 2 となる。
    //
    // 集合の中の 2 つ以上の数が、共通の素因数 p で構成されていると、
    // gcd(Ai, Aj) = p となり、gcd(Ai, Aj) = 1 が成立しない。
    //
    // そのため pairwise coprime ではない。
    if (cnt > 1) {
      pairwise = false;
    }
  }

  if (pairwise) {
    cout << "pairwise coprime" << endl;
    return 0;
  }

  // ### 例: A = { 6, 24, 15 } の場合
  //
  // g = 0
  //   g = gcd(0, 6) = 6
  // g = 6
  //   g = gcd(6, 24) = 6
  // g = 15
  //   g = gcd(6, 15) = 3
  //
  // 最終的に g = 3 となる
  //
  int g = 0;
  for (int i = 0; i < n; i++) {
    g = gcd(g, a.at(i));
  }
  if (g == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }

  cout << "not coprime" << endl;
  return 0;
}


Measured memory_bytes: 11020
#include <iostream>
#include <vector>
#include <queue>
#include <numeric>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> graph_base(n, vector<int>(n));
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    graph_base[a-1][b-1] = graph_base[b-1][a-1] = 1;
  }

  int ans = 0;

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (graph_base[i][j] == 0)
        continue;

      vector<vector<int>> graph = graph_base;
      graph[i][j] = 0;

      vector<int> vec(n, 0);
      queue<int> que;
      que.push(0);
      vec[0] = 1;

      while (not que.empty()) {
        int cur = que.front();
        que.pop();
        for (int k = 0; k < n; ++k)
          if (graph[cur][k] == 1 && vec[k] == 0) {
            que.push(k);
            vec[k] = 1;
          }
      }

      ans += accumulate(vec.begin(), vec.end(), 0) != n;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3640
using System;
using System.Collections;
using System.Collections.Generic;

class Program {
    static void Main (string[] args) {
        long N = long.Parse (Console.ReadLine ());
        N %= 1000;
        N = 1000 - N;
        if (N == 1000) {
            N = 0;
        }
        Console.WriteLine (N);
    }

}

//dotnet run --project test

Measured memory_bytes: 27528
H, W = map(int, input().split())

HW_list = []
for i in range(H):
    x = input()
    char_list = list(x)
    if "#" in char_list:
        HW_list.append(char_list)
    else:
        pass

i = 0
while True:
    count = 0
    for j in range(len(HW_list)):
        if HW_list[j][i] == ".":
            count += 1
        
    if count == len(HW_list):
        for j in range(len(HW_list)):
            del HW_list[j][i]

    else:
        i += 1
    if i > len(HW_list[0]) - 1:
        break
    
for j in range(len(HW_list)):
    print("".join(HW_list[j]))

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


void solve(long long A, long long B){
    if(A<10 and B<10) cout<<A*B;
    else cout<<-1;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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 {
	static Scanner sc = new java.util.Scanner(System.in);

	public static void main(String[] args) {
		String st = sc.nextLine();
		String[] str = st.split(" ");
		int[] num = new int[str.length];

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str.length; j++) {
				if (i != j) {
					if (str[i].equals(str[j])) {
						num[i]++;
					}
				}
			}
		}

		int maxf = 0;
		for (int i = 1; i < str.length; i++) {
			if (num[i] > num[maxf]) {
				maxf = i;
			}
		}

		int maxl = 0;
		for (int i = 1; i < str.length; i++) {
			if (str[i].length() > str[maxl].length()) {
				maxl = i;
			}
		}

		System.out.println(str[maxf] + " " + str[maxl]);

	}

}

Measured memory_bytes: 26016
#include <iostream>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <list>
#include <array>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <random>
#include <chrono>

#define PI 3.14159265359
#define mt make_tuple
#define mp make_pair
#define pii pair <int, int>
#define pll pair <long long, long long>
#define all(x) (x).begin(), (x).end()

//mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());

using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;
	vector <int> a(N + 5, 0);
	vector <int> b(N + 5, 0);
	for (int i = 1; i <= N; ++i)
		cin >> a[i];
	bool done = false;
	while (K-- > 0 && !done)
	{
		for (int i = 0; i <= N + 1; ++i)
			b[i] = 0;
		for (int i = 1; i <= N; ++i)
		{
			int left = max(1, i - a[i]);
			int right = min(N, i + a[i]);
			b[left] += 1;
			b[right + 1] -= 1;
		}
		for (int i = 1; i <= N; ++i)
		{
			b[i] += b[i - 1];
			a[i] = b[i];
		}
		int cnt = 0;
		for (int i = 1; i <= N; ++i)
			cnt += (a[i] == N);
		if (cnt == N)
			done = true;
	}
	for (int i = 1; i <= N; ++i)
		cout << a[i] << " ";
	return 0;
}



Measured memory_bytes: 4372
#include<iostream>

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

    int chair_space;
    int space_between_man;
    int man_space;

    std::cin >> chair_space >> man_space >> space_between_man;

    /** 初めのスペースは確定 **/
    chair_space -= space_between_man;

    /** 1人分の幅を算出 **/
    man_space = man_space + space_between_man;

    /** 残りスペースから座れる人数を算出 **/
    int answer = chair_space / man_space;
    std::cout << answer << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,x,y) for(ll i=x; i<=y; i++)
#define BIT(t) ((long long 1) << t)
#define PER(i,y,x) for(ll i=y; i>=x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
using namespace std;
typedef long long ll;

ll const MOD = 998244353;
ll mod_p(ll x, ll y) {
	   x %= MOD;
	   y %= MOD;
	   return (x + y + MOD) % MOD;
}

ll mod_m(ll x, ll y) {
	   x %= MOD;
	   y %= MOD;
	   return x * y%MOD;
}

ll mod_pow(ll x, ll t) {
	   x %= MOD;
	   if (t == 0) {
			   return 1;
	   }
	   else {
			   ll v = mod_pow(x, t / 2);
			   if (t % 2 == 0) {
					   return v * v % MOD;
			   }
			   else {
					   return v * v%MOD * x %MOD;
			   }
	   }
}

ll mod_inv(ll x) {
	   return mod_pow(x, MOD - 2);
}
ll const MAX = 3e5 + 5;
vll ball(MAX, 0);

int main(){
	ll n;
	cin >> n;
	string s;
	cin >> s;
	ll ans = 1; 
	REP(i,1,3*n){
		char c = s[i-1];
		if(c == 'R') ball[i] = 1;
		else if(c == 'G') ball[i] = 2;
		else ball[i] = 4;
	}	

	deque<pair<ll,ll>> dq;
	vll x(10, 0);
	x[0] = n;
	REP(i,1,3*n){
		PER(j,6,0){
			if((ball[i]&j)==0 && x[j] != 0){
				ans = mod_m(ans, x[j]);
				x[j]--;
				x[j^ball[i]]++;
				break;
			}
		}
	}
	cout << ans << endl;
}

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


void solve(long long N, long long A, long long B){
    cout << min((int)(N*A), (int)B) << endl;
}

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


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

const lli mod = 1000000007LL;

int main() {
  for(lli N, T; cin >> N >> T; ) {
    vector<lli> D(N);
    for(lli i = 0; i < N; ++i) cin >> D[i];
    sort(D.begin(), D.end());
    lli res = 1;
    for(lli i = 1, j = 0; i < N; ++i) {
      while(D[j] < D[i] - T) ++j;
      res = res * (i - j + 1) % mod;
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1796
#include <bits/stdc++.h>
using namespace std;
 
#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	long long N,b,swp = 0;
  cin >> N;
  vector<long long> x;
  vector<long long> y;
  vector<long long> result;
  froop1(0,N){
    cin >> b;
    if(i % 2 == 0){
      x.push_back(b);
    }else{
      y.push_back(b);
    }
  }
  for(int i = x.size() - 1;i >= 0;i--) result.push_back(x.at(i));
    for(int i = 0;i < y.size();i++) result.push_back(y.at(i));
  if(N % 2 != 0){
  froop1(0,N){
    cout << result.at(i);
    if(i != N - 1) cout << " ";
      else         cout << endl;
   }
  }else{
      for(int i = N - 1;i >= 0;i--){
    cout << result.at(i);
    if(i != 0) cout << " ";
      else         cout << endl;
   }
  }
  return 0;
}

Measured memory_bytes: 5480
import java.util.*;

public class Main {
	
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		for (int i = 0; i < s.length() - 1; i++) {
			if (s.charAt(i) == s.charAt(i + 1)) {
				System.out.println((i + 1) + " " + (i + 2));
				return;
			}
		}
		for (int i = 0; i < s.length() - 2; i++) {
			if (s.charAt(i) == s.charAt(i + 2)) {
				System.out.println((i + 1) + " " + (i + 3));
				return;
			}
		}
		System.out.println(-1 + " " + (-1));
	}
}


Measured memory_bytes: 23380
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

typedef struct queue
{
  char a;
  struct queue *next;
} queue;

typedef struct Queue
{
  queue *front;
  queue *back;
  int size;
} Queue;

Queue *Queue_init()
{
  Queue *Q = (Queue *)malloc(sizeof(Queue));
  Q->front = NULL;
  Q->back = NULL;
  Q->size = 0;
  return Q;
}

queue *queue_create(char a)
{
  queue *q = (queue *)malloc(sizeof(queue));
  q->a = a;
  q->next = NULL;
  return q;
}

void queue_free(queue *q)
{
  if (q != NULL)
    free(q);
}

bool Queue_empty(Queue *Q)
{
  if (Q->size == 0)
    return true;
  return false;
}

void Queue_free(Queue *Q)
{
  if (Q != NULL)
  {
    if (Queue_empty(Q))
      free(Q);
    else
      printf("queue isn't empty.\n");
  }
  return;
}

queue *Queue_back(Queue *Q)
{
  return Q->back;
}

queue *Queue_front(Queue *Q)
{
  return Q->front;
}

void Queue_pop(Queue *Q)
{
  if (Queue_empty(Q))
    return ;
  queue *qf = Q->front;
  Q->front = qf->next;
  Q->size--;
  queue_free(qf);
  return ;
}

void Queue_push(Queue *Q, char a)
{
  queue *aq = queue_create(a);
  if (Queue_empty(Q))
  {
    Q->front = aq;
    Q->back = aq;
    Q->size++;
    return;
  }
  queue *bq = Queue_back(Q);
  bq->next = aq;
  Q->back = aq;
  Q->size++;
  return;
}

void Queue_stack(Queue *Q, char a)
{
  queue *aq = queue_create(a);
  aq->next = Q->front;
  Q->front = aq;
  Q->size++;
  return;
}

int Queue_size(Queue *Q)
{
  return Q->size;
}

int main() {
  char s[100005];
  scanf("%s", s);
  int n = strlen(s);
  Queue *Q = Queue_init();
  for (int i=0; i<n; i++)
    Queue_push(Q, s[i]);
  int q;
  scanf("%d", &q);
  bool inverse = false;
  int t, f;
  char c;
  for (int i=0; i<q; i++) {
    scanf("%d", &t);
    if (t == 1)
      inverse = (inverse) ? false : true;
    else {
      scanf("%d %c", &f, &c);
      if (inverse) {
        if (f == 1)
          Queue_push(Q, c);
        else
          Queue_stack(Q, c);
      } else {
        if (f != 1)
          Queue_push(Q, c);
        else
          Queue_stack(Q, c);
      }
    }
  }
  int size = Queue_size(Q);
  char ans[size+1];
  ans[size] = '\n';
  if (inverse) {
    for (int i=0; i<size; i++) {
      queue *Qf = Queue_front(Q);
      ans[size-i-1] = Qf->a;
      Queue_pop(Q);
    }
  } else {
    for (int i=0; i<size; i++) {
      queue *Qf = Queue_front(Q);
      ans[i] = Qf->a;
      Queue_pop(Q);
    }
  }
  Queue_free(Q);
  for (int i=0; i<size; i++) {
    printf("%c", ans[i]);
  }
  printf("\n");
  //printf("%s", ans);
  return 0;
}


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

int main(void){
    string s;
    cin >> s;
    ll n = s.size();
    vector<ll> h(n+1);
    rep(i,n){
        if (s[i] == '<') {
            h[i+1] = h[i] + 1;
        } else {
            h[i+1] = 0;
        }
    }
    rep(j,n){
        int i = n-1-j;
        if (s[i] == '>') {
            h[i] = max(h[i+1] + 1, h[i]);
        }
    }
    ll sum = 0;
    rep(i,n+1){
        sum += h[i];
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 4740
# Guidebook https://atcoder.jp/contests/abc128/tasks/abc128_b

N = int(input())

P = [[0 for i in range(3)] for j in range(N)]

for i in range(N):
    P[i][0],P[i][1]  = input().split()
    P[i][1] = 100 - int(P[i][1])
    P[i][2] = i + 1

P.sort()

for i in range(N):
    print(P[i][2])


Measured memory_bytes: 3060
import numpy as np
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
A=(a+9)//10*10
B=(b+9)//10*10
C=(c+9)//10*10
D=(d+9)//10*10
E=(e+9)//10*10
F=max(A-a,B-b,C-c,D-d,E-e)
print(A+B+C+D+E-F)

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

int main() {
  // 標準入力が早くなる。Cスタイルの入出力とC++スタイルの入出力を混合させてはならない。
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int N;
  string S;
  cin >> N >> S;

  long r = 0;
  long g = 0;
  long b = 0;

  for (int i = 0; i < N; i++) {
    /* code */
    if (S[i] == 'R') {
      ++r;
    } else if (S[i] == 'G') {
      ++g;
    } else {
      ++b;
    }
  }

  long long all = r * g * b;

  long long rem = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      int k = j * 2 - i;
      if (S[i] == S[j] || S[i] == S[k] || S[j] == S[k] || k >= N) {
        continue;
      }
      ++rem;
    }
  }

  cout << all - rem << endl;

  return 0;
}


Measured memory_bytes: 3664
import numpy as np
import sys

N = int(input())
if N == 1:
    print(0)
    sys.exit()

d = int(N ** .5)

def eratosthenes(N):
	is_prime = [True] * (N + 1)
	is_prime[0], is_prime[1] = False, False
	for i in range(2, int(N**(1/2)) + 1):
		if is_prime[i]:
			for j in range(i * 2, N + 1, i):
				is_prime[j] = False
	return [i for i in range(N+1) if is_prime[i]]

p_num = eratosthenes(d+1)
MAX_p = p_num[-1]
ans = 0
used = []
for p in p_num:
    t_p = p
    while N % p == 0:
        N //= p
        ans += 1
        p *= t_p
    while N % t_p == 0:
        N //= t_p

if N > MAX_p:
    dd = int(N ** .5)
    cond = 1
    for i in range(2, dd+1):
        if N % i == 0:
            cond = 0
            break
    if cond:
        ans += 1
    
print(ans)

Measured memory_bytes: 37952
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>S;
    bool yes = true, C = false;
    if(S[0] != 'A') yes = false;
    reps(i,2,S.size() - 1) C |= S[i] == 'C';
    N = 0;
    reps(i,1,S.size()) N += S[i] - 'a' < 0;
    cout<<(yes&&C&&(N == 1) ? "AC" : "WA")<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
using namespace std;

int main(){
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int x3, y3, x4, y4;
    int dx = x2 - x1;
    int dy = y2 - y1;
    x3 = x2 - dy;
    y3 = y2 + dx;
    x4 = x3 - dx;
    y4 = y3 - dy;
    printf("%d %d %d %d\n", x3, y3, x4, y4);
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000009)
	sc.Split(bufio.ScanWords)

	a, p := oneInt(), oneInt()

	fragment := a * 3
	fmt.Println((fragment + p) / 2)
}

func oneInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

func scanNums(len int) (nums []int) {
	for i := 0; i < len; i++ {
		nums = append(nums, oneInt())
	}
	return nums
}

func scanStrings(len int) (strs []string) {
	for i := 0; i < len; i++ {
		strs = append(strs, oneStr())
	}
	return strs
}

func abs(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

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

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}

func cumSum(nums []int) []int {
	sums := []int{0}

	for i := 0; i < len(nums); i++ {
		sums = append(sums, sums[i]+nums[i])
	}
	return sums
}


Measured memory_bytes: 640
import numpy as np
import fractions as fra

def che(s):
    n=len(s)
    if(n%2==1):return 0
    for i in range(n//2):
        if(s[i]!=s[i+n//2]):
            return 0
    return 1

s=input()
ans=0
for i in range(len(s)):
    for j in range(i,len(s)):
        if(i==0 and j==len(s)-1):
            continue
        if(che(s[i:j+1])):
            ans=max(ans,j+1-i)

print(ans)

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

using namespace std;

int main() {

  set<int> se;
  
  
  int n;
  cin>>n;  int a;
  
  while(n--){
  
    cin>>a;
    
    if(se.count(a)){
    se.erase(a);
    }
    
  else {se.insert(a);}
  
  
  }
  cout<<se.size();



}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


bool found;

bool check(vector<string>&s) {
  int H = s.size();
  int W = s[0].size();
  vector<string> t(W, string(H, '.')), r(W);
  REP(h, H) REP(w, W) t[w][h] = s[h][w];
  REP(w, W) {
    r[w] = t[w];
    reverse(ALL(r[w]));
  }

  int done = 0;
  int alone = 0;
  REP(w, W) if ((done >> w & 1) == 0) {
    bool ok = false;
    for (int w2 = w + 1; w2 < W; w2++) if ((done >> w2 & 1) == 0) {
      if (t[w] == r[w2]) {
        done |= (1 << w);
        done |= (1 << w2);
        ok = true;
        break;
      }
    }
    if (!ok) {
      if (W % 2 == 0) return false;
      if (alone >= 1) return false;
      if (t[w] != r[w]) return false;
      alone++;
      done |= (1 << w);
    }
  }
  return true;
}

void dfs(vector<string> hist, const vector<string> &s, const vector<string>& bin, int d, int used) {
  if (found) return;
  int H = (int)s.size();
  if (d >= (H+1)/2) {
    if (check(hist)) {
      found = true;
    }
    return;
  }

  if (d == H - d - 1) {
    for (int i = 0; i < H; i++) if (!(used >> i & 1)) {
      hist[d] = s[i];
      dfs(hist, s, bin, d+1, used | (1 << i));
    }
  } else {

    for (int i = 0; i < H; i++) if (!(used >> i & 1)) {
      for (int j = i + 1; j < H; j++) if (i != j && !(used >> j & 1)) {
        if (bin[i] == bin[j]) {
          hist[d] = s[i];
          hist[H - d - 1] = s[j];
          dfs(hist, s, bin, d+1, used | (1 << i) | (1 << j));
        }
      }
    }

  }
}

int main2() {
  int H, W; cin >> H >> W;
  vector<string> s, bin;
  REP(i, H) {
    string line; cin >> line;
    s.push_back(line);
  }
  REP(i, H) {
    bin.push_back(s[i]);
    sort(ALL(bin[i]));
  }

  found = false;
  dfs(vector<string>(H), s, bin, 0, 0);

  cout << (found ? "YES":"NO") << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

using namespace std;

#define debug(x,y) cout<<(#x)<<" " <<(#y)<<" is " << (x) <<" "<< (y) << endl
#define watch(x) cout<<(#x)<<" is " << (x) << endl
#define fast ios_base::sync_with_stdio(false)
#define fie(i,a,b) for(i=a;i<b;i++)
#define MOD 1000000007
#define mod 998244353
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ll long long
#define lld long long int
#define ALL(x) (x).begin(),(x).end()

typedef vector<lld> vi;
typedef vector<vector<lld>> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<pair<lld, lld>> vpi;
typedef long long LL;

int main() {
  fast;
  cin.tie(0);
/*#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w" , stdout);
#endif*/
  lld a, b, c, k;
  cin >> a >> b >> c >> k;
  lld sum = 0;
  if (k >= a) {
    sum += a;
    k -= a;
    if (k >= b && k > 0) {
      k -= b;
    }
    else {
      k = 0;
    }
    if (k > 0) {
      sum -= k;
    }
  }
  else {
    sum = k;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3612
import java.util.*;
public class Main {
	static int N, num[];
	static double dp[][][];
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		num = new int[3]; //要素番号＋１個の寿司が乗った皿の数
		for(int i=0;i<N;i++) {
			int a = sc.nextInt()-1;
			num[a]++;
		}
 		sc.close();
 		
 		dp = new double[N+1][N+1][N+1];//dp[i][j][k]:= 3貫の皿i枚, 2:j枚,1:k枚の状態から食べ終わるまでの期待回数
 		for(int i=0;i<N+1;i++) {
 			for(int j=0;j<N+1;j++) {
 				for(int k=0;k<N+1;k++) {
 					dp[i][j][k]=-1;
 				}
 			}
 		}

 		double ans = rec(num[2],num[1],num[0]);
 		System.out.println(ans);
	}
	static double rec(int i, int j,int k) {
		if(i==0&&j==0&&k==0)return 0;
		if(dp[i][j][k]!=-1)return dp[i][j][k];
		double ret = 0;
		if(i-1>=0)ret += (double)i * rec(i-1,j+1,k);
		if(j-1>=0)ret += (double)j * rec(i,j-1,k+1); 
		if(k-1>=0)ret += (double)k * rec(i,j,k-1);
		ret += (double)N;
		ret /= (i+j+k);
		return dp[i][j][k] = ret;
	}
	
}


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

int main(int argc, const char * argv[]) {
    
    int K = 0;
    ll sum = 0;
    
    cin >> K;
 
    rep(a, K){
        rep(b, K){
            rep(c, K){
              sum += gcd(a, gcd(b, c));
            }
        }
    }
        
    cout << sum;
    
    return 0;

    
}

Measured memory_bytes: 3632
from typing import List


class RollingHash:
    __slots__ = ["source", "length", "base", "mod", "hash", "power"]

    def __init__(self, source: str, base: int = 1007, mod: int = 10 ** 9 + 7):
        self.source = source
        self.length = len(source)
        self.base = base
        self.mod = mod
        self.hash = self._get_hash_from_zero()
        self.power = self._get_base_pow()

    def _get_hash_from_zero(self) -> List[int]:
        """Compute hash of interval [0, right)."""
        cur, hash_from_zero = 0, [0]
        for e in self.source:
            cur = (cur * self.base + ord(e)) % self.mod
            hash_from_zero.append(cur)
        return hash_from_zero

    def _get_base_pow(self) -> List[int]:
        """Compute mod of power of base."""
        cur, power = 1, [1]
        for i in range(self.length):
            cur *= self.base % self.mod
            power.append(cur)
        return power

    def get_hash(self, left: int, right: int):
        """Compute hash of interval [left, right)."""
        return (
            self.hash[right] - self.hash[left] * self.power[right - left]
        ) % self.mod


def abc141_e():
    # https://atcoder.jp/contests/abc141/tasks/abc141_e
    N = int(input())
    S = input().rstrip()
    rh = RollingHash(S)
    ok, ng = 0, N // 2 + 1
    while ng - ok > 1:
        mid = (ok + ng) // 2
        flg, memo = 0, set()
        for i in range(N - 2 * mid + 1):
            memo.add(rh.get_hash(i, i + mid))
            if rh.get_hash(i + mid, i + 2 * mid) in memo:
                flg = 1
                break
        if flg:
            ok = mid  # next mid will be longer
        else:
            ng = mid  # next mid will be shorter
    print(ok)  # max length of substrings appeared twice or more


if __name__ == "__main__":
    abc141_e()


Measured memory_bytes: 27348
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <numeric>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <string>

using namespace std;

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define vec_all(vec) vec.begin(), vec.end()

struct UnionFind
{
    vector<int> parent;
    // 葉からの高さ
    vector<int> rank;

    UnionFind(int n)
    {
        parent = vector<int>(n);
        rank = vector<int>(n);
        rep(i, n)
        {
            parent[i] = i;
            rank[i] = 0;
        }
    }

    int root(int index)
    {
        if (parent[index] == index)
        {
            return index;
        }
        else
        {
            return root(parent[index]);
        }
    }

    void unite(int a, int b)
    {
        int a_root = root(a);
        int b_root = root(b);
        if (rank[a_root] < rank[b_root])
        {
            parent[a_root] = b_root;
        }
        else if (rank[a_root] > rank[b_root])
        {
            parent[b_root] = a_root;
        }
        else
        {
            parent[a_root] = b_root;
            rank[b_root]++;
        }
    }

    bool same_root(int a, int b)
    {
        return root(a) == root(b);
    }
};

// vectorデバッグ
template <typename T>
void dump_vec(vector<T> vec)
{
    rep(i, vec.size())
    {
        cout << vec[i] << endl;
    }
}

int main()
{
    int n, k, l;
    cin >> n >> k >> l;

    UnionFind road_map(n);
    UnionFind train_map(n);

    int start;
    int end;
    rep(i, k) {
        cin >> start >> end;
        road_map.unite(start - 1, end - 1);        
    }
    rep(i, l) {
        cin >> start >> end;
        train_map.unite(start - 1, end - 1);
    }

    int road_root;
    int train_root;
    string key;
    map<string, int> child_count;
    rep(i, n) {
        road_root = road_map.root(i);
        train_root = train_map.root(i);
        key = to_string(road_root) + "-" + to_string(train_root);
        child_count[key]++;
    }

    rep(i, n) {
        road_root = road_map.root(i);
        train_root = train_map.root(i);
        key = to_string(road_root) + "-" + to_string(train_root);
        cout << child_count[key] << " ";
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 26496
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
#define REP(i, d, n) for(int i=(d); i<(n); i++)
typedef long long ll;
const int mod = 1e9 + 7;

ll f(vector<int> &x, int n, int &base){
    int left = 0, right = n-1, mid;
    while(left < right){
        mid = (left + right) / 2;
        if(x[mid] == base){
            break;
        }
        else if(x[mid] < base){
            left = mid  + 1;
        }
        else{
            right = mid - 1;
        }
    }
    base = x[left];
    return (ll) (n - mid);
}

int main() {

    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];

    sort(a.begin(), a.end());
    sort(c.begin(), c.end());

    ll ans = 0;
    rep(i, n){
        int base = b[i];
        ll an = lower_bound(a.begin(), a.end(), base) - a.begin();
        ll cn = c.end() - upper_bound(c.begin(), c.end(), base);
        ans += an * cn;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

void yes(){
   cout<<"Yes"<<endl;
   //exit (0);
}
void no(){
   cout<<"No"<<endl;
   //exit (0);   
}

int n, a[N];
string s, t;

int32_t main(){_
   
   int a, b, c;
   cin >> a >> b >> c;

   cout<<c<<" "<<a<<" "<<b;

   return 0;
}

Measured memory_bytes: 256
N = gets.to_i
S = gets.chomp
westing = 0
W = S.chars.map{ |a|
  w = westing
  westing += a == "W" ? 1 : 0
  w
} + [westing]

E = N - W[-1]
p S.chars.map.with_index{ |a,i|
  E - (i+1) + W[i+1] + W[i]
}.min

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

int cal(int p, int x){
    return p*(100+x)/100;
}

int main() {
    int x,y,s;
    while(cin>>x>>y>>s, x&&y&&s){
        int ans=0;
        for(int i = 1; i <= s;i++){
            for(int j = 1; j <= s;j++){
                if(cal(i,x) + cal(j,x) == s) ans = max(cal(i,y)+cal(j,y), ans);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3032
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    if sum(A) < sum(B):
        print(-1)
        return

    ans = 0
    up = []
    sum_shortage = 0
    for i in range(N):
        if A[i] < B[i]:
            sum_shortage += B[i] - A[i]
            ans += 1
        if A[i] > B[i]:
            up.append(A[i] - B[i])

    for val in sorted(up, reverse=True):
        if sum_shortage > 0:
            sum_shortage -= val
            ans += 1
            
        if sum_shortage <= 0:
            break

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 19256
#include<bits/stdc++.h>
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))  
#define lli long long int
#define ll long long 
#define ld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second 
#define LB lower_bound
#define UB upper_bound
#define BS binary_search
#define pii pair<lli,lli>
const long long int mod=1000000007;
//const long long int mod=998244353;
const long double PI=3.141592653589793;
const long long int inf=1e18;
const long long int inf2=LLONG_MAX;
#define setBitCount(x) __builtin_popcountll(x)
#define all(a) (a).begin(), (a).end()
#define all_r(a) (a).rbegin(), (a).rend()
lli gcd(lli a,lli b)
{
    if(b==0)
    return a;
    else
    return gcd(b,a%b);
}
// calculating (x^y)%p
lli power(lli x,lli y,lli p)
{
    lli res = 1;      
    x = x % p;  
    while (y > 0)
    {
        if (y & 1) //y is odd  
        res = (res*x) % p;
        y = y>>1; 
        x = ( (x%p)*(x%p) )% p;  
    }
    return res%p;
}
// calculating modular inverse using fermat little theorem
lli modInverse(lli n,lli p) 
{
    return power(n, p-2, p)%p;
}

// policy based data structures !!
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update>
// s.order_of_key (k) : Number of items strictly smaller than k
// *(s.find_by_order(k)) : K-th element in a set (counting from zero)

void solve()
{
   lli r,c;
   cin>>r>>c;
   
   char a[r+5][c+5];
   for(lli i=1;i<=r;i++)
   for(lli j=1;j<=c;j++)
   cin>>a[i][j];
   
   lli dp[r+5][c+5];
   dp[1][1]=1;
   for(lli i=2;i<=c;i++)
   {
      if(a[1][i]=='#' || dp[1][i-1]==0)
      dp[1][i]=0;
      else
      dp[1][i]=1;
   }
   for(lli i=2;i<=r;i++)
   {
      if(a[i][1]=='#' || dp[i-1][1]==0)
      dp[i][1]=0;
      else
      dp[i][1]=1;
   }
   for(lli i=2;i<=r;i++)
   {
      for(lli j=2;j<=c;j++)
      {
         if(a[i][j]=='#')
         dp[i][j]=0;
         else
         dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
      }
   }
   
   cout<<dp[r][c];
}
int main()
{
   
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    lli T;
    //cin>>T;
    T=1;
    while(T--)
    {
        solve();
    }




    return 0;
}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
/*--------------------template--------------------*/

int main() {
    ll N;
    cin >> N;
    if (N <= 999) cout << "ABC" << endl;
    else cout << "ABD" << endl;
    return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>v(n); for(auto&i:v)cin>>i;
	int cnt=0;
	for(int i=0;i<n;++i){
		for(int j=n-2;j>=i;--j){
			if(v.at(j)>v.at(j+1)){
				int tmp=v.at(j);
				v.at(j)=v.at(j+1);
				v.at(j+1)=tmp;
				++cnt;
			}
		}
	}
	for(int i=0;i<n;++i){
		cout<<v.at(i);
		if(i!=n-1)cout<<" "s;
		else cout<<"\n"s<<cnt<<"\n"s;
	}
}


Measured memory_bytes: 3208
package main

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

var (
	H, N, sum int
	a         []int
	line      string
	word      string
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	H, _ = strconv.Atoi(scanner.Text())
	scanner.Scan()
	N, _ = strconv.Atoi(scanner.Text())
	a = make([]int, N)
	for i := 0; i < N; i++ {
		scanner.Scan()
		a[i], _ = strconv.Atoi(scanner.Text())
	}
	for _, v := range a {
		sum += v
	}
	if H > sum {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}

Measured memory_bytes: 1920
#include <set>
#include <cstdio>
using namespace std;

char s[1000000 + 10];

int cnt[3];
char m[128];

int main(){
  scanf("%s", s);
  m['J'] = 0; m['O'] = 1; m['I'] = 2;

  int k = 0;
  for(char *c = s; *c; c++){
    int i = m[*c];

    if(i == 0 && cnt[1] + cnt[2])
      cnt[0] = cnt[1] = cnt[2] = 0;
    if(i == 1 && cnt[2])
      cnt[0] = cnt[1] = cnt[2] = 0;

    cnt[i]++;

    if(i == 2 && cnt[0] >= cnt[1] && cnt[2] >= cnt[1])
      k = max(k, cnt[1]);
  }

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

  return 0;
}

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

int main()
{
	long long N,M,a,b;
	cin>>N>>M;
	vector<pair<long long,long long> > v;
	for(int i=0;i<N;i++)
	{
		cin>>a>>b;
		v.push_back(make_pair(a,b));
	}
	sort(v.begin(),v.end());
	long long ans = 0;
	int j=0;
	while(M)
	{
		a = v[j].first;
		b = v[j].second;
		if(b<M)
		{
			M-=b;
			ans+=(a*b);
		}
		else
		{
			ans+=(a*M);
			M=0;
		}
		j++;
	}
	cout<<ans<<endl;
	return 0;
}

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

int N;
string S;

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

    if (N % 2 == 0) {
        bool f = true;
        for (int i = 0; i < N/2; i++) {
            if (S[i] != S[N/2 + i]) {
                f = false;
                break;
            }
        }

        cout << (f ? "Yes" : "No") << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int x[300006];
int y[300006];
int a[300006];
int b[300006];
int main () {
    int h, w, m;
    cin >> h >> w >> m;
    for (int i=0; i<m; i++) {
        int c, d;
        cin >> c >> d;
        x[c]++;
        y[d]++;
        a[i]=c;
        b[i]=d;
    }
    int mxx=0, mxy=0;
    for (int i=0; i<=300000; i++) {
        mxx=max(mxx, x[i]);
        mxy=max(mxy, y[i]);
    }
    int xn=0, yn=0;
    for (int i=0; i<=300000; i++) {
        if (x[i]==mxx) {
            xn++;
        }
        if (y[i]==mxy) {
            yn++;
        }
    }
    int sum=0;
    for (int i=0; i<m; i++) {
        if (x[a[i]]==mxx && y[b[i]]==mxy) {
            sum++;
        }
    }
    if (sum==xn*yn) {
        cout << mxx+mxy-1 << endl;
    }
    else {
        cout << mxx+mxy << endl;
    }
}

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

#define INF 100000000

int d[201][201];
int r[8], a[8];
bool v[8];
int ans;

void dfs(int n, int cur, int pas, int dis)
{
    if (cur == n) {
        if (ans > dis) ans = dis;
        return;
    }
    for (int i = 0; i < n; i++) {
        if (!v[i]) {
            v[i] = true;
            if (pas == -1) dfs(n, cur + 1, i, 0);
            else dfs(n, cur + 1, i, dis + d[r[pas]][r[i]]);
            v[i] = false;
        }
    }
}

int main(void)
{
    int N, M, R;
    scanf("%d%d%d", &N, &M, &R);
    for (int i = 1; i <= N; i++)
        for (int j = 1; j <= N; j++)
            if (i != j) d[i][j] = d[j][i] = INF;
    for (int i = 0; i < R; i++) scanf("%d", &r[i]);
    for (int i = 0; i < M; i++) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        d[a][b] = d[b][a] = c;
    }
    for (int k = 1; k <= N; k++)
        for (int i = 1; i <= N; i++)
            for (int j = 1; j <= N; j++)
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    ans = INF;
    dfs(R, 0, -1, 0);
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 384