akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 1000000000000000000
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}

// string to integer stuuu()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

//////////////

#define S second
#define F first
#define int long long  
int mo=1000000007;

//////////

signed main()
{
	fastio;
	// #ifndef ONLINE_JUDGE
	// 	freopen("inputf.in","r",stdin);
	// 	freopen("outputf.in","w",stdout);
	// #endif
	int n;
	cin>>n;
	vector<pair<int,int>> ans;
	for(int i=1;i<=n;++i)
	{
		for(int j=i+1;j<=n;++j)
		{
			if(n%2==0)
			{
				if(j!=n-i+1)
				{
					ans.push_back({i,j});
				}
			}
			else
			{
				if(j!=n-i)
				{
					ans.push_back({i,j});
				}
			}
		}
	}
	cout<<ans.size()<<"\n";
	for(auto r:ans)
	{
		cout<<r.F<<" "<<r.S<<"\n";
	}
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1e+9;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



int main() {
  int X,A,B;
  cin >> X >> A >> B;
  X-=A;
  cout << X%B << endl;

  return 0;
}


Measured memory_bytes: 632
#include<stdio.h>
#define N 100
#define MAX 100000
#define INFTY (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2


int A[N][N], n;

void aoj();


int main(){
  int i, j, a;
  int b,c;
  int d,e;
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      A[i][j] = INFTY;
    }
  }

  for(i = 0; i < n; i++){
    scanf("%d%d", &b, &e);
    for(j = 0; j < e; j++){
      scanf("%d%d", &c, &d);
      A[b][c] = d;
    }
  }

  aoj();

  return 0;
}

void aoj(){
  int i,a,b, min;
  int sum = 0;
  int B[N], color[N];

  for(i = 0; i < n; i++){
    B[i] = INFTY;
    color[i] = WHITE;
  }

  B[0] = 0;
  color[0] = GRAY;

  while(1){
    min = INFTY;
    a = -1;
    for(i = 0; i < n; i++){
      if(min > B[i] && color[i] != BLACK){
        a = i;
        min = B[i];
      }
    }
 if(a == -1) break;

 
    color[a] = BLACK;

    for(b = 0; b < n; b++){
      if(color[b] != BLACK && A[a][b] != INFTY){
        if(B[b] > B[a] + A[a][b]){
          B[b] = B[a] + A[a][b];

	  
          color[b] = GRAY;
        }
      }
    }

  }

  for(i = 0; i < n; i++){
    printf("%d ",i);
    if(B[i]==INFTY) printf("-1\n");
    else printf("%d\n",B[i]);
  }

}




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

using namespace std;

long long t1, t2, a1, a2, b1, b2;

long solve(long long s, long long n, long long p) {
	cout << s << " " << n << " " << p << endl;
	if (n == s)
		return 1;
	else if (n > s)
		return solve(n - s, p, n) + 1;
	else
		return 0;
}

long long gcd(long long c1, long long c2) {
	long long d = c2 - c1;
	long long n = c1 / d;
	if (c1 % d == 0)
		return n * 2;
	else
		return n * 2 + 1;
}

int main() {
	long long c1, c2;
	cin >> t1 >> t2;
	cin >> a1 >> a2;
	cin >> b1 >> b2;

	if ((a1 > b1 && a2 > b2) || (a1 < b1 && a2 < b2)) {
		cout << 0;
	} else {
		if (a1 < b1) {
			c1 = t1 * (b1 - a1);
			c2 = t2 * (a2 - b2);
		} else {
			c1 = t1 * (a1 - b1);
			c2 = t2 * (b2 - a2);
		}
		if (c1 == c2)
			cout << "infinity";
		else if (c1 > c2)
			cout << 0;
		else
			cout << gcd(c1, c2);
	}
	cout << endl;
    return 0;
}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int a, b, c, d; cin >> a >> b >> c >> d;
  cout << ((abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

char a[100];

int main(){
	scanf("%s",a + 1);
	if((a[1] == a[2] && a[2] == a[3]) || (a[2] == a[3] && a[3] == a[4])){
		printf("Yes");
	}
	else printf("No");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int num,k,h[100100],dp[100100];
int main(){
	cin>>num>>k;
	for(int i=1;i<=num;i++)cin>>h[i];
	for(int i=2;i<=num;i++){
		dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
		for(int j=2;j<=k;j++)
			if(i>j)
				dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
	}
	cout<<dp[num]<<endl;
	return 0;
}

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

#define MOD 10000007
#define f first
#define s second
#define es " "
#define pb push_back
#define endl "\n"
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define ll long long int
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int n, v[200005], bit[200005];

void upd(int x){
    while(x<=n){
        bit[x]=1;
        x+=x&-x;
    }
}

int get1(int x){
    int resp=0;
    while(x>0){
        resp+=bit[x];
        x-=x&-x;
    }
    return resp;
}

/*int get2(int x){
    int resp=0;
    while(x<=n){
        resp+=bit[x];
        x+=x&-x;
    }
    return resp;
}*/

int main(){
    fastio;
    int ans=0;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> v[i];
    }
    for(int i=0; i<n; i++){
        if(get1(v[i])==0){
            ans++;
        }
        upd(v[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import sys
input = sys.stdin.readline

def fibo(i, dp):
	if dp[i] != -1:
		return dp[i]
	dp[i] = fibo(i-1, dp) + fibo(i-2, dp)
	return dp[i]

def main():
	n = int(input().strip())
	dp = [-1 for i in range(n+1)]
	dp[0] = 1
	dp[1] = 1
	print(fibo(n, dp))

if __name__ == '__main__':
	main()



Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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 dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    vector<ll> h(n);
    REP(i,n) cin>>h[i];
    vector<ll> dp(n+1,INF);
    
    dp[0]=0;

    for(int i=0;i<n;i++){
        for(int j=1;j<=k;j++){
            if(i+j<n) chmin(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
        }
    }
    cout<<dp[n-1]<<endl;
}


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

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi > 
const int N = 100010;
int main()
{
    string s;
    int x;
    cin>>s>>x;
    for(int i=0;i<s.size();i++)
    {
        if(i%x==0) cout<<s[i];
    }
    return 0;
}

Measured memory_bytes: 256
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
 
using ll = long long;
using P = std::pair<ll, ll>;
 
#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << #i <<" "<<i<<std::endl;
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;
 
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  ll n;
  std::cin>>n;

  std::vector<std::vector<ll>> graph(n);

  rep(i,0,n-1){
    ll a,b;
    std::cin>>a>>b;
    a--;b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  std::vector<ll> d(n,MOD);

  std::queue<ll> que;

  d[0]=0;
  que.push(0);

  while(!que.empty()){
    ll now=que.front();que.pop();

    for(ll next:graph[now]){
      if(chmin(d[next],d[now]+1)){
        que.push(next);
      }
    }
  }

  ll max=-1,itr=-1;

  rep(i,0,n){
    if(chmax(max,d[i]))itr=i;
  }

  rep(i,0,n)d[i]=MOD;

  d[itr]=0;
  que.push(itr);

  while(!que.empty()){
    ll now=que.front();que.pop();

    for(ll next:graph[now]){
      if(chmin(d[next],d[now]+1)){
        que.push(next);
      }
    }
  }

  max=-1;

  rep(i,0,n)chmax(max,d[i]);

  if(max%3==1)std::cout<<"Second";
  else std::cout<<"First";


  return 0;
}





Measured memory_bytes: 15984
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000007
//0=48,A=65,a=97

int main() {
    string s;cin >> s;
    string k="keyence";
    if(s[0]!='k' && s[s.size()-1]!='e'){
        cout << "NO" << endl;
        return 0;
    }

    int f=0,l=0;

    for(int i = 1; i < 8; i++) {
        if(s.substr(0,i)==k.substr(0,i)) f=i;
        else break;
    }
    for(int i = 1; i < 8; i++){
        if(s.substr(s.size()-i)==k.substr(k.size()-i)) l=i;
        else break;
    }
    
    if(s[0]=='k' && s[s.size()-1]=='e'){
        if(f+l>=7){
            cout <<"YES" << endl;
            return 0;
        }
    }
    if(f>=7 || l>=7){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;

    return 0;
}

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

flag=list(range(N))
def takeflag(p):
    stock=[]
    while flag[flag[p]]!=flag[p]:
        stock.append(p)
        p=flag[p]
    p=flag[p]
    for i in stock:
        flag[i]=p
    return p

for i in range(M):
    x,y,z = map(int,input().split())
    x,y=x-1,y-1
    x,y = map(takeflag,(x,y))
    x,y = min(x,y),max(x,y)
    flag[x]=y

st=set()
for i in range(N):
    st.add(takeflag(i))

print(len(st))

Measured memory_bytes: 89816
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define MOD 1000000007
#define mod 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 1e18
#define common cout << "Case #" << w+1 << ": "  


int add(int a, int b) {
	a += b;
	if (a >= MOD) a -= MOD;
	return a;
}

int mul(int a, int b) {
	return a * 1LL * b % MOD;
}

int binpow(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res = mul(res, a);
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}

int main()
{
    int n;
    cin >> n;
    int a=binpow(10,n);
    int b=(binpow(9,n)*1LL*2)%MOD;
    int c=binpow(8,n);
    a=(a*1LL-b)%MOD;
    a=(a*1LL+c)%MOD;
    a=(a*1LL+MOD)%MOD;
    cout << a << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()

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

const ll oo = 1e18;
const ll mod = 998244353,maxn = 3030;
const double PI = acos(-1);


int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll a, b, c, k, ans = 0;
    cin >> a >> b >> c >> k;
    ans += min(a, k);
    k-=a;
    if (k > 0) k-=b;
    if (k > 0) ans -= k;

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

Measured memory_bytes: 3628
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = list(Counter(a).items())
c.sort()
if len(c) > 2:
    print("No")
    exit()
if len(c) == 1:
    if c[0][0] <= n//2 or c[0][0] == n-1:
        print("Yes")
    else:
        print("No")
    exit()
if c[1][0]-c[0][0] != 1:
    print("No")
    exit()
if c[0][1] > c[0][0] or (c[1][0]-c[0][1])*2>c[1][1]:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 21532
//Authore :: Rabbi

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define MOD   1000000007
#define PI  acos(-1)
#define clr(x) memset(x,-1,sizeof(x))
#define End return 0
#define Start ios_base::sync_with_stdio(0);cin.tie(0);
vector<ll>v;

void fun(){
 ll i,j,ans;
 for(i=1; i<=9; i++){
    for(j=i;j<=9;j++){
        ans=i*j;
        v.push_back(ans);
    }
 }
}


int main()
{
 Start;
fun();
 ll a,b,c,i,ok=0;
  cin>>a;
  sort(v.begin(),v.end());
  for(i=0;i<v.size();i++){
    if(v[i]==a){ok=1;cout<<"Yes"<<endl;return 0;}
  }
  if(ok==0)cout<<"No"<<endl;

 End;
}




Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
/*                   وتزودوا فإن خير الزاد التقوى                    */
/*       وما تدري نفس ماذا تکسب غدا وما تدري نفس باي ارض تموت      */
#include <bits/stdc++.h>
#include<unordered_map>
#include<iomanip>
#include<fstream>
using namespace std;
#include<iostream>
#define endl '\n'
#define ll long long
#define ull unsigned long long
#define dll double
#define PI acos(-1)
#define watch(x) cout<<#x<<" = { "<<x<<" }\n"
#define sz(n) n.size()
#define M_Sayed fast() 
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define RT(v) return cout<<v,0
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
const double EPS = (1e-7);
ll Ceil(ll x, ll y) { return (x + y - 1) / y; }
void run() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#else
#endif
}
ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }
ll power(ll x, ll y, ll mod) {
	if (y == 0) return 1;
	if (y == 1) return x % mod;
	ll r = power(x, y >> 1, mod);
	return (((r * r) % mod) * power(x, y & 1, mod)) % mod;
}
void fast() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }
ll n, m, k,su,cnt;
ll vis[100009][5];
struct ch
{
	int a,  b,  c;
};
vector<ch>v;
ll Hap(int x,int par) {
	if (x == n)
		return 0;
	ll &ret = vis[x][par];
	if (~ret)return ret;
	ret = 0;
	if (par != 1)
		ret=max(ret,Hap(x + 1, 1)+v[x].a);
	if (par != 2) 
		ret = max(ret, Hap(x + 1, 2) + v[x].b);
	if (par != 3) 
		ret = max(ret, Hap(x + 1, 3) + v[x].c);
	return ret;
}
int main()
{
	//run();
	M_Sayed;
	cin >> n ;
	memset(vis, -1, sizeof vis);
	v.resize(n);
	for (int i = 0; i <n; i++) {
		cin >> v[i].a>>v[i].b>>v[i].c;
	}
	RT(Hap(0,0));
}

Measured memory_bytes: 13184
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
    int n,ans=0,ca=0,cb=0,score[10000],l,a=0,b=0,c=0;
    char s[10000][11];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%s",s[i]);
        l=strlen(s[i]);
        if(s[i][0]=='B'){
            b++;
        }
        if(s[i][l-1]=='A'){
            a++;
        }
        if(s[i][0]=='B'&&s[i][l-1]=='A'){
            c++;
        }
        for(int j=0;j<l;j++){
            if(s[i][j]=='A'&&s[i][j+1]=='B'){
                ans++;
            }
        }
    }
    if(a==c&&b==c&&c){
        printf("%d\n",ans+c-1);
    }
    else{
        printf("%d\n",ans+min(a,b));
    }
}


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

int abs(int x) {
  if(x >= 0) {
    return x;
  }
  else {
    return -1 * x;
  }
}

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


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

int main()
{
    int a, b;
    cin >> a >> b;
    double ret = 0.0;
    for (int i = 1; i <= a; i++)
    {
        double tmp = 1.0 / a;
        int now = i;
        while (now < b)
        {
            now *= 2.0;
            tmp /= 2.0;
        }
        ret += tmp;
    }
    cout << fixed << setprecision(12) << ret << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int N;
char shop[30], S[112][112];
char sign[112];
bool flag = true;
int ans = 0;

int main(void) {
	scanf("%d", &N);
	scanf("%s", &shop);
	for (int i = 0; i < N; ++i) { scanf("%s", &S[i]); }

	for (int i = 0; i < N; ++i) {
		if (strcmp(shop, S[i]) == 0) {
			ans++;
		}
		else {
			for (int j = 0; j < strlen(S[i]) - strlen(shop); ++j){
				for (int d = 0; strlen(S[i]) >= j + strlen(shop) + (strlen(shop) - 1)*d; ++d) {
					// j == ????§???????
					// d == ??????
					if (flag == true) {
						if (S[i][j] == shop[0]) {
							for (int k = 0; k < strlen(shop); ++k) {
								sign[k] = S[i][j + (d + 1)*k];
								if (sign[k] != shop[k]) {
									break;
								}
							}
						}
						if (strcmp(shop, sign) == 0) { flag = false; }
						for (int i = 0; i < strlen(sign); ++i) { sign[i] = '\0'; }
					}
				}
			}
		}
		if (flag == false) { ans++; flag = true; }
	}

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2716
package main

import "fmt"

func main(){
	var n,have,money,buy,sell int
	fmt.Scan(&n)
	money = 1000
	a := make([]int,n)
	for i:=0 ; i<n ; i++ {
		fmt.Scan(&a[i])
//fmt.Println(sell)
		if i==0 {
			buy = a[i]
			sell = a[i]
		} else if i < n-1{
			if sell <= a[i] {
				sell = a[i]
			} else {
				//売る
//fmt.Println("sell")
				have = int(money/buy)
//fmt.Println(have)
				money -= have*buy
				money += have*sell
				have = 0
				buy = a[i]
				sell = a[i]
			}
		} else {
			if sell > a[i] {
				have = int(money/buy)
				money -= have*buy
				money += have*sell
			} else if buy < a[i] {
				have = int(money/buy)
				money -= have*buy
				money += have*a[i]
			}
		}
	}
	fmt.Println(money)
}


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

using namespace std;

int main()
{
    int n;
    vector<int> p;

    cin >> n;

    p.resize(n);

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

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

    cout << count << endl;
}

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

public class Main {

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

	Scanner sc = new Scanner(System.in);

	void run() {
		for(;;){
			int n = sc.nextInt();
			int m = sc.nextInt();
			int t = sc.nextInt();
			int p = sc.nextInt();
			
			if((n|m|t|p) == 0){
				break;
			}
			
			int d[] = new int[t];
			int c[] = new int[t];
			for(int i =0 ; i < t; i++){
				d[i] = sc.nextInt();
				c[i] = sc.nextInt();
			}
			
			int x[] = new int[p];
			int y[] = new int[p];
			for(int i = 0; i < p; i++){
				x[i] = sc.nextInt();
				y[i] = sc.nextInt();
			}
			
			int left = 0;
			int buttom = 0;
			
			int[] depth1 = new int[n*100];
			int[] depth2 = new int[m*100];
			for(int i = 0; i< n;i++){
				depth1[i] = 1;
			}
			for(int i = 0; i< m;i++){
				depth2[i] = 1;
			}
			
			for(int i = 0 ; i < t; i++){
				if(d[i] == 1){
					left += c[i];
//					System.out.println("-----"+c[i]+" "+d[i]);
					for(int j = 0 ; j < c[i];j++){
//						System.out.println((left-j-1)+" "+(left+j));
						depth1[left+j] += depth1[left - j - 1];
						depth1[left - j - 1] = 0;
					}
				}else{
					buttom += c[i];
					for(int j = 0 ; j < c[i];j++){
						depth2[buttom+j] += depth2[buttom - j - 1];
						depth2[buttom - j - 1] = 0;
					}
				}
			}
			
//			System.out.println(Arrays.toString(depth1));
//			System.out.println(Arrays.toString(depth2));
			for(int i = 0 ; i < p ;i++){
				int xx = x[i]+left;
				int yy = y[i]+buttom;
				
				System.out.println(depth1[xx] * depth2[yy]);
			}
		}
		
	}
}



Measured memory_bytes: 43904
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter

n = int(readline())
a = tuple(map(int, readline().split()))
memo = tuple(Counter(a).items())
ans = 0
for x, y in memo:
    if x <= y:
        ans += y - x
    else:
        ans += y
print(ans)


Measured memory_bytes: 20880
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define int long long
using namespace std;

const int P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  if(N<=1999&&N>=N/100*100&&N<=N/100*105)
  {
    cout << 1 << endl;
  }
  else if(N>=2000)
  {
    cout << 1 << endl;
  }
  else
  {
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import sys
from heapq import *
input = sys.stdin.readline


def main():
    n, m, s = map(int, input().split())
    
    s = min(s, 2500)
    
    railway = [[] for _ in range(n)]
    for i in range(m):
        u, v, a, b = map(int, input().split())
        railway[u-1].append((v-1, a, b))
        railway[v-1].append((u-1, a, b))
    
    exchange = [None]*n
    for i in range(n):
        exchange[i] = tuple(map(int, input().split()))
    
    
    judge = [(0, 0, s)]
    heapify(judge)
    time = [[-1]*2501 for _ in range(n+1)]*n
    
    while judge:
        t, now, money = heappop(judge)
        if time[now][money] == -1:
            time[now][money] = t
        elif time[now][money] <= t:
            continue
        else:
            time[now][money] = min(time[now][money], t)
        
        if money < 2500:
            c, d = exchange[now]
            if time[now][min(2500, money+c)] == -1:
                heappush(judge, (t+d, now, min(2500, money+c)))
        for (v, a, b) in railway[now]:
            if money-a < 0:
                continue
            if time[v][money-a] == -1:
                heappush(judge, (t+b, v, money-a))
    
    for i in range(1, n):
        print(min(time[i]))
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 113820
#include <cstdio>

int main(){
	char s[100005];
	int ans=0, i=0;
	scanf("%s", s);
	while(s[i]){
		if(i & 1){
			if(s[i] == 'g')
				++ans;
		}
		else{
			if(s[i] == 'p')
				--ans;
		}
		++i;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n;
    cin >> n;
    vector<int> arr(n, 0);
    for(int& val: arr)
        cin >> val;
    vector<int> ans;
    while(!arr.empty()) {
        bool found = false;
        for(int i = arr.size()-1; i >= 0; i--) {
            if (arr[i] == i+1) {
                ans.push_back(arr[i]);
                for(int j = i; j < arr.size()-1; j++) {
                    arr[j] = arr[j+1];
                }
                arr.pop_back();
                found = true;
                break;
            }
        }
        if (!found && !arr.empty()) {
            cout << -1 << endl;
            return 0;
        }
    }
    reverse(ans.begin(), ans.end());
    for(int val: ans)
        cout << val << endl;
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a[51]={};
  int st[51]={};
  int n,r;
  int p,c;
  while(1){
    //in
    cin >> n >> r;
    if(n==0&&r==0)break;
    for(int i=0;i<n;i++){
      a[i]=n-i;
    }
    for(int i=0;i<r;i++){
      cin >> p >>c; 
      for(int j=0;j<n;j++){
	st[j]=a[j];
      }
      for(int j=0;j<c;j++){
	a[j]=st[p+j-1];
      }
      for(int j=0;j<p-1;j++){
	a[j+c]=st[j];
      }
    }
    cout << a[0] << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define INF (1<<30)
#define LINF (1ll<<60ll)
#define MOD 1000000007
#define pb(a) push_back(a)
#define _overload4(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload4(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)
#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))
#define d(a) cerr<<#a<<":"<<a<<endl
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl

inline int s(int a){
    return a*(a+1)/2;
}

inline int startpos(int all,int a){
    return s(all)-s(all-a);
}

int main(){
    int n;
    cin>>n;
    if(n==1){
        Yes(1);
        cout<<2<<endl<<"1 1"<<endl<<"1 1"<<endl;
        return 0;
    }
    int x=0,k=0;
    while(x<n){
        x+=++k;
        if(x>n){
            Yes(0);
            return 0;
        }
    }
    Yes(1);
    // 対角線を組む的な?
    cout<<k+1<<endl; // k(集合の個数)
    REP(i,k+1){
        cout<<k<<" ";
        REP(j,i){
            cout<<startpos(k,j)+(i-j)<<" ";
        }
        //cout<<"|";
        int st=startpos(k,i);
        //d(startpos(k,i));
        REP(j,(k-i)){
            cout<<st+j+1<<" ";
        }
        cout<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 1408
var s:string;a,i:longint;f:boolean;
begin
	readln(s);
	a:=(length(s)-1)div 2;
	while true do begin
		f:=true;
		for i:=1 to a do begin
			if s[i]<>s[a+i] then begin
				f:=false;
				break;
			end;
		end;
		if f then begin
			writeln(a*2);
			exit;
		end;
		dec(a);
	end;
end.


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

int main()
{
    int a, b,ans;
    char op;
    cin >> a >> op >> b;
    if(op=='+'){
        ans = a + b;
    }else{
        ans = a - b;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
def main():
    S = list(map(int,list(input())))

    count_0 = 0
    count_1 = 0
    for val in S:
        if val == 0:
            count_0 += 1
        else:
            count_1 += 1
    print(min(count_0, count_1)*2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 49392
#include <stdio.h>
#include <string.h>
int main(void){
  int w,a,b,dis;
  scanf("%d %d %d",&w,&a,&b);
  if(a+w<=b) dis=b-(a+w);
  else dis=a-(b+w);
  if(dis<0) puts("0");
  else printf("%d\n",dis);
  return 0;
}

Measured memory_bytes: 128
open System
open System.Collections.Generic
open System.Linq
open System

// Following contents are my library. The Main processes are on the bottom of this code.

let puts = Console.WriteLine : 'a -> unit
let put = Console.Write : 'a -> unit
let Read() = Console.ReadLine()
let Reads () = Console.ReadLine().Split()
let ReadInt () = Read() |> int
let ReadDouble () = Reads() |> (fun x -> x.[0], x.[1])
let ReadTriple () = Reads() |> (fun x -> x.[0], x.[1], x.[2])
let ReadQuadruple () = Reads() |> (fun x -> x.[0], x.[1], x.[2], x.[3])
let FuncDouble f1 f2 (t1, t2) = (f1 t1, f2 t2)
let FuncTriple f1 f2 f3 (t1, t2, t3) = (f1 t1, f2 t2, f3 t3)
let FuncQuadruple f1 f2 f3 f4 (t1, t2, t3, t4) = (f1 t1, f2 t2, f3 t3, f4 t4)

let ReadIntQuadruple () = ReadQuadruple() |> FuncQuadruple int int int int
let ReadIntTriple () = ReadTriple () |> FuncTriple int int int
let ReadIntDouble () = ReadDouble () |> FuncDouble int int
let ensmallen l = l % 1000000007L
let manhattan x y = abs (fst x - fst y) + abs (snd x - snd y)
let sayYESNO b = if b then puts "YES" else puts "NO"


// The main contents of this submission are below this line.

Read()
    |> Seq.mapi (fun i c -> i, c)
    |> Seq.filter (fun (i, _) -> i % 2 = 0)
    |> Seq.map snd
    |> String.Concat
    |> puts


Measured memory_bytes: 16212
#include<cstdio>
#include<cstring>

char s[111111];
int len, seg, ans;
char pre, suf;

int main() {
	scanf("%s", s);
	len = strlen(s);
	
	pre = s[0]; suf = s[len-1]; 
	seg = 0;
	for(int i=1;i<len;i++)
		if(s[i] != s[i-1]) seg ++;
	printf("%d\n", seg);
	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const ll MOD=10000007;
int main(){
int a,b;cin >> a >> b;a--;b--;
vector<bool> ok(3);
ok[a]=true;
ok[b]=true;
rep(i,3){
    if(!ok[i]){
        cout << i+1 << endl;
        break;
    }
}
}

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

using namespace std;

int main(void)
{
	int  s, n, k;

	cin >> n >> k;

	double p = 0.0;

	if (n >= k) {
		p += double(n - k + 1) / ((double)n);
	}

	for (int i = 1; i < k && i <= n; i++)
	{
		p += 1 / ((double)n) * exp2(-ceil(log2((double)k / (double)i)));
	}
	printf("%.9lf\n", p);
	return 0;
}

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

int main()
{
    int n; cin >> n;
    vector<long long> a(n);
    rep(i,n) cin >> a.at(i);

    int ans = 30, tmp;

    arep(x, a) {
        tmp = 0;
        while(x%2 == 0) {
            x /= 2;
            tmp++;
        }
        ans = min(ans, tmp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define show(x) cout<<#x<<"="<<x<<"\n"
using namespace std;

int n,q;

struct SegmentTree{
 int size;
 vector<int> data;
 const int inf=(1LL<<31)-1;
 SegmentTree(int n){
  size=1;
  while(size<n){
   size<<=1;
  }
  data.resize(2*size-1,0);
 }
 void update(int k,int x){
  k+=size-1;
  data[k]+=x;
  while(k>0){
   k=(k-1)/2;
   data[k]=data[k*2+1]+data[k*2+2];
  }
 }
 int query(int a,int b,int k,int l,int r){
  if(r<=a || b<=l)return 0;
  if(a<=l && r<=b)return data[k];
  return query(a,b,k*2+1,l,(r+l)/2)+query(a,b,k*2+2,(r+l)/2,r);
 }
 int query(int a,int b){
  return query(a,b,0,0,size);
 }
};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
 cin>>n>>q;
 SegmentTree rsq(n);
 for(int i=0;i<q;i++){
  int a,b,c;cin>>a>>b>>c;
  if(a){
   cout<<rsq.query(b-1,c)<<"\n";
  }else{
   rsq.update(b-1,c);
  }
 }
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

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

using namespace std;

#define debug(x) cout << #x << "==" << x << endl;

const int inf = 100000000;

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  // dp[i][x] := 0;
  // dp[i][x] := dp[i-1][]

  int pos = 0;
  int i = 0;
  while(pos < N) {
    pos += i;
    i++;
  }
  i--;
  cout << i;

  return 0;
}


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

int calcMP(int A, int B, int C, int sa, int sb, int sc, int ta, int tb, int tc) {    
    if(sa == 0 || sb == 0 || sc == 0) return -1;

    int mp_a = (sa - 1) * 10 + abs(A-ta);
    int mp_b = (sb - 1) * 10 + abs(B-tb);
    int mp_c = (sc - 1) * 10 + abs(C-tc);

    return mp_a + mp_b + mp_c;
}

int main() {
    int N, A, B, C;
    int sa, sb, sc;
    int ta, tb, tc;

    cin >> N >> A >> B >> C;
    vector<int> l(N);
    for(int i = 0; i < N; i++) {
        cin >> l[i];
    }

    int minMP = 99999999;
    for(int i = 0; i < pow(4, N); i++) {
        sa = sb = sc = 0;
        ta = tb = tc = 0;

        for(int j = 0; j < N; j++) {
            int kind = (i>>(2*j)) % 4;
            switch(kind) {
            case 1:
                sa++;
                ta += l[j];
                break;
            case 2:
                sb++;
                tb += l[j];
                break;
            case 3:
                sc++;
                tc += l[j];
                break;
            default:
                break;
            }
        } 
        int mp = calcMP(A, B, C, sa, sb, sc, ta, tb, tc);
        if(mp < 0) continue;
        minMP = min(minMP, mp);
    }

    cout << minMP << endl;   
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <utility>
using namespace std;

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

bool fill(int idx, vector<vector<pair<int,int> > > &adj, vector<int> &alloc){
    for(int i=0; i<(int)adj[idx].size(); i++){
        int nidx = adj[idx][i].first;
        int change = adj[idx][i].second;
        if(alloc[nidx]!=-1){
            if((alloc[nidx]+alloc[idx])%2 != change) return false;
        }else{
            alloc[nidx] = (alloc[idx]+change)%2;
            if(!fill(nidx, adj, alloc)) return false;;
        }
    }
    return true;
}

bool check(vector<vector<pair<int,int> > > &adj){
    int n = adj.size();
    vector<int> alloc(n, -1);
    for(int i=0; i<n; i++){
        if(alloc[i] == -1){
            alloc[i]=0;
            if(!fill(i, adj, alloc)){
                return false;
            }
        }
    }
    return true;
}

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;

        map<pair<int,int>, int> coord;
        for(int i=0; i<n; i++){
            int x,y;
            char c;
            cin >> x >> y >> c;
            coord[make_pair(x,y)] = 2*i;
            if(c=='x') x++;
            else y++;
            coord[make_pair(x,y)] = 2*i+1;
        }
        
        vector<vector<pair<int,int> > > adj(2*n);
        for(int i=0; i<2*n; i+=2){
            adj[i].push_back(make_pair(i+1, 1));
            adj[i+1].push_back(make_pair(i, 1));
        }

        for(map<pair<int,int>, int>::iterator itr=coord.begin(); itr!=coord.end(); itr++){
            int x = itr->first.first, y = itr->first.second;
            int idx = itr->second;
            int p = (idx%2==0)? 1: -1;
            for(int i=0; i<4; i++){
                pair<int, int> key(x+dx[i], y+dy[i]);
                if(coord.count(key)!=0 && coord[key]!=idx+p){
                    adj[idx].push_back(make_pair(coord[key], 0));
                }
            }
        }
        
        if(check(adj)){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

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

int main(){
	int N,M;
	cin >> N >> M;
	vector<long long> A(N);
	for(auto &i:A)cin >> i;
	long long sum=accumulate(A.begin(),A.end(),0LL);
	
	priority_queue<long long> que;
	for(auto i:A)que.push(i);
	
	for(int i=0;i<M;i++){
		sum-=que.top();
		sum+=que.top()/2;
		que.push(que.top()/2);
		que.pop();
	}
	cout << sum << endl;
	return 0;
}

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

d = [0] * N
flg = [0] * N
for i in range(M):
    s,c = map(int, input().split())
    s -= 1
    if N != 1 and s == 0 and c == 0:
        print("-1")
        exit()

    if flg[s] == 1 and d[s] != c:
        print("-1")
        exit()
    d[s] = c
    flg[s] = 1

if N >= 2:
    if d[0] == 0:
        d[0] = 1
              
str_d = []
for i in range(N):
    str_d.append(str(d[i]))

print(''.join(str_d))

Measured memory_bytes: 38384
n=int(input())
h=[int(i) for i in input().split(' ')]


dp=[0]*(n)
dp[1]=abs(h[1]-h[0])

for i in range(2,n):
    t1=dp[i-2]+abs(h[i]-h[i-2])
    t2=dp[i-1]+abs(h[i]-h[i-1])
    dp[i]=min(t1,t2)

    
print(dp[n-1])
    
    

Measured memory_bytes: 20548
#include<iostream>

using namespace std;

int main(){
	int height;
	int high[3] = {0, 0, 0};
	for(int i=0;i<10;++i){
		cin >> height;
		if(height > high[0]){
			high[2] = high[1];
			high[1] = high[0];
			high[0] = height;
		}
		else if(height > high[1]){
			high[2] = high[1];
			high[1] = height;
		}
		else if(height > high[2]){
			high[2] = height;
		}
	}
	for(int i=0;i<3;++i){
		cout << high[i] << endl;
	}
	return 0;
}

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
	IOS;
	int n;
	cin >> n;
	vector<ll> a(n),s(n+1,0);
	
	REP(i, n) {
		cin >> a[i];
		s[i + 1] = s[i] + a[i];
	}

	ll res = LLONG_MAX;
	REP(i, n) {
		ll t1 = s[i+1];
		ll t2 = s.back() - t1;
		chmin(res, abs(t1 - t2));
	}
	put(res);
	return 0;
}


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

int main()
{
	string S;
	cin >> S;
	int counter = 700;
	if (S[0] == 'o') counter += 100;
	if (S[1] == 'o') counter += 100;
	if (S[2] == 'o') counter += 100;
	cout << counter << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define scl(n) scanf("%lld", &n)
#define ull unsigned long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define uu first
#define vv second
#define MOD 1000000007
#define inf 1000000001
#define limit 10001000

int dp[100005];
int ar[100005];

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    ios_base::sync_with_stdio(0);

    int i, n, x;

    while(scanf("%d", &n)==1)
    {
        for(i=1; i<=n; i++)
        {
            scanf("%d", &ar[i]);
            dp[i]=inf;
        }

        dp[1]=0;

        for(i=1; i<=n; i++)
        {
            x=inf;

            if(i+1<=n)
            {
                x=abs(ar[i+1]-ar[i])+dp[i];

                dp[i+1]=min(dp[i+1], x);
            }

            if(i+2<=n)
            {
                x=abs(ar[i+2]-ar[i])+dp[i];

                dp[i+2]=min(dp[i+2], x);
            }
        }

        printf("%d\n", dp[n]);
    }

    return 0;
}





Measured memory_bytes: 1024
def args():
    N, W = tuple(map(int, input().split()))

    Wi, Vi = [], []
    for _ in range(N):
        w, v = tuple(map(int, input().split()))
        Wi.append(w)
        Vi.append(v)

    # print(N, W)
    # print(Wi, Vi)

    return N, W, Wi, Vi


def solve(N, W, Wi, Vi):
    DP = [[float("inf")] * (sum(Vi) + 1) for _ in range(N + 1)]

    DP[0][0] = 0

    for i in range(N):
        value = Vi[i]
        w_max = sum(Vi) + 1
        for v in range(w_max):
            remain = v - value
            if 0 <= remain:
                # 選ぶ
                DP[i + 1][v] = min(DP[i + 1][v], DP[i][remain] + Wi[i])
            # 選ばない
            DP[i + 1][v] = min(DP[i + 1][v], DP[i][v])

    # print(DP)
    ans = 0
    for line in DP:
        for v, e in enumerate(line):
            if not e == float("inf") and e <= W:
                # print(v, e)
                ans = max(ans, v)

    # print(DP)

    return ans


if __name__ == '__main__':
    res = solve(*args())
    print(res)


Measured memory_bytes: 309720
#include <bits/stdc++.h> 
using namespace std; 
#define for_(i, s, e) for (int i = s; i < e; i++)
#define for__(i, s, e) for (ull i = s; i < e; i++)
#define SSTR(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x)).str()
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;

vector<vi> fAdj, bAdj;
vi comp;
vi compSize;

int dfs(int i, int c) {
    comp[i] = c;
    int s = 1;
    for (int j: fAdj[i]) {
        if (comp[j] == -1) s += dfs(j, c);
    }
    return s;
}

int main() {
    #ifndef ONLINE_JUDGE
	// freopen("test.in", "r", stdin);
    #endif
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m, k; cin >> n >> m >> k;
    fAdj.resize(n);
    bAdj.resize(n);
    comp.resize(n, -1);

    for_(i, 0, m) {
        int a, b; cin >> a >> b;
        a -= 1; b -= 1;
        fAdj[a].push_back(b);
        fAdj[b].push_back(a);
    }

    for_(i, 0, n) {
        if (comp[i] == -1) {
            // cout << "for " << i << endl;
            int s = dfs(i, compSize.size());
            compSize.push_back(s);
            // cout << s << endl;
        }
    }

    vi red(n);

    for_(i, 0, k) {
        int a, b; cin >> a >> b;
        a -= 1; b -= 1;
        if (comp[a] == comp[b]) {
            red[a] += 1;
            red[b] += 1;
        }
    }

    for_(i, 0, n) cout << compSize[comp[i]] - red[i] - fAdj[i].size() - 1 << ((i == n-1) ? "" : " ");

    return 0;
}

Measured memory_bytes: 10368
#!/usr/bin/perl

my ($n,$m) = map { $_ - 0 } split(/\s+/,<STDIN>);
my @h = map { $_ - 0 } split(/\s+/,<STDIN>);

my @t = ();
$#t = $n - 1;

for(my $i=0;$i<$m;$i++){
  my @ab = map { $_ - 0 } split(/\s+/,<STDIN>);
  $t[$ab[0]-1]->{($ab[1]-1)} = 1;
  $t[$ab[1]-1]->{($ab[0]-1)} = 1;
}

my $r = 0;
for(my $i=0;$i<$n;$i++){
  if( ref($t[$i]) ){
    my $own = $h[$i];
    my $ok = 1;
    foreach my $k (keys %{$t[$i]}){
      if( $h[$k - 0] >= $own ){
        $ok = 0;
        last;
      }
    }
    if( $ok == 1 ){ $r++;}
    
  } else {
    $r ++;
  }
}
print "$r\n";



Measured memory_bytes: 54176
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <cmath>
#include <cstring>

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

using namespace std;
typedef long long ll;

bool match(char c1, char c2) {
    return c1 == '?' || c2 == '?' || c1 == c2;
}

const int OFS = 50000;
bool ab[100000];
bool ac[100000];
bool bc[100000];

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    rep(i, a.size()) rep(j, b.size()) if(!match(a[i], b[j])) ab[i-j+OFS] = true;
    rep(i, a.size()) rep(j, c.size()) if(!match(a[i], c[j])) ac[i-j+OFS] = true;
    rep(i, b.size()) rep(j, c.size()) if(!match(b[i], c[j])) bc[i-j+OFS] = true;
    int ans = 6000;
    for (int i = -4000; i <= 4000; i ++) {
        for (int j = -4000; j <= 4000; j ++) {
            if (!ab[i+OFS] && !ac[j+OFS] && !bc[j-i+OFS]) {
                int L = min(0, min(i, j));
                int R = max((int)a.size(), max(i + (int)b.size(), j + (int)c.size()));
                ans = min(ans, R - L);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
//void _(){
//    ll k;
//    cin >> k;
//    ll fills = (k+49)/50;
//    vl arr(50,fills+49);
//    k = fills*50-k;
//    ll extra = 0;
//    rep(i,0,49){
//        if(i < k){
//            arr[i] -= 50;
//            ++extra;
//        }
//    }
//    rep(i,0,k-1)
//        arr[i] += extra-1;
//    rep(i,k,49)
//        arr[i] += extra;
//    print(50);
//    print(arr);
//}
#include <iomanip>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define REP_INT(i,l,r) for(int i = l; i <= r; ++i)
#define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT)(__VA_ARGS__)
#define all(v) (v).begin(), (v).end()
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
T1 void print(T x, string end = "\n"){
    cout << x << end;
}
T1 ostream& print(T b, T e, string sep = " ", ostream& stream = cout){
    for(T it = b; it != e; ++it){
        stream << *it;
        if(it + 1 != e)
            stream << sep;
    }
    return stream;
}
T1 void print(vector<T> arr, string sep = " "){
    if(arr.empty()){
        return;
    }
    print(arr.begin(), arr.end(), sep);
    cout << '\n';
}
void _(){
    ll k;
    cin >> k;
    ll fills = (k+49)/50;
    vl arr(50,fills+49);
    k = fills*50-k;
    ll extra = 0;
    rep(i,0,49){
        if(i < k){
            arr[i] -= 50;
            ++extra;
        }
    }
    rep(i,0,k-1)
        arr[i] += extra-1;
    rep(i,k,49)
        arr[i] += extra;
    print(50);
    print(arr);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        _();
}


Measured memory_bytes: 256