akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
typedef long long ll;

ll abs(ll a) {
  return a > 0 ? a : -a;
}

int main(void) {
  ll i, j, k, n, a, b, ans = 10e15;
  scanf("%lld%lld%lld", &a, &b, &n);
  for(i = 1; i <= n; ++i) if(!(b % i))for(j = 1; j <= n; ++j) if(abs(b / i * j - a) < ans) ans = abs(b / i * j - a);
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 2732
N,K = gets.split.map(&:to_i)
LR = K.times.map{ gets.split.map(&:to_i) }
M = 998244353

D = [0]*N
d,D[0],D[1] = 0,1,-1
(0..N-1).each{|i|
	d = (d + D[i]) % M
	LR.each{|l,r|
		next unless i+l < N
		D[i+l] = (D[i+l] + d) % M
		next unless i+r+1 < N
		D[i+r+1] = (D[i+r+1] - d) % M
	}
}
p d


Measured memory_bytes: 15976
/**************************
*                         *
*  Nothing Is Impossible  *
*                         *
**************************/
#include <algorithm>
#include <pthread.h>
#include <iostream>
#include <fstream>
#include <ctype.h>
#include <string>
#include <vector>
#include <thread>
#include <math.h>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <set>
#include <map>
#define GetRand(Min, Max) ((rand()%(int)(((Max) + 1)-(Min))) + (Min))
#define Rep(i, min, max) for(int i = min; i < max; ++i)
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef long double ld;
using namespace std;

void Solve(){
	int m,n;	cin >> m >> n;
	int arr[n];
	Rep(i,0,n){
		cin >> arr[i];
	}
	int ans = 0;
	Rep(i,1,n){
		ans = max(ans,arr[i]-arr[i-1]);
	}
	ans = max(ans,arr[0]+(m-arr[n-1]));
	cout << m-ans << endl;
}

int main(){
	ios::sync_with_stdio(NULL);
	cin.tie(NULL); cout.tie(NULL);
	Solve();
	return 0;
}

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

int main() {
    string s1, s2;
    cin >> s1 >> s2;
    string r1 = s1;
    reverse(r1.begin(), r1.end());
    string r2 = s2;
    reverse(r2.begin(), r2.end());
    
    if (s1 == r2 && s2 == r1) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

#include<bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
//#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
// mp::cpp_int
#define pp pair<pii,pii>
const int hell =1000000007;



int power(int a,int b)
{
  if(b==0)return 1;
  if(b==1)return a;
  int t=power(a,b/2);
  t%=hell;
  t*=t;
  t%=hell;
  if(b%2)return (t*a)%hell;
  else
     return t;
}

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

int digitsum(int x)
{
  while(x>9)
    {  int ans=0;
       while(x!=0)
       {
        ans+=x%10;
        x/=10;
       }
       x=ans;
    }
    return x;
}

int pw(int a,int b)
{
  int x=a;
  rep(i,1,b){a=a*x;}
  return a;
}

int lcs[3001][3001];


string a,b;
int LCS(int n,int m)
{
    if(n==0||m==0)return 0;
    if(lcs[n][m])return lcs[n][m];
       int t;
    if(a[n-1]==b[m-1])
    {
       
       t=LCS(n-1,m-1)+1;
        
    }
    else
      t = max(LCS(n-1,m),LCS(n,m-1));
      lcs[n][m]=t;
      return t;
}

int solve( ){


cin>>a>>b;
int n=a.size();
int m=b.size();
memset(lcs,0,sizeof(lcs));



lcs[0][0]=0;
for(int i=1;i<=n;i++)
{ 

  for(int j=1;j<=m;j++)
  {
    if(a[i-1]==b[j-1])
    {
      lcs[i][j]=1+lcs[i-1][j-1];
    }
    else
    {
      lcs[i][j]=max(lcs[i][j-1],lcs[i-1][j]);
    }
  }

}

int i=n,j=m;
string ans="";
while(i>0&&j>0)
{ 
  if(a[i-1]==b[j-1]){ans+=a[i-1];//cout<<a[i-1]<<endl;
    i--;j--;continue;}
   if(lcs[i-1][j]>lcs[i][j-1])
   {
    i--;
   }
   else
    j--;

}
reverse(all(ans));
cout<<ans;

return 0;
}

signed main()
{  int t=1;
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cin.exceptions(cin.failbit);

 

  clock_t time_req;

    // Without using pow function
    time_req = clock();
    
//cin>>t;

    int k=1;
   while(t--)
     {
       //cout<<"case #"<<k<<":"<<" ";k++;
      solve();
     }

         time_req = clock() - time_req;
    //cout <<endl<< "Processor time taken is "
      //<< (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;


    return 0;
}

Measured memory_bytes: 70656
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) FOR(i, 0, n)

const int MaxN = 300, MaxM = 300;
const int Mod = (int)1e9 + 7;
int N, M;
int dp[MaxN + 1][MaxN + 1][MaxN + 1];
vector<pair<int, int>> Q[MaxN + 1];

bool OK(int a, int b, int c, int last) {
	for (auto q : Q[last]) {
		int cnt = (a >= q.first && a <= last) + (b >= q.first && b <= last) + (c >= q.first && c <= last);
		if (cnt != q.second) return false;
	}
	return true;
}

void solve() {
	dp[0][0][0] = 1;
	int ans = 0, val;
	rep(a, N + 1) rep(b, N + 1) rep(c, N + 1) if ((val = dp[a][b][c]) > 0) {
		int last = max(a, max(b, c));
		if (!OK(a, b, c, last)) continue;
		if (last == N) { (ans += val) %= Mod; continue; }
		(dp[last + 1][b][c] += val) %= Mod;
		(dp[a][last + 1][c] += val) %= Mod;
		(dp[a][b][last + 1] += val) %= Mod;
	}
	cout << ans << endl;
}

int main() {
	cin >> N >> M;
	rep(i, M) {
		int L, R, x;
		cin >> L >> R >> x;
		Q[R].push_back(make_pair(L, x));
	}
	solve();
	return 0;
}

Measured memory_bytes: 106752
#include <iostream>
#include <algorithm>

int main(){
	int a, b, c;
	std::cin >> a >> b >> c;
	if(a>b)
		std::swap(a,b);
	if(b>c)
		std::swap(b,c);
	if(a>b)
		std::swap(a,b);
	std::cout << a << ' ' << b << ' ' << c << std::endl;
	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
int main(){
	unsigned char usW_D_str[1200];
	int i, j;
	int string_count;
	
	for(i = 0;i < 1200;i++){
		usW_D_str[i] = '\0';
	}
	
	for(i = 0;i < 1200;i++){
		scanf("%c", &usW_D_str[i]);
		if(usW_D_str[i] == '\0'){
			break;
		}
	}
	
	for(i = 0;i < 1200;i++){
		if(usW_D_str[i] >= 'A' && usW_D_str[i] <= 'Z'){
			usW_D_str[i + j] += 32;
		}
		else if(usW_D_str[i] >= 'a' && usW_D_str[i] <= 'z'){
			usW_D_str[i] -= 32;
		}
		else;
	}
	
	for(i = 0;usW_D_str[i] != '\0';i++){
		printf("%c", usW_D_str[i]);
	}
	
	return 0;
}


Measured memory_bytes: 2100
//(・ω・)
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
using namespace std;

int main(){
  string a, b;
  cin >> a >> b;
  int c=(stoi)(a+b);
  int d=sqrt(c);
  if(c%d==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {
   public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long temp = a+b;
        long temp1 = (n/temp) * a;
       if(n%temp != 0) { 
               if(n % temp >= a) {
                      temp1 += a;
               }
               else 
                       temp1 += (n % temp);
       }
       System.out.println(temp1);
   }
}

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

using namespace std;

int main()
{
    int n,m,sum=0;
    cin>>n>>m;
    int a[m];
    for(int i=0;i<m;i++){
        cin>>a[i];
        sum+=a[i];
    }if(n-sum>=0)cout<<n-sum;
    else cout<<-1;
    return 0;
}

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

int kakuketa(int n){
    int ans=0;
    while(n){
        ans+=n%10;
        n/=10;
    }
    return ans;
}

int main(){
    int N;
    cin>>N;
    if(N%kakuketa(N)==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

int func(int A, int B, int C)
{
  if(A%2 == 1 || B%2 == 1 || C%2 == 1) return 0;
  if(A==B && A==C) return -1;
  return func((B+C)/2, (C+A)/2, (A+B)/2) + 1;
}

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  int ans = func(A, B, C);
  cout << ans << endl;
  return 0;
}

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

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

    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());

    if (s < t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
int main(){
  char s[111];
  long long i,k;
  scanf("%s%lld",s,&k);
  for(i=0;i<strlen(s);i++){
    if(s[i]!='1') break;
  }
  if(k<=i) puts("1");
  else printf("%c",s[i]);
}

Measured memory_bytes: 128
//
// Created by kuroneko on 2019-07-27.
//

#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

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

    for (int i = 0; i < N; i++) {
        for (int j = i; j < N; j++) {
            for (int k = 0; k < N-1; k++) {
                int tmp = k;
                int tmp1 = k + 1;
                if (tmp == i) {
                    tmp = j;
                } else if (tmp == j) {
                    tmp = i;
                }

                if (tmp1 == i) tmp1 = j;
                else if (tmp1 == j) tmp1 = i;

                if (v[tmp] > v[tmp1]) break;
                if (k == N - 2) {
                    cout << "YES" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}




Measured memory_bytes: 888
n = gets.to_i
abs_list = gets.split(' ').map(&:to_i)

sorted_abs_list = abs_list.sort

expected_list = (1..n).select { |d|
  if n.odd?
    (d % 2).even?
  else
    (d % 2).odd?
  end
}

expected_list += expected_list
sorted_abs_list -= [0]
sorted_expected_list = expected_list.sort

mod = 10 ** 9 + 7
if sorted_abs_list == sorted_expected_list
  print("#{2 ** (n / 2) % mod}\n")
else
  print "0\n"
end

Measured memory_bytes: 12400
d, g = gets.split.map(&:to_i)
p, c = Array.new(d) { gets.split.map(&:to_i) }.transpose
min = 1000

(2**d).times do |b|
  bit = format("%0#{d}d", b.to_s(2))
  score = count = 0

  bit.each_char.with_index do |b, idx|
    if b == '1'
      score += 100 * (idx + 1) * p[idx] + c[idx]
      count += p[idx]
    end
  end

  if score < g
    idx = bit.rindex('0')
    tmp = ((g - score) / (100.0 * (idx + 1))).ceil
    next if tmp > p[idx] - 1

    count += tmp
  end

  min = count if min > count
end

puts min

Measured memory_bytes: 3836
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <stack>

using namespace std;
////////////////*My library*////////////////////////
#define rep_to(a,i,n) for(int i=a;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_r(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) cout<<x<<endl
#define s_1(x) cin>>x
#define s_2(x,y) cin>>x>>y
////////////////////////////////////////////////////

////////////////////////
/*prime()*/
/*primecount()*/
/*sort()*/
/*imos???*/
/*????????¢?´¢*/
/*??±???????????¢?´¢*/
/*???????¨???????*/
///////////////////////
int main()
{
	int num[100][100]={};

	rep(i,2)rep(j,10)cin>>num[i][j];

	rep(i,2)
	{
		rep(j,10)
		{
			rep_to(j,k,10)
			{
				if(num[i][j]<num[i][k])
				{
					int key;
					key=num[i][j];
					num[i][j]=num[i][k];
					num[i][k]=key;
				}
			}
		}
	}
	cout<<num[0][0]+num[0][1]+num[0][2]<<" "<<num[1][0]+num[1][1]+num[1][2]<<endl;
	return 0;
}

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

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

  char xg, yg;

  if(x==4 || x==6 || x==9 || x==11){
    xg='B';
  }
  else if(x==2){
    xg='C';
  }
  else{
    xg='A';
  }

  if(y==4 || y==6 || y==9 || y==11){
    yg='B';
  }
  else if(y==2){
    yg='C';
  }
  else{
    yg='A';
  }

  if(xg==yg){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

return 0;  
}

Measured memory_bytes: 256
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
inf = -9999999999
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    h, w = nm()
    s = s = [['#'] * (w+1)]
    for _ in range(h):
        temp = ['#']
        temp.extend(list(ns()))
        temp.extend(['#'])
        s.append(temp)
    s.append(['#'] * (w+1))
        
    def bfs(arr, x, y):
        que = deque([[x, y]])
        dist = [[0]*(w+2) for _ in range(h+2)]
        visited = set((x, y))
        for i in range(h+2):
            for j in range(w+2):
                if i == 0 or i == h + 1 or j == 0 or j == w + 1 or arr[i][j] == '#':
                    dist[i][j] = inf
                    visited.add((i, j))
        while True:
            #print(x, y, que)
            #print(dist)
            now = que.popleft()
            visited.add((now[0], now[1]))
            if arr[now[0]][now[1]] == '.':
                if (now[0]+1, now[1]) not in visited:
                    que.append([now[0]+1, now[1]])
                    visited.add((now[0]+1, now[1]))
                    dist[now[0]+1][now[1]] += dist[now[0]][now[1]] + 1
                if (now[0], now[1]+1) not in visited:
                    que.append([now[0], now[1]+1])
                    visited.add((now[0], now[1]+1))
                    dist[now[0]][now[1]+1] += dist[now[0]][now[1]] + 1
                if (now[0]-1, now[1]) not in visited:
                    que.append([now[0]-1, now[1]])
                    visited.add((now[0]-1, now[1]))
                    dist[now[0]-1][now[1]] += dist[now[0]][now[1]] + 1
                if (now[0], now[1]-1) not in visited:
                    que.append([now[0], now[1]-1])
                    visited.add((now[0], now[1]-1))
                    dist[now[0]][now[1]-1] += dist[now[0]][now[1]] + 1
            if que == deque():
                break 
        mx = []
        for i in range(h+2):
            mx.append(max(dist[i]))       
        return max(mx)

    ans = []
    #print(bfs(s, 1, 1))
    for i in range(1, h+1):
        for j in range(1, w+1):
            ans.append(bfs(s, i, j))

    print(max(ans))


if __name__ == '__main__':
    main()

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

int solve() {
    int N, K;
    cin >> N >> K;
    int K2 = 2*K;
    vector<vector<int>> B(K2, vector<int>(K2)), W(K2, vector<int>(K2));
    int x, y;
    char c;
    for ( int i = 0; i < N; i++ ) {
        cin >> x >> y >> c;
        if ( c == 'B' ) B[x%K2][y%K2]++;
        else W[x%K2][y%K2]++;
    }
    vector<vector<int>> NB(K*3+1, vector<int>(K*4+1)), NW(K*3+1, vector<int>(K*4+1)); // [0,i)[0,j)
    for ( int i = 1; i <= K*3; i++ ) {
        for ( int j = 1; j <= K*4; j++ ) {
            NB[i][j] = NB[i-1][j] + NB[i][j-1] - NB[i-1][j-1] + B[(i-1)%K2][(j-1)%K2];
            NW[i][j] = NW[i-1][j] + NW[i][j-1] - NW[i-1][j-1] + W[(i-1)%K2][(j-1)%K2];
        }
    }
    // [x-K,x)[y-K,y)
    auto get_n = [](vector<vector<int>>& num, int k, int x, int y) {
        int x1 = x + k;
        int y1 = y + k;
        return num[x1][y1] - num[x][y1] - num[x1][y] + num[x][y];
    };
    ll ans = 0;
    for ( int i = 0; i <= K; i++ ) {
        for ( int j = 0; j <= K2; j++ ) {
            int m = 0;
            m += get_n(NB, K, i, j);
            m += get_n(NB, K, i + K, j + K);
            m += get_n(NW, K, i, j + K);
            m += get_n(NW, K, i + K, j);
            if ( ans < m ) ans = m;
        }
    }

    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

int main(){
  int n; cin>>n;
  vector<ll>V(n);
  rep(i,n){
    cin>>V[i];
    if (V[i]==0){
      cout << 0;
      return 0;
    }
  }
  ll ans = V[0];
  for(int i=1;i<n;i++){
    if (V[i]>(1000000000000000000/ans)){
      ans = -1;
      break;
    }
    else ans *= V[i];
  }
  cout << ans;
}

Measured memory_bytes: 3988
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
	cin>>n;
	vector<int>v; 
    int ans[300000]={0};
	for(int i=0;i<n-1;i++){
		int a;
		cin>>a;
		v.push_back(a);
		ans[a-1]++;
	} 
	for(int i=0;i<n;i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 5420
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N;
ll X[15], Y[15], P[15];
vector<ll> x, y;

vector<vector<ll>> ans1[16], ans2[16];

int popcount(ll n){
    int ret = 0;
    while(n > 0){
        ret += n&1;
        n >>= 1;
    }
    return ret;
}

signed main(){
    scanf("%d", &N);
    rep(i, N){
        scanf("%lld%lld%lld", &X[i], &Y[i], &P[i]);
        x.pb(X[i]);
        y.pb(Y[i]);
    }
    sort(all(x));
    sort(all(y));

    rep(i, (1<<N)){
        vector<ll> tmp(N, 1e16L);
        rep(j, N){
            rep(k, N){
                if((i>>k)&1){
                    tmp[j] = min(tmp[j], P[j]*abs(X[j]-x[k]));
                }
            }
            tmp[j] = min(tmp[j], P[j]*abs(X[j]));
        }
        ans1[popcount(i)].pb(tmp);
    }

    rep(i, (1<<N)){
        vector<ll> tmp(N, 1e16L);
        rep(j, N){
            rep(k, N){
                if((i>>k)&1){
                    tmp[j] = min(tmp[j], P[j]*abs(Y[j]-y[k]));
                }
            }
            tmp[j] = min(tmp[j], P[j]*abs(Y[j]));
        }
        ans2[popcount(i)].pb(tmp);
    }

    random_device seed_gen;
    mt19937 engine(seed_gen());
    rep(i, N+1){
        if(ans1[i].size() > 3000){
            shuffle(all(ans1[i]), engine);
        }
        if(ans2[i].size() > 3000){
            shuffle(all(ans2[i]), engine);
        }
    }

    rep(i, N+1){
        ll ans = 1e18L;
        rep(j, i+1){
            rep(k, min((int)ans1[j].size(), 3000)){
                rep(l, min((int)ans2[i-j].size(), 3000)){
                    ll tmp = 0;
                    rep(n, N){
                        tmp += min(ans1[j][k][n], ans2[i-j][l][n]);
                    }
                    ans = min(ans, tmp);
                }
            }
        }
        printf("%lld\n", ans);
    }
}

Measured memory_bytes: 13156
#include<bits/stdc++.h>
using namespace std;
const int mx = 300005;
const int md = 998244353;
int n, t = md - 2;
long long fact[mx] = {1}, a, b, k, u, in[mx], comb[mx], ans;

int main(){
    scanf("%d%lld%lld%lld", &n, &a, &b, &k);
    for(int i = 1; i <= n; i++) fact[i] = fact[i-1] * i % md;
    u = fact[n]; in[n] = 1;
    while(t){
        if(t&1) in[n] = in[n] * u % md;
        u = u * u % md;
        t >>= 1;
    }
    for(int i = n; i > 0; i--) in[i-1] = in[i] * i % md;
    for(int i = 0; i <= n; i++) comb[i] = fact[n] * in[n-i] % md * in[i] % md;
    for(int i = 0; i <= n; i++){
        if((k - a*i) % b == 0){
            long long u = (k - a*i) / b;
            if(0 <= u && u <= n) ans = (ans + comb[i] * comb[u]) % md;
        }
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 7296
def run():
  N = int(input())
  a_li = list(map(int, input().split()))
  ans = 0
  i = 1
  for a in a_li:
    if a == i:
      i += 1
      continue
    else:
      ans += 1
  if ans == N:
    print(-1)
  else:
    print(ans)
  
if __name__ == '__main__':
  run()

Measured memory_bytes: 77516
#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--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  auto dfs = [&](auto dfs, string out, char ma) -> void {
    if (out.size() == n) {
      cout << out << endl;
      return;
    }
    for (char c = 'a'; c <= ma; c++) {
      string s = out + c;
      char m = *max_element(all(s)) + 1;
      dfs(dfs, s, m);
    }
  };
  dfs(dfs, "", 'a');
}


Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc1 = new Scanner(System.in);

		while(true) {

			int h = sc1.nextInt();
			int w = sc1.nextInt();

			if ( h == 0 && w == 0) {
				break;
			}

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

				for ( int j = 0 ; j < w ; j++) {
					if ( i == 0 || i == h-1 ) {
						System.out.print("#");
					}
					else {
						if ( j == 0 || j == w-1) {
							System.out.print("#");
						}
						else {
							System.out.print(".");
						}
					}
				}

				System.out.println();

			}

			System.out.println();

		}

		sc1.close();

	}
}



Measured memory_bytes: 34888
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <fstream>
#include <bitset>
#include <time.h>
#include <assert.h>

#define LL long long
#define VI vector<int>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

using namespace std;


void dfs(int v, int parent, vector<LL> &dist, const map<int, vector<pair<int, LL>>> &edges) {
    FOE(p, edges.at(v)) {
        if (p.first != parent && p.first != v) {
            dist[p.first] = dist[v] + p.second;
            dfs(p.first, v, dist, edges);
        }
    }
}

// rootからの各頂点への距離を求める
// n: 頂点数
// edges: edges[v] = [{u1, cost1}, {u2, cost2}, ...]
vector<LL> distance(unsigned int n, int root, const map<int, vector<pair<int, LL>>> &edges) {
    vector<LL> dist(n, INT_MAX);
    dist[root] = 0;
    dfs(root, -1, dist, edges);
    return dist;
}

int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, a, b, c;
    cin >> N;
    map<int, vector<pair<int, LL>>> edges;
    FOR(_, 0, N - 1) {
        cin >> a >> b >> c;
        a--; b--;
        edges[a].push_back({b, c});
        edges[b].push_back({a, c});
    }

    int Q, K, x, y;
    cin >> Q >> K;
    K--;

    vector<LL> dist = distance(N, K, edges);
    FOR(i, 0, Q) {
        cin >> x >> y;
        x--; y--;
        cout << dist[x] + dist[y] << endl;
    }

    return 0;
}

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

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)

using namespace std;

using ll = long long;
using triple = tuple<int, int, int>;

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

    constexpr int A_MAX = 50;
    constexpr ll INF = 1LL << 62;

    int N, M, S;
    cin >> N >> M >> S;
    vector<vector<triple>> g(N);
    vector<int> C(N), D(N);
    REP(i, M) {
        int U, V, A, B;
        cin >> U >> V >> A >> B;
        --U;
        --V;
        g[U].emplace_back(V, A, B);
        g[V].emplace_back(U, A, B);
    }
    REP(i, N) {
        cin >> C[i] >> D[i];
    }

    int fare_max = (N - 1) * A_MAX;

    vector<vector<ll>> dp(N, vector<ll>(fare_max + 1, INF));
    using T = tuple<ll, int, int>;
    priority_queue<T, vector<T>, greater<T>> q;

    REP(i, min(S, fare_max) + 1) {
        dp[0][i] = 0;
        q.emplace(dp[0][i], 0, i);
    }

    while (!q.empty()) {
        ll time;
        int u, money;
        tie(time, u, money) = q.top();
        q.pop();
        if (time > dp[u][money]) continue;

        // stay at vertex u
        if (money + C[u] <= fare_max && dp[u][money + C[u]] > time + D[u]) {
            dp[u][money + C[u]] = time + D[u];
            q.emplace(dp[u][money + C[u]], u, money + C[u]);
        }

        // go to vertex v
        for (const auto &[v, A, B]: g[u]) {
            if (money >= A && dp[v][money - A] > time + B) {
                dp[v][money - A] = time + B;
                q.emplace(dp[v][money - A], v, money - A);
            }
        }
    }

    FOR(u, 1, N) {
        ll time = INF;
        REP(money, fare_max + 1) {
            time = min(time, dp[u][money]);
        }
        cout << time << '\n';
    }
    cout << flush;

    return 0;
}


Measured memory_bytes: 5252
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int N, M;
  cin >> N >> M;
  vector<int> memo(M);
  for (int i = 0; i < N; i++) {
    int K;
    cin >> K;
    for (int j = 0; j < K; j++) {
      int A;
      cin >> A;
      memo.at(A - 1)++;
    }
  }
  int ans = 0;
  for (int i = 0; i < M; i++) {
    if (memo.at(i) == N) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

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

using namespace std;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return mint(-x); }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator+(long long y,const mint& m){ return m+y; }
mint operator*(long long y,const mint& m){ return m*y; }

int main(){
	int n,k; scanf("%d%d",&n,&k);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	mint ans=0;
	rep(i,n){
		int cnt1=0,cnt2=0;
		rep(j,n) if(a[j]>a[i]) {
			if(j<i) cnt1++;
			cnt2++;
		}
		ans+=mint(k)*cnt1+mint(k)*(k-1)/2*cnt2;
	}
	printf("%d\n",ans.to_int());

	return 0;
}


Measured memory_bytes: 256
import sys

class Node:
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left = self.right = None

root = None

def insert(key):
    global root
    x, y = root, None
    while x: x, y = x.left if key < x.key else x.right, x
    if y is None: root = Node(key)
    elif key < y.key: y.left = Node(key)
    else: y.right = Node(key)

def find(target):
    result = root
    while result and target != result.key:
        result = result.left if target < result.key else result.right
    return result is None

def inorder(node):
    return inorder(node.left) + f' {node.key}' + inorder(node.right) if node else ''
def preorder(node):
    return f' {node.key}' + preorder(node.left) + preorder(node.right) if node else ''

input()
for e in sys.stdin:
    if e[0] == 'i': insert(int(e[7:]))
    elif e[0] == 'f': print(['yes','no'][find(int(e[5:]))])
    else: print(inorder(root)); print(preorder(root))


Measured memory_bytes: 55688
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define mod 1000000007
using namespace std;
int a[110];
int c[110];

int main()
{
    int n,i,k;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        c[a[i]]++;
    }

    sort(a,a+n);

    if(n==2)
    {
        if(a[0]==a[1] && a[0]==1) cout<<"Possible";
        else cout<<"Impossible";
        return 0;
    }

    if(a[n-1]%2==0) k=a[n-1]/2;
    else k=a[n-1]/2+1;

    if(a[n-1]!=a[n-2]) {cout<<"Impossible"; return 0;}

    i=1;
    if(a[n-1]%2==1)
    {
        if(a[0]!=k || a[1]!=k || a[2]==k) {cout<<"Impossible"; return 0;}
        i++;
    }
    else
    {
        if(a[0]!=k || a[1]==k) {cout<<"Impossible"; return 0;}
    }

    for(i;i<n;i++)
    {
        if(a[i]-k>1) {cout<<"Impossible"; return 0;}
        else k=a[i];
    }

    cout<<"Possible";

}





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

int main() {
  int count=0;
  int N,dog = -1;
  cin>>N;
  vector<int>L(N);
  rep(i,N){
    cin>>L[i];
  }
  rep(i,N){
    if(L[i]>dog){
      dog=L[i];
    }
    count+=L[i];
  }
  if(count-dog>dog){
    cout<<"Yes";
  }
  else cout<<"No";
}


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

char a[205], b[205];

int main(){
	int k, ans;
	char *p, *q, *wp, *wq;
	char *s[3] = { "IDENTICAL", "CLOSE", "DIFFERENT" };

	while (scanf("%s", a) && a[0] != '.') {
		scanf("%s", b); p = a, q = b; ans = -1, k = 0;
		while (*p && *q) {
			if (*p != *q) { ans = 2; break; }
			if (*p == '"') {
			    wp = ++p, wq = ++q;
				while (*p != '"'){
				    p++;
				}while (*q != '"'){
				    q++;
				}
				*p = *q = 0;
				k += 1 - (strcmp(wp, wq) == 0);
				if (k > 1) {
				    ans = 2;
				    break;
				    }
			}
			p++, q++;
		}
		if (ans < 0){
		    if (*p == *q){
		        ans = k;
		        }else{
		            ans = 2;
		        }
		}
		puts(s[ans]);
	}
	return 0;
}


Measured memory_bytes: 2032
import java.io.*;

class Main{
 public static void main(String[] args)throws IOException{
   BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   String[] strAry; 
   long n,max,min,sum;
    n = Integer.parseInt(br.readLine()); 
   int i;   
   strAry = br.readLine().split(" ");
   min = Integer.parseInt(strAry[0]);  
   max = Integer.parseInt(strAry[0]);
   
     
   
   for(i=0,sum=0;i<n;i++){
     sum=sum + Integer.parseInt(strAry[i]);  
    if(min>Integer.parseInt(strAry[i])){ 
       min=Integer.parseInt(strAry[i]);
     }
     if(max<Integer.parseInt(strAry[i])){
       max=Integer.parseInt(strAry[i]);
      }
      
   }
       
      System.out.println(min+ " " + max +" "+sum);   

  }
}

Measured memory_bytes: 28756
package main

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

func main() {
	N, D := ReadInt(), ReadInt()
	c := 0
	for i := 0; i < N; i++ {
		x, y := ReadInt(), ReadInt()
		if D*D >= x*x+y*y {
			c++
		}
	}
	fmt.Println(c)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 6024
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long int
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define mod (int)(998244353)
#define PI 3.14159265358979323846264338327950L
#define debug(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << "[ " << *it << " = " << a << " ] ";
    err(++it, args...);
}

signed main(){

    fastIO

    int n;
    cin >> n;
    string ans = "";
    int num = 26;
    if (n%num == 0) {
        ans = 'z' + ans;
    }else {
        ans = (char)(('a' + n%num - 1)) + ans;
    }
    bool in = false;
    if (n > num) in = true;
//    n -= num;
    int sub = 26;
    while (n-sub > 0) {
//        n -= sub*26;
        n -= sub;
        if (((n+sub-1)/sub)%26 == 0) {
            ans = 'z' + ans;
        }else {
            ans = (char)(('a' + ((n+sub-1)/sub)%26 - 1)) + ans;
        }
        sub *= 26;
    }
//    sub *= 26;
//    if (((n+sub-1)/sub)%26 == 0 && in) {
//        ans = 'z' + ans;
//    }else if (in){
//        trace((n/sub)%26)
//        ans = (char)(('a' + ((n+sub-1)/sub)%26 - 1)) + ans;
//    }
//    trace(ans);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3612
import sys
import numpy as np
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    coin = [6**i for i in range(10) if 6**i <= N]
    coin += [9**i for i in range(10) if 9**i <= N]

    dp = np.zeros(N+1,dtype=np.int32)
    dp += MOD
    dp[0] = 0
    for c in coin:
        for _ in range(9):
            dp[c:] = np.minimum(dp[:-c]+1, dp[c:])
    print(dp[-1])


if __name__ == '__main__':
    main()

Measured memory_bytes: 14072
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
ll exp(ll x,ll y){
    if(y==0)return 1;
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    ll t=exp(x,y/2);
    return (t*t)%big;
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}


int main(){
  //cout << fixed << setprecision(10);
  int n,k;cin >> n >> k;
  vector<bool> have(n,false);
  rep(i,k){
    int d;cin >> d;
    rep(j,d){
      int t;cin >> t;t--;
      have[t]=true;
    }
  }
  int cnt=0;
  rep(i,n)if(!have[i])cnt++;
  cout << cnt << endl;
  
  return 0;
}

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

int N,M;
vector<int> a(50),b(50);

int main()
{
    cin>>N>>M;
    std::vector<int> cnt(N);
    for (int i=0; i<M; i++) {
        cin>>a.at(i)>>b.at(i);
        cnt.at(a.at(i)-1)++;
        cnt.at(b.at(i)-1)++;
    }
    for (int i=0; i<N; i++) cout<<cnt.at(i)<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(200000)

def dfs(i, total):
    if (i > A - 1):
        return False
    if (total - SPECIALS[i] <= 0):
        return True
    else:
        return dfs(i + 1, total - SPECIALS[i])

H, A = map(int, input().split())
SPECIALS = map(int, input().split())
SPECIALS = list(reversed(sorted(SPECIALS)))

print("Yes" if dfs(0, H) else "No")


Measured memory_bytes: 96124
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
#define REP(i,n) for(int i=0;i<(int)n;++i)
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

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

    ll N, K, C;
    cin >> N >> K >> C;
    string S;
    cin >> S;

    vector<ll> dp(N, 0);
    for(int i=N-1;i>=0;i--){
        if(S[i]=='x'){
            if(i!=N-1) dp[i] = dp[i+1];
        }else{
            if(i+C+1>N-1){
                dp[i] = 1;
            }else{
                dp[i] = dp[i+C+1] + 1;
            }
        }
    }

    ll now = 0;
    ll cnt = 0;
    vector<ll> res;
    while(now<N){
        if(S[now]=='o'){
            ll tasu = (now==N-1 ? 0 : dp[now+1]);
            if(cnt+tasu<K) res.push_back(now);
            cnt++;
            now += C+1;
        }else{
            now++;
        }
    }

    for(auto x: res){
        cout << x + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 5000
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let xs: Vec<i64> = sc.vec(n);
    let ys: Vec<i64> = sc.vec(n);

    let mut offset = 0;
    loop {
        if (0..n).all(|i| xs[i] != ys[(i + offset) % n]) {
            let ans = ys[offset..]
                .iter()
                .chain(ys[..offset].iter())
                .collect::<Vec<_>>();
            put!("Yes");
            put!(..ans);
            return;
        }
        for i in (0..n).rev() {
            while xs[i] == ys[(i + offset) % n] {
                offset += 1;
                if offset >= n {
                    put!("No");
                    return;
                }
            }
        }
    }

    put!("No");
}

use std::collections::VecDeque;
use std::io::{self, Write};
use std::str::FromStr;

struct Scanner {
    stdin: io::Stdin,
    buffer: VecDeque<String>,
}
impl Scanner {
    fn new() -> Self {
        Scanner {
            stdin: io::stdin(),
            buffer: VecDeque::new(),
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.cin::<String>().chars().collect()
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.cin()).collect()
    }
}


Measured memory_bytes: 18852
#include <bits/stdc++.h>
using namespace std;
int a,b;
int main(){
    cin>>a>>b;
    if(a<=0&&b>=0){
        cout<<"Zero"<<endl;
    }
    else if(a<0&&(min(0,b)-a+1)%2!=0){
        cout<<"Negative"<<endl;
    }
    else{
        cout<<"Positive"<<endl;
    }
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;

public class Main{
  public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  
	  long A = sc.nextLong();
	  long B = sc.nextLong();
	  long C = sc.nextLong();
	  long D = sc.nextLong();
	  

	 A--;
	  //A-1までの対象の数の数を求める
	  long c = A/C;
	  long d = A/D;
	  long cANDd = A / lcm(C,D);
	  long a = A - (c + d - cANDd);
	  
	  
	  //1~Bまでのry
	  c = B/C;
	  d = B/D;
	  cANDd = B / lcm(C,D);
	  long b = B - (c + d - cANDd);
	  
	  out.println(b - a); 
	  
	}
  //最小公倍数を求めるメソッド
  private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}
  //最大公約数を求めるメソッド
  private static long gcd(long m, long n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}
  }	

Measured memory_bytes: 23124
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int A, B; cin >> A >> B;
  cout << A * B - A - B + 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

#define INF 100100100100100
string S;
vector<long long> num(500100, INF);
int N;

long long ans(int x) {
    if (num[x] != INF) return num[x];
    if (x == 0) {
        if (S[0] == '<') num[x] = 0;
        else num[x] = ans(x + 1) + 1;
        return num[x];
    }
    if (x == N - 1) {
        if (S[N - 2] == '>') num[x] = 0;
        else num[x] = ans(x - 1) + 1;
        return num[x];
    }
    if (S[x - 1] == '>' && S[x] == '<') {
        num[x] = 0;
        return num[x];
    }
    if (S[x - 1] == '<' && S[x] == '<') {
        num[x] = ans(x - 1) + 1;
        return num[x];
    }
    if (S[x - 1] == '>' && S[x] == '>') {
        num[x] = ans(x + 1) + 1;
        return num[x];
    }
    num[x] = max(ans(x - 1), ans(x + 1)) + 1;
    return num[x];
}

int main() {
    cin >> S;
    N = (int)S.size() + 1;
    long long a = 0;
    rep(i, N) a += ans(i);
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 28164
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args){
		int n = stdIn.nextInt();
		int k = stdIn.nextInt();
		int[] v = new int[n];
		for(int i=0; i<n; i++){
			v[i] = stdIn.nextInt();
		}

		int max = 0;
		Integer[] temp;
		for(int l=0; l<=50; l++){
			for(int r=0; r<=50; r++){
				if(l+r > n || l+r > k)
					continue;
				temp = new Integer[l+r];
				for(int i=0; i<l; i++){
					temp[i] = v[i];
				}
				for(int i=0; i<r; i++){
					temp[l+i] = v[n-i-1];
				}
				Arrays.sort(temp);
				int idx = 0;
				int times = 0;
				while(idx < temp.length-1 && temp[idx] < 0 && l+r+times<k){
					idx++;
					times++;
				}
				int sum = 0;
				for(int i=idx; i<temp.length; i++){
					sum += temp[i];
				}
				if(max < sum){
					max = sum;
				}
			}
		}

		System.out.println(max);
	}
}


Measured memory_bytes: 38804
#include<bits/stdc++.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-10;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}

int main(void) {
  int a,b;
  cin>>a>>b;
  cout<<(a-1)*(b-1)<<endl;
  return 0;
}


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

#define ALL(a) (a).begin(), (a).end()
#define ll long long

using namespace std;

signed main(){
	ll n,k; cin >> n >> k;
	vector<ll> a(n), b(n);
	for(ll i = 0; i < n; i++){
		cin >> a[i] >> b[i];
	}
	map<ll,ll> m;
	for(ll i = 0; i < n; i++){
		if(m.find(a[i]) != m.end())m[a[i]] += b[i];	
		else m[a[i]] = b[i];
	}
	auto itr = m.begin();
	//for(auto e : m)cerr << e.first << ":" << e.second << endl;
	for(; itr != m.end(); ++itr){
		k -= itr->second;
		if(k <= 0)break;
	}
	cout << itr->first << endl;


	return 0;
}



Measured memory_bytes: 5760