akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//最大公約数
ll gcd(ll a,ll b)
{
    if(a%b == 0)
        return b;
    else
        return gcd(b, a % b);
}

double arr[10];
ll n;
int main(){
    cin >> n;
    int p[20];
    for (ll i = 0; i < n;i++)
    {
        cin >> p[i];
        //cout << p[n] << endl;
    }
    ll count = 0;
    for (ll i = 1; i < (n - 1);i++)
    {
        //cout << i - 1 << "," << i << "," << i + 1 << endl;
        //cout << p[i - 1] << "," << p[i] << "," << p[i + 1] << endl;
        if(((p[i]>p[i-1])&&p[i]<p[i+1]))
            count++;
        else if(p[i]<p[i-1] && p[i]>p[i+1])
            count++;
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define inf 1072114514
#define llinf 1145141919810364364
#define mod 1000000007

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    int n,k,l[64],r=0,i;
    scanf("%d%d",&n,&k);
    for(i = 0;i < n;i++){scanf("%d",&l[i]);}
    qsort(l,n,sizeof(int),sortfnckj);
    for(i = 0;i < k;i++){r+=l[i];}
    printf("%d\n",r);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
const int LEN_MAX = 100;
int main (void) {
    char s[LEN_MAX];
    char t[LEN_MAX];

    cin >> s;
    cin >> t;

    int s_len = strlen(s);
    int t_len = strlen(t);

    sort(s, s + s_len);
    sort(t, t + t_len, greater<int>());

    string s_str = string(s);
    string t_str = string(t);

    if (s_str < t_str) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}

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

int main(){
	int a, b, c, d, e, k;
	cin >> a >> b >> c >> d >> e >> k ;
	
	if ( ( e - a ) <= k )
	{
	cout << " Yay! " ;  
	}
	else
	{
	cout << " :( " ;
	}
}


Measured memory_bytes: 256
n=gets.to_i
k=[1,6,9,36,81,216,729,1296,6561,7776,46656,59049]
s=Array.new(100001,0)
for j in 1..n
  s[j]=j
end
for i in 1..11
  if k[i] <= n then
    for j in k[i]..n
      s[j]=1+s[j-k[i]] if s[j] > 1+s[j-k[i]]
    end
  end
end
puts s[n]

Measured memory_bytes: 2556
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  //if(x=='a'||x=='i'||x=='u'||x=='e'||x=='o')){cout << "vowel" << endl;}
  //else{cout << "consonant" << endl;}
  int x = a*b;
  int y = c*d;
  if(x<y){cout << y << endl;}
  else if(y<x){cout << x << endl;}
  else{cout << x << endl;}
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair < int, int >
typedef vector<int> vi;
typedef  long long ll;
const int mod =1e9+7;
const int N = (int)2e5 + 5;



void solve(){
		int n;
  		cin>>n;
		int a[n];
		int mn=1e9,mx=-1e9;
		rep(i,n)cin>>a[i],mn=min(mn,a[i]),mx=max(mx,a[i]);
		cout<<mx-mn;	

}

int main(){
	Red;
	int t=1;
	// cin>>t;
	while(t--)
	solve();
	return 0;
}

Measured memory_bytes: 256
import java.util.InputMismatchException;
import java.util.Scanner;

public class Main {

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

			Main testB = new Main();
			System.out.println(testB.unevenNumbers(n));

			scanner.close();

		} catch (InputMismatchException e) {
			// TODO: handle exception
			System.out.println("整数を入力してください");
		}
	}


	public int unevenNumbers(int n){
		if (n < 10) {
			return n;
		} else if (n < 100){
			return 9;
		} else if (n < 1000) {
			return n - 90;
		} else if (n < 10000) {
			return 909;
		} else if (n < 100000) {
			return n - 9090;
		} else {
			return 90909;
		}
	}

}



Measured memory_bytes: 23380
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

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

    int k;
    int f[n];
    fill(f, f+n, 0);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> k;
            if (k == 1) f[i] |= (1<<j);
        }
    }

    int p[n][11];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 11; j++) {
            cin >> p[i][j];
        }
    }

    int ans;
    int tmp_ans;
    ans = INT_MIN;

    for (int i = 1; i < 1<<10; i++) {
        tmp_ans = 0;

        for (int j = 0; j < n; j++) {
            tmp_ans += p[j][__builtin_popcount(i&f[j])];
        }

        ans = max(ans, tmp_ans);
    }

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

Measured memory_bytes: 256
nk=input().split()
n=int(nk[0])
k=int(nk[1])
if k==1:
    print(n**3)
elif k%2==0:
    #あまりhalf
    h=int(k/2)
    x=(n-h)//k
    #あまり０
    y=n//k
    print((x+1)**3+y**3)
else:
    x=n//k
    print(x**3)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
long long a, ans, n;
int main() {
  scanf ("%lld", &n);
  for (int i = 1; i <= 5; i++) {
    scanf ("%lld", &a);
    ans = max(ans, (n - 1) / a);
  }
  cout << ans + 5 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pq priority_queue
using namespace std; typedef pair<int, int> P; typedef pair<int, P> P2; typedef pair<int, P2> P3;
constexpr long long gcd(long long a, long long b){return b ? gcd(b, a % b) : a;}
constexpr long long lcm(long long a, long long b){return a / gcd(a, b) * b;}
constexpr int INF = 1e9, MOD = INF + 7, around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
constexpr int mod_pow(long long x, long long n, const int mod){long long ret=1;while(n){if(n&1)(ret*=x)%=mod;(x*=x)%=mod;n>>=1;}return ret;}
template<int n> struct Prime{bool arr[n+1];constexpr bool operator[](int k){return arr[k];}constexpr Prime():arr(){for(int i=2;i<n;i++){arr[i]=true;for(int j=2;j*j<=i;j++){if(!(i%j))arr[i]=false;}}}};
template<int n> struct Factorial{long long arr[n+1],ary[n+1];constexpr Factorial():arr(),ary(){arr[0]=1;ary[0]=1;for(int i=0;i<n;i++){arr[i+1]=arr[i]*(i+1)%MOD;ary[i+1]=mod_pow(arr[i+1],MOD-2,MOD);}}};
constexpr Factorial<1010> fact; constexpr Prime<10> prime;
constexpr long long comb(int a, int b){if(a < b) return 0LL;if(!a or !b) return 1LL; long long pos = fact.arr[a], pot = fact.ary[a - b], por = fact.ary[b]; return pos * pot % MOD * por % MOD;}
template<int n> struct Bernoulli{long long arr[n+1];constexpr Bernoulli():arr(){arr[0]=1;for(int i=1;i<=n;i++){long long sum=0;for(int j=0;j<i;j++){(sum+=comb(i+1,j)*arr[j]%MOD)%=MOD;}arr[i]=(MOD-mod_pow(i+1,MOD-2,MOD))%MOD*sum%MOD;}}};
constexpr int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
constexpr long double PI = abs(acos(-1));
constexpr int sqrtN = 512, logN = 32;
constexpr long long LINF=1e18;

int main(){
	int n; cin >> n; vector<int> vec(n);
	for(int i = 0; i < n; i++) cin >> vec[i];
	vector<int> pos = vec; sort(begin(pos), end(pos));
	
	int c = 0;
	for(int i = 0; i < n; i++){
		int k = lower_bound(begin(pos), end(pos), vec[i]) - begin(pos);
		
		if(k % 2 != i % 2) c++;
	}
	
	cout << c / 2 << endl;
	return 0;
}


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

using namespace std;

#define ll long long

const int N = 1e6+15,mod = 1e9+7;

ll fac[N],inv[N];

ll combi(ll n,ll k){
	if(k>n || k<0)return 0;

	ll ret= (fac[n]*inv[k])%mod;
	ret= (ret*inv[n-k])%mod;
	return ret;

}
ll mypow(ll r,ll c){
	ll ret=1;
	while(c){
		if(c&1){
			ret = (ret*r)%mod;
		}
		c/=2;
		r = (r*r)%mod;
	}
	return ret;
}
ll f(int n,int k){

	int a = k-1,b = n-k-1;

	if(b<0 || 2*k-n<0)return 0;
	ll ret = (combi(a,b)*fac[k])%mod;

	ret = (ret *fac[n-k-1])%mod;
	
	return ret;
}

int main(){

    //freopen("input.txt","r",stdin);

    fac[0]= 1;inv[0]= 1;
    int n;
    scanf("%d",&n);

    if(n==2){

    	cout<<1<<endl;return 0;
    }
    for(int i=1;i<N;++i){
    	fac[i]= (fac[i-1]*i)%mod;
    }
    inv[n]= mypow(fac[n],mod-2);


    for(int i=n-1;i>=1;--i){
    	inv[i]= (inv[i+1]*(i+1))%mod;
    }

    ll ret=0;

    for(int i=1;i<n;++i){
    	ret = (ret + (i*(f(n,i)-f(n,i-1) + mod))%mod  )%mod;
    }
    cout<<ret<<'\n';
    return 0;
}

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

int main()
{
    int X, Q, R;

    cin >> X;

    Q = X / 100;
    R = X % 100;

    for (int i = 0; i < Q; i++)
    {
        R -= 5;
    }

    if (R <= 0)
    {
        cout << 1 << endl;
    }

    else
    {
        cout << 0 << endl;
    }
}


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

#define P pair<int,int>
#define vv vector<vector<int>>
#define v vector<int>
#define rep(i,n) for(int i=0;i<(int)n;i++)
using namespace std;

int main()
{
  rep(i,5)
  {
    int t;
    cin>>t;
    if(t==0){
      printf("%d",i+1);
      return 0;
    }
  }
}


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

int main(){
    long int n,x;
    cin >> n >> x;
    vector<long int> a(n);
    long int sum=0;
    int i;

    for(i=0; i<n; i++){
        cin >> a.at(i);
        sum+=a.at(i);
    }
    sort(a.begin(),a.end());

    if(x>sum) cout << n-1 << endl;
    else if(x==sum) cout << n << endl;
    else{
        for(i=0; i<n; i++){
            sum-=a.at(n-1-i);
            if(x>=sum) break;
        }
        cout << n-1-i << endl;
    }
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)
#define Rep(i, n) for(i = 1; i < n; i++)
#define Ans(s) cout << s << endl;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

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

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;


int main()
{
	int n;
	cin >> n;
	cout << 180 * (n - 2) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
#define pb push_back

typedef long long int ll;
const ll INF=1LL<<50;
struct Edge {
  ll to, cost;
  Edge(ll a, ll b){to=a;cost=b;}
};
vector<vector<Edge> > graph;
vector<ll> dist;

/* num of vertex is 'n', start at 's' */
bool bellman_ford(ll n, ll s) {
  //dist.resize(n, INF);
  //dist[s] = 0;

  for (ll i = 0; i < n; i++) {
    for (ll v = 0; v < n; v++) {
      for (ll k = 0; k < graph[v].size(); k++) {
        Edge e = graph[v][k];
	if(dist[v]==INF) continue;
        if (dist[e.to] > dist[v] + e.cost) {
          dist[e.to] = dist[v] + e.cost;
          if (i == n - 1) return true; /* detect cycle */
        }
      }
    }
  }
  return false;
}


int main(void){
  ll n,m,i,a,b,c;

  cin>>n>>m;
  graph.resize(n);
  for(i=0;i<m;i++){
    cin>>a>>b>>c;
    graph[a-1].pb(Edge(b-1,-c));
  }
  ll res1,res2;
  dist.resize(n, INF);
  dist[0]=0;
  bellman_ford(n,0);
  res1=-dist[n-1];
  bellman_ford(n,0);
  res2=-dist[n-1];
  if(res2>res1) cout<<"inf"<<endl;
  else cout<<res1<<endl;
  /*
    if(bellman_ford(n,0)) cout<<"inf"<<endl;
    else cout<<-dist[n-1]<<endl;
  */
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#include<ctype.h>
 
int main(int argc, char* argv[])
{
  char w[20], t[1000];
  int i, j, k, st;
 
  k = 0;
  scanf("%s", w);
  scanf("%s", t);
  while(strcmp(t, "END_OF_TEXT")){
    st = 1;
    j = 0;
    for(i = 0; t[i] != '\0'; i++){
	  if(t[i] == ' '){
        st = 1;
        j = 0;
      }else if(st == 1){
        if(toupper(w[j]) == toupper(t[i])){
          j++;
		  if((w[j] == '\0') && ((t[i+1] == ' ') || (t[i+1] == '\0'))){
            k++;
		  }
		}else{
		  st = 0;
		}
      }
    }
    scanf("%s", t);
  }
 
  printf("%d\n", k);
 
  return(0);
}

Measured memory_bytes: 540
#!/usr/bin/ruby
#encoding: utf-8

# 配るDPで書く

n = gets.to_i
h = gets.split.map(&:to_i)

dp = Array.new(n+1,1e9.to_i)

dp[0] = 0

(0..n-2).each do |i|
  dp[i+1] = [dp[i+1] , dp[i] + (h[i+1] - h[i]).abs].min
  if i != n-2
    dp[i+2] = [dp[i+2] , dp[i] + (h[i+2] - h[i]).abs].min
  end
end

puts dp[n-1]

Measured memory_bytes: 11396
#include <iostream>
#include <string>

int main()
{
	int input_a, input_b;
	int hours, minutes, seconds;
	std::string answer;

	std::cin >> input_a >> input_b;

	if (input_a < input_b)
	{
		answer = "a < b";
	}
	else if (input_a > input_b)
	{
		answer = "a > b";
	}
	else
	{
		answer = "a == b";
	}

	std::cout << answer << std::endl;

	return 0;
}


Measured memory_bytes: 3224
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>
#include <chrono>
#include <set>


#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

vector<vector<ll>> graph;
vector<ll> query;
vector<ll> ans;
vector<ll> visited;


const long long MAX_N = 1 << 17;

long long dat[2 * MAX_N - 1];

ll ecd(ll a, ll b) {
	if (a < b) swap(a, b);
	if (b == 0) return a;
	else {
		return ecd(b, a % b);
	}
}

ll pow(ll a, ll b) {
	vector<ll> d = vector<ll>((ll)(log(b)) + 2);
	d[0] = a;
	rep(i, 1, d.size()) d[i] = d[i - 1] * d[i - 1];
	ll ret = 1;
	rep(i, 0, log(b) + 1) {
		if (b & 1 << i) ret *= d[i];
	}
	return ret;
}

//144 A
int main(void) {
	ll a, b;
	cin >> a >> b;
	if (1 <= a && a <= 9 && 1 <= b && b <= 9)
		cout << a * b << endl;
	else cout << -1 << endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

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

int main() {
    ios::sync_with_stdio(false);
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans;

    ll sets = n / (a + b);
    ans = sets * a;

    ll diff = n % (a + b);
    diff = min(a, diff);
    ans += diff;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

string getreverse(string str) {
	reverse(str.begin(), str.end());

	return str;
}

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

	for (int t = 0; t < n; t++) {
		string s; cin >> s;

		set<string> set;

		for (int i = 0; i < s.size(); i++) {
			string forward = s.substr(0, i);
			string back = s.substr(i,s.size());

			set.insert(forward+back);
			set.insert(forward+getreverse(back));

			set.insert(getreverse(forward)+ back);
			set.insert(getreverse(forward)+ getreverse(back));
			
			set.insert(back+ forward);
			set.insert(back+ getreverse(forward));

			set.insert(getreverse(back)+ forward);
			set.insert(getreverse(back)+ getreverse(forward));
		}

		cout << set.size() << endl;
	}

	return 0;
}


Measured memory_bytes: 3216
#include<iostream>
#include<vector>
#include<string.h>
using namespace std;

vector<int> adj[210];
int match[210];
bool used[210];

bool dfs(int v)
{
	used[v] = true;

	for (int i = 0; i < adj[v].size(); i++)
	{
		int u = adj[v][i], w = match[u];

		if (w < 0 || (!used[w] && dfs(w)))
		{
			match[v] = u;
			match[u] = v;
			return true;
		}
	}
	return false;
}

int main()
{
	int n, a[110], b[110], c[110], d[110];

	cin >> n;

	for (int i = 1; i <= n; i++)
	{
		cin >> a[i] >> b[i];
	}
	for (int i = 1; i <= n; i++)
	{
		cin >> c[i] >> d[i];
	}

	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (a[i] < c[j] && b[i] < d[j])
			{
				adj[i].push_back(j + n);
				adj[j + n].push_back(i);
			}
		}
	}

	int res = 0;

	memset(match, -1, sizeof(match));

	for (int i = 1; i <= n; i++)
	{
		if (match[i] < 0)
		{
			memset(used, 0, sizeof(used));

			if (dfs(i))
			{
				res++;
			}
		}
	}
	cout << res << endl;
}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll k;
    string s;
    cin >> s >> k;
    const ll n = s.size();

    auto dp = make_v<ll>(n, n, k+1);
    REP(i, n) REP(j, k+1) dp[i][i][j] = 1;
    REP(l, n-1) {
        ll r = l+1;
        if(s[l]==s[r]) {
            REP(i, k+1) dp[l][r][i] = 2;
        }
        else {
            dp[l][r][0] = 1;
            FOR(i, 1, k+1) dp[l][r][i] = 2;
        }
    }
    REP(i, k+1) {
        FOR(w, 3, n+1) {
            REP(l, n-w+1) {
                ll r = l+w-1;
                if(s[l]!=s[r]) {
                    if(i) dp[l][r][i] = max(dp[l][r][i-1], dp[l+1][r-1][i-1]+2);
                    dp[l][r][i] = max({dp[l][r][i], dp[l+1][r][i], dp[l][r-1][i]});
                } else if(s[l]==s[r]) {
                    dp[l][r][i] = dp[l+1][r-1][i] + 2;
                    if(i) chmax(dp[l][r][i], dp[l][r][i-1]);
                }
            }
        }
    }

    // REP(i, n) {
    //     FOR(j, i, n) {
    //         cout << dp[i][j][0] << " ";
    //     }
    //     cout << endl;
    // }

    cout << dp[0][n-1][k] << endl;

    return 0;
}


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

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

const int maxN = 311;

struct cvad {
    pair<int, int> a, b;
    int id;

    cvad() {}

    cvad(int p1, int p2, int p3, int p4, int _id) {
        a = mp(p1, p2);
        b = mp(p3, p4);
        id = _id;
    }

    bool operator<(const cvad& who)const {
        return mp(a, b) < mp(who.a, who.b);
    }

    bool operator==(const cvad& who)const {
        return mp(a, b) == mp(who.a, who.b);
    }
};

int n, i, j, x, y, xx, yy, dim, full, pos;
char s[maxN][maxN];
int data[maxN][maxN][2];
vector<cvad> ord;

void give(const cvad& act, int val) {
    static int id, x, y, tp;

    id = act.id;
    if (id < 0) {
        tp = 1;
        id = -id;
    } else {
        tp = 0;
    }

    x = (id - 1) / n;
    y = (id - 1) % n;

    data[x][y][tp] = val;
}

int main()
{
   // freopen("test.in","r",stdin);

    scanf("%d\n", &n);
    for (i = 0; i < n; i++) {
        scanf("%s\n", s[i]);
        for (j = 0; j < n; j++)
            data[i][j][0] = data[i][j][1] = s[i][j] - 'a' + 1;
    }

    ord.reserve(n * n * 2);

    for (dim = 1; dim < n; dim <<= 1) {
        full = min(n, dim * 2);
        ord.clear();
        pos = 0;

        for (x = 0; x < n; x++) {
            for (y = 0; y < n; y++) {
                xx = (x + full - dim) % n;
                yy = (y + full - dim) % n;
                pos++;

                ord.pb(cvad(data[x][y][0],
                            data[x][yy][0],
                            data[xx][y][0],
                            data[xx][yy][0],
                            pos));

                ord.pb(cvad(data[x][y][1],
                            data[xx][y][1],
                            data[x][yy][1],
                            data[xx][yy][1],
                            -pos));
            }
        }

        sort(ord.begin(), ord.end());
        pos = 1;

        give(ord[0], pos);
        for (i = 1; i < ord.size(); i++) {
            if (!(ord[i - 1] == ord[i])) pos++;
            give(ord[i], pos);
        }
    }

    int ans = 0;
    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++)
            if (data[i][j][0] == data[i][j][1])
                ans++;

    printf("%d", ans);


    return 0;
}


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

int main(){

  int W, H;
  cin>>W>>H;

  int x,y,r;
  cin>>x>>y>>r;

  if(x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H)
    cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}



Measured memory_bytes: 3120
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long,long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};

int main() {
    int H,W;
    cin >> H >> W;
    vector<string> G(H);
    REP(i,H) cin >> G[i];
    vecveci dist(H,veci(W,-1));
    queue<P> que;
    REP(i,H) REP(j,W) if(G[i][j] == '#') {
        dist[i][j] = 0;
        que.push(P(i,j));
    }
    while(!que.empty()) {
        P p = que.front();
        que.pop();
        int y = p.first;
        int x = p.second;
        REP(dir,4) {
            int ny = dy[dir]+y;
            int nx = x + dx[dir];
            if(ny < 0 || ny >= H || nx < 0 || nx >= W || dist[ny][nx] != -1 || G[ny][nx] == '#') continue;
            dist[ny][nx] = dist[y][x] + 1;
            que.push(P(ny,nx));
        }
    }
    int ans = 0;
    REP(i,H) {
        REP(j,W) chmax(ans,dist[i][j]);
    }
    cout << ans << endl;
}



Measured memory_bytes: 13456
import copy

n = int(input())

nums = []
for i in range(n):
    nums.append(int(input()))

taiou = {}
reprica = copy.copy(nums)
reprica.sort()
for i, r in enumerate(reprica):
    taiou[r] = i
ans = 0
for i, num in enumerate(nums):
    if i % 2 != taiou[num] % 2:
        ans += 1

print(ans // 2)

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

using namespace std;

int a, b;

void Enter()
{
    cin >> a >> b;
}

void Solve()
{
    if (a <= 5)
        cout << 0;
    else if (6 <= a && a <= 12)
        cout << b/2;
    else
        cout << b;
}

int main()
{
    Enter();
    Solve();
    return 0;
}


Measured memory_bytes: 256
a, b, k = input().split()

a=int(a)
b=int(b)
k=int(k)

def divisor(n):
    div_list = []
    for i in range(1,n+1):
        if n % i == 0:
            div_list.append(i)
    return div_list

list=divisor(a)+divisor(b)
s_list=sorted(list)[::-1]

c=0
for i, s in enumerate(s_list[:-1]):
    if s_list[i] == s_list[i+1]:
        c+=1
        if c==k:
            print(s)

Measured memory_bytes: 3064
n=int(input())
l=[0]*5
m='MARCH'
for i in range(n):
  s=input()
  f=s[0]
  for i in range(5):
    if f==m[i]:
      l[i]+=1
      break
a=[]
for i in l:
  if i!=0:
    a.append(i)
if len(a)<3:
  print(0)
elif len(a)==3:
  print(a[0]*a[1]*a[2])
elif len(a)==4:
  print(a[0]*a[1]*(a[2]+a[3])+a[2]*a[3]*(a[0]+a[1]))
else:
  x=0
  for i in range(3):
    for j in range(i+1,4):
      for k in range(j+1,5):
        x+=a[i]*a[j]*a[k]
  print(x)
        

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

int main(){
    int n;
    string s;
    cin >> n >> s;
    bool ok=true;
    if(n&1) ok=false;
    else{
        rp(i,n/2){
            if(s.at(i)!=s.at(i+n/2))
            ok=false;
        }
    }
    if(ok) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	
	static Map<Integer,Integer> x2y;
	static int xl[];
	static int yl[];
	static Map<Integer, Integer> deleteY;
	static Map<Integer, Integer> deleteX;
	static int sum ,rsum,usum,  N, K;
	public static void main(String[] args) {		
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt(); K = sc.nextInt();
		x2y = new HashMap<Integer,Integer>();
		int xlm[] = new int[N];
		int ylm[] = new int[N];
		for(int i=0;i<N;i++) {
			int x = sc.nextInt(), y = sc.nextInt();
			xlm[i]=x; ylm[i]=y;
			x2y.put(x,y); 
		}
		sc.close();
		Arrays.sort(xlm);
		Arrays.sort(ylm);
			
		long ans = Long.MAX_VALUE;
		for(int l=0;l<N;l++) {
			sum = N;
			xl = xlm.clone();
			yl = ylm.clone();
			deleteY = new HashMap<Integer, Integer>();;
			
			int lmin = xl[l];	
			removeY(l,true);//plus:true
			sum -= l;
			rsum = sum;
			if(sumOut()) break;
			for(int r=0;r+l<N;r++) {
				sum = rsum;
				int rmax = xl[N-1-r];
				removeY(r,false);//plus:true
				if(r!=0)sum -=r;
				if(sumOut()) break;
				boolean firstChoice = true;
				usum = sum;
				for(int u=0;u<N;u++) {
					sum = usum;
					int umax = yl[N-1-u];
					if(deleteY.containsKey(umax)) continue;
					if(!firstChoice)usum --;
					else firstChoice = false;
					if(sumOut()) break;
					sum = usum;
					boolean firstChoiceD = true;
					for(int d=0;u+d<N;d++) {	
						int dmin = yl[d];
						if(deleteY.containsKey(dmin)) continue;
						if(!firstChoiceD)sum --;
						else firstChoiceD = false;
						if(sumOut()) break;
						
						long Squ = ((long)rmax - lmin)*((long)umax-dmin);
 						ans = Math.min(ans, Squ);
						
					}
				}
			}
		}
		System.out.println(ans);
	}


	static void removeY(int times, boolean plus) {
		if(plus) {
			for(int i=0;i<times;i++) {
				int keyX = xl[i];
				int valueY = x2y.get(keyX);
				if(!deleteY.containsKey(keyX))deleteY.put(valueY, 1);
			}
		}else {
			for(int i=0;i<times;i++) {
				int keyX = xl[N-1-i];
				int valueY = x2y.get(keyX);
				if(!deleteY.containsKey(keyX))deleteY.put(valueY, 1);
			}
		}
	}
	static boolean sumOut() {
		return sum<K;
	}

}

Measured memory_bytes: 36900
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vector<int>s(m);
  vector<char>c(m);
  int i;
  for(i=0;i<m;i++){
    cin >> s[i] >> c[i];
    s[i]--;
  }
  string ans = "";
  if(n==1)ans="0";
  else{
    ans = "1";
    for(i=1;i<n;i++)ans+="0";
  }
  bool chk = true;
  vector<bool>keta(n,true);
  for(i=0;i<m;i++){
    if(s[i]>=n){
      chk=false;
      break;
    }else{
      if(keta[s[i]]==false){
        if(c[i]!=ans[s[i]])chk=false;
      }else{
        ans[s[i]]=c[i];
        keta[s[i]]=false;
      }

    }
  }
  if(chk && (n==1 || ans[0]!='0'))cout<<ans<<endl;
  else cout<<-1<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int N, X;
vector<int> L;

int main() {
  cin >> N >> X;
  L.resize(N);
  rep(i, N) cin >> L[i];

  int D = 0;
  int ans = 1;
  rep(i, N) {
    D += L[i];
    if (D <= X) ++ans;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long Int;
const Int inf = 1<<22;

const int nsize = 101;
const int msize = 1001;
const int lsize = 1001;
int N, M, L;
Int D[nsize][nsize];
Int P[lsize];
Int T[lsize];
Int E[nsize][nsize];
int EC[nsize];

void init() {
    for ( int i = 0; i < nsize; i++ ) {
        for ( int j = 0; j < nsize; j++ ) {
            D[i][j] = i==j?0:inf;
        }
    }
    for ( int i = 0; i < nsize; i++ ) {
        EC[i] = 0;
    }
}

// Graph
typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

// bipartite matching
bool augment(const Graph& g, int u,
    vector<int>& matchTo, vector<bool>& visited) {
  if (u < 0) return true;
  FOR(e, g[u]) if (!visited[e->dst]) {
    visited[e->dst] = true;
    if (augment(g, matchTo[e->dst], matchTo, visited)) {
      matchTo[e->src] = e->dst;
      matchTo[e->dst] = e->src;
      return true;
    }
  }
  return false;
}
int bipartiteMatching(const Graph& g, int L, Edges& matching) {
  const int n = g.size();
  vector<int> matchTo(n, -1);
  int match = 0;
  REP(u, L) {
    vector<bool> visited(n);
    if (augment(g, u, matchTo, visited)) ++match;
  }
  REP(u, L) if (matchTo[u] >= 0) // make explicit matching
    matching.push_back( Edge(u, matchTo[u], 0) );
  return match;
}

//
int main() {
    while ( cin >> N >> M >> L ) {
        if ( N == 0 && M == 0 && L == 0 ) break;
        init();

        for ( int i = 0; i < M; i++ ) {
            int u, v, d;
            cin >> u >> v >> d;
            D[u][v] = D[v][u] = d;
        }
        for ( int i = 0; i < L; i++ ) {
            int p, t;
            cin >> p >> t;
            P[i] = p;
            T[i] = t;
        }

        // wf
        for ( int k = 0; k < N; k++ ) {
            for ( int i = 0; i < N; i++ ) {
                for ( int j = 0; j < N; j++ ) {
                    D[i][j] = min( D[i][j], D[i][k] + D[k][j] );
                }
            }
        }

        Graph g( 2*L );
        for ( int i = 0; i < L; i++ ) {
            for ( int j = 0; j < L; j++ ) {
                if ( i == j ) continue;
                if ( T[i] + D[P[i]][P[j]] <= T[j] ) {
                    g[i].push_back( Edge( i, j+L, 1 ) );
                }
            }
        }

        Edges edges;
        int answer = L - bipartiteMatching( g, L, edges );
        cout << answer << endl;
    }
    return 0;
}

Measured memory_bytes: 8880
#include <iostream>
#include <vector> 
#include <algorithm> 
#define range(i,a,b) for(int (i) = (a) ; (i) < (b) ; (i)++)
#define drange(i,a,b) for(int (i) = (a) ; (i) >= (b) ; (i)--)
using namespace std;

int n, m;
int solve(int s, int* dp, vector<int>* neigh)
{
      if(dp[s]!=-1) return dp[s];
      if(neigh[s].size()==0) {dp[s] = 0; return 0;}
      vector<int> n = neigh[s];
      int m = -1;
      for(auto i : n) m = max(m,solve(i,dp,neigh));
      dp[s] = m + 1;
      return m + 1;
}
int main() 
{
	cin >> n >> m;
	vector<int> neigh[n+1];
	int dp[n+1];
	range(i,0,n+1) dp[i] = -1;
	range(i,1,m+1)
	{
	      int u,v;
	      cin >> u >> v;
	      neigh[u].push_back(v);
	}
	range(i,1,n+1)
	{
	      if(dp[i]==-1) solve(i,dp,neigh);
	}
	cout << *max_element(dp+1,dp+n+1);
	return 0;
}

Measured memory_bytes: 10880
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

a=list(input())
from collections import Counter
c= Counter(a)
cv=list(c.values())
s=len(a)*(len(a)-1)/2
for i in cv:
 s-=i*(i-1)/2
print(int(s)+1)

Measured memory_bytes: 61808
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort()
F.reverse()
#print('A = {}'.format(A))
#print('F = {}'.format(F))
M = [0] * N
for i in range(N):
    M[i] = A[i] * F[i]

def Below(X, K):
    for i in range(N):
        if A[i]*F[i] <= X:
            continue
        else:
            cost = X // F[i]
            K -= (A[i] - cost)
    if K >= 0:
        return True
    else:
        return False

left = 0
right = max(M)
while left != right:
    mid = (left + right) // 2
    #print('For mid={}, {}'.format(mid, Below(mid, K)))
    if Below(mid, K):
        right = mid
    else:
        left = mid + 1

print(left)

Measured memory_bytes: 119628
#pragma warning disable
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System;
using System.Collections;
using static System.Math;
using static System.Console;
class E { static void Main() => new J(); }
class J
{
	const int Mod = 1000000007;
	int F() => int.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	public J()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G();
		Array.Sort(I);
		var M = I.Sum();
		var f = new long[M];
		f[0] = 1;
		for (var i = 1; i < M; i++) f[i] = f[i - 1] * i % Mod;
		var d = I[1] - I[0];
		if (d >= 2) WriteLine(0);
		else if (d == 1) WriteLine(f[I[0]] * f[I[1]] % Mod);
		else WriteLine(f[I[0]] * f[I[1]] * 2 % Mod);
	}
	long GCD(long a, long b)
	{
		var n = (ulong)Abs(a); var m = (ulong)Abs(b);
		if (n == 0) return (long)m; if (m == 0) return (long)n;
		int zm = 0, zn = 0;
		while ((n & 1) == 0) { n >>= 1; zn++; }
		while ((m & 1) == 0) { m >>= 1; zm++; }
		while (m != n)
		{
			if (m > n) { m -= n; while ((m & 1) == 0) m >>= 1; }
			else { n -= m; while ((n & 1) == 0) n >>= 1; }
		}
		return (long)n << Min(zm, zn);
	}
}

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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

ll n, l;
ll a[100000];

int main() {
    cin >> n >> l;
    rep(i,n) cin >> a[i];
    int pos;
    bool ok = false;
    rep(i,n-1) {
        if (a[i]+a[i+1] >= l) {
            ok = true;
            pos = i;
            break;
        }
    }
    if (!ok) {
        puts("Impossible");
        return 0;
    }
    puts("Possible");
    for (int i = 1; i <= pos; i++) cout << i << endl;
    for (int i = n-1; i >= pos+2; i--) cout << i << endl;
    cout << pos+1 << endl;
}


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

int main(){
    double a,b,c,d;
    scanf("%lf %lf %lf %lf",&a,&b,&c,&d);
    printf("%.12f\n",sqrt((a-c)*(a-c)+(b-d)*(b-d)));
}


Measured memory_bytes: 3232
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n,ans=0; cin>>n; 
    vi a(n);
    for (int i=0;i<n;i++) {
        cin>>a[i];
        if (i&1) ans -= a[i];
        else ans += a[i];
    }
    cout << ans << " ";
    for (int i=0;i<n-1;i++){
        int h=a[i]-(ans/2);
        ans = h*2;
        cout << ans << " ";
    }
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}

/*
5
3 8 7 5 5
2 4 12 2 8

*/

Measured memory_bytes: 4044
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()
const long long INF = 1e18;
using namespace std;
typedef long long ll;
int main() {
  ll N, M;
  cin >> N >> M;
  vector<vector<ll>> t(M);
  REP(i, N) {
    ll a, b;
    cin >> a >> b;
    if (a > M) continue;
    t[M - a].push_back(b);
  }

  priority_queue<ll> q;
  ll ans = 0;
  FORR(i, M - 1, 0) {
    for (ll b : t[i]) {
      q.push(b);
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }

  cout << ans;

  return 0;
}

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

int main(void){
    ll n, a[10010], b[10010];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    
    ll ope_a = 0, ope_b = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] > b[i]) ope_b += a[i] - b[i];
        else if (a[i] < b[i]) {
            if (a[i] % 2 == b[i] % 2) ope_a += (b[i] - a[i]) / 2;
            else ope_a += (b[i] - a[i]) / 2 + 1;
            ope_b += (b[i] - a[i]) % 2;
        }
    }
    if (ope_a >= ope_b) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int ans;
int gcd(int a,int b){
  if(a < b) swap(a,b);
  if(b == 0) return a;
  ++ans;
  return gcd(b,a%b);
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b;
  while(cin >> a >> b&&a&&b){
    ans = 0;
    int k = gcd(a,b);
    cout << k <<" " << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
int INF = 100000;
vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};
int main(){
  int H, W;
  cin >> H >> W;
  vector<string> A(H);
  for (int i = 0; i < H; i++){
    cin >> A[i];
  }
  vector<vector<int>> d(H, vector<int>(W, INF));
  queue<pair<int, int>> Q;
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if (A[i][j] == '#'){
        d[i][j] = 0;
        Q.push(make_pair(i, j));
      }
    }
  }
  while (!Q.empty()){
    int y = Q.front().first;
    int x = Q.front().second;
    Q.pop();
    for (int i = 0; i < 4; i++){
      int y2 = y + dy[i];
      int x2 = x + dx[i];
      if (0 <= y2 && y2 < H && 0 <= x2 && x2 < W){
        if (d[y2][x2] == INF){
          d[y2][x2] = d[y][x] + 1;
          Q.push(make_pair(y2, x2));
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      ans = max(ans, d[i][j]);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 13456
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
#include<atcoder/all>

using namespace atcoder;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int K = 20;
const int KM = 1 << (K - 1);
ll dat[1 << K];
ll laz[1 << K];
ll zero = 0;

const int mod = 998244353;
ll pre[20];
constexpr ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}

void eval(int A, int l, int r) {
	if (laz[A] == zero) return;
	if (A * 2 < 1 << K) {
		laz[A * 2] = laz[A];
		laz[A * 2 + 1] = laz[A];
	}
	dat[A] = laz[A] * pre[__builtin_ctz(r - l)] % mod;
	laz[A] = zero;
}

int update(int L, int R, int X, int A, int l, int r) {
	eval(A, l, r);
	if (r <= L || R <= l) return dat[A];
	if (L <= l && r <= R) {
		laz[A] = X;
		return X * pre[__builtin_ctz(r - l)] % mod;
	}
	ll tmp1 = update(L, R, X, A * 2, l, (l + r) / 2) * modpow(10, (r - l) / 2) % mod;
	ll tmp2 = update(L, R, X, A * 2 + 1, (l + r) / 2, r);
	dat[A] = (tmp1 + tmp2) % mod;
	return dat[A];
}

void add(int L, int R, int X) {
	update(L, R, X, 1, 0, KM);
}

int check(int L, int R, int A, int l, int r) {
	eval(A, l, r);
	if (r <= L || R <= l) return zero;
	if (L <= l && r <= R) return dat[A];
	ll tmp1 = check(L, R, A * 2, l, (l + r) / 2) * modpow(10, (r - l) / 2) % mod;
	ll tmp2 = check(L, R, A * 2 + 1, (l + r) / 2, r);
	return (tmp1 + tmp2) % mod;
}

int query(int L, int R) {
	return check(L, R, 1, 0, KM);
}

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


	pre[0] = 1;
	rep(i, 19) {
		pre[i + 1] = pre[i] * modpow(10, 1 << i) % mod + pre[i];
		pre[i + 1] %= mod;
	}

	int N, Q;
	cin >> N >> Q;

	add(0, N, 1);
	ll are = modpow(modpow(10, (1 << 19) - N), mod - 2);
	ce(query(0, 1 << 19) * are % mod);

	rep(i, Q) {
		int l, r, d;
		cin >> l >> r >> d;
		l--;
		r--;
		add(l, r + 1, d);
		co(query(0, 1 << 19) * are % mod);
	}




	Would you please return 0;
}

Measured memory_bytes: 10016
#include <iostream>

using namespace std;

long long target;
int ans = 0;

int calc(string s , bool flag) {
  if (stoll(s) > target)return 0;
  if (!flag) {
    flag = (s.find("3") != std::string::npos && s.find("5") != std::string::npos && s.find("7") != std::string::npos );
  }
  if (flag) {ans++;}
  //cout << s << " " << flag << "\n";

  calc(s + "3", flag);
  calc(s + "5", flag);
  calc(s + "7", flag);
  return 0;
}

/*
3,5,7のみで構成される数字をすべて生成し、それが753であるのかを判定する
*/
int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> target;
  calc("0", false);

  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
b, c = map(int, input().split())
a = list(map(int, input().split()))
d = sum(a)
new_a = list(reversed(sorted(a)))
e = 0
f = 0
g = 4*c
while new_a[e] >= d/g:
    e = e+1
    f = f+1
    if e == b:
        break
if f >= c:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060