akhauriyash/Code-Regression huggingface dataset:
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<climits>
#include<cfloat>
 
using namespace std;
 
double EPS = 1e-10;
 
double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}
 
struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}
 
  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }
 
  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }
 
  point operator * (double d){
    return point(x*d,y*d);
  }
};
 
struct segment{
  point a,b;
};
 
double dot(point a, point b) {
  return (a.x * b.x + a.y * b.y);
}
 
double cross(point a, point b) {
  return (a.x * b.y - a.y * b.x);
}
 
int is_intersected_ls(point a1, point a2, point b1, point b2) {
  return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
         ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );
}

int is_point_on_line(point a, point b, point c) {
  return cross(b-a, c-a)==0.0 &&
         (dot(b-a, c-a) > -EPS) &&
         (dot(a-b, c-b) > -EPS);
}

int inside(point p, vector<point> ps, int n){
  segment t;
  t.a=t.b=p;
  t.b.x=DBL_MAX;
  ps.push_back(ps[0]);
  double ymx=-DBL_MAX,ymn=DBL_MAX;
  for(int i=0;i<n;i++){
    ymx=max(ymx,ps[i].y);
    ymn=min(ymn,ps[i].y);
  }
  if(t.a.y<=ymn||t.a.y>=ymx)return 0;

  int cnt1=0;
  for(int i=0;i<n;i++)
    if(is_point_on_line(t.a,t.b,ps[i]))cnt1++;
  
  int cnt=0;
  for(int i=0;i<n;i++)
    if(is_intersected_ls(ps[i],ps[i+1],t.a,t.b))cnt++;

  return (cnt-cnt1)%2;
}

int main(void){
  int n;
  point k,s,in;
  vector<point>p; 

  cin >> n;
  while(n--){
    p.clear();
    for(int i=0;i<3;i++){
      cin >> in.x >> in.y;
      p.push_back(in);
    }     

    cin >> k.x >> k.y >> s.x >> s.y;

    if(inside(k,p,3)!=inside(s,p,3))cout << "OK" << endl;
    else cout << "NG" << endl;
     
  }
 
  return 0;
}

Measured memory_bytes: 956
#include<iostream> 
#include<string> 
#include<vector> 
#include<algorithm> 
#include<cmath> 
using namespace std; 
int main()
{

	string a; 
	cin >> a; 
	int s = a.size(); 
	vector<char> k(s);
	int ans = 0;
	for (int i = 0; i < s; i++)
	{
		char p = a.at(i);  
		int qq = 0;
		for (int k = 0; k < s; k++)
		{
			
			if (a.at(k)==p)
			{
				qq++;

			}
		}
		if (qq%2==1)
		{
			ans = 1; 
			break;
		}




	} 
	if (ans==1)
	{
		cout << "No" << endl;
	} 
	else
	{
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256
#n = int(input())
a,b=map(int,input().split()) #横並び
#x=[int(input()) for i in range(3)] #縦に並んだのを配列に
#y=list(map(int,input().split())) #横に並んだのを配列に
ret = b
if a < 13:
    ret//=2
if a<=5:
    ret = 0
print(ret)
#print('YNEOS'[1::2])


Measured memory_bytes: 2940
import sys

n = int(input())
a_list = list(map(int, input().split()))

if 0 in a_list:
    print(0)
    sys.exit()

ans = 1
for a in a_list:
    ans = ans * a
    if ans > 1000000000000000000:
        print(-1)
        sys.exit()
print(ans)

Measured memory_bytes: 21756
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
//#include<bits/stdc++.h>
#include<tuple>
#include<queue>
#include<map>
#include<algorithm>
//#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

bool _predicate(int a,const int& element) {
	return (element == a); // This will cause all elements to be deleted that are larger than 3
}
int main() {
	int n;
	cin >> n;
	map<ll, ll> num{};// (1000001, 0);
	//vector<int> div(0);
	vector<int> numlist(0);
	rep(i, n) {
		ll a;
		cin >> a;
		if (num[a] == 0) {
			numlist.push_back(a);
		}
		num[a]++;
	}
	sort(ALL(numlist));
	bool tmp;
	ll ans = 0;
	
	for (int ii = 0; ii < numlist.size(); ii++) {
		//cout << i << endl;
		int i = numlist[ii];
		if(num[i]!=0){
		tmp = false;
		ll  nummax = numlist[numlist.size() - 1];
		//cout << "I" << i << endl;
		/*for (int j = ii+1; j < numlist.size(); j++) {
			if (numlist[j] % i == 0) {
			//	cout << "J" << j << endl;
				numlist.erase(numlist.begin()+j);
				j--;
			}
		}*/
		for (ll j = i+i; j <= nummax; j += i) {
			num[j] = 0;
		}
		if (num[i] == 1) {
			//cout << i << endl;
			ans++;
		}
		/*if (num[i] != 0) {
			for (int d : div) {
				if (i % d == 0) {
					tmp = true;
					break;
				}
			}
			if (!tmp) {
				div.push_back(i);
				if (num[i] == 1) {

					ans++;
				}
			}

		}*/
	
		}
	}
	cout << ans << endl;
}

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

int main() {
    string S, T;
    cin >> S >> T;
    
    int ans = 0;
    for (int i = 0; i < (int)S.size(); i++) {
        if (S[i] != T[i]) ans++;
    }

    cout << ans << endl;
}

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

typedef long long lli;

const lli MAXN = 4004;
const lli INF = 1LL<<60;
lli N;
lli w[MAXN], dp[MAXN][MAXN], K[MAXN][MAXN];

int main() {
  while (cin >> N) {
    w[0] = 0;
    for (lli i = 0; i < N; ++i) {
      cin >> w[i+1];
      w[i+1] += w[i];
    }
    fill(dp[0], dp[MAXN], INF);
    for (lli i = 0; i < N; ++i) {
      dp[i][i] = 0;
      K[i][i] = i;
    }
    for (lli l = 2; l <= N; ++l) {
      for (lli i = 0, j; (j = i + l - 1) < N; ++i) {
        for (lli s = K[i][j-1]; s <= K[i+1][j]; ++s) {
          lli v = dp[i][s] + dp[s+1][j] + (w[j+1] - w[i]);
          if (dp[i][j] > v) {
            dp[i][j] = v;
            K[i][j] = s;
          }
        }
      }
    }
    cout << dp[0][N-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 251688
S = list(input())
#swt = 0 なら黒、 swt = 1 なら白
def counting(swt):
    cnt = 0
    for i in S:
        if swt == 0 and i == "1":
            i = "0"
            cnt += 1
            swt = 1
        elif swt == 1 and i == "0":
            i = "1"
            cnt += 1
            swt = 0
        else:
            if swt == 0:
                swt = 1
            else:
                swt = 0
    return cnt

print(min(counting(0),counting(1)))


Measured memory_bytes: 3956
#include <iostream>
using namespace std;
typedef long long ll;
#define MOD 1000000007

ll pow(ll a, ll n) {
  ll res = 1;
  for (; n; n >>= 1) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
  }
  return res;
}

ll fact(int n) {
  ll res = 1;
  for (int i = 2; i <= n; i++)
    res = res * i % MOD;
  return res;
}

ll comb(ll n, ll r) {
  ll inv_fact_p = pow(fact(n-r), MOD-2);
  ll inv_fact_q = pow(fact(r), MOD-2);
  ll tmp = inv_fact_p * inv_fact_q % MOD;
  return tmp * fact(n) % MOD;
}

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

    ll N, M, K; cin >> N >> M >> K;
    ll res = 0;
    for (int i = 1; i < N; i++) {
        res += (N - i) * M * M * i % MOD;
        res %= MOD;
    }
    for (int i = 1; i < M; i++) {
        res += (M - i) * N * N * i % MOD;
        res %= MOD;
    }
    cout << comb(N*M-2, K-2) * res % MOD << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<vector>
using namespace std;
int main() {
  int n, k, p, sum = 0;
  vector<int> v;
  scanf("%d %d", &n , &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &p);
    v.push_back(p);
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < k; i++) {
    sum += v[i];
  }
  printf("%d\n", sum);
}

Measured memory_bytes: 3748
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const ll INF = 1e18;
inline ll read(){
	ll X = 0,w = 0 ;
	char ch = 0;
	while(!isdigit(ch)) {w |= ch == '-';ch = getchar();}
	while(isdigit(ch)) X = (X<<3) + (X<<1) + (ch ^ 48),ch = getchar();
	return w ? -X : X;
}
ll n;
ll a[100005];
ll b[100005];
vector<ll>v;
bool A[100005];
bool B[100005];
ll cnt0,cnt1;
multiset<ll> one,tmp;
multiset<ll> zero;
set<ll>final;
ll ans;
int main()
{
	cin>>n;
	for(ll i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
		v.push_back(a[i]);
		v.push_back(b[i]);
	}
	sort(v.begin(),v.end());
	for(ll i=0;i<n;i++)
	{
		one.insert(v[i]);
	}
	for(ll i=n;i<2*n;i++)
	{
		zero.insert(v[i]);
	}
	tmp=one;
	for(ll i=1;i<=n;i++)
	{
		if(tmp.count(a[i]))
		{
			A[i]=1;
			tmp.erase(tmp.find(a[i]));
		}
		if(tmp.count(b[i]))
		{
			B[i]=1;
			tmp.erase(tmp.find(b[i]));
		}
		if(!A[i] and !B[i])
		{
			cnt0++;
		}
		if(A[i] and B[i])
		{
			cnt1++;
		}
	}
	for(multiset<ll>::iterator it=one.begin();it!=one.end();it++)
	{
		ans+=*it;
	}
	if(cnt0 or cnt1)
	{
		cout<<ans<<endl;
		return 0;
	}
	for(ll i=1;i<=n;i++)
	{
		final.insert(A[i]==1?1:0);
	}
	if(final.size()==1)
	{
		cout<<ans<<endl;
		return 0;
	}
	ll res=INF;
	for(ll i=1;i<=n;i++)
	{
		if(A[i])
		{
			multiset<ll>::iterator it=zero.begin();
			if(b[i]==*it)
			{
				it++;
			}
			res=min(res,ans+(*it-a[i]));
		}
		else
		{
			multiset<ll>::iterator it=zero.begin();
			if(a[i]==*it)
			{
				it++;
			}
			res=min(res,ans+(*it-b[i]));
		}
	}
	cout<<res<<endl;
	return 0;
}


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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int A,B; cin >> A >> B;
    cout << (A+B)%24 << endl;
    return 0;
}

Measured memory_bytes: 3580
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#define ll long long
#define mod 1000000007
#define maxn 110
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static int buf[20],len; len=0;
	if(x<0)x=-x,putchar('-');
	for(;x;x/=10)buf[len++]=x%10;
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]+'0');
}
inline void writeln(ll x){write(x); putchar('\n');}
inline void writesp(ll x){write(x); putchar(' ');}
int x[maxn*maxn],y[maxn*maxn];
int n,k,tot;
int main()
{
	n=read(); k=read();
	if(k>(n-1)*(n-2)/2){
		puts("-1"); return 0;
	}
	tot=0;
	for(int i=1;i<n;i++)
		x[++tot]=i,y[tot]=n;
	int now=(n-1)*(n-2)>>1;
	for(int i=1;i<n;i++)
		for(int j=1;j<i;j++)
			if(now>k)x[++tot]=i,y[tot]=j,--now;
	writeln(tot);
	for(int i=1;i<=tot;i++)
		writesp(x[i]),writeln(y[i]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
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);
}
int main()
{
    string S;
    cin >> S;
    bool H = false, I = false;
    if (S.size() % 2 == 1)
    {
        cout << "No";
        return 0;
    }
    rep(i, S.size())
    {
        if (i % 2 == 0 and S[i] != 'h')
        {
            cout << "No";
            return 0;
        }
        if (i % 2 == 1 and S[i] != 'i')
        {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}

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

int main(){
    ll n;
    cin >> n;
    if(n % 2 == 1){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0;
    n /= 10;
    while(n){
        ans += n;
        n /= 5;
    }
    cout << ans << endl;
    return 0;
}

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


void solve(long long A, long long B, long long K){
    if(A >= K){
        A -= K;
        K = 0;
        cout<<A<<" "<<B<<endl;
        return;
    }
    K -= A;
    A = 0;
    cout<<A<<" "<<max(B-K, 0LL)<<endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long K;
    scanf("%lld",&K);
    solve(A, B, K);
    return 0;
}


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

int main(){
    cin.sync_with_stdio(false);
    
    int n, k; cin >> n >> k;
    vector<int>v(n);
    int mini = INT_MAX;
    for(int i = 0; i < n; i++){
        cin >> v[i];
        mini = min(mini, v[i]);
    }

    vector<vector<bool>>dp(k+1, vector<bool>(2, false));
    for(int i = 0; i < mini; i++){
        dp[i][0] = false;
        dp[i][1] = true;
    }

    for(int i = mini; i <= k; i++){
        for(int j = 0; j < n; j++){
            if(i-v[j]>=0){
                dp[i][0] = dp[i][0] | dp[i-v[j]][1];
            }
        }

        dp[i][1] = true;
        for(int j = 0; j < n; j++){
            if(i-v[j]>=0){
                dp[i][1] = dp[i][1] & dp[i-v[j]][0];
            }
        }
    }

    if(dp[k][0]){
        cout<<"First";
    }else{
        cout<<"Second";
    }
}


Measured memory_bytes: 10388
import math

A, B, H ,M = list(map(int, input().split()))

Atheta = (H+M/60)/12*360
Btheta = M/60*360
Ax = A*math.sin(math.radians(Atheta))
Ay = A*math.cos(math.radians(Atheta))
Bx = B*math.sin(math.radians(Btheta))
By = B*math.cos(math.radians(Btheta))

print(math.sqrt(pow(Ax-Bx, 2) + pow(Ay-By, 2)))

Measured memory_bytes: 9520
#include<bits/stdc++.h>
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ii = pair<int, int>;

int main(){
	ios::sync_with_stdio(0);
	map<string, int> mp;
	int n;
	cin >> n;
	for(int i=0; i<n; ++i){
		string st;
		cin >> st;
		sort(all(st));
		if(mp.find(st)==mp.end())
			mp[st]= 1;
		else
			++mp[st];
	}
	ll ans = 0;
	for(auto x:mp){
		ll k = x.ss;
		ans += (k*(k-1))/2LL;	
	}
	cout << ans << endl;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define per(i,r,l) for (int i=r,i##end=l;i>=i##end;--i)
#define ll long long
using namespace std;
int main(){
    int n; cin>>n; ll s1=0,s2=0;
    rep(i,1,n){
        int d; ll c; scanf("%d%lld",&d,&c);
        s1+=c,s2+=d*c;
    }
    cout<<s1-1+(s2-1)/9<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;

void solve() {
	int x, y; cin >> x >> y;
	for (int i = 0; i <= x; i++) {
		if ((y - 2 * i) % 4 == 0 && (y - 2 * i) / 4 + i == x) {cout << "Yes"; return ;}
	}
	cout << "No";


}

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


	// int t; cin >> t;
	// while (t--)
	solve();

}

Measured memory_bytes: 3620
import java.util.Scanner;
import java.util.Arrays;
public class Main {
  public static void main (String[]args) {
    int Alice_score =0;
    int Bob_score =0;
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int ai[] = new int[N];
    
    for(int i = 0; i<N; i++){
      ai[i] = sc.nextInt();
    }
    
    Arrays.sort(ai);


    for(int i = 1; i<=N; i++){
      if(i % 2 != 0){
        Alice_score += ai[N-i];
      } else {
        Bob_score += ai[N-i];
      }
    }

    System.out.println(Alice_score - Bob_score);
  }
}


Measured memory_bytes: 23764
#include <stdio.h>

int main(void){

    int a, b, k;
    int i;
    scanf("%d %d %d", &a, &b, &k);

    if(b - a + 1 >= 2 * k){
        for(i = 0; i < k; i++){
            printf("%d\n", a + i);
        }
        for(i = k - 1; i >= 0; i--){
            printf("%d\n", b - i);
        }
    } else {
        for(i = a; i <= b; i++){
            printf("%d\n", i);
        }
    }

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 #define int long long

#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second


using namespace __gnu_pbds;
using namespace std;
const int mod=1e9+7;
 // const int mod=998244353;
 // const int mod=1e9+9;
// const int INF=4e18+10;
const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define read(n) int n; cin>>n;
#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i;


typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

template<typename T1,typename T2>
void set_min(T1& a, T2 b)
{
    a=min(a, (T1)b);
}


int multiply(int a, int b, int in_mod){return (a*b)%in_mod;}
int mult_identity(int a){return 1;}


auto power(auto a, int b, int in_mod)
{
    auto prod=mult_identity(a);
    auto mult=a%in_mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod=multiply(prod,mult, in_mod);

        }
        mult=multiply(mult, mult,in_mod);
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int in_mod)
{

    return power(q, in_mod-2,in_mod);
}
void solve()
{
    int n;
    cin>>n;
    readv(a,n);;
    int z_count=0;
    for(auto i:a)
        if(i==0)
            z_count++;

    if(z_count>0)
    {
        cout<<0<<endl;
        return;
    }
    int mult = a[0];

    for(int i=1;i<n;i++)
    {
        if((int)1e18/ mult < a[i])
        {
            cout<<-1<<endl;
            return;
        }
        mult*=a[i];
    }
    cout<<mult<<endl;


}

signed main()

{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    auto clk=clock();
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // -------------------------------------Code starts here---------------------------------------------------------------------
    int t=1;
    // cin>>t;
    for(int test=1;test<=t;test++)
    {
        // cout<<"Case #"<<test<<": ";
        // cout<<endl;
        solve();
        // cout<<endl;

    }

    // -------------------------------------Code ends here------------------------------------------------------------------


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
    return 0;
}


Measured memory_bytes: 4024
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    int H,W;
    cin >> H >> W;
    char S[H][W];
    rep(i,H) cin >> S[i];
    bool ans=true;
    rep(i,H) rep(j,W){
        bool check=false;
        if(S[i][j]=='.') continue;
        if(i!=0) if(S[i-1][j]=='#') check=true;
        if(i!=H-1) if(S[i+1][j]=='#') check=true;
        if(j!=0) if(S[i][j-1]=='#') check=true;
        if(j!=W-1) if(S[i][j+1]=='#') check=true;
        if(!check) ans=false;
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int X,Y,Z,P;
    scanf("%d%d%d",&X,&Y,&Z);
    P=X;
    X=Y;
    Y=P;
    P=X;
    X=Z;
    Z=P;
    printf("%d %d %d\n",X,Y,Z);
    return 0;

}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define MAXVAL 1000000000000

ll H, N;
vector<P> AB;
vector<ll> dp;
int a, b;


int main(){
  cin >> H >> N;
  dp.resize(H+1, MAXVAL);
  dp[H] = 0;  //初期値は0

  for(int i = 0; i < N; i++){
    cin >> a >> b;
    AB.push_back(make_pair(a, b));
  }

  for(int i = H; i > 0; i--){
    if(i != H && dp[i] == MAXVAL) continue; //到達不可
    for(int j = 0; j < N; j++){
      P p = AB[j]; //ABのj番目のペアを取る
      a = p.first; b = p.second;
      if(i-a > 0) dp[i-a] = min(dp[i-a], dp[i] + b);
      else if(i-a <= 0) dp[0] = min(dp[0], dp[i]+b);
    }
  }

  cout << dp[0] << endl;
  return 0;
}

  

Measured memory_bytes: 384
<?php
$ans = 0;
$array = [];

function cmp ($a, $b){
	$a = $a%10;
	$b = $b%10;
	$a = $a == 0 ? 10 : $a;
	$b = $b == 0 ? 10 : $b;
	return $b <=> $a;
}
for($i=0; $i<5; $i++){
	$array[] = trim(fgets(STDIN));
}
usort($array, "cmp");

function calc ($num){
	$plus = $num % 10;
	$plus = $plus == 0 ? 0 : 10-$plus;
	return $num+$plus;
}
for($i=0; $i<5; $i++){
	if($i<4){
		$ans+=calc($array[$i]);
	}else{
		$ans+=$array[$i];
	}
}

echo $ans . "\n";

?>

Measured memory_bytes: 4728
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
 
#n = int(input())
n,t = [int(i) for i in readline().split()]
a = [int(i) for i in readline().split()]

m = gain = 0
ans = 0
for ai in reversed(a):
    m = max(ai,m)
    if gain < m-ai:
        ans = 1
    elif gain == m-ai:
        ans += 1
    gain = max(gain,m-ai)

print(ans)    






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

int main()
{
    int n;
    string s;
    cin >> n >> s;
    string t = s.substr(n / 2, n / 2);
    s = s.substr(0, n / 2);
    if (n % 2 == 0 && t == s) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7

ll gcd(ll a, ll b) {
	if (a < b)return gcd(b, a);
	ll r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

ll count(ll lim, ll a, ll b) {
	ll obj = a * b / gcd(a, b);

	ll tgt = lim / a;
	tgt += lim / b;
	tgt -= lim / obj;

	return lim - tgt;
}

int main()
{
	ll A, B, C, D;
	cin >> A >> B >> C >> D;
	cout << count(B, C, D) - count(A - 1, C, D) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define fi                      first
#define se                      second
#define pb                      push_back
#define pbb                     pop_back
#define mp                      make_pair
#define pii     	            pair<int,int>
#define all(x)                  x.begin(), x.end()
#define mem(array, value)       memset(array, value, sizeof(array))
#define fastRead 	            ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#ifdef Lollipop
    #define line                    cout << "\n===================\n"
    #define trace(...)              __f( #__VA_ARGS__ , __VA_ARGS__ )
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " = " << arg1 << "\n";
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " = " << arg1 << " , ";
    __f(comma + 1, args...);
    }
#else
    #define line
    #define trace(...)
#endif

int main ()
{
    #ifdef Lollipop
        //freopen ("input.txt", "r", stdin);
        //freopen ("output.txt", "w", stdout);
    #endif
    //fastRead;
    char ch;
    cin >> ch;
    ch++;
    cout << ch << endl;
    return 0;
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
strToInt s = (read :: String -> Int) s
strToInteger s = (read :: String -> Integer) s
strToDouble s = (read :: String -> Double) s

main :: IO ()
main = do
    -- スペース区切り整数の入力
    [x, t] <- map strToInteger . words <$> getLine
    -- 出力
    putStrLn $ show $ max (x-t) 0


Measured memory_bytes: 508
#include <stdio.h>

int main(void){
	int n;
	int i;
	char s;
	int ac = 0;
	int unc = 0;
	int j = 0;
	
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		scanf("%c",&s);
		scanf("%c",&s);
		if(s == 'A'){
			ac++;
		}else if(s == 'U'){
			unc++;
			if(ac < unc) j = 1;
			scanf("%c",&s);
		}
	}
	if(ac == unc && j == 0){
		printf("YES");
	}else{
		printf("NO");
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2096
import heapq

N, M = map(int, input().split())
A = list(map(lambda x: int(x) * -1, input().split()))

heapq.heapify(A)

for _ in range(M):
    heapq.heappush(A, (heapq.heappop(A) + 1) // 2)

ans = sum(A) * -1

print(ans)


Measured memory_bytes: 14180
#include <iostream>
#include <string>
#include <vector>
#define ll long long
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll p = 0;
	string S; cin >> S;
	for (int i = 0; i < S.length(); i++) if (S[i] == 'p') p++;
	cout << S.length() / 2 - p << endl;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;
int s(int m)
{
    int n=0,i;
    for(i=1;;i++)
    {
        n+=i;
        if(n>=m)
            break;
    }
    return i;
}
int main()
{
    int x;
    while(cin>>x)
    {
        int t=s(x);
        cout<<t<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
/*
    Author : DemonStar
*/

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx2,tune=native")

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define ll long long
#define pi pair<int, int>
#define pl pair<long long, long long>
#define pld pair<long double, long double>
#define endl '\n'
#define loop(i, n) for (ll i = 0; i < n; i++)
#define rep(i, begin, end) for (__typeof(begin) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(x) x.begin(), x.end()
#define vl vector<ll>
#define vi vector<int>
#define ml map<ll, ll>
#define vpl vector<pair<ll, ll>>
const ll mod = 1e9 + 7;

template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t)
{
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t)
{
    for (auto &i : t)
        os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (T &t : v)
        is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v)
{
    for (pair<T1, T2> &t : v)
        is >> t.first >> t.second;
    return is;
}

int main()
{
    ll n, k;
    cin >> n >> k;
    vl v(n);
    cin >> v;
    vector<vl> dp(n + 1, vl(k + 1, 0));
    loop(i, k + 1) dp[0][i] = 1;
    for (int i = 1; i < n + 1; i++)
    {
        for (int j = 0; j <= k; j++)
        {
            int l = max(0LL, j - v[i - 1]), r = j;
            dp[i][j] = (mod + dp[i - 1][r] - (l ? dp[i - 1][l - 1] : 0)) % mod;
            if (j)
                (dp[i][j] += dp[i][j - 1]) %= mod;
        }
    }
    cout << (mod + dp[n][k] - (k ? dp[n][k - 1] : 0)) % mod << endl;

#ifdef LOCAL
    cerr
        << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif

    return 0;
}

Measured memory_bytes: 80256
MAX = 101

def judge_center(Cx, Cy, cords):
    H = -1
    for x, y, h in cords:
        if h > 0:
            tmpH = abs(x - Cx) + abs(y - Cy) + h
            if H == -1:
                H = tmpH
            else:
                if tmpH != H:
                    return -1
    for x, y, h in cords:
        if h == 0:
            tmpH = abs(x - Cx) + abs(y - Cy) + h
            if H > tmpH:
                return -1
    return H

def main():
    N = int(input())
    cords = [list(map(int, input().split(' '))) for _ in range(N)]

    for tmp_Cx in range(MAX):
        for tmp_Cy in range(MAX):
            H = judge_center(tmp_Cx, tmp_Cy, cords)
            if H != -1:
                print('{} {} {}'.format(tmp_Cx, tmp_Cy, H))
                return 0


if __name__ == '__main__':
    main()

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

int dp[100007][3];

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int a, b, c;
        cin >> a >> b >> c;

        dp[i][0] = a + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = b + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = c + max(dp[i-1][0], dp[i-1][1]);
    }

    cout << max({dp[n][0], dp[n][1], dp[n][2]});
}


Measured memory_bytes: 1408
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll a,c,d,n,m;
	ll cost=0,cans = 0;
	cin>>n>>m;
	vector<pair<ll,ll> > eh;
	for(ll i = 0;i<n;i++){
		cin>>a>>c;
		eh.push_back(make_pair(a,c));
	}
	sort(eh.begin(),eh.end());
	for(ll i = 0;i<n;i++)
	{
		a =eh[i].first;
		c = eh[i].second;
		if(cans+c<=m)
			{cans+=c;cost+=c*a;}
		else 
		{
			ll diff = m-cans;
			cost+=diff*a;
			break;
		}
				
	}
	cout<<cost<<endl;
}

Measured memory_bytes: 2420
from itertools import permutations,product
N,A,B,C = map(int,input().split())
L = [int(input()) for _ in range(N)]
G = {0:[],1:[],2:[]}
cmin = 10**5
for x in permutations(range(N),3):
    for y in product(range(4),repeat=N-3):
        G[0] = [x[0]]
        G[1] = [x[1]]
        G[2] = [x[2]]
        G[3] = []
        Ind = list(range(N))
        Ind.remove(x[0])
        Ind.remove(x[1])
        Ind.remove(x[2])
        for i in range(N-3):
            G[y[i]].append(Ind[i])
        cA = 0
        nA = len(G[0])
        cA = (nA-1)*10
        xA = 0
        for j in range(nA):
            xA += L[G[0][j]]
        cA += abs(A-xA)
        cB = 0
        nB = len(G[1])
        cB = (nB-1)*10
        xB = 0
        for j in range(nB):
            xB += L[G[1][j]]
        cB += abs(B-xB)
        cC = 0
        nC = len(G[2])
        cC = (nC-1)*10
        xC = 0
        for j in range(nC):
            xC += L[G[2][j]]
        cC += abs(C-xC)
        cmin = min(cmin,cA+cB+cC)
print(cmin)

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


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };
bool valid_pos(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }


vector<int> calc_required_level_to_rooms()
{
	int w, h, sx, sy;
	static int req[512][512];
	cin >> w >> h >> sx >> sy;
	--sx, --sy;
	for (int y = 0; y < h; ++y)
		for (int x = 0; x < w; ++x)
			cin >> req[y][x];


	static int min_level[512][512];
	for (int y = 0; y < h; ++y)
		for (int x = 0; x < w; ++x)
			min_level[y][x] = 1e9;

	vector<int> res;
	min_level[sy][sx] = 1;
	res.push_back(0);

	typedef pair<int, pint> P;
	priority_queue<P, vector<P>, greater<P> > q;
	q.push(P(1, pint(sx, sy)));
	while (res.size() <= w * h)
	{
		P tt = q.top(); q.pop();
		int level = tt.first;
		int x = tt.second.first, y = tt.second.second;
		if (level > min_level[y][x])
			continue;

		res.push_back(level);

		for (int i = 0; i < 4; ++i)
		{
			int tx = x + dx[i], ty = y + dy[i];
			if (valid_pos(tx, ty, w, h))
			{
				int nl = max(level, req[ty][tx]);
				if (nl < min_level[ty][tx])
				{
					q.push(P(nl, pint(tx, ty)));
					min_level[ty][tx] = nl;
				}
			}
		}
	}
	return res;
}
int main()
{
	ios::sync_with_stdio(false);

	int r;
	while (cin >> r, r)
	{
		vector<int> a = calc_required_level_to_rooms();
		vector<int> b = calc_required_level_to_rooms();

		int res = 1e9;
		for (int i = min<int>(r, a.size() - 1); i >= 0 && r - i < b.size(); --i)
			min_swap(res, a[i] + b[r - i]);
		cout << res << endl;
	}
}

Measured memory_bytes: 5464
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
const double PI = 3.14159265358979323846;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"



int main() {
int A, B;
  cin >> A >> B;
  cout << A * B << endl;
	return 0;
}




Measured memory_bytes: 3624
use num_bigint::{BigInt, ToBigInt};
fn main() {
    proconio::input! {
        n: usize,
        a_s: [BigInt; n],
    }
    let mut ans = ToBigInt::to_bigint(&1).unwrap();
    if a_s.iter().any(|a| a == &ToBigInt::to_bigint(&0).unwrap()) {
        println!("0");
        return;
    }
    let mut limit = ToBigInt::to_bigint(&1).unwrap();
    for i in 0..18 {
        limit *= ToBigInt::to_bigint(&10).unwrap();
    }
    for a in a_s {
        ans *= a;
        if ans > limit {
            println!("-1");
            return;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 10784
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; } 
ll modc(ll a, char op, ll b, ll _mod=mod) { a %= _mod; b %= _mod; ll res = 1; switch(op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break; } if (res < 0) res += _mod; return res; }


int main()
{
        string s;
        cin >> s;
        string l(s.begin(), s.begin()+4);
        string r(s.begin()+4, s.end());

        cout << l << ' ' << r << endl;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
 
int main(){
  int i,j,cnt;
  int n;
  cin>>n;
  int d[n];
  for(i=0;i<n;i++)cin>>d[i];
  sort(d,d+n);
  cout<<d[n/2]-d[n/2-1];
}

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


int main() {
  ll N;cin>>N;
  vector<ll> a(N);rep(i,N) cin>>a[i];
  
  vector<ll> ans(100010,0);
  for(int i=0;i<N;i++){
    if(a[i]==0){
      ans[a[i]]++;
      ans[a[i]+1]++;
    }
    else{
      ans[a[i]-1]++;
      ans[a[i]]++;
      ans[a[i]+1]++;
    }
  }
  
  sort(ans.begin(),ans.end());
  reverse(ans.begin(),ans.end());
  
  cout << ans[0] << endl;
    
}
 

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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, start, end) for(int i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define INFL (1e18)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    ll n, x;
    cin >> n >> x;

    vector<ll> nums(n);
    rep(i, n) cin >> nums[i];

    ll cnt = 0;
    rep(i, n-1){
        ll *a = &nums[i], *b = &nums[i + 1], sum = nums[i] + nums[i+1];
        if(sum > x){
            ll minus_val = sum - x, tmp = min(*b, minus_val);
            cnt += minus_val;
            *b -= tmp;
            minus_val -= tmp;
            *a -= minus_val;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<vector<int> > data;
vector<int> C, comp, g;
int counter;
bool cmp(int a, int b){
    if (C[a] < C[b]) return true;
    return false;
}
void dfs(int vertex){
    comp[vertex] = counter;
    for (int i=0; i < data[vertex].size(); i++){
        int to = data[vertex][i];
        if (comp[to] != -1) continue;
        dfs(to);
    }
}
signed main() {
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n>> m;
    for (int i=0; i < n; i++){
        int A;
        cin >> A;
        C.push_back(A);
        vector<int> help;
        data.push_back(help);
        comp.push_back(-1);
        g.push_back(i);
    }
    sort(g.begin(), g.end(), cmp);
    for (int i=0; i < m; i++){
        int A, B;
        cin >> A >> B;
        data[A].push_back(B);
        data[B].push_back(A);
    }
    counter = 0;
    for (int i=0; i < n; i++){
        if (comp[i] != -1) continue;
        dfs(i);
        counter++;
    }
    if (counter==1){
        cout << 0 << endl;
        return 0;
    }
    int ans = 0;
    vector<bool> rat(counter);
    fill(rat.begin(), rat.end(), false);
    vector<bool> used(n);
    fill(used.begin(), used.end(), false);
    for (int i=0; i < n; i++){
        int j = g[i];
        int Cn = comp[j];
        if (rat[Cn]) continue;
        ans += C[j];
        rat[Cn] = true;
        used[i] = true;
    }
    int u = counter-2;
    for (int i=0; i < n; i++){
        if (u==0) break;
        if (used[i]) continue;
        ans += C[g[i]];
        u--;
    }
    if (u>0){
        cout << "Impossible" << endl;
        return 0;
    }
    cout << ans << endl;
    return 0;
}








Measured memory_bytes: 9128
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int N, M, X;
	cin >> N >> M >> X;

	int left = 0, right = 0;
	for(int i = 0; i < M; i++) {
		int tmp;
		cin >> tmp;
		if(tmp > X) right++;
		else left++;
	}

	cout << (left > right ? right : left) << endl;

	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
	"os"
)

func MinInts(nums []int) (int, int) {
	var minIdx, minVal int
	for i, e := range nums {
		if i == 0 || e < minVal {
			minIdx = i
			minVal = e
		}
	}
	return minVal, minIdx
}

func ReadInt(f *os.File) int {
	var n int
	fmt.Fscanf(f, "%d", &n)
	return n
}

func ReadInts(f *os.File, n int) []int {
	nums := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(f, "%d", &nums[i])
	}
	return nums
}

func diff(a, b int) int {
	return int(math.Abs(float64(a - b)))
}

// took 15min
func main() {
	N := ReadInt(os.Stdin)
	h := ReadInts(os.Stdin, N)

	dp := make([]int, N)
	dp[0], dp[1] = 0, diff(h[0], h[1])
	for i := 2; i < N; i++ {
		dp[i], _ = MinInts([]int{
			dp[i-1] + diff(h[i-1], h[i]),
			dp[i-2] + diff(h[i-2], h[i]),
		})
	}

	fmt.Println(dp[N-1])
}

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

using namespace std;
long long  dp[100][100000],we[100],val[100],W;
int n;

long long  solve(int i,int left)
{

	if(i>=n||left<0)
	{
		return 0;
	}
	
	if(dp[i][left]!=-1)return dp[i][left];
	
	dp[i][left]=max(solve(i+1,left),dp[i][left]);
	if(left-we[i]>=0)
	{
		dp[i][left]=max(solve(i+1,left-we[i])+val[i],dp[i][left]);
	}
	
	return dp[i][left];
}

int main()
{

ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

cin>>n>>W;
for(int i=0;i<n;i++)
{
cin>>we[i]>>val[i];
}
memset(dp,-1,sizeof(dp));

cout<<solve(0,W);

}

Measured memory_bytes: 78336
import numpy as np
H, W, N, *A = map(int, open(0).read().split())
ls = []
for i in range(N):
  ls += [str(i+1)]*A[i]
ls = np.array(ls)
ls = ls.reshape((H,W))
ls[1::2] = ls[1::2,::-1]
for a in ls:
  print(' '.join(a))

Measured memory_bytes: 13236
N, M, X = map(int, input().split())

C = [0] * N
A = [0] * N
for i in range(N):
    ca = list(map(int, input().split()))
    C[i] = ca[0]
    A[i] = ca[1:]

ans = 10**11
for i in range(2**N):
    b = format(i, "0" + str(N) + "b")
    r = [0] * M
    c = 0
    for j in range(N):
        f = int(b[j])
        c += C[j] * f
        for k in range(M):
            r[k] += f * A[j][k]
        if min(r) >= X:
            ans = min(c, ans)

if ans == 10**11:
    print("-1")
else:
    print(ans)

Measured memory_bytes: 9256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
int main() {
	int n;
	cin >> n;
	vector<vector <int> > v;
	int x,l;
	for(int i = 0; i < n; i++){
		cin >> x >> l;
		v.push_back({x+l,x-l});
	}
	sort(v.begin(),v.end());
	int cnt = 1;
	int rightpos = v[0][0];
	for(int i = 1; i < v.size(); i++){
		if(v[i][1] >= rightpos){
			cnt++;
			rightpos = v[i][0];
			//cout << i << endl;
		}
	}
	cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 6964
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {

static long[] list=new long[87];

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

  // String nyuA=sc.nextLine();
//  String nyuB=sc.nextLine(); 
 

   String[] s=sc.nextLine().split(" ");
 //    String[] t=sc.nextLine().split("");

//int N=Integer.parseInt(nyuA);
int N=Integer.parseInt(s[0]);
int X=Integer.parseInt(s[1]);
//int X=Integer.parseInt(s[2]);

TreeSet<Integer> list=new TreeSet<>();
int set=0;
for(int i=0;i<N;i++){
int temp=Integer.parseInt(sc.nextLine());
set+=temp;
list.add(temp);
}
ArrayList<Integer> lists=new ArrayList<>(list);
X-=set;
int res=X/lists.get(0);
res+=N;

System.out.println(res);



}

}



Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			(3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
template<class T> void chmax(T &a, const T &b){if(a<b)a=b;}
template<class T> void chmin(T &a, const T &b){if(a>b)a=b;}
void YN(bool b){cout<<(b?"YES":"NO")<<endl;}
void Yn(bool b){cout<<(b?"Yes":"No")<<endl;}
void yn(bool b){cout<<(b?"yes":"no")<<endl;}

class compare {
public:
	bool operator()(tuple<ll, ll> a, tuple<ll, ll> b) {
		return (get<1>(a) > get<1>(b));
	}
};


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll H,W,h,w;
	cin>>H>>W>>h>>w;
	ll sum=(H/h)*(W/w);
	if(0>=(H*W-sum)*1000-sum*((h*w-1)*1000+1))cout<<"No"<<endl;
	else{
		cout<<"Yes"<<endl;
		rep(i,H){
			rep(j,W){
				cout<<((i+1)%h==0&&(j+1)%w==0?-(h*w-1)*1000-1:1000)<<(j!=W-1?" ":"\n");
			}
		}
	}
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
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 main() {
  int N; string S, T;
  cin >> N >> S >> T;
  rep(i, N) {
    cout << S[i] << T[i];
  }
}

Measured memory_bytes: 256