akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int N = scanner.nextInt();
			int K = scanner.nextInt();

			// input
			Map<Integer, Integer> map = new HashMap<Integer, Integer>();
			for (int i = 0; i < N; i++) {
				int val = scanner.nextInt();
				if (map.containsKey(val)) {
					map.put(val, map.get(val) + 1);
				} else {
					map.put(val, 1);
				}
			}
			// map のvalue で降順ソート
			List<Entry<Integer, Integer>> list = new ArrayList<Map.Entry<Integer, Integer>>(map.entrySet());
			Collections.sort(list, new Comparator<Entry<Integer, Integer>>() {
				@Override
				public int compare(Entry<Integer, Integer> o1, Entry<Integer, Integer> o2) {
					return o2.getValue() - o1.getValue();
				}
			});

			// 集計
			if (list.size() < K) {
				System.out.println(0);
			} else {
				int sum = 0;
				for (int i = K; i < list.size(); i++) {
					sum += list.get(i).getValue();
				}
				System.out.println(sum);
			}
		}
	}
}

Measured memory_bytes: 101432
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
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);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
  int A=0,B=0;
  cin >> A >> B;
  cout << ((A%3==0)||(B%3==0)||((A+B)%3==0)?"Possible":"Impossible") << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int n; cin >>n;
  vector<int> a(n); rep(i, n) cin >>a[i];
  ll even = 1;
  ll odd = 1;
  rep(i, n){
    even *= 3;
    ll tmp = 1;
    if (a[i] % 2 == 0) tmp++;
    odd *= tmp;
  }
  ll res = even - odd;
  cout <<res <<endl;
}

Measured memory_bytes: 256
n = int(input())
P = list(map(int, input().split()))

ans = 0
for i in range(n-1):
    if i+1 == P[i]:
        ans += 1
        P[i], P[i+1] = P[i+1], P[i]
    else:
        continue

if P[n-1] == n:
    ans += 1

print(ans)

Measured memory_bytes: 14008
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;


public class Main{
	
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
	
	static class Pair
	{
		int p;
		int q;
		Pair(int p,int q)
		{
			this.p = p;
			this.q = q;
		}
	}
	
	static int gcd(int a,int b)
	{
		if(a == 0) return b;
		if(b == 0) return a;
		
		return gcd(b,a%b);
	}
	
	static boolean check(char x)
	{	
		if(x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u') return false;
		return true;
	}
	public static void main(String[] args) 
	{
		OutputStream outputStream = System.out;
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(outputStream);
        
        int a = sc.nextInt();
        
        out.println(a*a);
        out.close();
	}

}


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

int a[100005], b[100005], c[100005], n;

int main() {
  scanf("%d",&n);
  for(int i=0;i<n;i++) scanf("%d",a+i);
  for(int i=0;i<n;i++) scanf("%d",b+i);
  for(int i=0;i<n;i++) scanf("%d",c+i);
  sort(a,a+n);
  sort(b,b+n);
  sort(c,c+n);
  long long ans = 0, tmp = 0;
  int j=n-1,k=n-1;
  for(int i=n-1;i>=0;i--) {
    while(j>=0) {
      if(b[j] <= a[i]) break;
      while(k>=0) {
        if(c[k] <= b[j]) break;
        k--;
      }
      tmp += n-k-1;
      j--;
    }
    ans += tmp;
  }
  printf("%lld\n",ans);
}


Measured memory_bytes: 1408
package main

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

type queue []int

func (q queue) Push(p int) queue {
	return append(q, p)
}

func (q queue) Pop() (int, queue) {
	if len(q) == 1 {
		return q[0], make(queue, 0)
	}
	return q[0], q[1:]
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	N, _ := strconv.Atoi(sc.Text())

	sc.Scan()
	M, _ := strconv.Atoi(sc.Text())

	graph := make([]map[int]int, N)
	for i := 0; i < N; i++ {
		graph[i] = make(map[int]int)
	}

	for i := 0; i < M; i++ {
		sc.Scan()
		ui, _ := strconv.Atoi(sc.Text())

		sc.Scan()
		vi, _ := strconv.Atoi(sc.Text())

		graph[ui-1][vi-1] = 1
	}

	graphDash := make([]map[int]int, 3*N)
	for i := 0; i < N; i++ {
		graphDash[3*i] = make(map[int]int)
		graphDash[3*i+1] = make(map[int]int)
		graphDash[3*i+2] = make(map[int]int)
		for t, _ := range graph[i] {
			graphDash[3*i][3*t+1] = 1
			graphDash[3*i+1][3*t+2] = 1
			graphDash[3*i+2][3*t] = 1
		}
	}

	sc.Scan()
	S, _ := strconv.Atoi(sc.Text())
	S = (S - 1) * 3

	sc.Scan()
	T, _ := strconv.Atoi(sc.Text())
	T = (T - 1) * 3

	dones := make([]int, N*3)

	que := make(queue, 0)
	que = que.Push(S)
	for len(que) > 0 {
		var current int
		current, que = que.Pop()

		for vertex, _ := range graphDash[current] {
			if vertex != S && dones[vertex] == 0 {
				dones[vertex] += dones[current] + 1
				que = que.Push(vertex)
				if vertex == T {
					goto done
				}
			}
		}
	}

done:
	if dones[T] == 0 {
		fmt.Println(-1)
	} else {
		fmt.Println(dones[T] / 3)
	}
}


Measured memory_bytes: 109528
//include
//------------------------------------------
#include <bits/stdc++.h> // only for GCC

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

//container util
//------------------------------------------
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

//repetition
//------------------------------------------
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)

//constant
//--------------------------------------------
const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

// output vector
// ------------------------------------------
namespace std {
    template<typename T>ostream&operator<<(ostream&os, vector<T>const&v){
        iter(it,v) os<<*it<<(it+1==v.end()?"":",");
        return os;
    }
    template<typename T, typename U>ostream&operator<<(ostream&os,const pair<T,U>&p){
        return os << "[" << p.dirst << "," << p.second << "]";
    }
}

//clear memory
// ------------------------------------------
#define clr(a,i) memset((a), (i) ,sizeof(a))

int main(){
   double x;
   ull q;
   while(cin >> q && q!=-1){
      x=q/2.0;
      while(abs(pow(x,3)-q)>0.00001*q){
         x=x-(pow(x,3)-q)/(3*pow(x,2));
         //cout << x << endl;
      }
      printf("%.8f\n",x);
   }
}

Measured memory_bytes: 1248
#include<bits/stdc++.h>
#define ll  long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 1000000000000000
#define mod 1000000007
#define ld long double
#define pll pair<ll,ll>
using namespace std;

int main()
{ 
   

fast;

ll n;
cin>>n;

ll ans=0;

for(ll  i=1;i<=n;i++)
{
    ll al=n/i;

  
    ll val=(al)*(al+1)/2;
    val*=i;

      // cout<<i<<" "<<al<<" "<<val<<endl;


    ans+=val;
}
cout<<ans;


}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vector <ll> vec
#define pair <ll,ll> pa
#define make_pair mp
#define push_back pb
int main()
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,m;
	cin>>n>>m;
	ll count=0;
	count+=(n*(n-1))/2;
	count+=(m*(m-1))/2;
	cout<<count;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int p = sc.nextInt();
        int q = sc.nextInt();
        int r = sc.nextInt();
        sc.close();

        int max = Math.max(Math.max(p, q), r);
        System.out.println(p + q + r - max);
    }

}


Measured memory_bytes: 21716
import Control.Monad

toIntList list = map (\x -> read x :: Int) . words $ list

getTrio n x = [(a, b, c) | a <- [1..n], b <- [a..n], c <- [b..n], a < b, b < c, a + b + c == x]

main = do
  a <- return . filter (/= [0, 0]) . map toIntList . lines =<< getContents
  mapM_ (print . length) $ map (\[n, x] -> getTrio n x) a

Measured memory_bytes: 4944
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,sum=0;
  int d,x;
  int a[100];
  
  cin>>n;
  cin>>d>>x;

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

  sum+=x;
  cout<<sum<<endl;
}

  


Measured memory_bytes: 256
N,M=map(int,input().split())
S = []
for i in range(M):
  S.append(list(map(int,input().split())))
P = list(map(int,input().split()))

def check(num, i, P):
  SS = S[i]
  PP = P[i]
  on = 0
  for j in range(1,1+SS[0]):
    on += num>>(SS[j]-1) & 1
    on = on%2
  if on == PP:
    return True
  else:
    return False
cnt = 0
for nu in range(2**N):
  ck = True
  for i in range(M):
    ck = ck and check(nu,i,P)
    if ck == False:
      break
  if ck == True:
    cnt +=1
print(cnt)

Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};

int main(){
	char s[100001];
	cin>>s;
	int win=0,lose=0;
	bool par=0;
	for(int i=0;i<strlen(s);i++){
		if(par){
			if(s[i]=='g')
				win++;
			par=0;
		}
		else{
			if(s[i]=='p')
				lose++;
			par=1;
		}
	}
	cout<<win-lose<<endl;
	return 0;
}

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

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,c,b) for(int i=(c);i<(b);i++)
#define rrep(i,c,b) for(int i=(b)-1;i>=(c);i--)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int N; cin >> N;
	string S; cin >> S;
	vector<int> cnt(26, 0);
	rep(i, 0, N)if (isalpha(S[i]))cnt[S[i] - 'a']++;

	bool first = true;
	int ans = 0;

	rep(i, 1, 10) {
		//?????°?????????alphabet
		int c = count(cnt.begin(), cnt.end(), i);
		if (c == 0)continue;

		if (first)first = false;
		else ans++; //...+...

		ans += 2 * c - 1; //?+?+...+?
		if (i != 1) {
			if (c == 1)ans += 2; //*i
			else ans += 4; //()*i
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3200
n,a,b = map(int,input().split())
s = input()
a_count = 0
b_count = 0
for i in s:
    if i == 'a':
        if a_count + b_count < a + b:
            print('Yes')
            a_count += 1
        else:
            print('No')
    elif i == 'b':
        if (a_count + b_count < a + b 
            and b_count < b):
            print('Yes')
            b_count += 1
        else:
            print('No')
    else:
        print('No')




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

int N; int a[300000];
long long res;

int main() {
  cin >> N;
  for(int i = 0; i < 3 * N; ++i) cin >> a[i];
  sort(a, a + 3 * N);
  for(int i = 0; i < N; ++i) {
    res += a[3 * N - 2 - 2 * i];
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1408
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
history = []
device2point = {'r' : p, 's': r, 'p': s}
device2hand = {'r': 'p', 's': 'r', 'p': 's'}
point = 0
for i in range(n):
    d = t[i]
    if i - k >= 0 and device2hand[d] == history[i-k]:
        history.append(None)
    else:
        point += device2point[d]
        history.append(device2hand[d])
print (point)

Measured memory_bytes: 10164
// ------------------
// author: MatsuTaku
// date  : 22/02/2020
// ------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int N,K; cin>>N>>K;
  int d = 0;
  while (N) {
    d++;
    N /= K;
  }
  cout << d << endl;

  return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())

if n==1:
  print(1)
  exit()
if n==2:
  if m==0:
    print(2)
  else:
    print(1)
  exit()

fib=[0 for i in range(n+2)]
fib[1]=1
for i in range(2,n+2):
  fib[i] = (fib[i-1]+fib[i-2]) % 1000000007

com=1
anow=-1
for i in range(m):
  a=int(input())
  if a-anow==1:
    print(0)
    exit()
  com = (com * fib[a-anow-1]) % 1000000007
  anow=a

com = (com * fib[n-anow]) % 1000000007
print(com)

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

int main(void)
{
    string s, t;

    cin >> s;

    t = s[0] + to_string(s.size() - 2) + s[s.size() - 1];

    cout << t << endl;

    return 0;
}

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

int main(){
  string x;
  cin >> x;
  cout << x[0] << (x.size() - 2) << x[x.size()-1] << endl; 
}

Measured memory_bytes: 256
k = int(input())
from collections import deque
queue = deque([i+1 for i in range(9)])
anses = [i+1 for i in range(9)]
while len(anses) < k:
    now = deque.popleft(queue)
    last = now%10
    if last == 0:
        look = [0, 1]
    elif last == 9:
        look = [8, 9]
    else:
        look = [last-1, last, last+1]
    for i in look:
        anses.append((10*now) + i)
        queue.append((10*now) + i)
print(anses[k-1])

Measured memory_bytes: 16756
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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 IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int N, Z, W; 
  cin >> N >> Z >> W;

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  if(N == 1){
    cout << abs(A[0]-W) << endl;
  }else{
    cout << max(abs(W-A[N-1]), abs(A[N-1]-A[N-2])) << endl;
  }

  return 0;
}

Measured memory_bytes: 256
n,t=map(int,input().split())
a=[list(int(i) for i in input().split())for i in range(n)]
ans=float("inf")
for i in range(n):
    if a[i][1]<=t:
        cost=a[i][0]
        ans=min(cost,ans)
if ans==float("inf"):
    print("TLE")
else:
    print(ans)


Measured memory_bytes: 3060
s = input()
t = input()
slen = len(s)
tlen = len(t)
dp = [[0 for j in range(tlen + 1)] for i in range(slen + 1)]
for i in range(slen):
  for j in range(tlen):
    if s[i] == t[j]:
      dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1)
    dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j])
    dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1])
result = ''
i = slen
j = tlen
while i > 0 and j > 0:
  if dp[i - 1][j] == dp[i][j]:
    i -= 1
  elif dp[i][j - 1] == dp[i][j]:
    j -= 1
  else:
    result = s[i - 1] + result
    i -= 1
    j -= 1
print(result)

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

int main()
{
    int n,a,b,c;
    std::cin >> n >> a >> b >>c;
    std::vector<int> l(n);
    for(int i = 0; i < n; i++)std::cin >> l[i];
    int res = 1000000000;
    std::vector<std::vector<int>> ans(3);

    for(int bit0 = 0; bit0 < (1 << n); bit0++){             //aに使う
        for(int bit1 = 0; bit1 < (1 << n); bit1++){         //bに使う
            if(bit0 & bit1)continue;
            for(int bit2 = 0; bit2 < (1 << n); bit2++){     //cに使う
                if(bit0 & bit2)continue;
                if(bit1 & bit2)continue;
                int cur = 0;
                std::vector<int> va,vb,vc;
                for(int i = 0; i < n; i++)  if(bit0 & (1 << i))va.push_back(l[i]);
                for(int i = 0; i < n; i++)  if(bit1 & (1 << i))vb.push_back(l[i]);
                for(int i = 0; i < n; i++)  if(bit2 & (1 << i))vc.push_back(l[i]);
                if(!va.size() || !vb.size() || !vc.size())continue;
                cur += std::abs(std::accumulate(va.begin(),va.end(),0) - a) + ((int)va.size() - 1) * 10;
                cur += std::abs(std::accumulate(vb.begin(),vb.end(),0) - b) + ((int)vb.size() - 1) * 10;
                cur += std::abs(std::accumulate(vc.begin(),vc.end(),0) - c) + ((int)vc.size() - 1) * 10;
                res = std::min(res, cur);
            }
        }
    }
    std::cout << res << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int read()
{
	char s;
	int k=0,base=1;
	while((s=getchar())!='-'&&s!=EOF&&!(s>='0'&&s<='9'));
	if(s==EOF)exit(0);
	if(s=='-')base=-1,s=getchar();
	while(s>='0'&&s<='9')
	{
		k=k*10+(s-'0');
		s=getchar();
	}
	return k*base;
}
void write(int x)
{
	if(x<0)
	{
		putchar('-');
		write(-x);
	}
	else
	{
		if(x/10)write(x/10);
		putchar(x%10+'0');
	}
}
const int maxn=500010;
const int maxm=1010010;
int n,k,T;
int rd[maxn];
int p[maxn],q[maxn];
int ans[maxn];
int id,to[maxm<<1],ne[maxm<<1],po[maxn];
inline void add(int x,int y)
{
	id++;
	to[id]=y;ne[id]=po[x];
	po[x]=id;
	rd[y]++;
}
set<int> s;
set<int>::iterator it;
priority_queue<int,vector<int>,greater<int> > Q;
int main()
{
	n=read();k=read();
	for (int i=1;i<=n;i++) q[p[i]=read()]=i;
	for (int i=1;i<=n;i++)
	{
		if (i>k) s.erase(p[i-k]);
		it=s.insert(p[i]).first;
		if (++it!=s.end()) add(i,q[*it]);
	}
	for (int i=n;i>=1;i--)
	{
		if (i+k<=n) s.erase(p[i+k]);
		it=s.insert(p[i]).first;
		if (++it!=s.end()) add(i,q[*it]);
	}
	for (int i=1;i<=n;i++)
	{
		if (rd[i]==0) Q.push(i);
	}
	for (int i=1;i<=n;i++)
	{
		T=Q.top();Q.pop();
		ans[T]=i;
		for (int j=po[T];j;j=ne[j])
		{
			rd[to[j]]--;
			if (rd[to[j]]==0) Q.push(to[j]);
		}
	}
//	printf("-----------------------\n");
	for (int i=1;i<=n;i++)
	{
		printf("%d\n",ans[i]);
	}
	return 0;
}


Measured memory_bytes: 48384
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	ll n, m;

	cin>>n>>m;

	ll ansx=0, ansy=0;

	vll x(n), y(m);

	rep(i, n) cin>>x[i];

	rep(i, m) cin>>y[i];

	rep(i, n-1){
		ll xc=(ll)(n-1-i)*(ll)(i+1);
		ansx+=(xc*(x[i+1]-x[i]))%MOD;
		ansx=(ansx)%MOD;
	}

	rep(i, m-1){
		ll yc=(ll)(m-1-i)*(ll)(i+1);
		ansy+=(yc*(y[i+1]-y[i]))%MOD;
		ansy=(ansy)%MOD;
	}
	cout<<(ansx*ansy)%MOD<<endl;
}


Measured memory_bytes: 1792
using System.Collections.Generic;
using static System.Console;

class Program {
    static void Main() {
        var S = NextString();
        var x = new HashSet<char>();
        var y = new HashSet<char>();

        foreach (var v in S) {
            switch (v) {
                case 'N':
                    goto case 'S';
                case 'S':
                    y.Add(v);
                    break;
                case 'W':
                    goto case 'E';
                case 'E':
                    x.Add(v);
                    break;
            }
        }
        if (x.Count % 2 == 0 && y.Count % 2 == 0) {
            WriteLine("Yes");
        } else {
            WriteLine("No");
        }
    }

    static string NextString() {
        var result = new List<char>();
        while (true) {
            int next = Read();
            if (next < 0)
                break;
            var nextChar = (char)next;
            if (!char.IsWhiteSpace(nextChar))
                result.Add(nextChar);
            else if (nextChar != '\r')
                break;
        }
        return string.Join("", result);
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <cstring>
using namespace std;
bool s[21][21];
int e[4][2] = {
  { 0,1 }, { 1,0 }, { 0,-1 }, { -1,0 },
};
int main()
{
  int n,x,y,m,i,j;
  char d;
  for(;;){
    cin >> n;
    if(n==0)break;
    memset(s,0,sizeof(s));
    for(j=0;j<n;j++){
      cin >> x >> y;
      s[y][x] = true;
    }
    cin >> m;
    x = y = 10;
    if(s[y][x]) {
      s[y][x] = false;
      n--;
    }
    for(j=0;j<m;j++){
      cin >> d >> i;
      switch(d){
      case 'N': d = 0; break;
      case 'E': d = 1; break;
      case 'S': d = 2; break;
      case 'W': d = 3; break;
      }
      while(i--){
	x += e[d][0];
	y += e[d][1];
	if(s[y][x]) {
	  s[y][x] = false;
	  n--;
	}
      }
    }
    if(n) cout << "No" << endl;
    else cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#ifndef DEBUG
#pragma GCC optimize("O3,unroll-loops")
#pragma loop_opt(on)
#endif
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define FAST ;
#else
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define cerr
#endif
#define _ <<' '<<
#define Fr(i, s, e) for(auto i = s; i < e; ++i)
#define All(v) v.begin(),v.end()
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MOD = 998'244'353;

signed main() {
    FAST;

    ll a, b, n;
    cin >> a >> b >> n;
    cout << min(b-1,n)*a/b << endl;

}


Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
const ll MOD = 1e9 + 7;
using namespace std;

int main() {
	//四日目
	ll n = 0, a[100] = {};
	ll ans = 0;
	map<ll, ll> color; // 0:gray 1:brown 2:green 3:mizu 4:blue 5:yellow 6:orange 7:red 8:freedom
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		color[a[i] / 400]++;
	}
	color[8] += (color[9] + color[10] + color[11] + color[12]);
	rep(i, 8) {
		if (color[i] >= 1) {
			ans++;
		}
	}
	if (ans == 0) { ans++; }
	if(color[8] == n){
		cout << ans << " " << n << endl;
	}
	else {
		cout << ans << " " << ans + color[8] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int N,D;
	cin>>N>>D;
	int Min=D+1;
	int ans=1;
	while (Min+D+1<=N){
		ans++;
		Min+=2*D+1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static Scanner in = new Scanner(System.in);
	static boolean[][] r;
	public static void main(String[] args){
		int N = in.nextInt();
		int[] a = new int[N];
		for(int i = 0; i < N; i++){
			a[i] = in.nextInt();
		}
		
		int ud = 0;
		int sum = 1;
		for(int i = 1; i < N; i++){
			if(i == 0){
				
			}else if(ud == 1){
				if(a[i - 1] > a[i]){
					ud = 0;
					sum++;
				}
			}else if(ud == -1){
				if(a[i - 1] < a[i]){
					ud = 0;
					sum++;
				}
			}else{
				if(a[i - 1] < a[i]){
					ud = 1;
				}else if(a[i - 1] > a[i]){
					ud = -1;
				}
			}
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 50884
import java.util.*;
 
public class Main{
  public static void main (String args[]){
    Scanner sc = new Scanner(System.in);
    int numA = sc.nextInt();
    int numB = sc.nextInt();
    int ans = 0;
    
    if (numA <= 9 && numB <= 9){
      ans = numA*numB;
    } else {
      ans = -1;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23760
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

//macro
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define EPS (1e-8)
#define equals(a,b)(fabs((a)-(b))<EPS)

using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
//func
template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H); REP(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); REP(i, n)os << v[i] << (i == n - 1 ? "" : " "); return os; }
template <class T = int> inline T IN() { T x; cin >> x; return x; }
template<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(6);*/ } } pre__;

int main(void) {
	int A, B, C, X;
	cin >> A >> B >> C >> X;
	int ans = 0;
	REP(a, A + 1) {
		REP(b, B + 1) {
			REP(c, C + 1) {
				if (500 * a + 100 * b + 50 * c == X)ans++;
			}
		}
	}
	OUT(ans);
	return 0;
}

Measured memory_bytes: 256
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readLine >>= print . solve 

solve :: [Int] -> Int
solve [k, a, b]
    | k <= a || b - a < 3 = k + 1
    | odd d = (n + 1) * (b - a) + a
    | otherwise = n * (b - a) + a + 1
    where
        d = k - a
        n = d `div` 2

readLine :: IO [Int]
readLine = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

int main() {
    int n;
    cin >> n;
    deque<int> dq;
    for (int i = 1, a, p = n % 2; i <= n; i++) {
        cin >> a;
        if (p == i % 2) dq.push_front(a);
        else dq.push_back(a);
    }
    for (int i = 0; i < n; i++) {
        if (i > 0) cout << ' ';
        cout << dq[i];
    }
    cout << endl;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
bool a[10];
bool f(int n)
{
	while(n>0)
	{
		if(a[n%10]) return 0;
		n/=10;
	}
	return 1;
}
int main()
{
	ios::sync_with_stdio(false);
	int n,k,d;
	cin>>n>>k;
	for(register int i=1;i<=k;i++)
	{
		cin>>d;
		a[d]=1;
	}
	for(register int i=n;;i++)
	{
		if(f(i))
		{
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using ll = long long;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;

int digit_length(ll n)
{
    return int(to_string(n).size());
}

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
        cin >> a.at(i);

    ll mod_num = 1000000000000000000;

    for (ll i = 0; i < n; i++)
    {
        if(a.at(i)==0){
            cout << 0 << endl;
            return 0;
        }
    }

    ll answer = a.at(0);
    for (ll i = 1; i < n; i++)
    {
        if(a.at(i)==0){
            answer = 0;
            break;
        }
        // cout << answer << " " << a.at(i) << " " << log10(double(answer)) + log10(double(a.at(i))) << endl;
        if (log10(double(answer)) + log10(double(a.at(i))) >= 18.0)
        {
            if (answer * a.at(i) != mod_num)
            {
                answer = -1;
                break;
            }
        }
        answer *= a.at(i);
        if (log10(double(answer)) >= 18.0)
        {
            if (answer != mod_num)
            {
                answer = -1;
                break;
            }
        }
    }
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 4116
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
struct WRRYYYYY{
long long d,x;
};
int main(){
while(1){
int i,j,l,r,n,m,k[151];
long long up[151][11][151]={0},ans=0x7f7f7f7f;
WRRYYYYY p[151][11]={0};
scanf("%d%d",&n,&m);
if(n==0&&m==0)return 0;
for(i=0;i<n;i++){
	scanf("%d",&k[i]);
	for(j=0;j<k[i];j++){
		scanf("%lld%lld",&p[i][j].x,&p[i][j].d);
	}
}
memset(up,0x7f,sizeof(up));
for(i=0;i<k[0];i++){
	up[0][i][0]=0;
}
for(i=0;i<k[1];i++){
	up[1][i][1]=0;
}
for(i=0;i<n;i++){
	for(j=0;j<k[i];j++){
		for(l=0;l<k[i+1];l++){
			for(r=0;r<=m;r++){
				up[i+1][l][r]=min(up[i+1][l][r],up[i][j][r]+(p[i][j].d+p[i+1][l].d)*abs(p[i][j].x-p[i+1][l].x));
			}
		}
		if(i==n-1)continue;
		for(l=0;l<k[i+2];l++){
			for(r=0;r<m;r++){
				up[i+2][l][r+1]=min(up[i+2][l][r+1],up[i][j][r]+(p[i][j].d+p[i+2][l].d)*abs(p[i][j].x-p[i+2][l].x));
			}
		}
	}
}
for(i=0;i<=m;i++){
	for(j=0;j<k[n-1];j++){
		ans=min(ans,up[n-1][j][i]);
	}
	if(i==m)continue;
	for(j=0;j<k[n-2];j++){
		ans=min(ans,up[n-2][j][i]);
	}
}
printf("%lld\n",ans);
}
return 0;
}



Measured memory_bytes: 5212
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int X;
    cin >> X;
    cout << ((X == 7 || X == 5 || X == 3) ? "YES" : "NO") << endl;
}


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

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

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  int n,W;
  cin >> n >> W;
  VI w(n);
  VI v(n);

  rep(i,n) cin >> w[i] >> v[i];

  VLL dp(W+1,0);
  rep(i,n)for(int j = W; j >= 0; j--){
    if(w[i] + j <= W ) dp[w[i] + j] = max(dp[w[i] + j] , dp[j] + v[i]);
  }
  ll ans = 0;
  rep(i,W+1) ans = max(dp[i],ans);

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


Measured memory_bytes: 1024
tuplet=set()
count=0
input()
x=map(int,input().split())
for a in x:
    if a<400:
        tuplet.add("gr")
    elif a<800:
        tuplet.add("br")
    elif a<1200:
        tuplet.add("gre")
    elif a<1600:
        tuplet.add("wa")
    elif a<2000:
        tuplet.add("bl")
    elif a<2400:
        tuplet.add("ye")
    elif a<2800:
        tuplet.add("ore")
    elif a<3200:
        tuplet.add("red")
    else:
        count+=1
if count>0:
    ma=len(tuplet)+count
    mi=max(len(tuplet),1)
else:
    ma=len(tuplet)
    mi=ma
print("{} {}".format(mi,ma))

    

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

int main(){
  int N;
  cin>>N;
  vector<int> d(N);
  for(int &i:d)
    cin>>i;
  int k=0;
  for(int i=0;i<N;i++)
    for(int j=i+1;j<N;j++)
      k+=d.at(i)*d.at(j);
  cout<<k<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <bitset>

constexpr int INF = 1 << 30;

void solve() {
    int h, w, k;
    std::cin >> h >> w >> k;

    std::vector<std::string> ss(h);
    for (auto& s : ss) std::cin >> s;

    int ans = INF;
    for (int b = 0; b < (1 << (h - 1)); ++b) {
        std::vector<std::vector<int>> idxs;
        for (int x = 0; x < h; ++x) {
            if (x == 0 || (b >> (x - 1) & 1)) {
                idxs.push_back(std::vector<int>());
            }
            idxs.back().push_back(x);
        }

        int l = idxs.size();
        int cnt = 0;
        std::vector<int> sums(l, 0);
        for (int y = 0; y < w; ++y) {
            std::vector<int> tmps(l, 0);

            bool judge = true;
            for (int i = 0; i < l; ++i) {
                for (auto x : idxs[i]) {
                    tmps[i] += (ss[x][y] - '0');
                }

                if (tmps[i] > k) cnt = INF;
                if (sums[i] + tmps[i] > k) judge = false;
            }

            if (!judge) {
                ++cnt;
                std::fill(sums.begin(), sums.end(), 0);
            }
            for (int i = 0; i < l; ++i) sums[i] += tmps[i];
        }

        ans = std::min(ans, cnt + l - 1);
    }

    std::cout << ans << std::endl;
}

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

    solve();

    return 0;
}


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

int main(){
	ll a,b,c,d;
	cin >> a >> b >> c >> d;
	ll ans = max({a*c, a*d, b * c, b*d});
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3644
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         fozubaoyou    pass System Test!
*/

#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  int n,q;cin >> n >> q;
  string s;cin >> s;
  string key = "AC";
  vector<int> data(s.size(),0);
  REP(i,0,s.size()-1){
    if(s[i]=='A'&&s[i+1]=='C'){
      data[i+1] = data[i]+1;
    }
    else data[i+1] = data[i];
  }
  /*for(auto &i:data) cout << i << " ";
  cout << endl;*/
  rep(i,q){
    int l,r;cin >> l >> r;
    int ans = 0;
    l--,r--;
    cout << data[r]-data[l] << endl;
  }

}


Measured memory_bytes: 1408
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

///////////////////////////////////////////////////////////////////////////////////////

int main() {
	ll dp[35] = {};
	dp[0] = dp[1] = 1;
	dp[2] = 2;
	repi(i, 3, 31) {
		dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3];
	}
	while (1) {
		ll n;
		rd(n);
		if (n == 0) break;
		ll ans = ((dp[n] + 9) / 10 + 364) / 365;
		wrln(ans);
	}
	return 0;
}



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


int main() {
  vector<vector<char>> N(3, vector<char>(3));
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      cin >> N[i][j];
    }
  }

  cout << N[0][0] << N[1][1] << N[2][2] << endl;



  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

minus_num = 0
for a in A:
  if a < 0:
    minus_num += 1


A_abs = [abs(a) for a in A]
if minus_num % 2 == 0:
  print(sum(A_abs))
else:
  print(sum(A_abs) - 2*min(A_abs))

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

using namespace std;

int main(){
	int a[3];

	cin >> a[0] >> a[1] >> a[2];
	
	sort(a, a + 3);
	cout << a[0] << " " << a[1] << " "  << a[2] << endl;


	return 0;
}

Measured memory_bytes: 1180
if __name__ == "__main__":
    N, K = map(int, input().split())
    x = list(map(int, input().split()))

    ans = 10 ** 10
    for i in range(N-K+1):
        L = x[i]
        R = x[i+K-1]
        if L <= 0 and R <= 0:
            tmp = abs(L)
        elif L >= 0 and R >= 0:
            tmp = R
        else:
            tmp = abs(L) + (R-L)
            if tmp > 2 * R + abs(L):
                tmp = 2 * R + abs(L)
        if tmp < ans:
            ans = tmp
    print(ans)


Measured memory_bytes: 62576
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int f = 0;

		if (N % 10 == 7) {
			f++;
		}
		N /= 10;

		if (N % 10 == 7) {
			f++;
		}
		N /= 10;

		if (N == 7) {
			f++;
		}

		if (f == 0) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}

}

Measured memory_bytes: 35572
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

using pll = pair<ll, ll>;

ll solve(ll N, vector<ll> A, vector<ll> B) {
	vector<pll> v;
	REP(i, 3) if (A[i] < B[i]) v.emplace_back(A[i], B[i] - A[i]);
	
	if (v.size() == 0) return N;
	if (v.size() == 1) return N + N / v[0].fi * v[0].se;
	
	if (v.size() == 2) {
		// N <= 2.5*10^7
		ll l = v[0].fi * v[1].fi;
		ll res = N;
		if (N >= 2 * l) {
			ll c = (N - 2 * l) / l + 1;
			res += c * max(v[1].fi * v[0].se, v[0].fi * v[1].se);
			N -= c * l;
		}
		ll mx = 0;
		if (v[0].fi < v[1].fi) swap(v[0], v[1]);
		
		// N < 2*l
		REP(i, 2 * v[1].fi) {
			ll diff = N - v[0].fi * i;
			if (diff < 0) break;
			chmax(mx, v[0].se * i + diff / v[1].fi * v[1].se);
		}
		res += mx;
		return res;
	}
	if (v.size() == 3) {
		// N <= 5000
		vector<ll> dp(N + 1);
		REP(i, N) {
			chmax(dp[i + 1], dp[i]);
			REP(j, v.size()) {
				if (i + v[j].fi > N) continue;
				chmax(dp[i + v[j].fi], dp[i] + v[j].se);
			}
		}
		return dp[N] + N;
	}
}

int main() {
	ll N;
	vector<ll> A(3), B(3);
	cin >> N;
	REP(i, 3) cin >> A[i];
	REP(i, 3) cin >> B[i];
	
	ll ans = solve(N, A, B);
	ans = solve(ans, B, A);
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
N,X,Y=map(int,input().split())

ans=[0]*(N)
for i in range(1,N):
    for j in range(i+1,N+1):
        res=min(abs(j-i),abs(X-i)+abs(Y-j)+1,abs(X-j)+abs(Y-i)+1)
        ans[res]+=1

print('\n'.join(map(str,ans[1:])))

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt();
		int H = sc.nextInt();
		int N = sc.nextInt();
		int[] x = new int[N];
		int[] y = new int[N];
		int[] a = new int[N];
		for(int i = 0 ; i < N ; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			a[i] = sc.nextInt();
		}

		int xmax = W,xmin = 0, ymax = H, ymin = 0;
		for(int i = 0 ; i < N ; i++) {
			if(a[i] == 1) {
				xmin = Math.max(xmin, x[i]);
			} else if(a[i] == 2) {
				xmax = Math.min(xmax, x[i]);
			} else if(a[i] == 3) {
				ymin = Math.max(ymin, y[i]);
			} else if(a[i] == 4) {
				ymax = Math.min(ymax, y[i]);
			}
		}
		if(xmax - xmin > 0 && ymax - ymin > 0) {
			System.out.println((ymax - ymin) * (xmax - xmin));
		} else {
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 21844
n = int(input())
c = []
s = []
f = []
for i in range(n - 1):
    ci, si, fi = map(int, input().split())
    c.append(ci)
    s.append(si)
    f.append(fi)
#c, s, f
for i in range(n - 1):
    time = s[i] + c[i]
    for j in range(i + 1, n - 1):
        if time < s[j]:
            time = s[j] + c[j]
        elif time % f[j] != 0:
            time += f[j] - time % f[j] + c[j]
        else:
            time += c[j]
    print(time)
print(0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long; //using lll=__int128;
using pii=pair<int,int>;
#define repeat(i,a,b) for(int i=(a),iE=(b);i<iE;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,iE=(a);i>=iE;i--)
#define mst(a,x) memset((a),(x),sizeof(a))
#define N 100010
#define inf 1e9
#define qwq {cout<<"qwq"<<endl;}
#define int ll
const int mod=1000000007;
int co[4];
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	mst(co,0);
	cin>>n;
	int ans=1;
	repeat(i,0,n){
		int x;
		cin>>x;
		int *p=co+3,cnt=0;
		repeat(j,0,3)
		if(x==co[j]){
			cnt++;
			p=co+j;
		}
		ans=(ans*cnt)%mod;
		(*p)++;
		//cout<<i<<' '<<cnt<<' '<<co[0]<<' '<<co[1]<<' '<<co[2]<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;

    return 0;
}

Measured memory_bytes: 3624
//-- In the name of ALLAH --
// We're nothing and you're everything.
// Ya Ali!
#include<bits/stdc++.h>
using namespace std;

#define      pai              acos(-1)
#define      ff               first
#define      ss               second
#define      ll               long long
#define      pb               push_back
#define      mp               make_pair
#define      pll              pair<ll,ll>
#define      sz(a)            (ll)a.size()
#define      endl             "\n"
#define      gcd(a, b)        __gcd(a, b)
#define      lcm(a, b)        ((a)*((b)/gcd(a,b))
#define      all(vec)         vec.begin(),vec.end()
#define      ms(a, b)         memset(a,b,sizeof(a))
#define      TEST_CASE(t)     for(int zz=1;zz<=t;zz++)
#define      PRINT_CASE       printf("Case %d: ",zz)
#define      fii              freopen("input.txt","r",stdin);
#define      foo              freopen("output.txt","w",stdout);
#define      FAST             ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

const ll M   = 1e9+7;
const ll mxn = 1e5+7;


int  main()
{
    ll i,j,k,a,b,c,d,n,m,t,x,y,z,u,v;
    cin>>n>>m;
    a=n*2;
    b=n*4;
    if(m>=a && m<=b && m%2==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3636