akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>

using namespace std;

typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;

#ifdef DEBUG
#define dprintf      printf
#define dputs        puts
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)  {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dputs        (1)?0:puts
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(int i=0){}else
#define drep(i,n)    if(int i=0){}else
#define dstop()
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__)
#define array(T,id,n) T id[(n)]; for(int i=0;i<(n);i++)cin>>id[i]
#define putv(n)     cout<<(n)<<endl

//#define int long long
#ifndef int
#define INF __INT32_MAX__
#else
#define INF __INT64_MAX__
#endif

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

signed main(void)
{
  int a[112345]={};

  in(string,s);

  int n=(int)s.length();
  int cnt=0;
  int i;
  
  rep(i,n)
    {
    if(a[s[i]-'a']==0)
      {
	a[s[i]-'a']=1;
	cnt++;
      }
    }
  if(cnt==2)
    puts("Second");
  else
    if(s[0]==s[n-1])
      puts((n-3)&1?"First":"Second");
    else
      puts((n-2)&1?"First":"Second");
 
  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n;
int a[505];
long long dp[505][505];
long long pref[505];
int main(){
	cin>>n;
	for(int i=1;n>=i;i++)
	{
		cin>>a[i];
		pref[i]=pref[i-1]+a[i];
	}
	for(int i=1;n>i;i++)
		dp[i][i+1]=a[i]+a[i+1];
	for(int len=3;n>=len;len++)
		for(int poz=1;poz+len-1<=n;poz++)
	{
		dp[poz][poz+len-1]=1e15;
		for(int siz=1;len>siz;siz++)
			dp[poz][poz+len-1]=min(dp[poz][poz+len-1],dp[poz][poz+siz-1]+dp[poz+siz][poz+len-1]+pref[len+poz-1]-pref[poz-1]);
	}
	cout<<dp[1][n];
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    int x,i,count=0;
    char r;
    cin>>s>>t;
    x=s.length();
    for(i=0;i<x;i++)
    {
        if(s[i]!=t[i])
        {
            r=t[i];
            s[i]=r;
            count++;
        }
    }
    cout<<count;
    return 0;
}


Measured memory_bytes: 3916
#include <stdio.h>
 
#define N 102
#define WHITE 0
#define GRAY 1
#define BLUE 2
#define INF 1000000
 
int n,adj[N][N],color[N],d[N],Q[N],head=1,tail=1;
 
int Queempty(){
  if (head==tail){
    return 1;
  } else {
    return 0;
  }
}
 
void Enqueue(int r){
  int i;
  Q[tail] = r;
  tail++;
}
 
int Dequeue(){
  int i;
  i = Q[head];
  Q[head] = -1;
  head++;
  return i;
}
 
void BFS(int s){
  int u,v;
  color[s]=GRAY;
  d[s]=0;
  Enqueue(s);
  while(Queempty()==0){
    u = Dequeue();
    for (v=1;v<=n;v++){
      if (color[v]==WHITE&&adj[u][v]==1){
	color[v]=GRAY;
	d[v]=d[u]+1;
	Enqueue(v);
      }
    }
    color[u]=BLUE;
  }
   
}
 
int main() {
  int i,j,u,k,v,s=1;
  
  for (i=1;i<N;i++){
    for (j=1;j<N;j++){
      adj[i][j]=0;
    }
    Q[i]=-1;
    color[i]=WHITE;
    d[i]=INF;
  }
  
 
  scanf ("%d",&n);
  for (i=1;i<=n;i++){
    scanf ("%d%d",&u,&k);
    for (j=1;j<=k;j++){
      scanf("%d",&v);
      adj[u][v]=1;
    }
  }
 
  BFS(s);
  for (i=1;i<=n;i++){
    if (d[i]==INF) {
      d[i]=-1;
    }
    printf("%d %d\n",i,d[i]);
  }
  return 0;
}

Measured memory_bytes: 640
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

fn read_n<T: FromStr>(n: u32) -> Vec<T> {
  read_n_logic::<T>(n, vec![])
}

fn read_n_logic<T: FromStr>(n: u32, mut a: Vec<T>) -> Vec<T> {
  match n {
    0 => a,
    _ => {
      a.push(read::<T>());
      read_n_logic(n - 1, a)
    }
  }
}

fn main() {
  let n = read::<usize>();
  let x = read::<usize>();
  let l_list = read_n::<usize>(n as u32);
  let mut sum = 0;
  let mut bound = 1;

  for i in 0..n {
    if l_list[i] + sum <= x {
      bound += 1;
    }
    sum += l_list[i];
  }

  println!("{}", bound);
}


Measured memory_bytes: 4352
#include<iostream>
using namespace std;
#define endl '\n'

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int X, Y;
    cin >> X >> Y;
    int maxfoot;
    maxfoot = 4 * X;
    while(X!=0){
        if(maxfoot>Y){
            maxfoot = maxfoot - 2;
        }
        if(maxfoot==Y){
            cout << "Yes" << endl;
            break;
        }
        X--;
    }
    if(maxfoot!=Y){
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int nax=12;
vector<vector<int>> v[11];
int lev=0;
void fun(int l){
    if(l==1){
        for(int i=1;i<=9;i++){
            vector<int> v1(1,i);
            v[1].push_back(v1);
        }
        return ;
    }
    fun(l-1);
    int z=0;
    for(auto x : v[l-1]){
        int r=x[l-2];
        for(int i=r-1;i<=r+1;i++){
            if(i<0 || i>9) continue;
            v[l].push_back(x);
            v[l][z].push_back(i);
            z++;
        }
    }
    lev+=v[l].size();
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int k;
    cin>>k;
    int i=1;
    fun(10);
    while(true){
        if(v[i].size() < k ){
            k-=(int)v[i].size();
            i++; 
            continue;
        }
        for(auto x : v[i][k-1]){
            cout<<x;
        }
        break;
    }
    return 0;
}


Measured memory_bytes: 20144
# -*- coding: utf-8 -*-
from collections import Counter
import math
N = int(input())
S1 = input()
S2 = input()

i = 0
ans = 1
before = -1 #0:直前が縦、1:直前が横
while i < N :
    if S1[i] == S2[i]:#縦に置かれている
        if before == 1:#直前が横
            ans *= 1
        elif before == 0:#直前が縦
            ans *=2
        else:#最初
            ans *= 3
        ans = ans % 1000000007
        i += 1
        before = 0
    else:#横に置かれている
        if before == 1:#直前が横
            ans *= 3
        elif before == 0:#直前が縦
            ans *= 2
        else:#最初
            ans *= 6
        ans = ans % 1000000007
        i += 2
        before = 1

print(ans)




Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define de(c) cout << #c << " = " << c << endl
#define dd(c) cout << #c << " = " << c << " "
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int k,a,b;
int main(int argc, char const *argv[])
{
#ifdef indiewar
    freopen("in.txt","r",stdin);
#endif
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> k  >> a >> b;
    for(int i = a; i <= b; i++)
    {
        if(i % k == 0)
        {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

/* when you submit
	1.n = 0 or n = 1 ?
	2.array bounds ?
	3.int overflow ?
	4.multiple test cases ?
	Keep calm  think twice and code once
*/

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

using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; ++i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)

const int MAX = 1e5+10;
const ll INF = 1e10+10;

ll N, W, w, v;
ll dp[MAX];
ll ans;

int main () {
  cin >> N >> W;
  REP (i, MAX) dp[i] = INF;
  dp[0] = 0;
  REP (i, N) {
    cin >> w >> v;
    for (int j = MAX-v; j >= 0; --j) if (dp[j]+w <= W)
      dp[j+v] = min(dp[j+v], dp[j]+w);
  }
  for (int i = 1e5; i >= 0; --i) if (dp[i] < INF) {
    cout << i << endl;
    break;
  }
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector<int> dp(31, 0);
		dp[0] = 1;
		dp[1] = 1;
		dp[2] = 2;
		for (int j = 3; j <= n; j++) {
			dp[j] = dp[j-1]+dp[j-2]+dp[j-3];
		}
		int y = dp[n]/3650;
		if (dp[n] % 3650 > 0) {
			y++;
		}
		cout << y << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
 
using namespace std;
 
int main(){
    int W, H, x, y, r;
    cin >> W;
    cin >> H;
    cin >> x;
    cin >> y;
    cin >> r;
 
    int lowerLimmit = r;
    int upperLimmitX = W - r;
    int upperLimmitY = H - r;
 
    if (    lowerLimmit <= x && x <= upperLimmitX 
        &&  lowerLimmit <= y && y <= upperLimmitY ) {
        cout << "Yes" << endl;
     
    } else {
        cout << "No" << endl;       
    }
}

Measured memory_bytes: 1156
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(ll i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)

const double EPS = 1e-14;
int main(void){
	ll n;
	cin >> n;
	vector<pair<double, double> > point(n);//fi???;x??§?¨???? se ;y??§?¨?
	rep(i, n) scanf("%lf %lf", &point[i].fi, &point[i].se);

	//n????\???°?????¨??????????§°??????????????????
	if(n % 2 == 1){
		printf("NA\n");
		return 0;
	}

	//???????????§??????
	vector<double> len(n);
	rep(i, n - 1){
		double tmp = pow(point[i + 1].fi - point[i].fi, 2) + pow(point[i + 1].se - point[i].se, 2);
		len.push_back(tmp);
	}
	double tmp = pow(point[0].fi - point[n - 1].fi, 2) + pow(point[0].se - point[n - 1].se, 2);
	len.push_back(tmp);
	sort(all(len));
	if(len[n - 1] - len[0] > EPS){
		printf("NA\n");
		return 0;
	}

	//????±???¨???????????????????±???????
	vector<double> Px;
	vector<double> Py;
	rep(i, n / 2){
		double x = (point[i].fi + point[i + n / 2].fi) / 2.0;
		Px.push_back(x);
		double y = (point[i].se + point[i + n / 2].se) / 2.0;
		Py.push_back(y);
		//printf("%f %f %f\n", x, y, Py[i]);
	}

	sort(all(Px));
	if(Px[n / 2 - 1] - Px[0] > EPS){
		printf("NA\n");
		return 0;
	}
	sort(all(Py));
	if(Py[n / 2 - 1] - Py[0] > EPS){
		printf("NA\n");
		return 0;
	}

/*
	
	rep(i, n / 2){
		printf("%f %f\n", Px[i], Py[i]);
	}
*/	

	printf("%.9f %.9f\n", Px[0], Py[0]);
	return 0;
}

Measured memory_bytes: 3232
N,M,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
x.append(X)
y.append(Y)
x = sorted(x)
y = sorted(y)

for z in range(-100,101):
    ans = "War"
    if z > max(x) and z <= min(y):
        ans = "No War"
        break
        
print(ans)


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


int main() {
    // エラトステネスのふるい
    int MAX = 101010;
    vector<int> is_prime(MAX, 1);
    is_prime[0] = 0, is_prime[1] = 0;
    for (int i = 2; i < MAX; ++i) {
        if (!is_prime[i]) continue;
        for (int j = i*2; j < MAX; j += i) is_prime[j] = 0;
    }

    // 2017-like 数かどうか
    vector<int> a(MAX, 0);
    for (int i = 0; i < MAX; ++i) {
        if (i % 2 == 0) continue;
        if (is_prime[i] && is_prime[(i+1)/2]) a[i] = 1;
    }

    // 累積和
    vector<int> s(MAX+1, 0);
    for (int i = 0; i < MAX; ++i) s[i+1] = s[i] + a[i];

    // クエリ処理
    int Q; cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int l, r;
        cin >> l >> r;
        ++r;

        cout << s[r] - s[l] << endl;
    }
}


Measured memory_bytes: 4496
package main

import (
	"fmt"
)

func main() {

	Traveling()
}

//Traveling C
func Traveling(){

	var K,N int

	fmt.Scan(&K,&N)

	A := make([]int,N)

	for i:=0;i<N;i++{

		fmt.Scan(&A[i])
	}

	maxDistance :=0

	temp :=0

	for i:=0;i<N;i++{

		if i==0{

			maxDistance = A[i+1]-A[i]

		}else if i!=N-1{

			temp = A[i+1]-A[i]

			if maxDistance <=temp{

				maxDistance = temp
			}
		}else {

			temp = K + A[0]-A[i]

			if maxDistance < temp{

				maxDistance = temp
			}
		}
	}


	result := K- maxDistance

	fmt.Println(result)


}

Measured memory_bytes: 5504
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  for(int i=0;i<n;i++) cin >> s[i];

  vector<ll> cnt(5);
  cnt.assign(5,0);
  for(int i=0;i<n;i++){
    if(s[i][0] == 'M') cnt[0]++;
    if(s[i][0] == 'A') cnt[1]++;
    if(s[i][0] == 'R') cnt[2]++;
    if(s[i][0] == 'C') cnt[3]++;
    if(s[i][0] == 'H') cnt[4]++;
  }

  ll ans = 0;
  for(int i=0;i<3;i++){
    for(int j=i+1;j<4;j++){
      for(int k=j+1;k<5;k++){
        ans += cnt[i]*cnt[j]*cnt[k];
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 6144
#include <iostream>
#include <stdio.h>

int main()
{
    int daily_point = 0;
    int weekly_point = 0;
    int goal_point = 0;
    
    std::cin >> daily_point;
    std::cin >> weekly_point;
    std::cin >> goal_point;
    
    const int total_weekly_point = daily_point * 7 + weekly_point;
    
    const int weekly_count = goal_point / total_weekly_point;
    
    const int nokori_point = goal_point - (total_weekly_point * weekly_count);
    int daily_count = (nokori_point) / daily_point + ((nokori_point) % daily_point == 0 ? 0 : 1);
    if(nokori_point > daily_point * 7)
    {
        daily_count = 7;
    }
    printf("%d\n",weekly_count * 7 + daily_count);
    
    return 0;
}


Measured memory_bytes: 3216
#include<iostream>

using namespace std;

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

    int mx=-1, sum=0;
    for(int i=0; i<N; ++i) {
        int temp;
        cin >> temp;
        sum+=temp;
        mx=max(mx,temp);
    }
    cout << ((sum-mx>mx)?"Yes":"No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define M 1046527
#define h1(key) (key%M)
#define h2(key) (1+(key%(M-1)))
string s[M];

int getCode(char c){
  switch(c){
  case 'A':
    return 1;
    break;
  case 'C':
    return 2;
    break;
  case 'G':
    return 3;
    break;
  }
  return 4;
}

long long getKey(string in){
  long long sum = 0, p = 1;
  for(int i = 0 ; i < (int)in.size() ; i++){
    sum += (getCode(in[i]) * p);
    p *= 5;
  }
  return sum;
}

long long hash_f(long long key, int i){
  return (h1(key) + i * h2(key)) % M;
}

bool find(string in){
  long long key = getKey(in);
  
  for(int i=1;;i++){
    long long h = hash_f(key, i);
    if(s[h] == in) return true;
    else if(s[h].size() == 0) return false;
  }
}

void insert(string in){
  long long key = getKey(in);
  int i;
  for(i=1;;i++){
    long long h = hash_f(key, i); 
    if(s[h].size() == 0){
      s[h] = in;
      break;
    }
  }
}

int main(){
  int n;
  string command, in;
  cin >> n;
  for(int i = 0 ; i < n ; i++){
    cin >> command >> in;
    if(command == "insert"){
      insert(in);
    }else{
      if(find(in)){
    cout << "yes" << endl;
      }else{
    cout << "no" << endl;
      }
    }
  }
    
}


Measured memory_bytes: 42832
#include <iostream>
#include <string>
using namespace std;
signed main(){
  string s;
  
  cin>>s;
  
  int ans = 0;
  
  for( int i = 0; i < 3; i++ ) {
    
    if( s[i] == '1' ) ans++;
    
  }
  
  cout << ans << endl;
  
  return 0;
  
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(void){
    // Your code here!
    int n,s;
    cin>>n>>s;
    int ans1 =-1,ans2=-1,ans3=-1;
    for (int i=0; i<=n; i++){
        for (int j=0; j<=n-i; j++){
            if (i*10000+j*5000+(n-i-j)*1000==s){
               ans1=i;
               ans2=j;
               ans3=n-i-j;
            }

        }
    } cout<<ans1<<" "<<ans2<<" "<<ans3<<endl;
}


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

using LL = long long;

#define ALL(a) begin((a)), end((a))
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); (i)--)
#define debug(x) cerr << #x << " : " << x << '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const LL LINF = 1e16;

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

  LL ans;
  string S;
  cin >> S;

  int size = S.size();

  while (size > 2) {
    S.pop_back();
    size = S.size();

    if (size % 2) {
      continue;
    }

    int half = size / 2;
    string s1 = S.substr(0, half);
    string s2 = S.substr(half, half);

    if (s1 == s2) {
      ans = size;
      break;
    }
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu

const ll INF=1e9+7;
const ll N = 10002;
ll a,b,c,ans=INF,x,y;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>a>>b>>c>>x>>y;
	for(ll i=0;i<200001;i+=2){
		ll w=i*c;
		ll aa=x-i/2;
		ll bb=y-i/2;
		if(aa>0)w+=aa*a;
		if(bb>0)w+=bb*b;
		ans=min(ans,w);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        if(4*a*b<(c-a-b)*(c-a-b) && a<c&&b<c){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
 
}

Measured memory_bytes: 23764
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <iterator>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
#define tenll(x) ((ll)1e##x)

int main(){
	string s; cin >> s;
	vector<char> t;
	for (auto c : s) {
		if (sz(t) % 2 == 0 && c == 'A') t.push_back(c);
		else if (sz(t) % 2 == 1 && c == 'Z') t.push_back(c);
	}

	if (sz(t) % 2 == 1) t.pop_back();
	if (sz(t) == 0) cout << -1 << endl;
	else cout << string(t.begin(),t.end()) << endl;
}

Measured memory_bytes: 1196
#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(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(){
  int N;
  cin >> N;
  string s1,s2;
  cin >> s1 >>s2;

  mint ans;
  int i;
  int t;
  if(s1[0]==s2[0]){
    ans = 3;
    i = 1;
    t = 0;
  }else{
    ans = 6;
    i = 2;
    t = 1;
  }

  while(i<N){
    if(s1[i]==s2[i]){
      if(t==0)ans*=2;
      i++;
      t = 0;
    }else{
      if(t==0)ans *= 2;
      else ans *= 3;
      i+=2;
      t = 1;
    }
  }

  cout << ans.x << endl;
}




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

int main()

{
    int x, a, b;
    scanf("%d%d%d", &x, &a, &b);
    
    int diff_1, diff_2;
    diff_1 = abs(x - a);
    diff_2 = abs(x - b);
    
    if(diff_1 == diff_2){
        printf("Invalid");
    }
    else if(diff_1 < diff_2){
        printf("A");
    }
    else
        printf("B");
    
    return 0;

    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <unordered_map>

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<string> s(N);
	for (int i = 0; i < N; i++) {
		cin >> s[i];
		sort(s[i].begin(), s[i].end());
	}
	long long count = 0;
	unordered_map<string, int> M;
	for (int i = 0; i < N; i++) {
		if (M[s[i]] != 0) count += M[s[i]];
		M[s[i]]++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 13372
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1e9+1;

//string dp[3010][3010];
//stringでやるとTLEなどをした
ll dp[3010][3010];

void solve(){
    string s,t;
    cin >> s >> t;
    int n,m;
    n = s.size();
    m = t.size();
    rep(i,n+1){
        dp[i][0] = 0;
    }
    rep(j,m+1){
        dp[0][j] = 0;
    }


    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            if(s[i-1]==t[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
            else if(dp[i-1][j] > dp[i][j-1]) dp[i][j]=dp[i-1][j];
            else dp[i][j]=dp[i][j-1]; 
        }
    }
    /*
    dp[i][j-1], dp[i-1][j]のうち、dp[i][j]に等しい方へとジャンプ。
    どちらも等しくなければ、s[i]を足す。
    */
    int a = n;
    int b = m;
    string ans="";
    while(a>0&&b>0){
        if(dp[a][b]!=dp[a-1][b] && dp[a][b]!=dp[a][b-1]) {
            ans = s[a-1] + ans;
            a = a-1;
            b = b-1;
        }
        else if (dp[a][b-1]==dp[a][b]) b = b-1;
        else a = a-1;
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 70784
N = gets.strip.to_i

def calc(s)
  return 0 if s.to_i > N
  if s.include?('3') && s.include?('5') && s.include?('7')
    calc(s + '3') + calc(s + '5') + calc(s + '7') + 1
  else
    calc(s + '3') + calc(s + '5') + calc(s + '7')
  end
end 

puts calc('0')


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	ll N; cin >> N;
	vector<ll> H(N+1, 0); for (ll i = 0; i < N; ++i) cin >> H[i+1];

	ll res{0};

	for (ll i = 0; i < N; ++i)
	{
		res += max(0ll, H[i+1]-H[i]);
	}

	std::cout << res << std::endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        Stack<Long> st = new Stack<Long>();

        while (sc.hasNext()){
            String s = sc.next();
            switch (s){
                case "+":
                    st.push(st.pop()+st.pop());
                    break;
                case "-":
                    st.push(-st.pop()+st.pop());
                    break;
                case "*":
                    st.push(st.pop()*st.pop());
                    break;
                default:
                    st.push(new Long(s));
            }
        }
        System.out.println(st.pop());
    }
}

Measured memory_bytes: 26224
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

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

    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll mx = -inf;
    chmax(mx, a * c);
    chmax(mx, a * d);
    chmax(mx, b * c);
    chmax(mx, b * d);

    cout << mx << endl;

    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#include <queue>
#include <cstring>
#define mp make_pair
#define pb push_back
#define p push

#define FOR(a,c) for(int a = 0;a<c;a++)
#define ll long long int

#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d%d",&a,&b)
#define getIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define getL(a) scanf("%lld",&a)
#define getLL(a,b) scanf("%lld%lld",&a,&b)
#define getLLL(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define BEND(c) (c).begin(),(c).end()
#define BEND2(c) (c).rbegin(),(c).rend()
#define fi first
#define se second
#define pi 3.1415926535897932384626
#define getS(a) scanf("%s",a)
#define pfi(a) printf("%d",a);
#define pfii(a,b) printf("%d%d",a,b);
#define pfl(a) printf("%lld",a);
#define pfll(a,b) printf("%lld%lld",a,b);
#define pfd(a) printf("%lf",a);
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);

#define sag (sol|1)
#define sol (root<<1)
#define ort (bas+son)/2
#define SIZE 1000000007
#define MAXN 100005

using namespace std;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vl;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<vi> graph ;



int main(){
    IOS
    ll r,d,x;
    cin >>r>>d>>x;
    for (int i = 0; i <10 ; ++i) {
        int res= r*x - d;
        x = res;
        cout << res <<"\n";
    }

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a,b,buf;
    scanf("%d %d", &a, &b);
    buf=b;
    while(buf){
        buf/=10;
        a*=10;
    }
    a+=b;
    buf=0;
    for(int i=1;i<=400;i++){
        if((a%i==0)&&(a/i==i)){
            buf=1;
            break;
        }
    }
    printf("%s\n", (buf==1)?"Yes":"No");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int w, a, b;
    cin >> w >> a >> b;
    int ans = 0;
    if (a >= b) {
        ans = a - (b + w);
    } else {
        ans = b - (a + w);
    }
    cout << max(ans, 0) << endl;
    return 0;
}


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

int main()
{
	int h=0,m=0,s;
	cin >>s;
	while (s >= 60) {
		if (s >= 60) {
			s -= 60;
			m += 1;
		}if (m>=60) {
			m -= 60;
			h += 1;
		}
	}
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}

Measured memory_bytes: 3084
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_8_A
// Binary search trees - Binary Search Tree I

#define SUBMIT

#include <utility>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <limits>
#include <numeric>
#include <functional>
#include <set>
#include <cmath>
#include <cstring>
#include <climits>
#include <memory>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

struct node {
    int key;
    shared_ptr<node> parent, left, right;
};

shared_ptr<node> root;

void print_preorder(const shared_ptr<node>& r) {
    function<void(shared_ptr<node>)> print_loop = [&print_loop](shared_ptr<node> u) {
        cout << " " << u->key;
        if (u->left != nullptr) print_loop(u->left);
        if (u->right != nullptr) print_loop(u->right);
    };

    print_loop(r);
    cout << endl;
}

void print_inorder(const shared_ptr<node>& r) {
    function<void(shared_ptr<node>)> print_loop = [&print_loop](shared_ptr<node> u) {
        if (u->left != nullptr) print_loop(u->left);
        cout << " " << u->key;
        if (u->right != nullptr) print_loop(u->right);
    };

    print_loop(r);
    cout << endl;
}

void print_tree(const shared_ptr<node>& root) {
    print_inorder(root);
    print_preorder(root);
}

void insert(shared_ptr<node>& root, const shared_ptr<node>& new_node) {
    shared_ptr<node> y = nullptr;
    auto x = root;
    while (x != nullptr) {
        // set parent
        y = x;

        // find a position to insert the new_node.
        if (new_node->key < x->key) x = x->left;
        else x = x->right;
    }

    new_node->parent = y;

    if (y == nullptr) root = new_node;
    else if (new_node->key < y->key) y->left = new_node;
    else y->right = new_node;
}

int main() {
    int n;
    cin >> n;
    string command;
    int key;
    for (int i = 0; i < n; ++i) {
        cin >> command;
        if (command[0] == 'p') print_tree(root);
        else {
            cin >> key;
            auto new_node = make_shared<node>();
            new_node->key = key;
            insert(root, new_node);
        }
    }
    return 0;
}


Measured memory_bytes: 42216
#include<cstdio>
#include<cstring>
char s[1050];
int main(){
	scanf("%s",s+1);
	int firstc=1,len=strlen(s+1);
	for(int &i=firstc;i<=len;i++)
		if(s[i]=='C') break;
    if(firstc>=len){
    	puts("No");
    	return 0;
	}
	int nextf=firstc+1;
	for(int &i=nextf;i<=len;i++)
		if(s[i]=='F') break;
	if(nextf>len){
		puts("No");
		return 0;
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
ll mod = 1e9 + 7;


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

	long long n;
	cin >> n;
	vector<long long> a(n), b(n), c(n);

	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];
	for (int i = 0; i < n; i++) cin >> c[i];
	
	sort(all(a));
	sort(all(b));
	sort(all(c));
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		auto it = c.end() - upper_bound(c.begin(), c.end(), b[i]);
		auto it2 = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
		ans += it*it2;
		//cout << it << " " << it2 << endl;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n;
cin>>n;
  vector<int> p(n);
for(int i=0;i<n;i++)
cin>>p[i];

int cnt=0;
for(int i=0;i<n-2;i++)
if((p[i]<p[i+1])&&(p[i+1]<p[i+2])||(p[i]>p[i+1])&&(p[i+1]>p[i+2]))
cnt++;

cout<<cnt<<endl;

  return 0;
}


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

int evenstring(string s) {
    int n = s.size();
    int h = n/2;
    rep(i,h) {
        if (s[i] != s[h+i]) {
            return 0;
        }
    }
    return n;
}

int main() {
    string s;
    cin >> s;
    int n = s.size();
    if (n % 2 == 1) {
        s.erase(n-1);
    }
    else {
        s.erase(n-2);
    }
    int ans = 0;
    for (int t_len = n; t_len >= 0; t_len-=2) {
        string t = s.substr(0, t_len);
        ans = max(evenstring(t), ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

const double EPS=1e-6;

int main(void){
	while(1){
		int n; cin >> n;
		if(!n) break;

		double x[333], y[333];
		for(int i=0; i<n; i++){
			cin>>x[i]>>y[i];
		}

		int ans=1;
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				if(i==j) continue;
				double dx = x[i]-x[j];
				double dy = y[i]-y[j];
				double dist = sqrt(dx*dx+dy*dy);
				if(dist > 2.0+EPS) continue;

				double r = sqrt(1.0-dist*dist/4);
				double vx = -dy/dist*r;
				double vy = dx/dist*r;
				double xx = (x[i]+x[j])/2+vx;
				double yy = (y[i]+y[j])/2+vy;
				int cnt=0;
				for(int k=0; k<n; k++){
					if((x[k]-xx)*(x[k]-xx)+(y[k]-yy)*(y[k]-yy) < 1.0+EPS)cnt++;
				}
				ans = max(ans, cnt);
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3160
import math
a, b, c = map(int, input().split())
ans = (c-a-b)*(c-a-b) - 4*a*b
# ans = math.sqrt(c) - (math.sqrt(a) + math.sqrt(b))
if c-a-b <= 0:
    print("No")
elif ans>0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
// Created by abhay
#include <bits/stdc++.h>
#define sz(a) int((a).size())
#define pb push_back
#define allc c.begin(),c.end()
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(allc,x) != c.end())
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
using namespace std;

int main()

{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    ll n;
    cin>>n;
    vector <int> v;
    for(ll i=1;i<=n;i++)
    {
        if(i%3==0)
            v.push_back(0);
        else if(i%5==0)
            v.push_back(0);
        else if((i%3==0)&&(i%5==0))
            v.push_back(0);
        else v.push_back(i);
    }
    ll sum=0;
    for(auto x:v)
    {
        sum+=x;
    }
    cout<<sum<<endl;
}

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

namespace AOJ0009
{
    class Program
    {
        static void Main()
        {
            var primeTable = GeneratePrimeTable(1000000);

            string line;
            while ((line = Console.ReadLine()) != null)
            {
                var n = int.Parse(line);
                var count = primeTable.TakeWhile(i => i <= n).Count();
                Console.WriteLine(count);
            }
        }

        private static int[] GeneratePrimeTable(int max)
        {
            var primeTable = new bool[max + 1];

            for (var i = 2; i <= max; i++)
            {
                primeTable[i] = true;
            }

            for (var i = 4; i <= max; i += 2)
            {
                primeTable[i] = false;
            }

            var currentPrime = 3;
            while (currentPrime <= max)
            {
                for (var i = currentPrime * 2; i <= max; i += currentPrime)
                {
                    primeTable[i] = false;
                }

                for (currentPrime += 2; currentPrime <= max; currentPrime += 2)
                {
                    if (primeTable[currentPrime]) break;
                }
            }

            return (from n in Enumerable.Range(0, max + 1)
                    where primeTable[n]
                    select n).ToArray();
        }
    }
}

Measured memory_bytes: 8184
N = int(input())
txy = [input() for i in range(N)]
now_pos = [0, 0]
now_time = 0
fail_flag = False
for i in range(N):
    t, x, y = map(int, txy[i].split(' '))
    if (x+y) % 2 != t % 2:
        fail_flag = True
    distance = (abs(now_pos[0]-x) + abs(now_pos[1]-y))
    if distance > t-now_time:
        fail_flag = True
    if fail_flag:
        print('No')
        exit()
    now_pos = [x,y]
    now_time = t
print('Yes')


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



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

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

#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, x;
    cin >> n >> x;
    int a[n];
    int res = 0;
    for (int i = 0; i < n; i++) {
        int y;
        cin >> y;
        if (y>x) {
            res += y-x;
            y -= y-x;
        }
        a[i] = y;
    }
    /*cout << "res=" << res << '\n';
    cout << "a= ";
    for (int i = 0; i < n; i++) cout << a[i] << ' ';
    cout << '\n';*/
    for (int i = 1; i < n; i++) {
        if (a[i-1]+a[i] > x) {
            int d = a[i-1]+a[i]-x;
            //cout << "d = " << d << '\n';
            res += d;
            if (d > a[i]) {
                d -= a[i];
                a[i] = 0;
                a[i-1] -= d;
            } else {
                a[i] -= d;
            }
        }
    }
    cout << res << '\n';
}
/*

 */

Measured memory_bytes: 4408
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
#define FOR(i,a,b) for(ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
int main(){
    int n,y; cin >> n >> y;
    int price = n*1000;
    int one=n,five=0,ten=0;
    while(true){
        if(price==y) break;
        else if(ten==n){
            ten = five = one = -1;
            break;
        }else if(one==0){
            ten++; five=0; one = n-ten;
        }else {
            one--; five++;
        }
        price = ten*10000+five*5000+one*1000;
    }
    cout << ten <<" "<<five<<" "<<one<<endl;
}




Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
const int maxn = 100100;
const int lg = 22;
int lca[lg][maxn], w[lg][maxn];
int sz[maxn], depth[maxn], cnt, n;
vector<int> g[maxn];
void init(int cur, int pr){
    lca[0][cur] = pr;
    w[0][cur] = 1;
    sz[cur] = 1;
    for(int v : g[cur]) if(v != pr){
        depth[v] = depth[cur] + 1;
        init(v, cur);
        sz[cur] += sz[v];
    }
}
void dfs(int cur, int pr, int blocked){
    cnt++;
    for(int v : g[cur]) if(v != pr && v != blocked)
        dfs(v, cur, blocked);
}
int M(){
    if(!~scanf("%d", &n)) return 0;
    for(int e = 0; e < n; e++) g[e].clear();
    for(int e = 0; e < n-1; e++){
        int from, to; scanf("%d %d", &from, &to); from--; to--;
        g[from].push_back(to);
        g[to].push_back(from);
    }
    init(0, -1);
    vector<int> first;
    for(int v = n-1; v != -1; v = lca[0][v])
        first.push_back(v);
    reverse(first.begin(), first.end());
    int pos = first.size() / 2;
    int blocked = first[pos + (first.size() & 1)];
    cnt = 0;
    dfs(0, -1, blocked);
    // printf("%d\n", cnt);
    if(cnt > (n - cnt)) printf("Fennec\n");
    else printf("Snuke\n");
    return 1;
}
int main(){
    while(M());
    return 0;
}


Measured memory_bytes: 13436
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n,m = [int(e) for e in input().split()]
res = 0
if n >= 2:
    res += comb(n,2)
if m >= 2:
    res += comb(m,2)
print(res)

Measured memory_bytes: 3060
#include<stdio.h>
int lis[200020],r=0,ans[200020],d[200020];
int ta[200020],nt[400040],to[400040];
int lb(int l,int r,int n,int *d){
  int m=(l+r)/2;
  if(l==r)return m;
  return n<=d[m]?lb(l,m,n,d):lb(m+1,r,n,d);
}
void f(int s,int t){//printf("%d %d\n",s,t);
  int rn,rp,i;
  ans[s]=r;
  for(i=ta[s];i+1;i=nt[i]){
    if(to[i]==t)continue;
    //int j;printf("lis %d:",s);
    //for(j=0;j<r;j++)printf("%d ",lis[j]);printf("\n");
    if(lis[r-1]<d[to[i]]){
      rn=-1;
      rp=-1;
      lis[r++]=d[to[i]];
    }
    else{
      rp=lb(0,r,d[to[i]],lis);
      rn=lis[rp];
      lis[rp]=d[to[i]];
    }
    f(to[i],s);
    if(rp+1)lis[rp]=rn;
    else    r--;
  }
}    
int main(){
  int n,i,a,b;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&d[i+1]);
  for(i=0;i<n;i++)ta[i+1]=-1;
  for(i=0;i<n-1;i++){
    scanf("%d %d",&a,&b);
    nt[i    ]=ta[to[n-1+i]=a];
    nt[n-1+i]=ta[to[i    ]=b];
    ta[a]=i;
    ta[b]=n-1+i;
  }
  lis[r++]=d[1];
  f(1,0);
  for(i=0;i<n;i++)printf("%d\n",ans[i+1]);
  return 0;
}


Measured memory_bytes: 21512
import heapq
n, m = map(int, input().split())
cards = list(map(int, input().split()))
heapq.heapify(cards)
rules = []
for _ in range(m):
    x, y = map(int, input().split())
    rules.append((x, y))
for c, v in sorted(rules, key=lambda x: x[1], reverse=True):
    count = 0
    while count < c:
        p = heapq.heappop(cards)
        if p < v:
            heapq.heappush(cards, v)
            count += 1
        else:
            heapq.heappush(cards, p)
            break
print(sum(cards))

Measured memory_bytes: 94032
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input = br.readLine().split(" ");
        int n = Integer.parseInt(input[0]);
        long c = Long.parseLong(input[1]);
        long forwardMax[] = new long[n+1];
        long backwardMax[] = new long[n+1];

        long positions[] = new long[n+1];
        long values[] = new long[n+1];

        positions[0] = 0;
        values[0] = 0;
        for(int i = 1; i <= n; i++){
            input = br.readLine().split(" ");
            positions[i] = Long.parseLong(input[0]);
            values[i] = Long.parseLong(input[1]);
        }

        long max = 0;
        long sum = 0;
        for(int i = 0; i <= n; i++){
            sum += values[i];
            max = Math.max(max, sum - positions[i]);
            forwardMax[i] = max;
        }

        max = 0;
        sum = 0;
        for(int i = n; i >= 0; i--){
            sum += values[i];
            max = Math.max(max, sum - (c - positions[i]) );
            backwardMax[i] = max;
        }

        long res = 0;
        // backward OA + OB + OB
        for(int i = n; i >= 0; i--){
            res = Math.max(res , backwardMax[i]);
            if(i != 0) 
                res = Math.max(res , backwardMax[i] - (c - positions[i]) + forwardMax[i-1]);
        }

        // forward OA + OA + OB
        for(int i = 0; i <= n; i++){
            res = Math.max(res, forwardMax[i]);
            if(i != n)
                res = Math.max(res, forwardMax[i] - (positions[i]) + backwardMax[i+1]);
        }

        System.out.println(res);
    }
}

Measured memory_bytes: 47428
#pragma GCC optimize "O2"
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <queue>
// for iota, accumulate, partial_sum
// #include <numeric>
// #include <iomanip>
// #include <fstream>
// #include <deque>
// #include <cmath>
// #include <unordered_map>
// #include <utility>
// #include <unordered_set>
// #include <ctime>
// #include <stack>
// #include <bitset>
// #include <random>
// #include <cstring>
// #include <cassert>
// #include <complex>
using namespace std;
typedef long long int lu;
typedef long long int ll;
typedef long double ld;
#define v vector<ll>
#define vu vector<lu>
#define vvu vector<vector<lu>>
#define vld vector<ld>
#define vs vector<string>
#define pll pair<ll, ll>
#define vpll vector<pair<ll, ll>>
#define puu pair<lu, lu>
#define vpuu vector<pair<lu, lu>>
const lu MOD = 1000000007;
const ld PI = 2 * acos(0.0);
#define round(x, y) ((x + y - 1) / y)
#define ce(x, y) ((x + y - 1) / y)
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define sq(x) ((x) * (x))
#define cb(x) ((x) * (x) * (x))

#define all(x) x.begin(), x.end()

v ga(ll n)
{
    v a;
    for (ll i = 0; i < n; i++)
    {
        ll p;
        // scanf("%lld", &p);
        cin >> p;
        a.push_back(p);
    }
    return move(a);
}

vu gau(lu n)
{
    vu a;
    for (lu i = 0; i < n; i++)
    {
        lu p;
        // scanf("%lu", &p);
        cin >> p;
        a.push_back(p);
    }
    return move(a);
}
vs gas(lu n)
{
    vs a;
    for (lu i = 0; i < n; i++)
    {
        string p;
        // scanf("%lu", &p);
        cin >> p;
        a.push_back(p);
    }
    return move(a);
}

template <typename T, typename A>
void pa(vector<T, A> const &a)
{
    for (T p : a)
    {
        // printf("%lu ", a[i]);
        cout << p << " ";
    }
    cout << "\n";
}

void yes()
{
    cout << "YES\n";
}

void no()
{
    cout << "NO\n";
}

void yesno(int f)
{
    if (f)
        yes();
    else
        no();
}

void solve()
{
    lu n;
    cin >> n;
    vu a = gau(n);
    vu dp(n + 1, 0);
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    for (lu i = 2; i < n; i++)
    {
        dp[i] = min(dp[i - 2] + abs(a[i] - a[i - 2]), dp[i - 1] + abs(a[i] - a[i - 1]));
    }
    cout << dp[n - 1];
}

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

    solve();
    return 0;
}

Measured memory_bytes: 1908
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC044A
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int K = int.Parse(Console.ReadLine());
            int X = int.Parse(Console.ReadLine());
            int Y = int.Parse(Console.ReadLine());

            if (N >= K)
                Console.WriteLine(K * X + (N - K) * Y);
            else
                Console.WriteLine(N * X);
        }
    }
}


Measured memory_bytes: 13140