akhauriyash/Code-Regression huggingface dataset:
x,y = 0.0,0.0
th = 90
loop do
  r,rot = gets.split(",").map(&:to_i)
  break if (r|rot)==0
  x+=r*Math.cos(th/180.0*Math::PI)
  y+=r*Math.sin(th/180.0*Math::PI)
  th-=rot
end
printf("%d\n%d\n",x,y)

Measured memory_bytes: 2436
#include <iostream>
#include <string>
#include <utility>

using namespace std;

typedef pair<int, int> pii;

int s2n(const string &str){
	if(str[0] == 'A'){
		return 1;
	}else if('2' <= str[0] && str[0] <= '9'){
		return str[0] - '0';
	}
	return 10;
}

pii calc(int *hand, int num){
	int elevens = 0, score = 0;
	for(int i = 0; i < num; ++i){
		if(hand[i] == 1){ ++elevens; score += 10; }
		score += hand[i];
	}
	while(score > 21 && elevens > 0){
		score -= 10;
		--elevens;
	}
	return pii(score, elevens);
}

int main(){
	int N;
	cin >> N;
	while(N--){
		int hptr = 0, dptr = 0;
		int hand[10] = { 0 }, deck[8] = { 0 };
		for(int i = 0; i < 2; ++i){
			string str;
			cin >> str;
			hand[hptr++] = s2n(str);
		}
		for(int i = 0; i < 8; ++i){
			string str;
			cin >> str;
			deck[i] = s2n(str);
		}
		pii result;
		while(true){
			result = calc(hand, hptr);
			if(result.first <= 16 || (result.second && result.first == 17)){
				hand[hptr++] = deck[dptr++];
			}else{ break; }
		}
		if(result.first == 21 && hptr == 2){
			cout << "blackjack" << endl;
		}else if(result.first > 21){
			cout << "bust" << endl;
		}else{
			cout << result.first << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
from copy import*
n=int(input())
d=[0]+list(map(int,input().split()))
c=dict(zip(list(range(13)),[0]*13))
for i in d:
  c[i]+=1
ans=0
for i in range(1,12):
  if c[i]==2:
    k=d.index(i)
    d[k]=24-d[k]
for i in range(1<<12):
  a=copy(d)
  cnt=24
  for j in range(1,12):
    if (i>>j)&1 and c[j]==1:
      k=d.index(j)
      a[k]=24-a[k]
  for j in range(n+1):
    for k in range(j+1,n+1):
      cnt=min(cnt,abs(a[j]-a[k]),24-abs(a[j]-a[k]))
  ans=max(cnt%24,ans)
print(ans)

Measured memory_bytes: 69916
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int h,w,n;
char data[1100][1100];
int tesu[1100][1100];
int chx[10];
int chy[10];

bool inrange(int x,int y){
	if(x<0||y<0||x>h-1||y>w-1) return false;
	else return true;
}
queue<int> qx;
queue<int> qy;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int bfs(int chnum){
	while(!qx.empty()){
		int sx = qx.front();
		int sy = qy.front();
		qx.pop(); qy.pop();
		REP(i,4){
			int nx = sx + dx[i];
			int ny = sy + dy[i];
			if(!inrange(nx,ny)) continue;
			if(data[nx][ny]!='X'){
				if(tesu[nx][ny]==-1||tesu[nx][ny]>tesu[sx][sy]+1){
					tesu[nx][ny] = tesu[sx][sy]+1;
					qx.push(nx);
					qy.push(ny);
				}
				if(data[nx][ny]==(chnum+'0')){
					return tesu[nx][ny];
				}
			}
		}
	}
	return -1;
}

int main(){
	cin >> h >> w >> n;
	REP(i,h){
		string tmp;
		cin >> tmp;
		REP(j,tmp.size()) {
			data[i][j] = tmp[j];
			if(data[i][j] == 'S'){
				chx[0] = i;
				chy[0] = j;
			}
			if('1'<=data[i][j]&&data[i][j]<='9'){
				chx[data[i][j]-'0'] = i;
				chy[data[i][j]-'0'] = j;
			}
		}
	}
	ll int ans = 0;
	FOR(i,0,n){
		REP(j,1100) REP(k,1100) tesu[j][k] = -1;
		qx.push(chx[i]);
		qy.push(chy[i]);
		tesu[chx[i]][chy[i]] = 0;
		ans += bfs(i+1);
		while(!qx.empty()) qx.pop();
		while(!qy.empty()) qy.pop();
	}
	/*FOR(i,0,n+1){
		cout << chx[i] << " " << chy[i] << endl;
	}
	REP(i,h){
		REP(j,w) cout << tesu[i][j] << " ";
		cout << endl;
	}*/
	cout << ans << endl;
}

Measured memory_bytes: 7024
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
 a.append(a[i] + A[i])
for i in range(M):
 b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
 if a[i] > K:
  break
 while b[j] > K - a[i]:
  j -= 1
 ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47428
#include <iostream>

int ans = 0;
std::string s;

int main()
{
    std::cin >> s;
    for (int i = 0; i < 3; i++) {
        if (s[i] == 'R') {
            ans++;
        }
        else if (ans == 1) {
            std::cout << ans << std::endl;
            return 0;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<map>
#include<cassert>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define MAX 500001

using namespace std;

map<string,int> getIndex;
int t,s;
bool found;
int T[MAX],S[MAX];
string type[12] = {"C","C#","D","D#","E","F","F#","G","G#","A","A#","B"};
int dc[] = {+0,+1,-1};
int dx[] = {-1,-2,+1};

void dfs(int cur_t,int cur_s)
{
  if(cur_s < 0)
    {
      if(cur_t == -1)found = true;
      return;
    }

  rep(i,3)
    {
      int music = (T[cur_t] + dc[i] + 12)%12;
      if(t <= cur_t+dx[i])continue;

      if(music == S[cur_s])
	{
	  dfs(cur_t+dx[i],cur_s-1);
	}
    }
}

bool compute()
{
  found = false;
  dfs(t-1,s-1);
  dfs(t-2,s-1);
  return found;
}

int main()
{
  rep(i,12)getIndex[type[i]] = i;
  int N;
  while(cin >> N)
    {
      while(N--)
	{

	  cin >> t >> s;
	  string input;
	  rep(i,t)
	    {
	      cin >> input;
	      T[i] = getIndex[input];
	    }
	  rep(i,s)
	    {
	      cin >> input;
	      S[i] = getIndex[input];
	    }
	  
	  cout << (compute()?"Yes":"No") << endl;

	}
    }
  return 0;
}

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

int main(){
  long long n; 
  cin >> n;
  
  vector<long long> l(n+1, 2);
  l.at(1) = 1;
  for(int i = 2; i <= n; i++){
    l.at(i) = l.at(i-1) + l.at(i-2);
  }
  
  cout << l.at(n) << endl;
}

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

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

    int res = 0;
    int i = 0;
    int j = N-1;
    while(true){
        while(i < N && S[i] == 'R') i++;
        while(j >=0 && S[j] == 'W') j--;
        if(i > j){
            break;
        }else{
            res++;
            swap(S[i], S[j]);
            i++;
            j--;
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3752
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long m = sc.nextLong();
        long n = sc.nextLong();
        long ans = 1;
        long mod = 1000000007;
        while(n > 0){
            if(n % 2 == 1)
                ans = (ans * m) % mod;
            m = (m * m) % mod;
            n /= 2;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 26396
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
int[] cp={0,13,1,2,3,4,5,6,7,8,9,10,11,12};
    int a = Integer.parseInt(sc.next());
    int b = Integer.parseInt(sc.next());
if(cp[a]>cp[b]){
    out.println("Alice");
}else if(cp[a]==cp[b]){
    out.println("Draw");
}else{
    out.println("Bob");
}
}}

Measured memory_bytes: 21844
#include <iostream>
#include <string>//
#include <vector>//
#include <map>
#include <cstdlib>
#include <numeric>
#include <algorithm>//ソート等に使用
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <thread>///////////////////
#include <queue>//幅優先等のキュー

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

#define MOD 1000000007
//#define MOD 998244353
#define MAX 

using namespace std;

using ll = long long int;
using ld = long double;
using std::swap;

vector<int> v;
vector<int> w;
vector<long long int> vll;
vector<long long int> wll;
//vector<vector<int>> vec(50, vector<int>(4, 0));
vector<vector<int>> vv;
vector<vector<int>> ww;


int main() {
	int X, N;
	cin >> X >> N;
	if (N == 0) {
		cout << X << '\n';
		return 0;
	}
	v.resize(N);
	rep(i, 0, N)cin >> v[i];
	sort(v.begin(), v.end());
	int border = lower_bound(v.begin(), v.end(), X) - v.begin();

	if (find(v.begin(), v.end(), X) == v.end()) {
		cout << X << '\n';
		return 0;
	}
	int a1 = v[N - 1] + 1, a2 = v[0] - 1;
	rep(i, border, N) {
		if (border < N-1 && v[i + 1] - v[i] > 1) {
			a1 = v[i] + 1;
			break;
		}
	}
	rem(i, border, 0) {
		if (v[i] - v[i - 1] > 1) {
			a2 = v[i] - 1;
			break;
		}
	}

	if (a1 - X < X - a2)cout << a1 << '\n';
	else cout << a2 << '\n';
	return 0;
}

Measured memory_bytes: 3600
#include<iostream>
using namespace std;
int dp[100000][3]={0};
int n,a[100000][3];
int ans(int i,int j)
{
	if(i==n)
		return 0;
 
	if(dp[i][j]!=0)
		return dp[i][j];
 
	int best=0;
	for(j;j<3;j++)
	{
		for(int k=0;k<3;k++) 
		{
			if(k==j)
				continue;
			best=max(best,a[i][j]+ans(i+1,k));
		}
		if(i!=0)
			break;
	}
	return dp[i][j]=best;
}
 
int main()
{
	ios_base::sync_with_stdio(0);           
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
			cin>>a[i][j];
	}
	cout<<ans(0,0);
    
    return 0;
}

Measured memory_bytes: 13720
import math

n, t = map(int, input().split())
h = [0] * n

for i in range(n):
    h[i] = int(input())

t_first = [0] * (n + 1)
w = [0] * n

print(math.ceil((t + 0.5) / h[0]))

t_first[1] = h[0]

for i in range(1, n):

    if t_first[i] > t:
        print(1)
        t_first[i + 1] = t_first[i] + h[i]
        continue
    
    if h[i - 1] + w[i - 1] > h[i]:
        w[i] = (h[i - 1] + w[i - 1]) - h[i]
        t_first[i + 1] = t_first[i] + h[i]

        delta_t = t - t_first[i]
        temp = math.ceil((delta_t + 0.5) / (h[i] + w[i]))

        if delta_t % (h[i] + w[i]) >= h[i]:
            print(temp + 1)
        else:
            print(temp)
        
    else:
        w[i] = 0
        t_first[i + 1] = t_first[i] + h[i]

        delta_t = t - t_first[i]
        print(math.ceil((delta_t + 0.5)/ h[i]))



Measured memory_bytes: 16216
#include<bits/stdc++.h>
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define fast ios_base:: sync_with_stdio( false ); cin.tie(0); cout.tie(0);
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define mod 1000000007
typedef long long ll;
using namespace std;

const int M = (int)(2e6 + 239);


int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast

    ll a,b;
    cin>>a>>b;
    if(b>=a)
    {
        cout<<"unsafe"<<endl;
    }
    else
    {
        cout<<"safe"<<endl;
    }
}


Measured memory_bytes: 3648
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
    public static void main(String[] args){
        FastScanner sc = new FastScanner();
        String charcter = sc.next();
        List<String> vowels = new ArrayList<>(Arrays.asList("a", "i", "u", "e", "o"));
        if(vowels.contains(charcter)){
            System.out.println("vowel");
        }else{
            System.out.println("consonant");
        }

    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
    }
}

Measured memory_bytes: 21332
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
typedef long long ll;
using namespace std;

int main(){
  string S;
  cin >> S;
  int n = S.size();
  vector<int> s(n);
  for(int i = 0; i < n; i++){
    s.at(i) = S.at(i) - '0';
  }

  ll sum = 0;
  int max_i = pow(2, n - 1);
  for(int bit = 0; bit < max_i;  bit++){
    ll d = 1;
    for(int i = 0; i < n; i++){
      sum += d * s.at(n - 1 - i);
      if(bit & 1 << i){
        d = 1;
      }else{
       d *= 10;
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#ifndef _MSC_VER
#include <bits/stdc++.h>
#else
#include <__msvc_all_public_headers.hpp>
#endif
using namespace std;

#define for0(i, n)      for (int i = 0; i < (int)(n); ++i)
#define for1(i, n)      for (int i = 1; i <= (int)(n); ++i)
#define forc(i, l, r)   for (int i = (int)(l); i <= (int)(r); ++i)
#define forr0(i, n)	    for (int i = (int)(n) - 1; i >= 0; --i)
#define forr1(i, n)     for (int i = (int)(n); i >= 1; --i)
#define wh(t)           while (t--)
	
#define endl "\n"

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

map<ll,int> f(ll n) {
	map<ll,int> s;
	ll k = 2;
	while (n > 1 && k * k <= n) {
		while (n % k == 0) {
			s[k]++;
			n /= k;
		}
		k++;
	}
	if (n > 1) s[n]++;
	return s;
}

const vector<int> tr = { 1,3,6,10,15,21,28,36,45, 55, 66, 78, 91,105,120, 136 };

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(10);

	ll n;
	cin >> n;
	auto s = f(n);
	int cnt = 0;
	for (auto a : s) {
		int i = 1;
		while (tr[i] <= a.second) i++;
		cnt += i;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 3632
fn eval_op(x: i32, y: i32, op: char) -> i32 {
    match op {
        '+' => x + y,
        '-' => x - y,
        '*' => x * y,
        '/' => x / y,
        _ => panic!("Unexpected op: `{}`", op),
    }
}

fn evaluate(inputs: &Vec<String>) {
    let num_or_ops = inputs
        .iter()
        .map(|input| {
            let c = &input;
            let num_or_op = match c.parse::<i32>() {
                Ok(num) => (Some(num), None),
                Err(_) => {
                    let op = c.chars().next().unwrap();
                    (None, Some(op))
                }
            };
            num_or_op
        })
        .collect::<Vec<_>>();

    // println!("{:?}", &num_or_ops);

    let n = inputs.len();
    let mut stack = vec![-1; n];
    let mut i_current = 0;

    for num_or_op in num_or_ops {
        match num_or_op {
            (Some(num), None) => {
                stack[i_current] = num;
                i_current += 1;
            }
            (None, Some(op)) => {
                let res = eval_op(stack[i_current - 2], stack[i_current - 1], op);
                stack[i_current - 2] = res;
                stack[i_current - 1] = -1;
                i_current -= 1;
            }
            _ => panic!("Unexpected num_or_ops"),
        }
    }
    // println!("{:?}", stack);
    println!("{}", stack[0]);
}

fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).ok();
    let inputs: Vec<String> = line.split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect();
    evaluate(&inputs);
}



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

bool palindrome(string &S){
  int N = S.size();
  bool palind = true;
  if (N % 2 == 1){
    for (int i = 0; i < (N - 1) / 2; i++){
      if (S.at(i) != S.at(N - i - 1)){
        palind = false;
        break;
      }
    }
  }
  else{
    for (int i = 0; i < N / 2; i++){
      if (S.at(i) != S.at(N - i - 1)){
        palind = false;
        break;
      }
    }
  }
  return palind;
}

int main(){
  string S;
  cin >> S;
  int N = S.size();
  
  int st_palind = 0;
  string Sf = "";
  for (int i = 0; i < (N - 1) / 2; i++){
    Sf.push_back(S.at(i));
  }
  string Sb = "";
  for (int i = (N + 1) / 2; i < N; i++){
    Sb.push_back(S.at(i));
  }
  
  if (palindrome(S)){
    st_palind++;
  }
  if (palindrome(Sf)){
    st_palind++;
  }
  if (palindrome(Sb)){
    st_palind++;
  }
  
  if (st_palind == 3){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  if(a>b){
    printf("a > b\n");
  }
  if(a<b){
    printf("a < b\n");
  }
  if(a==b){
    printf("a == b\n");
  }
  return(0);
}

Measured memory_bytes: 580
import sys

readline = sys.stdin.readline

N, M = map(int, readline().split())

LR = [list(map(int, readline().split())) for i in range(M)]

LR.sort(key=lambda x:x[0])


span = LR[0]
for l, r in LR:
    if l > span[1]:
        span = None
        break
    else:
        span[0] = l
        span[1] = min(r, span[1])

if span is None:
    print(0)
else:
    print(span[1] - span[0] + 1)

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

int main()
{
    string s, t; 
    cin >> s >> t; 
    short longueur = s.length(); 
    for (short i = 0; i < longueur; i ++) {
        if (s[i] != t[i])  {
            cout << "No"; 
            return 0; 
        }
    }
    cout << "Yes"; 
    return 0; 
}


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

typedef long long ll;

int main()
{
  int n;
  ll power = 1;

  cin >> n;
  for (int i = 1; i <= n; i++)
  {
    power *= i;
    power %= 1000000007;
  }

  cout << power << endl;
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
V = {v: 0 for v in range(1, N+1)}
E = {v: [] for v in V.keys()}
for _ in range(N-1):
    a, b = map(int, input().split())
    E[a].append(b)
    E[b].append(a)
added = {v: 0 for v in V.keys()}
for _ in range(Q):
    p, x = map(int, input().split())
    added[p] += x
stack = [(1, added[1])]
visited = {v: False for v in V.keys()}
while stack:
    v, value = stack.pop()
    visited[v] = True
    V[v] += value
    for u in E[v]:
        if not visited[u]:
            stack.append((u, value + added[u]))
print(*[val for val in V.values()])

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

int main() {
  string S;
  
  cin >> S;
  
  int a = S.size();
  
  for (int i = 0; i < a; i++) {
    S.at(i) = 'x';
  }
  
  cout << S << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for(int i=(l); i<(r); ++i)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

int n;
int t[110], v[110], cum[110];

double f(int i, double t){
    if(i==0) return t;
    if(i==n+1) return cum[n]-t;

    if(0<=t && t<=cum[i-1]) return v[i]+(cum[i-1]-t);
    else if(cum[i-1]<t && t<=cum[i]) return v[i];
    else return v[i]+(t-cum[i]);
}

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

    cin >> n;
    rep(i, 1, n+1) cin >> t[i];
    rep(i, 1, n+1) cin >> v[i];
    rep(i, 1, n+1) cum[i] = cum[i-1]+t[i];

    double ans=0.0;
    double a=0.0;
    for(double t=0.5; t<=cum[n]; t+=0.5){
        double b=500.0;
        rep(i, 0, n+2) chmin(b, f(i, t));
        ans += (a+b)*0.25;
        a=b;
    }
    printf("%.10lf\n", ans);
    
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())

def main():
    N = ii()
    B = lmis()
    B = [B[0]] + B + [B[-1]]
    ans = 0
    for i in range(N):
        ans += min(B[i], B[i+1])
    
    print(ans)

main()


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
    ll a, b, c; cin >> a >> b >> c;
    if (c - a - b <= 0) {
        cout << "No" << endl;
        return 0;
    }

    if (4 * a * b < (c - a - b) * (c - a - b)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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;

const int M = 1000005;

int main(){
  int n; cin >>n;
  vector<int> a(n);
  rep(i,n) cin >>a[i];
  vector<int> cnt(M);
  for(int x : a){
    if(cnt[x]!=0){
      cnt[x] = 2;
      continue;
    }
    for(int i = x; i<M; i+=x) cnt[i]++;
  }
  int ans = 0;
  for(int x : a){
    if(cnt[x]==1) ans++;
  }
  cout << ans << endl;
  return 0; 
}


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

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

using namespace std;


int main(){
    string s;
    int x;
    cin >> s;
    if(s=="SUN")
        x = 7;
    if(s=="MON")
        x = 6;
    if(s=="TUE")
        x = 5;
    if(s=="WED")
        x = 4;
    if(s=="THU")
        x = 3;
    if(s=="FRI")
        x = 2;
    if(s=="SAT")
        x = 1;
    cout << x << endl;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	char x, y;
	cin >> x >> y;
	if(x - y < 0) cout << "<" << endl;
	else if(x - y > 0) cout << ">" << endl;
	else cout << "=" << endl;
	return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
//#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}



int main(void) {
    FAST_IO;
    
    ll a, b, c;
    cin >> a >> b >> c;
    ll t = a + b - c;
    ll x = c - a - b;
    if (a > c || b > c) {
        cout << "No" << endl;
        return 0;
    }
    if (4 * a * b < x * x) {
        // puts("Yes");
        cout <<"Yes" << endl;
    } else {
        cout<< "No" << endl;
        // puts("No");
    }
    
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// 参考
// https://atcoder.jp/contests/abc138/submissions/6991530
fn main() {
    input! {
        n: usize,
        q: usize,
        abs: [(usize1, usize1); n-1],
        pxs: [(usize1, usize); q],
    }
    let mut to = vec![vec![]; n];
    for (a, b) in abs {
        to[a].push(b);
        to[b].push(a);
    }

    let mut ans = vec![0; n];
    for (p, x) in pxs {
        ans[p] += x;
    }

    dfs(0, 0, &to, &mut ans);

    for i in ans {
        println!("{}", i);
    }
}

fn dfs(v: usize, p: usize, to: &Vec<Vec<usize>>, ans: &mut Vec<usize>) {
    for &u in &to[v] {
        if u == p as usize {continue;}
        ans[u] += ans[v];
        dfs(u, v, to, ans);
    }
}

Measured memory_bytes: 39160
#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)

typedef long long LL;
typedef unsigned long UL;

using namespace std;

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

    int n;
    cin >> n;

    vector<string> w(n);
    REP(i, n) cin >> w[i];

    for (int i = 0; i < n; ++i)
    {
        for (int j = i + 1; j < n; ++j)
        {
            if (w[i] == w[j])
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    REP(i, n)
    {
        if (i < n - 1)
            if (w[i].back() != w[i + 1].front())
            {
                cout << "No" << endl;
                return 0;
            }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int MOD = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge{
    ll to, cost;
};


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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 素数
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true);
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i){
        if(IsPrime[i]){
            for(size_t j=2; i*j<=max; ++j){
                IsPrime[i*j] = false;
            }
        }
    }
}

// べき乗の余り
ll modpow(ll a, ll n){
    ll res = 1;
    while(n){
        if(n & 1){
            res = res * a % MOD;
        }
        a = a * a % MOD;
        n = n >> 1;
    }
    return res;
}

// コンビネーション
ll MAXN = 2e5+10;
vector<ll> inv(MAXN);
ll nCk(ll n, ll k) {
	ll res = 1;
	for(ll i = 1; i <= k; i++) {
		res = res*(n-i+1) % MOD;
	}
 
	for(ll i = 1; i <= k; i++) {
		res = res*inv[i] % MOD;
	}
	return res;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

string ans = "No";
ll k;
void dfs(ll n, ll x, ll y, ll z){
    if(x < y and y < z){
        ans = "Yes";
    }
    if(n == k){
        return;
    }
    dfs(n+1, x*2, y, z);
    dfs(n+1, x, y*2, z);
    dfs(n+1, x, y, z*2);
    return;
}

int main(){
    ll a, b, c;
    cin>>a>>b>>c;
    cin>>k;
    dfs(0, a, b, c);
    cout<<ans<<endl;
}

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

using namespace std;

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

    int a, b, c;
    cin >> a >> b >> c;
    cout << (a + b + c >= 22 ? "bust\n" : "win\n");

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
    ll n;
    cin >> n;
    vector<ll> ret;
    for(ll i = 1; i*i <= n; i++){
    if(n % i == 0){
        ret.push_back(i);
        if(i * i != n)ret.push_back(n/i);
    }
  }
  sort(all(ret));
  int s = ret.size();
  if(s % 2 == 0)cout << ret.at(s/2) + ret.at(s/2-1)-2;
  else cout << 2*ret.at(s/2)-2;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    string O, E;
    cin >> O >> E;

    int o_size = O.size();
    int e_size = E.size();
    int now_o_size = 0;
    int now_e_size = 0;
    string pass = "";
    while (now_o_size <= o_size) {
        if (now_o_size < o_size) {
            pass += O[now_o_size];
        }

        if (now_e_size < e_size) {
            pass += E[now_e_size];
        }

        now_o_size += 1;
        now_e_size += 1;
    }

    cout << pass << endl;

    return 0;
}

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

using namespace std;

int main(){
    int N,ans=0;
    cin >> N;
    vector<int> a(N,0);

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

for(int i=0;i<N;i++){
    while((a[i]%2)==0){
            a[i] /= 2;
            ans++;
        }
}

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int solve(int x) {
    int popcount = 0;
    REP(k, 20) if(x>>k&1) popcount++;
    if(popcount == 0) return 0;
    else return x % popcount;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int N;
    cin >> N;
    string X;
    cin >> X;
    int ones = 0;
    REP(i, N) if(X[i] == '1') ones++;
    int modp = 0;
    vector<int> modplist(N);
    modplist[N-1] = 1;
    int modm = 0;
    vector<int> modmlist(N);
    modmlist[N-1] = 1;
    IREP(i, N) {
        if(i != N-1) {
            modplist[i] = modplist[i+1] * 2 % (ones+1);
            if(ones > 1) modmlist[i] = modmlist[i+1] * 2 % (ones-1);
        }
        if(X[i] == '1') {
            modp = (modp + modplist[i]) % (ones+1);
            if(ones > 1) modm = (modm + modmlist[i]) % (ones-1);
        }
    }
    REP(i, N) {
        int ans = 1;
        if(X[i] == '1') {
            if(ones == 1) {
                ans = 0;
            } else {
                int val = (modm - modmlist[i] + (ones-1)) % (ones-1);
                while(val > 0) {
                    val = solve(val);
                    ans++;
                }
            }
        } else {
            int val = (modp + modplist[i]) % (ones+1);
            while(val > 0) {
                val = solve(val);
                ans++;
            }
        }
        cout << ans << "\n";
    }
}

Measured memory_bytes: 5172
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
#include <sstream>
#include <set>
#include <queue>
#include <tuple>

using namespace std;

#define For(i,a,n)	for(int i = a;i < n;i++)
#define rep(i,n)	For(i,0,n)
#define clr(n)		memset(n,0,sizeof n)
#define all(n)		(n).begin(),(n).end()

typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef pair<P, P> WP;
typedef long long ll;

const ll INF = 1e9;
int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
bool cheak(int x, int y, int mx, int my){
	return x >= 0 && y >= 0 && x < mx &&  y < my;
}

string s[2][51];

int d[51][51][51][51];

int main()
{
	int w, h;

	while (cin >> w >> h && w){
		clr(d);
		int sx[2], sy[2];
		int gx[2], gy[2];
		rep(y, h){
			cin >> s[0][y] >> s[1][y];
			rep(x, w){
				if (s[0][y][x] == '%')gx[0] = x, gy[0] = y;
				if (s[1][y][x] == '%')gx[1] = x, gy[1] = y;
				if (s[0][y][x] == 'L')sx[0] = x, sy[0] = y;
				if (s[1][y][x] == 'R')sx[1] = x, sy[1] = y;
			}
		}
		d[sy[0]][sx[0]][sy[1]][sx[1]] = 1;

		queue<P> q0, q1;
		q0.push(P(sy[0], sx[0]));
		q1.push(P(sy[1], sx[1]));

		while (q0.size()){
			int ly = q0.front().first, lx = q0.front().second;
			int ry = q1.front().first, rx = q1.front().second;
			q0.pop(), q1.pop();

			rep(i, 4){
				int nlx = lx + dx[i], nly = ly + dy[i];
				int nrx = rx - dx[i], nry = ry + dy[i];

				bool lf = (cheak(nlx, nly, w, h) && s[0][nly][nlx] != '#');
				bool rf = (cheak(nrx, nry, w, h) && s[1][nry][nrx] != '#');

				if ((rf || lf)){
					if (!lf)nlx = lx, nly = ly;
					if (!rf)nrx = rx, nry = ry;
					if (!d[nly][nlx][nry][nrx]){

						if (s[0][nly][nlx] == '%' || s[1][nry][nrx] == '%'){
							if (!(s[0][nly][nlx] == '%') || !(s[1][nry][nrx] == '%')){
								continue;
							}
						}
						d[nly][nlx][nry][nrx] = 1;
						q0.push(P(nly, nlx));
						q1.push(P(nry, nrx));
					}
				}
			}
		}
		if (d[gy[0]][gx[0]][gy[1]][gx[1]])cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
	 string s;
    cin>>s;
    int a,b,c,d;
    a=s[0]-48;
    b=s[1]-48;
    c=s[2]-48;
    d=s[3]-48;
    int x,y;
    x=a*10 + b;
    y=c*10 + d;
    if(x<=12 && x>0 && y<=12 &&y>0)
    {
        cout<<"AMBIGUOUS"<<endl;
    }
    else if(x<=12 && x>0 &&(y>12||y==0))
    {
        cout<<"MMYY"<<endl;
    }
    else if((x>12||x==0) && y<=12 &&y>0)
    {
        cout<<"YYMM"<<endl;
    }
    else
    {
        cout<<"NA"<<endl;
    }	
	
    return 0;
}


Measured memory_bytes: 256
import math

N, H = map(int, input().split())
a = []
b = []

for i in range(N):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)
max_a = max(a)
b = [i for i in b if i >= max_a]
b.sort()
b.reverse()
count = 0
for i in b:
    H -= i
    count +=1
    if H <= 0:
        print(count)
        quit()
print(math.ceil(H /max_a)+count)

Measured memory_bytes: 11864
import java.util.*;

public class Main{
    int N,M,L,K,A,H;
    int[] d;
    List<Edge>[] adj;
    int INF = 1000000000;
    boolean[] cancold;

    public static void main(String[] args){
	new Main().solve();
    }

    class Edge{
	int t, c;
	public Edge(int t, int c) {
	    this.t = t;
	    this.c = c;
	}
    }

    @SuppressWarnings("unchecked")
    void solve(){
	Scanner sc = new Scanner(System.in);
	N = sc.nextInt();
	while(N!=0){
	    M = sc.nextInt();
	    L = sc.nextInt();
	    K = sc.nextInt();
	    A = sc.nextInt();
	    H = sc.nextInt();
	    cancold = new boolean[N];
	    for(int i=0; i<L; i++){
		cancold[sc.nextInt()] = true;
	    }
	    cancold[A] = true; cancold[H] = true;
	    
	    adj = new List[N];
	    for(int i=0; i<N; i++)adj[i] = new ArrayList<Edge>();
	    for(int i=0; i<K; i++){
		int x = sc.nextInt();
		int y = sc.nextInt();
		int t = sc.nextInt();
		adj[x].add(new Edge(y,t));
		adj[y].add(new Edge(x,t));
	    }

	    d = new int[N*(M+1)];

	    dijkstra(A);

	    if(d[H*(M+1)+M]==INF){
		System.out.println("Help!");
	    }else{
		System.out.println(d[H*(M+1)+M]+Math.max(0,d[H*(M+1)+M]-M));
	    }

	    N = sc.nextInt();
	}
    }

    void dijkstra(int s){
	Arrays.fill(d,INF);
	d[s*(M+1)+M] = 0;
	PriorityQueue<Integer> q = new PriorityQueue<Integer>(N, new Comparator<Integer>() {
		public int compare(Integer o1, Integer o2) {
		    return d[o1]-d[o2];
		}
	    });

	q.add(s*(M+1)+M);
	while(!q.isEmpty()){
	    int v = q.poll();
	    int town = v/(M+1);
	    int left = v%(M+1);
	    for(Edge e:adj[town]){
		if(left-e.c<0)continue;
		int w = d[town*(M+1)+left]+e.c;
		if(cancold[e.t]){
		    if(w<d[e.t*(M+1)+M]){
			q.remove(e.t*(M+1)+M); 
			d[e.t*(M+1)+M] = w; 
			q.add(e.t*(M+1)+M);
		    }
		}else{
		    if(w<d[e.t*(M+1)+left-e.c]){
			q.remove(e.t*(M+1)+left-e.c); 
			d[e.t*(M+1)+left-e.c] = w; 
			q.add(e.t*(M+1)+left-e.c);
		    }
		}
	    }
	}
    }
}

Measured memory_bytes: 13000
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>

using namespace std;

typedef long long ll;
const ll nmax = 1e9 + 7;
const ll mod = 998244353;
const double PI = 2 * asin(1);


int main(){
  int N; ll M, V, P;
  cin >> N >> M >> V >> P;

  vector <ll> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  sort(A.begin(), A.end(), greater<ll>());

    
  int L = P - 1, R = N;
  while ((L + 1) < R){
    int now = (L + R) / 2;

    if (A[now] + M < A[P - 1]){
      R = now;
      continue;
    }

    ll rest = max(0ll, V - (N - now) - (P - 1));

    ll C = A[now] + M, sum = 0;
    for (int i = P - 1; i < now; i++){
      sum += C - A[i];
    }
    
    if (sum >= rest * M) L = now;
    else R = now;
  }

  cout << R << endl;

  return 0;
}


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

int main() {
	int a, b;
	string s;
	cin >> a >> b;
	cin >> s;
	for (int i = 0; i < a; i++) {
		if (!(48 <= (int)s[i] && (int)s[i] <= 57)) {
			cout << "No" << endl;
			return 0;
		}
	}
	if (s[a] != '-') {
		cout << "No" << endl;
		return 0;
	}
	for (int i = a + 1; i < a + b + 1; i++) {
		if (!(48 <= (int)s[i] && (int)s[i] <= 57)) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

void print(int a[], int n){
    for(int i=0; i<n-1; i++){
        cout << a[i] << " ";
    }
    cout << a[n-1] << endl;
}

int main(){
    int n;
    cin >> n;
    int a[10];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    if(prev_permutation(a, a+n)){
        print(a, n);
    }
    next_permutation(a, a+n);
    print(a, n);
    if(next_permutation(a, a+n)){
        print(a, n);
    }
    return 0;
}


Measured memory_bytes: 3104
#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) (v).begin(),(v).end()
#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; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> P;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int N, x;
int a[2000];
int d[2001][2000];

int main() {
	cin >> N >> x;
	REP(i, N) scanf("%d", a + i);
	
	REP(i, N) d[0][i] = a[i];
	REP(i, N) REP(j, N) d[i + 1][j] = min(d[i][j], d[i][(j - 1 + N) % N]);
	
	ll ans = 1ll<<60;
	
	REP(i, N + 1) {
		ll cost = (ll)x * i;
		
		REP(j, N) cost += d[i][j];
		
		chmin(ans, cost);
	}
	
	cout << ans << endl;
	
	return 0;
}


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  if (A == B && B != C) {
    cout << "Yes" << endl;
  } else if (A != B && B == C) {
    cout << "Yes" << endl;
  } else if (A != B && A == C) { 
    cout << "Yes" << endl;
  } else if (A != B && A != C) { 
    cout << "No" << endl;
  } else if (A == B && A == C) {
    cout << "No" << endl;
  } 
}


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

//#define DEBUG

using namespace std;

template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}


void solve(){
    int64_t A, B;
    uint64_t V, W, T;
    cin >> A >> V >> B >> W >> T;
    // assume B > A
    uint64_t distance = abs(A - B);
    if( distance == 0 ){
        cout << "YES" << endl;
    }else{
        if( V > W){
            uint64_t relative_speed = V - W;
            if( relative_speed * T >= distance){
                cout << "YES" << endl;
            }else{
                cout << "NO" << endl;
            }
        }else{
            cout << "NO" << endl;
        }
    }
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 3;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}


Measured memory_bytes: 3648
s=input()
p=[0]*2
for a,i in enumerate(s):
    if a%2==0 and i=="0":
        p[0]+=1
    if a%2==1 and i=="1":
        p[0]+=1
    if a%2==0 and i=="1":
        p[1]+=1
    if a%2==1 and i=="0":
        p[1]+=1

print(min(p))

Measured memory_bytes: 40048
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

int main() {
	ll N; cin >> N;
	ll a = 2;
	ll b = 1;

	if (N == 1) {
		cout << b << endl;
		return 0;
	}
	ll c = 0;
	repe(i, 2, N) {
		c = a + b;
		a = b;
		b = c;
	}
	cout << c << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main (void)
{
	int gr[101][101],gou,gyo,retu;
	int a,b; 

	scanf("%d %d",&gyo,&retu);

	for(a=0;a<=gyo;a++)//?????????
	{
		for(b=0;b<=retu;b++)
		{
			gr[a][b]=0;
		}
	}
	for(a=0;a<gyo;a++)//??\???
	{
		for(b=0;b<retu;b++)
		{
			scanf("%d",&gr[a][b]);
		}
	}

	gou=0;
	for(a=0;a<gyo;a++)//????????????
	{
		gou=0;
		for(b=0;b<retu;b++)
		{
			gr[a][retu]+=gr[a][b];
		}
	
	}

	gou=0;
	for(b=0;b<retu;b++)
	{
		gou=0;
		for(a=0;a<gyo;a++)//????????????
		{
			gr[gyo][b]+=gr[a][b];
		}
		gr[gyo][retu]+=gr[a][b];
	}

	
	for(a=0;a<=gyo;a++)
	{
		for(b=0;b<=retu;b++)
		{
			printf("%d",gr[a][b]);
			if(b!=retu)printf(" ");
		}
		if(a!=gyo)printf("\n");
		
	}

	printf("\n");
	return 0;
}

Measured memory_bytes: 644
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(a<b){
			if(b<c){
				System.out.println(a+" "+b+" "+c);
			}else{
				if(a<c){
					System.out.println(a+" "+c+" "+b);
				}else{
					System.out.println(c+" "+a+" "+b);
				}
			}
		}else{
			if(b>c){
				System.out.println(c+" "+b+" "+a);
			}else{
				if(a<c){
					System.out.println(b+" "+a+" "+c);
				}else{
					System.out.println(b+" "+c+" "+a);
				}
			}
		}
	}
}

Measured memory_bytes: 26332
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int count=0;

		StringTokenizer st1 = new StringTokenizer(br.readLine());
		int a=Integer.parseInt(st1.nextToken());
		int b=Integer.parseInt(st1.nextToken());
		int c=Integer.parseInt(st1.nextToken());
		if(c%a==0){
			count++;
		}
		a++;

		while(a<=b){
			if(c%a==0){
				count++;
			}
			a++;
		}

		System.out.println(count);
	}

}



Measured memory_bytes: 24316
from collections import deque

if __name__ == "__main__":
    n, q = map(int, input().split())
    incidenceGraph = [[] for j in range(0, n)]
    for i in range(0, n - 1):
        a, b = map((lambda x: int(x) - 1), input().split())
        incidenceGraph[a].append(b)
        incidenceGraph[b].append(a)

    operationTuples = [0]*n
    ans = [0]*n
    for i in range(0, q):
        p, x = map(int, input().split())
        operationTuples[p-1] += x

    visited = [False]*n
    stack = deque([0])
    while stack:
        i = stack.popleft()
        ans[i] += operationTuples[i]
        visited[i] = True
        for j in incidenceGraph[i]:
            if visited[j] is False:
                ans[j] += ans[i]
                stack.append(j)
    print(*ans)

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;


int main() {
    int h,w;cin>>h>>w;

    vector<vector<char>>s(h+2,vector<char>(w+2,'.'));
    rep2(i,1,h+1){
        rep2(j,1,w+1){
            cin>>s[i][j];
        }
    }

    rep2(i,1,h+2){
        rep2(j,1,w+2){
            if(s[i][j]=='#'){
                if(s[i-1][j]!='#'&&s[i+1][j]!='#'
                        &&s[i][j-1]!='#'&&s[i][j+1]!='#'){
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
    }

    cout<<"Yes"<<endl;
}



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

int d[100], a[100];
map<vector<int>, int>id;
vector<int>re[5040];
int dp[100][5040];

int main() {
	int n; scanf("%d", &n);
	rep(i, n)scanf("%d", &d[i]);
	rep(i, n)scanf("%d", &a[i]);
	vector<int>v{ 0,1,2,3,4,5,6 };
	int p = 0;
	do {
		id[v] = p; re[p] = v;
		int cnt = 0;
		bool t[7]{};
		for (int i : v) {
			rep(j, 7) {
				if (t[j] && abs(j - i) <= d[j])cnt += a[j];
			}
			t[i] = 1;
		}
		dp[0][p] = cnt;
		p++;
	} while (next_permutation(v.begin(), v.end()));
	int ans = 0;
	for (int i = 1; i + 6 < n; i++)rep(j, 5040)rep(k, 8) {
		auto t = re[j].begin();
		int cnt = 0, o = 0;
		bool p[8]{};
		vector<int>q(7);
		rep(l, 8) {
			if (k == l) {
				rep(y, 8) {
					if (p[y] && y + d[i - 1 + y] >= 7)
						cnt += a[i - 1 + y];
				}
				p[7] = 1; q[o++] = 6;
			}
			else {
				if (p[7] && 7 - d[i + 6] <= *t)cnt += a[i + 6];
				p[*t] = 1;
				if (*t)q[o++] = *t - 1;
				t++;
			}
		}
		int v = id[q];
		dp[i][v] = max(dp[i][v], dp[i - 1][j] + cnt);
		ans = max(ans, dp[i][v]);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 6084