akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

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

  ll c = N/15;
  ll ans = 0;

  rep(i,c){
    ans += 60+i*120;
  }

  ll d = N%15;

  vector<ll> v={1,2,4,7,8,11,13,14};

  repn(i,d){
    rep(j,8){
      if(i == v[j]){
        ans += v[j]+c*15;
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3628
N,K = map(int,input().split())
S = list(input())
cnt = 1
k = {}
if S[0] == "0":
    k[cnt] = [0]
    cnt += 1


flg = False
for i in range(N):
    if S[i] == '1':
        if flg == False :
            k[cnt] = []
        k[cnt].append(i)
        flg = True
    else:
        if flg == True:
            flg = False
            cnt += 1

if S[-1] == '0':
    k[cnt] = [N-1]

if '0' not in S:
    print(len(S))
    exit()
if N == 1:
    print(1)
    exit()
if cnt - K + 1 < 0:
    print(len(S))
    exit()

ans = 0
for i in range(1,cnt - K+1):
    ans = max(ans , k[i+K][-1]-k[i][0] + 1)
print(ans)


Measured memory_bytes: 52492
N = int(input())

# h <= 3N/4 <= N
for h in range(1, 3500 + 1):
    for n in range(1, 3500 + 1):
        if 4 * h * n - N * n - N * h == 0:
            continue
        w = (N * h * n) // (4 * h * n - N * n - N * h)
        if (N * h * n) % (4 * h * n - N * n - N * h) == 0 and w > 0:
            print(h, n, w)
            exit()

Measured memory_bytes: 67900
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
const int N = 2e5 + 10, OO = 0x3f3f3f3f, mod = 1e9 + 7;

#define PI acos(-1)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, n) for (int i = 0; i < int(n); i++)
#define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define xloop(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ALL(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
//int dx[] = {1, 0, -1, 0};
//int dy[] = {0, 1, 0, -1}; //4 Direction
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
//int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; //8 direction
int dx[] = {2, 1, -1, -2, -2, -1, 1, 2};
int dy[] = {1, 2, 2, 1, -1, -2, -2, -1}; //Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

//-- "كلٌّ من يسعى لابد يصل .. كلٌّ من يسعى مضمون له الوصول" --//

int n, parent[N], sz[N], comps, mxComp , e;
 
void init(){
    iota(parent, parent+n, 0);
    fill(sz, sz+n, 1);
    comps = n;
    mxComp = 1;
}
 
int find(int u){
    return u == parent[u] ? u : parent[u] = find(parent[u]);
}
 
void join(int u, int v){
    u = find(u);
    v = find(v);
    if(u == v)
      return;
    if (sz[u] > sz[v])
      swap(u, v);
    parent[u] = v;
    sz[v] += sz[u];
    --comps;
    mxComp = max(mxComp, sz[v]);
}

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

  scanf("%d %d", &n, &e);
  init();
  for (int i = 0; i < e; ++i)
  {
    int from, to;
    scanf("%d %d", &from, &to);
    join(from, to);
  }
  printf("%d\n", mxComp);

  return 0;
}

Measured memory_bytes: 5248
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n; cin>>n;
    string hoge; cin>>hoge;
    int d; cin>>d;
    int cnt=0;
    string ans;
    for(int i=0; i<hoge.size();i++){
        if(hoge[i]=='0'&&cnt<d){ans.push_back('1');cnt++;}
        else ans.push_back(hoge[i]);

    }
    int dif=d-cnt;
    for(int i=(int)hoge.size()-1; i>=0;i--){
        if(dif<=0)break;
        if(hoge[i]=='1'&&ans[i]=='1'){
            ans[i]='0';
            dif--;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front

// #define fisier 1

using namespace std;

typedef long long ll;

const int mod = 1000000007;
const double dancila = 3.14159265359; // PI 
const double eps = 1e-9;


int n; 
int val[200002], srt[200002], poz[200002], ps[200002];

int aint[800002];

vector<int> v[200002]; 

bool cmp(int a, int b)
{
	return val[a] < val[b];
}

void update(int node, int L, int R, int pos, int val)
{
	if(L == R)
	{
		aint[node] = val;
		return;
	}
	int mid = (L + R) / 2;
	if(pos <= mid)
		update(node << 1, L, mid, pos, val);
	else
		update(node << 1|1, mid+1, R, pos, val);
	aint[node] = max(aint[node << 1], aint[node << 1|1]);
}
int query(int node, int st, int dr, int L, int R)
{
	if(dr < L || st > R)
		return 0;
	if(L <= st && dr <= R)
		return aint[node];
	int mid = (st + dr) / 2;
	return max(query(node << 1, st, mid, L, R), query(node << 1|1, mid+1, dr, L, R));
}

int ans[200002];
void dfs(int dad, int nod)
{ 
	ans[nod] = 1 + query(1, 1, n, 1, ps[nod]);
	update(1, 1, n, poz[nod], ans[nod]);
	ans[nod] = max(ans[nod], ans[dad]);
	for(int i = 0; i < v[nod].size(); ++i)
	{
		int vecin = v[nod][i];
		if(vecin == dad)
			continue;
		dfs(nod, vecin);
	}
	update(1, 1, n, poz[nod], 0);
}
int main()
{

    #ifdef fisier
        ifstream f("input.in");
        ofstream g("output.out");
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	cin >> n;
	for(int i = 1; i <= n; ++i)
	{
		cin >> val[i];
		srt[i] = i;
	}
	sort(srt+1, srt+n+1, cmp);
	int prv = 0;
	for(int i = 1; i <= n; ++i)
	{
		if(val[srt[i]] > val[srt[i-1]])
			prv = i-1;
		poz[srt[i]] = i;
		ps[srt[i]] = prv;
	}
	for(int i = 1; i < n; ++i)
	{
		int a, b;
		cin >> a >> b;
		v[a].pb(b);
		v[b].pb(a);
	}
	dfs(0, 1);
	
	for(int i = 1; i <= n; ++i)	
		cout << ans[i] << '\n';
    return 0;
}


Measured memory_bytes: 32020
#include <iostream>
#include <vector>
#include <algorithm>

const int sum_vector(const std::vector<int>& given)
{
  int result = 0;
  for (const auto& e : given) result += e;
  return result;
}

int main()
{
  int N;
  std::vector<int> lineup;

  std::cin >> N;
  lineup.reserve(N + 1);
  for (int i = 0, p; i < N; ++i)
  {
    std::cin >> p;
    lineup.emplace_back(p);
  }
  std::stable_sort(lineup.begin(), lineup.end());
  lineup.back() /= 2;
  std::cout << sum_vector(lineup) << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<algorithm>
typedef long long ll;
#define INF 100000000000000
using namespace std;

int main() {
	ll a[100][100];
	int b, c;
	scanf("%d%d", &b, &c);
	for (int d = 0; d < b; d++) {
		for (int e = 0; e < b; e++) {
			a[d][e] = INF;
		}
		a[d][d] = 0;
	}
	for (int f = 0; f < c; f++) {
		int g, h, i;
		scanf("%d%d%d", &g, &h,&i);
		a[g][h] = i;
	}
	for (int x = 0; x < b; x++) {
		for (int y = 0; y < b; y++) {
			for (int z = 0; z < b; z++) {
			if(a[y][x]!=INF&&a[x][z]!=INF)	a[y][z] = min(a[y][z], a[y][x] + a[x][z]);
			}
		}
	}
	bool s = false;
	for (int x = 0; x < b; x++)if (a[x][x] < 0)s = true;
	if (s) {
		printf("NEGATIVE CYCLE\n");
	}
	else {
		for (int x = 0; x < b; x++) {
			for (int y = 0; y < b - 1; y++) {
				if (a[x][y] == INF)printf("INF ");
				else printf("%d ", a[x][y]);
			}
			if (a[x][b-1] == INF)printf("INF\n");
			else printf("%d\n", a[x][b-1]);
		}
	}
}

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

typedef long long ll;
ll mod = 1000000007;


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    ll total = 0;
    int cnt = 0;
    for(int i=0; i<s.length(); i++) if(s[i] == 'o') cnt++;
    cout << total + 700 + (100 * cnt) << endl;
}

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

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

    if (N == 1){
        cout << "Hello World" << endl;
    }

    if (N == 2){
        int A , B;
        cin >> A >> B;

        cout << A + B << endl;
    }
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool a[10];
int n,x,ans,cnt;
int main()
{
    cin>>n;
   for(int i=0;i<n;i++)
   {
        cin>>x;
        if (x<400 and !a[1])              a[1]=true,ans++;
        if (x>=400 and x<800 and !a[2])   a[2]=true,ans++;
        if (x>=800 and x<1200 and !a[3])  a[3]=true,ans++;
        if (x>=1200 and x<1600 and !a[4]) a[4]=true,ans++;
        if (x>=1600 and x<2000 and !a[5]) a[5]=true,ans++;
        if (x>=2000 and x<2400 and !a[6]) a[6]=true,ans++;
        if (x>=2400 and x<2800 and !a[7]) a[7]=true,ans++;
        if (x>=2800 and x<3200 and !a[8]) a[8]=true,ans++;
        if (x>=3200) cnt++;
      }
  cout<<max(ans,1)<<" "<<ans+cnt<<endl;
    return 0;
  }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll a,b,c,x,y;
int main(){
    cin>>a>>b>>c>>x>>y;
    ll ans = INF;
    ll now = 0;
    for(ll i = 0;i <= 2*max(x,y);i++){
        now = 0;
        if(i%2!=0) continue;
        now += i*c;
        ll aa = x-i/2,bb = y-i/2;
        if(aa<0) aa = 0;
        if(bb<0) bb = 0;
        now+=a*aa+b*bb;
        //cout<<i<<endl;
        //cout<<now<<endl<<endl;

        ans = min(now,ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
a, b, k = gets.chomp.split.map(&:to_i)
c = [a, b]
d = c.min
result = 0
for x in 1..d
  y = d + 1 - x
  if a % y == 0
    if b % y == 0
      result = result + 1
      if result == k
        puts y
        exit
      end
    end
  end
end


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

map<ll,ll> prime(ll n){
	map<ll,ll> mp;
	for(ll i = 2; i*i <= n; i++){
		while(n % i == 0){
			n /= i;
			mp[i]++;
		}
	}
	if(n > 1) mp[n] = 1;
	return mp;
}

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	ll n; cin >> n;

	int ans = 0;
	auto mp = prime(n);
	for(auto t : mp){
		//fprintf(stderr, "key: %lld\tval: %lld\n", t.first, t.second);
		ans += (int)(sqrt(8*t.second+1)-1)/2;
	}

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

Measured memory_bytes: 3692
import java.util.Scanner;

public class Main {
	static long mod = (long)1e9+7;
	public static long fact(long x) {
		long ret=1;
		for(int i=1; i<=x; i++)
			ret = ret*i%mod;
		return ret;
	}

	public static long count(long n, long m) {
		if(n-m>1||m-n>1)
			return 0;
		long tmp = fact(n)*fact(m)%mod;
		if(n==m) return 2*tmp%mod;
		else return tmp;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long m = sc.nextLong();
		sc.close();

		System.out.println(count(n, m));
	}
}


Measured memory_bytes: 22996
#include <stdio.h>

#define MAX (10000) //素数表最大数
int prime[MAX + 1]; //素数表配列
int idx, idx2, tmp;

void list(void); //素数表作成
void judge(int); //双子素数判定

int main(){
    
    int n;
    
    list();
    
    while (scanf("%d", &n)){
        if (n == 0) break;
        judge(n);
        printf("%d %d\n", idx2, idx);
    }
    
    return 0;
}

void list(void){
    int i, k;
    for (i = 2; i <= MAX ; i++){
        prime[i] = 1;
    }
    for (i = 2; i * i <= MAX; i++){
        if (prime[i]){
            for (k = 2 * i; k <= MAX; k += i){
                prime[k] = 0;
            }
        }
    }
}

void judge(int n){
    int i;
    for (i = n; 0 < n; i--){
        tmp = i - 2;
        if(prime[i]){
            if(prime[tmp]){
                idx = i;
                idx2 = tmp;
                break;
            }
        }
    }
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define range(i, a, n) for(int (i) = (a); (i) < (n); (i)++)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
using namespace std;
int main(void){
	for(char c; c = getchar(), c != '.';){
		string res = "yes";
		stack<char> stk;
		do {
			if(c == '(' || c == '[') stk.push(c);

			if(c == ')'){
                if(stk.empty() || stk.top() != '(') res = "no";
                else stk.pop();
            }
			if(c == ']'){
                if(stk.empty() || stk.top() != '[') res = "no";
                else stk.pop();
            }
		} while(c = getchar(), c != '.');
        if(stk.size()) res = "no";

        cout << res << endl;
        c = getchar();
	}

	return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdio.h>
using namespace std;

int main(){
	long long int n,k,i,diff=0;
	cin>>k>>n;
	long long int a[n+1];
	cin>>a[0]>>a[1];
	diff=a[1]-a[0];
	for(i=2;i<n;i++){
		cin>>a[i];
		if(a[i]-a[i-1]>diff){
			diff=a[i]-a[i-1];
		}		
	}
	a[n]=k+a[0];
	
		if(a[i]-a[i-1]>diff){
			diff=a[i]-a[i-1];
		}
		
	cout<<k-diff;	
	
	return 0;
}

Measured memory_bytes: 1792
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)*}
    };
}

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)*}
    };
}

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")
    };
}
fn main() {
    input! {
        v: [i64; 4],
    }

    let mut v = {
        let mut j = 0;
        let v = v.into_iter().map(|c| {j+=1; (c, j)}).collect::<Vec<_>>();
        v
    };

    v.sort_by_key(|k| k.0);
    if !(v[1].1 == 2 && v[2].1 == 3) && !(v[1].1 == 4 && v[2].1 == 1){
        println!("{}", v[2].0 - v[1].0);
    } else {
        println!("{}", 0);
    }
}

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

int main()
{
    long long int n, m;
    cin >> n >> m;

    if (n == 1 && m == 1)
    {
        cout << 1 << endl;
    }
    else if (n == 1)
    {
        cout << m-2 << endl;
    }
    else if (m == 1)
    {
        cout << n-2 << endl;
    }
    else
    {
        cout << (n-2)*(m-2) << endl;
    }

    return 0;
}

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

using namespace std;

#define DIM 3009
#define MODULO 1000000007
#define INF 1e11+9
#define amen exit(0)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define pairll pair<long long,long long>
#define fi first
#define se second
#define ld long double

long long i,j,k,l,n,m;

ld dp[DIM][DIM],a[DIM];

ld rec(long long n,long long m){
    if(m<0)return 0;
    if(n==0){
        if(m==0)return 1;
        return 0;
    }
    if(dp[n][m]!=INF)return dp[n][m];
    dp[n][m]=a[n]*rec(n-1,m-1)+(1-a[n])*rec(n-1,m);
    return dp[n][m];
}

ld res;

int main()
{
    cin>>n;

    for(i=1;i<=n;i++)cin>>a[i];

    for(i=1;i<=n;i++){
        for(j=0;j<=n;j++)dp[i][j]=INF;
    }

    for(i=n/2+1;i<=n;i++)res+=rec(n,i);

    cout<<fixed<<setprecision(10)<<res<<endl;

    return 0;
}


Measured memory_bytes: 141696
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
A = [list(map(int, input().split())) for i in range(N)]

ans = 0
for i in range(N):
  tmp = 0
  for j in range(M):
    tmp += A[i][j] * B[j]
  if tmp + C > 0:
    ans += 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	int A, B; cin >> A >> B;
	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
		cout << "Possible" << endl;
	}
	else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
-- String - Card Game

import Control.Applicative

main :: IO ()
main = do
  n  <- readLn
  xs <- map words . take n . lines <$> getContents
  putStrLn $ unwords $ map show $ foldr count [0, 0] xs

count :: [String] -> [Int] -> [Int]
count [a, b] [x, y]
  | a > b     = [x + 3, y]
  | a == b    = [x + 1, y + 1]
  | otherwise = [x, y + 3]



Measured memory_bytes: 4336
n,l = map(int,input().split())

sum = n * (l - 1) + (n * (n + 1)) / 2.0

if n + l - 1 < 0:
    print(int(sum - (n + l - 1)))
elif l > 0:
    print(int(sum - (l)))
else:
    print(int(sum))

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		int[] tosimiti = new int[N+1];
		for(int i =1;i<=M*2;i++) {
			tosimiti[sc.nextInt()]++;
		}

		for(int i =1;i<tosimiti.length;i++) {
		System.out.println(tosimiti[i]);
		}

	}
}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


void solve(){
    ll N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    ll cost[6] = {0};
    cost[2] = A;
    cost[3] = B;
    cost[5] = C;

    ll ans = LINF;
    priority_queue<LP, vector<LP>, greater<LP>> pq;
    map<ll, ll> memo;
    pq.emplace(0, N);
    while(!pq.empty()){
        auto [v, n] = pq.top(); pq.pop();
        if(v >= ans) continue;
        if(n <= 2*LINF / D) chmin(ans, v + n*D);
        for(int d : {2, 3, 5}){
            int r = n % d;
            ll nv = v + r * D + cost[d];
            if(nv < ans && (!memo.count(n/d) || nv < memo[n/d])){
                pq.emplace(nv, n/d);
                memo[n/d] = nv;
            }
            nv = v + (d - r) * D + cost[d];
            if(nv < ans && (!memo.count(n/d+1) || nv < memo[n/d+1])){
                pq.emplace(nv, n/d+1);
                memo[n/d+1] = nv;
            }
        }
    }
    cout << ans << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    // solve();
    int T; cin >> T; REP(t,T) solve();
}

Measured memory_bytes: 4600
N, A, B = map(int, input().split())


def f(x):
    res = 0
    while x > 0:
        res += x % 10
        x //= 10
    return res


res = 0
for i in range(1, N + 1):
    x = f(i)
    if A <= x and x <= B:
        res += i
print(res)


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define LL long long
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int main(){
  int A,B;
  cin>>A>>B;
  int map[100][100];
  FOR(i,0,50){
    FOR(j,0,100){
      map[i][j]=0;
    }
  }
  FOR(i,50,100){
    FOR(j,0,100){
      map[i][j]=1;
    }
  }
  A--;
  B--;
  int H=1,W=1;
  while(A){
    map[H][W]=1;
    A--;
    if(W==99){
      H+=2;W=1;
    }else{
      W+=2;
    }
  }
  H=51;W=1;
  while(B){
    map[H][W]=0;
    B--;
    if(W==99){
      H+=2;W=1;
    }else{
      W+=2;
    }
  }
  cout<<100<<" "<<100<<endl;
  FOR(i,0,100){
    FOR(j,0,100){
      cout<<(map[i][j]==0?'#':'.');
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
def print_all(a, b):
    for i in range(a - 1, b):
        print(i + 1)


a, b, k = map(int, input().split())
elem = b - a + 1

if elem <= 2 * k:
    print_all(a, b)

else:
    for i in range(k):
        print(a + i)

    for i in range(k):
        print(b - k + 1 + i)


Measured memory_bytes: 3060
n = list(input())
for i in range(8):
    ans = n[0]
    ans += '+-'[i%2] + n[1]
    ans += '+-'[i//4] + n[2]
    ans += '+-'[(i%4)//2] + n[3]
    if eval(ans) == 7:
        print(ans+"=7")
        break

Measured memory_bytes: 3060
(* O(n) *)
let n = Scanf.scanf " %d" @@ (+) 0
let abcs = Array.init n @@ fun _ -> Scanf.scanf " %d %d %d" @@ fun a b c -> [|a; b; c|]
let dp = Array.make_matrix n 3 0
let _ =
  for i = 0 to 2 do dp.(0).(i) <- abcs.(0).(i) done;
  for i = 1 to n - 1 do
    for j = 0 to 2 do
      for k = 0 to 2 do
        if j <> k then dp.(i).(j) <- max dp.(i).(j) @@ dp.(i - 1).(k) + abcs.(i).(j) done done done;
  Array.fold_left max 0 dp.(n - 1) |> Printf.printf "%d\n"

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

int abs(int n){
 if(n<0){
   return -n;
 }else{
   return n;
 }
}

int main(){
 int a,b,c,d;
 cin >> a>> b >> c >>d;
 if(abs(a-c)<=d){
    cout << "Yes" << endl;
 }else if(abs(a-b)<=d && abs(b-c)<=d){
    cout << "Yes" << endl;
 }else{
    cout << "No" <<endl;
 }
 return 0;
}

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

int main() {
  string S, T;
  cin >> S;

  string divide[4] = {"dream", "dreamer", "erase", "eraser"};

  reverse(S.begin(), S.end());
  for (int i = 0; i < 4; i++) {
    reverse(divide[i].begin(), divide[i].end());
  }

  bool can = true;
  for (int i = 0; i < S.size();) {
    bool can2 = false;
    for (int j = 0; j < 4; j++) {
      string d = divide[j];
      if ( S.substr(i, d.size()) == d ) {
        can2 = true;
        i += d.size();
        break;
      }
    }
    if (!can2) {
      can = false;
      break;
    }
  }
  if (can) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

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

typedef long long ll;
#define pii pair<int ,int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int a , b;

int main()
{
    _FastIO;
    cin >> a >> b;
    if(b % a == 0)
        cout << a + b << endl;
    else
        cout << b - a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  vl A(N);
  rep(i,N) {
    cin >> A[i];
  }
  vv(ll) sum(N+1,vl(62,0));
  rep(i,N) {
    rep(j,62) {
      sum[i+1][j] = sum[i][j] + ((A[i]>>j)&1);
    }
  }
  ll ans = 0;
  rep(i,N-1) {
    ll tmp = 0;
    rep(j,62) {
      ll a = (A[i]>>j)&1;
      ll b = sum[N][j]-sum[i+1][j];
      ll m = (1ll<<j);
      m %= MOD;
      if(a==1) {
        tmp += (1ll*(N-i-1)-b)*m;
      } else {
        tmp += b*m;
      }
      tmp %= MOD;
    }
    ans += tmp;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 159616
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<queue>
#include<cstring>
#include<vector>

using namespace std;

typedef long long ll;

int main(){
  ll a,b,n,ans=0,tmp_n;
  scanf("%lld %lld",&a,&b);
  n=b-a+1;
  tmp_n=n;

  for(ll i=1;i<=b;i*=2){
    ll los_l,los_r,cnt_1=0;
    los_l=a%(i*2);
    n+=los_l;
    cnt_1+=max<ll>(los_l-i,0);
    
    los_r=b%(i*2);
    n+=(i*2)-(los_r+1);
    cnt_1+=min<ll>(i,(i*2)-(los_r+1));

    if((n/2-cnt_1)%2) ans+=i;
    n=tmp_n;
  }

  printf("%lld\n",ans);

  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int dp[50010],n,m,temp;
    scanf("%d%d",&n,&m);
    dp[0]=0;
    for(int i=1;i<=n;i++)dp[i]=1<<30;
    while(m--){
        scanf("%d",&temp);
        for(int i=temp;i<=n;i++)if(dp[i-temp]<dp[i])dp[i]=dp[i-temp]+1;
    }
    printf("%d\n",dp[n]);
}

Measured memory_bytes: 2872
def main():
    N = int(input())
    robo = []

    for _ in range(N):
        x, l = map(int, input().split())
        robo.append((x-l, x+l))

    robo = sorted(robo, key=lambda x:x[1])

    ans = 0
    max = -10**9

    for r in robo:
        if r[0] >= max:
            ans += 1
            max = r[1]
    print(ans)
    return 0

if __name__ == '__main__':
    main()


Measured memory_bytes: 19008
#include<stdio.h>
void trace(int A[],int N){
  int i;
  for(i=0;i<N;i++){
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}

void insertionSort(int A[],int N){
  int i,j,v;
  for(i=1;i<N;i++){
    v=A[i];
    j=i-1;
    while(j >= 0&& A[j] > v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    trace(A,N);
  }
}

int main(){
  int A[100],N,i,j;
  scanf("%d",&N);
  for(i=0;i<N;i++) scanf("%d",&A[i]);
  trace(A,N);
  insertionSort(A,N);
  
  return 0;
}


Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =2e5+10;
const int mod=1e9+7;

int a[maxn];
int b[maxn];
int dp[3010][3010][2];


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,t;
    cin>>n>>t;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i];

    }
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=t-1;j++)
        {
            if(j>=a[i])
            {
                dp[i][j][0]=max(dp[i-1][j][0],dp[i-1][j-a[i]][0]+b[i]);
                dp[i][j][1]=max(dp[i-1][j][1],dp[i-1][j][0]+b[i]);
                dp[i][j][1]=max(dp[i][j][1],dp[i-1][j-a[i]][1]+b[i]);
            }
            else
            {
                dp[i][j][0]=dp[i-1][j][0];
                dp[i][j][1]=max(dp[i-1][j][0]+b[i],dp[i-1][j][1]);
            }
        }
    }
    cout<<dp[n][t-1][1]<<'\n';




}


Measured memory_bytes: 74152
#include <iostream>
#include <sstream>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <set>
#include <map>
#include <stdlib.h>
#include <cctype>
#include <bitset>
using namespace std;
int main()
{
    long int N, i, a;
    cin >> N;
    long int A[N];
    for (i = 0; i < N; i++) cin >> A[i];
    a = 0;
    for (i = 1; i < N; i++){
        if (A[i - 1] > A[i]){
            a = a + (A[i - 1] - A[i]);
            A[i] = A[i - 1];
        }
    }
    cout << a << endl;
}

Measured memory_bytes: 5180
#include <stdio.h>
typedef struct Dice{
	int	f[6];
}Dice;
int main(void)
{
	int i;
	char roll;
	Dice D0 = {0};
	Dice Dw = {0};
	for(i=0; i<6; i++){
		scanf("%d", D0.f+i);
	}
	while(scanf("%c", &roll) != EOF){
		for(i=0; i<6; i++){
			*(Dw.f+i) = *(D0.f+i);
		}
		switch(roll){
			case 'E':
				*(D0.f+0) = *(Dw.f+3);
				*(D0.f+2) = *(Dw.f+0);
				*(D0.f+3) = *(Dw.f+5);
				*(D0.f+5) = *(Dw.f+2);
				break;
			case 'N':
				*(D0.f+0) = *(Dw.f+1);
				*(D0.f+1) = *(Dw.f+5);
				*(D0.f+4) = *(Dw.f+0);
				*(D0.f+5) = *(Dw.f+4);
				break;
			case 'S':
				*(D0.f+0) = *(Dw.f+4);
				*(D0.f+1) = *(Dw.f+0);
				*(D0.f+4) = *(Dw.f+5);
				*(D0.f+5) = *(Dw.f+1);
				break;
			case 'W':
				*(D0.f+0) = *(Dw.f+2);
				*(D0.f+2) = *(Dw.f+5);
				*(D0.f+3) = *(Dw.f+0);
				*(D0.f+5) = *(Dw.f+3);
				break;
			default:
				break;
		}
	}
	printf("%d\n", *(D0.f));
	return 0;
}

Measured memory_bytes: 596
/*  /$$                                     /$$
      | $$                                    | $$
  /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$
 /$$__  $$ /$$__  $$ /$$_____/ /$$__  $$ /$$__  $$ /$$__  $$ /$$__  $$
| $$  | $$| $$$$$$$$| $$      | $$  \ $$| $$  | $$| $$$$$$$$| $$  \__/
| $$  | $$| $$_____/| $$      | $$  | $$| $$  | $$| $$_____/| $$
|  $$$$$$$|  $$$$$$$|  $$$$$$$|  $$$$$$/|  $$$$$$$|  $$$$$$$| $$
 \_______/ \_______/ \_______/ \______/  \_______/ \_______/|__//$$$$$$ /$$$$$$
                                                               |______/|______/

*/
#include <bits/stdc++.h>
#define fastio        ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ln            cout<<endl;
#define vi            vector<int>
#define vll           vector<long long>
#define sortl(vec)    sort(vec.begin(), vec.end());
#define sortr(vec)    sort(vec.rbegin(), vec.rend());
#define forn(i, x, n) for(long long i = x; i < n; i+=2)
#define revn(i, n, x) for(long long i = n; i >= x ; i--)
#define in(vec)       for(auto &it : vec) cin >> it;
#define loop(vec)     for(auto &it : vec)
#define	out(vec)      for(auto &it : vec) cout << it << " "; ln
#define ll            long long
#define mod           1000000007
#define debug(x)      cout << x << endl;
#define pb            emplace_back
#define mp            make_pair
#define um            unordered_map
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define f             first
#define s             second
#define pi            3.14159265359
#define CLOCK         cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
using namespace std;

ll power(ll x, ll y, ll p) {
	ll res = 1;
	x = x % p;

	while (y > 0) {
		if (y & 1)
			res = (res * x) % p;

		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

ll modulo(ll a, ll b) {
	ll c = a % b;
	return (c < 0) ? c + b : c;
}

int main() {
// in(vec) works for size-defined type vectors

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input1.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output1.txt", "w", stdout);
#endif

	fastio
	ll t = 1;
	while (t--) {
		ll n;
		cin >> n;
		unordered_map<ll, ll>hash;
		while (n % 2 == 0) {
			hash[2]++;
			n /= 2;
		}

		forn(i, 3, sqrt(n) + 1) {

			while (n % i == 0) {
				hash[i]++;
				n /= i;
			}
		}

		if (n > 2)
			hash[n]++;

		ll count = 0;
		for (auto it : hash ) {
			ll i = 1;
			while (it.s >= i) {
				it.s -= i++;
				count++;
			}
		}

		cout << count << endl;

	}
	CLOCK
	return 0;
}



Measured memory_bytes: 3832
#include <iostream>

using namespace std;

int main(void)
{
    int W, H, N;
    cin >> W >> H >> N;

    int xmin = 0;
    int ymin = 0;
    int xmax = W;
    int ymax = H;
    for(int i = 0; i < N; ++i)
    {
        int xi, yi, ai;
        cin >> xi >> yi >> ai;
        switch(ai)
        {
            case 1:
                xmin = max(xmin, xi);
                break;
            case 2:
                xmax = min(xmax, xi);
                break;
            case 3:
                ymin = max(ymin, yi);
                break;
            case 4:
                ymax = min(ymax, yi);
                break;
        }
    }

    int ans = 0;
    if(xmin < xmax && ymin < ymax)
    {
        ans = (xmax - xmin) * (ymax - ymin);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p.at(i);
  int ans = 0, mn = 1001001001;
  rep(i, n){
    if(p.at(i) <= mn){
      ans++;
      mn = p.at(i);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4052
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int a[4];
	cin >> a[0];
	cin >> a[1];
	cin >> a[2];
	cin >> a[3];
	sort(a, a + 4);
	if (a[0] == a[1] && a[2] == a[3])
	{
		cout << "yes" << endl;
	}
	else
	{
		cout << "no" <<endl;
	}
	return 0;
}

Measured memory_bytes: 3152
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  string T;
  cin >> T;
  const int64_t L = static_cast<int64_t>(T.length());
  int64_t result = 0;
  for (int64_t i = 0; i < L; ++i) {
    int64_t c = static_cast<int64_t>(T[i] - '0');
    result += c;
    result %= 9;
  }
  if (result == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<l_l> vpl;
typedef vector<string> vs;
typedef pair<l_l,ll> lll;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=1;i<=(n);i++)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
const ll dx[4]={1,-1,0,0};
const ll dy[4]={0,0,1,-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;
}
ll dat[510000];
void init(){
    rep(i,510000)dat[i]=0;
}
void add(ll ind,ll val){
    while(ind<510000){
        dat[ind]+=val;
        ind+=ind&-ind;
    }
    return;
}
ll sum(ll ind){
    ll res=0;
    while(ind){
        res+=dat[ind];
        ind-=ind&-ind;
    }
    return res;
}
ll rangesum(ll l,ll r){
    return sum(r)-sum(l-1);
}
vl qi[510000],qid[510000];
ll n,q;
ll c[510000],ans[510000],a[510000];
int main(){
    cin>>n>>q;
    rrep(i,n)cin>>c[i];
    ll l,r;
    rep(i,q){
        cin>>l>>r;
        qi[r].pb(l);
        qid[r].pb(i);
    }
    rep(i,510000)a[i]=0;
    init();
    for(int i=1;i<=n;i++){
        if(a[c[i]]>0)add(a[c[i]],-1);//場所iに存在する色と同じ色の場所で一番右にあったやつのデータ削除
        add(i,1);//場所iに存在する色に関してBITで加える
        a[c[i]]=i;//色ciに関する更新
        for(int j=0;j<sz(qi[i]);j++){
            ans[qid[i][j]]=rangesum(qi[i][j],i);
        }
    }
    rep(i,q)cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 63280
N=int(input())

print("?",*list(range(1,N+1)),flush=True)

RB={"Red":0, "Blue":1}

Left=RB[input()]
Right=1-Left

OK=1
NG=N+1

ANS=[-1]*(2*N+1)

while NG-OK>1:
    mid=(OK+NG)//2

    print("?",*list(range(mid,N+mid)),flush=True)

    MC=RB[input()]

    if Left==MC:
        OK=mid
    else:
        NG=mid

ANS[OK]=Left
ANS[OK+N]=Right

SAME1=list(range(OK+1,OK+N))

SAME2=[]
for i in range(N-1):
    SAME2.append((OK+N+i)%(2*N)+1)

SAMESET1=set(SAME1)
SAMESET2=set(SAME2)

for i in range(1,2*N+1):
    if ANS[i]!=-1:
        continue
    if i in SAMESET1:
        print("?",*[i]+SAME2,flush=True)

        ANS[i]=RB[input()]

    else:
        print("?",*[i]+SAME1,flush=True)

        ANS[i]=RB[input()]

ANS="".join(map(str,ANS[1:]))
print("!",ANS.replace("1","B").replace("0","R"),flush=True)
        


Measured memory_bytes: 3532
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int R;
    cin>>R;
    if(R<1200){cout<<"ABC"<<endl;}
    else if(R<2800){cout<<"ARC"<<endl;}
    else{cout<<"AGC"<<endl;}
    return 0; 
}

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

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define endl '\n'
#define FASTIO std::ios::sync_with_stdio(false)

#define PRIME (1000000007)
#define oo (1 << 30)

#define debug(x) cerr << #x << " = " << x << endl
#define all(x) x.begin(), x.end()

#define loop(i, begin, end)                            \
  for (__typeof(end) i = (begin) - ((begin) > (end)); \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

template <class T>
std::vector<T> ReadVec(int n) {
    std::vector<T> answer(n);

    loop(i, 0, n) {
        std::cin >> answer[i];
    }
    return answer;
}

template <class T>
void PrintVec(std::vector<T> v) {
    loop(i, 0, v.size()) {
        std::cout << v[i] << " ";
    }
    std::cout << endl;
}

using namespace std;

int main() {
    FASTIO;

    string s, ans;
    cin >> s;

    if(s == "Sunny") {
        ans = "Cloudy";
    }
    else if(s == "Cloudy") {
        ans = "Rainy";
    }
    else {
        ans = "Sunny";
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;
const int mod = 1e9 + 7;
ll f[100010];
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	f[0] = 1;
	rep(i, 100000) f[i + 1] = f[i] * (i + 1) % mod;
	
	int n, m; cin >> n >> m;
	if(abs(n - m) > 1){
		cout << 0 << endl;
		return 0;
	}
	ll ans = f[n] * f[m];
	if(n == m) ans *= 2;
	cout << ans % mod << endl;
	
	return 0;
}

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

typedef struct _team {
        int p;
        int s;
        int no;
} team_t;

int main()
{
        team_t t[100];
        int i = 0, j = 0;
        int number[31] = { 0 };
        char *str;

        while ( scanf( "%d,%d", &t[i].p, &t[i].s ) == 2 ){
                if ( t[i].p == 0 && t[i].s == 0 ) {
                        break;
                }
                number[t[i].s]++;
                i++;
        }

        j = 30;
        i = 1;
        while ( j >= 0 ) {
                if ( number[j] > 0 ) {
                        number[j] = i;
                        i++;
                }
                j--;
        }

        while ( scanf( "%d", &i ) == 1 ) {
                printf( "%d\n", number[t[i-1].s] );
        }

        return 0;
}



Measured memory_bytes: 2080
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int x, y;
		
		while(true) {
			x = scan.nextInt();
			y = scan.nextInt();
			if (x == 0 && y == 0) break;
			
			if (x <= y) {
				System.out.println(x + " " + y);
			}
			else {
				System.out.println(y + " " + x);
			}
		}
	}
}



Measured memory_bytes: 37196
import java.util.Scanner;
import java.util.Arrays;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int [n];
        for(int i = 0;i < n;i++){
            a[i] = sc.nextInt();
        }
        int[] sum1 = new int[n];
        int[] sum2 = new int[n];
        sum1[0] = a[0];
        sum2[0] = a[0];
        long count = 0;
        //System.out.println(solve1(sum1,a,count));
        //System.out.println(solve2(sum2,a,count));
        count = Math.min(solve1(sum1,a,count),solve2(sum2,a,count));
        System.out.println(count);
    }
    public static long solve1(int[] sum,int[] a,long count){
        if(sum[0] <= 0){
            count += 1 - sum[0];
            sum[0] = 1;
        }
        for(int i = 0;i < sum.length-1;i++){
            sum[i+1] = sum[i] + a[i+1];
            if((i+1) % 2 == 1){
                if(sum[i+1] >= 0){
                    count += 1 + sum[i+1];
                    sum[i+1] = -1;
                }
            }
            if((i+1) % 2 == 0){
                if(sum[i+1] <= 0){
                    count += 1 - sum[i+1];
                    sum[i+1] = 1;
                }
            }
        }
        return count;
    }
    public static long solve2(int[] sum,int[] a,long count){
        if(sum[0] >= 0){
            count += 1 + sum[0];
            sum[0] = -1;
        }
        for(int i = 0;i < sum.length-1;i++){
            sum[i+1] = sum[i] + a[i+1];
            if((i+1) % 2 == 1){
                if(sum[i+1] <= 0){
                    count += 1 - sum[i+1];
                    sum[i+1] = 1;
                }
            }
            if((i+1) % 2 == 0){
                if(sum[i+1] >= 0){
                    count += 1 + sum[i+1];
                    sum[i+1] = -1;
                }
            }
        }
        return count;
    }
}


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

int main(){
  int N;
  cin >> N;
  vector<int> A(2*N);
  int ans=0;
  for(int i=0;i<2*N;++i) cin >> A.at(i);
  sort(A.begin(),A.end());
  for(int i=0;i<2*N-1;i+=2){
    ans+=min(A.at(i),A.at(i+1));
  }
  cout << ans << endl;
}

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

using namespace std;

int main()
{
 	int n, m, c; cin >> n >> m >> c;
  	int b[m+1];
 	for (int i=1; i<=m; i++) cin >> b[i];
  	int res = 0;
  	for (int i=0; i<n; i++)
    {
      	int sum = 0;
     	for (int j=1; j<=m; j++)
        {
          	int x; cin >> x;
          	sum += x*b[j];
        }
      	if (sum+c>0) res++;
    }
  	cout << res;
  	return 0;
}

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

using namespace std;

int main()
{
	int longlen = 0;
	string str, longstr;
	vector<pair<int, string> > vc;

	while (cin >> str)
	{
		if((int)strlen(str.c_str()) > longlen){
			longlen = strlen(str.c_str());
			longstr = str;
		}
		
		bool bl = true;
		vector<pair<int, string> >::iterator it = vc.begin();
		while(it != vc.end())
		{
			if(it->second == str){
				it->first--;
				bl = false;
			}
			it++;
		}

		if(bl){
			vc.push_back(make_pair(0, str));
		}
	}
	
	sort(vc.begin(), vc.end());

	cout << vc[0].second << " " << longstr << endl;

	return 0;
}

Measured memory_bytes: 1200
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        long[] ABK = Console.ReadLine().Split(' ').Select(o => long.Parse(o)).ToArray();
        long A = ABK[0];
        long B = ABK[1];
        long K = ABK[2];

        A -= K;
        if (A < 0)
        {
            K = -A;
            A = 0;
        }
        else
            K = 0;

        B -= K;
        if (B < 0)
            B = 0;

        string O = A + " " + B;

        Console.WriteLine(O);
    }
}


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

int main()
{
    long H;
    int N;
    cin >> H;
    cin >> N;
    int A[N];
    long sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        sum += A[i];
    }
    if(sum >= H)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
    
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
using namespace std;

int main(void) {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	
	if (a*b > c*d) {
		cout << a*b << endl;
	}
	else if (a*b < c*d) {
		cout << c*d << endl;
	}
	else if(a*b == c*d){
		cout << a*b << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int BSM = (1 << (2 * n));
  int A, B, C;
  cin >> A >> B >> C;
  vector<int> x(n);
  for (int i = 0; i < n; i++) cin >> x[i];
  int minv = 1e9;
  for (int bs = 0; bs < BSM; bs++) {
    int a(0), b(0), c(0), cnta(0), cntb(0), cntc(0);
    for (int i = 0; i < n; i++) {
      int crr = (bs & (3 << (2 * i))) >> (2 * i);
      if (crr == 1) {
        a += x[i]; cnta++;
      } else if (crr == 2) {
        b += x[i]; cntb++;
      } else if (crr == 3) {
        c += x[i]; cntc++;
      }
    }
    if (cnta == 0 || cntb == 0 || cntc == 0) continue;
    int tmp = 0;
    tmp += abs(A - a) + abs(B - b) + abs(C - c);
    tmp += (cnta + cntb + cntc - 3) * 10;
    minv = min(minv, tmp);
  }
  cout << minv << '\n';
  return 0;
}

Measured memory_bytes: 256
N, = [int(x) for x in input().strip().split(" ")]
hs = [int(x) for x in input().strip().split(" ")]
d = [0] * N
d[1] = abs(hs[0] - hs[1])

for i in range(N-2):
    i = i+2
    d[i] = min(d[i-1] + abs(hs[i-1] - hs[i]), d[i-2] + abs(hs[i-2] - hs[i]))

print(d[-1])


Measured memory_bytes: 13928