akhauriyash/Code-Regression huggingface dataset:
N = int(input())
w = list(map(int,input().split()))
sum_w = sum(w)
ans = sum_w
T = 0
for i in range(N):
  if abs(sum(w[:i+1])-sum(w[i+1:]))<ans:
    ans = abs(sum(w[:i+1])-sum(w[i+1:]))
print(ans)

Measured memory_bytes: 3064
function stoneRemove(){
   yx.forEach(function(v,i){
      var str=v.join("").replace(/([1-9])\1{2,}/,function(x){
         point+=(x[0]-0)*x.length;
         return x.replace(/./g,"0");
      });
      yx[i]=str.split("").map(Number);
   });
   var flag=true;
   while(flag){
      flag=false;
      for(var i=0;i<H-1;i++){
         for(var j=0;j<5;j++){
            if(yx[i][j]!=0 && yx[i+1][j]==0){
               yx[i+1][j]=yx[i][j];
               yx[i][j]=0;
               flag=true;
            }
         }
      }
   }
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=(input.trim()).split("\n");
while(true){
   var h=arr.shift()-0;
   if(h==0)break;
   var H=h;
   var yx=[];
   while(h--)yx.push(arr.shift().split(" ").map(Number));
   var point=0;
   var p=point;
   while(true){
      stoneRemove();
      if(p==point)break;
      p=point;
   }
   console.log(point);
}

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

#define int long long
#define uint unsigned long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end());
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct Setup {
    static constexpr int PREC = 20;
    Setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N, M;
int s[440000], t[440000];
vint G[660], rev[660];
double prob[660], expect[660], nextsum[660];
signed main() {
    cin >> N >> M;
    rep(i, M) {
        cin >> s[i] >> t[i];
        G[s[i]].push_back(t[i]);
        rev[t[i]].push_back(s[i]);
    }
    prob[1] = 1;
    for (int i = 2; i <= N; i++) {
        rep(j, rev[i].size()) { prob[i] += prob[rev[i][j]] / G[rev[i][j]].size(); }
    }
    expect[N] = 0;
    for (int i = N - 1; i >= 1; i--) {
        rep(j, G[i].size()) { nextsum[i] += expect[G[i][j]]; }
        expect[i] = 1 + nextsum[i] / G[i].size();
    }
    double diff = 0;
    rep(i, M) {
        if (G[s[i]].size()) {
            chmax(diff, prob[s[i]] * (expect[s[i]] - (nextsum[s[i]] - expect[t[i]]) / (G[s[i]].size() - 1) - 1));
        }
    }
    cout << expect[1] - diff << endl;
}

Measured memory_bytes: 10368
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int a,b;
  cin>>a>>b;
  if(a<=0 && 0<=b){
    cout<<"Zero";
  }else if(b<0 && (b-a)%2==0){
    cout<<"Negative";
  }else{
    cout<<"Positive";
  }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int L = int.Parse(s[0]);
            int R = int.Parse(s[1]);

            if ( L / 2019 != R / 2019)
            {
                Console.WriteLine(0);
                return;
            }

            L %= 2019;
            R %= 2019;

            int ans = int.MaxValue;

            for (int l = L; l <= R; l++)
            {
                for(int r = l + 1; r <= R; r++ )
                {
                    ans = Math.Min(ans, (l * r) % 2019);
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
	using namespace std;
	typedef long long ll;
	#define endl "\n"
	#define space " "
	#define ll long long int
	#define vl vector<ll>
	#define vvl vector < vll >
	#define pii pair<int,int>
	#define pll pair<ll,ll>
	#define vpl vector < pll >
	#define mod 1000000007
	#define pi 3.1415926535897932384626433
	#define inf 1000000000000000001;
	#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y) 
	#define mem(a,val) memset(a,val,sizeof(a))
	#define pb push_back
	#define f first
	#define s second
	
	void solve()
	{
		ll a; float b;
		cin>>a>>b;
		int c = b*100+0.001;
		ll p=(a*c)/100;
		cout<<p;
	}

	signed main()
	{

	fast;
	#ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
     #endif

	ll T=1;
	// cin>>T;
	while(T--)
	{
		solve();
	}
	return 0;
	}


Measured memory_bytes: 3724
#include <iostream>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
using Graph = vector<vector<int>>;
using Graph_Wei = vector<vector<pair<int,int>>>;
using ll = long long;

//長さを記録する
Graph_Wei graph_wei;
// 二部グラフ判定
vector<int> color;
void dfs(const Graph_Wei &G, int v, int w,int cur = 0) {

    for (auto next_v : G[v]) {
        //訪問ずみならスルー
        if(color[next_v.first] != -1) continue;
        //first:頂点番号　second:長さ
        w += next_v.second;

        //距離が偶数の時、同色
        if(w % 2 == 0){
            color[next_v.first] = cur;
        }else{
            color[next_v.first] = 1 - cur;
        }
        
        dfs(G, next_v.first, w);
          
    }  
}

int main() {
    //初期化
    int a[50] = {0};
    
    int n;
    cin >> n ;
    for(int i =0;i < n;i++) cin >> a[i];
    int ans =0;
    for(int i = 0;i < n;i++){
        //1個ずつ取り出して自分以外のものと足していく
        
        for(int j = i + 1;j < n;j++){
            
            //自分同士以外なら加算
            ans += a[i] * a[j];
            
        }
    }
    cout << ans << endl;


    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
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;}
const int inf = 1001001001;

int main() {
    string s,t;
    cin >> s >> t;
    map<char,vector<ll>> m;
    rep(i,s.size()) m[s[i]].pb(i);
    ll ans = 0;
    rep(i,t.size()) {
        char c = t[i];
        if(m[c].size() == 0) {
            cout << -1 << endl;
            return 0;
        }
        auto it = lower_bound(all(m[c]),ans%s.size());
        if(it == m[c].end()) {
            ans += s.size();
            ans -= ans%s.size()-(m[c][0]+1);
        } else {
            ans += *it-(ans%s.size()-1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1728
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e5)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N , X;
    cin >> N >> X;
    vector<ll> L(N);
    rep(i, N) cin >> L[i];
    ll sum = 0;

    ll cnt = 1;
    rep(i, N) {
        sum += L[i];
        if (sum <= X) cnt++;
    }
    print(cnt);
    return 0;
}

Measured memory_bytes: 256
a,b = map(int,input().split())
if a < b:
  a_str = str(a)
  ans = ""
  for i in range(b):
    ans += a_str
  print(ans)
else:
  b_str = str(b)
  ans = ""
  for i in range(a):
    ans += b_str
  print(ans)

Measured memory_bytes: 3060
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
d.sort()
t.sort()
i=0
j=0
stat=''
while i < n and j < m:
  if d[i]==t[j]:
    i+=1
    j+=1
  elif d[i]>t[j]:
    print('NO')
    exit()
  elif d[i]<t[j]:
    i+=1
print('YES' if j==m else 'NO')



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

const ll INF = 1e18;
const int MX = 2005;

int main() {
  string s,a,b,S,A,B;
  cin >> s;
  int n = s.size();
  rep(i,(n-1)/2){
    a.push_back(s[i]);
  }
  rep(i,(n-1)/2){
    b.push_back(s[i + (n+1)/2]);
  }
  A = a;B = b;S = s;
  reverse(s.begin(),s.end());
  reverse(a.begin(),a.end());
  reverse(b.begin(),b.end());
  if(a == A && b == B && s == S){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n=int(input())

def dfs(s):
  if s!="" and int(s)>n:
    return 0
  
  if len(set(list(s)))<3:
    ret=0
  else:
    ret=1
  
  for i in "753":
    ret+=dfs(s+i)
  
  return ret

print(dfs(""))

Measured memory_bytes: 9176
#include<stdio.h>

int main(void){
    int n, b, f, r, v;
    int bg[4][3][10];
    for(int i=0; i<4; i++) for(int l=0; l<3; l++) for(int m=0; m<10; m++) bg[i][l][m] = 0;
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d%d%d%d", &b, &f, &r, &v);
        bg[b-1][f-1][r-1] += v;
    }
    for(int i=0; i<4; i++){
        for(int l=0; l<3; l++){
            for(int m=0; m<10; m++){
                printf(" %d", bg[i][l][m]);
            }
            printf("\n");
        }
        if(i==3) break;
        printf("####################\n");
    }
    return 0;
}


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

const int N=5010,M=210;
typedef long long ll;
ll ans,sum[N];
int a[N],b[M][N],q[M][N],top[M],n,m;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=2;i<=n;++i)cin>>a[i];
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)cin>>b[j][i],sum[i]+=b[j][i];
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			int la=0;
			for(;top[j]&&b[j][q[j][top[j]]]<b[j][i];--top[j]){
				sum[q[j][top[j]]]-=b[j][q[j][top[j]]]-la;la=b[j][q[j][top[j]]];
			}
			if(top[j]){sum[q[j][top[j]]]-=b[j][i]-la;}
			q[j][++top[j]]=i;
		}
		ll res=sum[i];
		for(int j=i;j;--j){
			ans=max(ans,res);
			res+=sum[j-1]-a[j];
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 6912
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int n, T; cin >> n >> T;
    int ret = INT_MAX;
    while(n--)
    {
        int c, t; cin >> c >> t;
        if(t > T) continue;
        ret = min(ret, c);
    }
    if(ret == INT_MAX) cout << "TLE";
    else cout << ret;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<(n);++i)
#define int long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define call(a) for(auto t:a)cout<<t<<" ";cout<<endl
#define ENDL printf("\n");
#define debg(a) cout<<#a<<":"<<a<<endl;
#define SORT(a) sort(all(a));
#define out(i) cout<<i<<endl;
#define m_p make_pair
#define m_t make_tuple
#define Vec vector
typedef long long ll;
typedef string str;
typedef vector<int> V;
typedef vector<pair<int,int>> VP;
typedef pair<int,int> P;
int min(int a,int b){if(a>b)return b;return a;}
int max(int a,int b){if(a>b)return a;return b;}
int gcd(int a,int b){if(b==0)return a; return gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
const ll INF=1ll<<60;
const ll MOD=1e9+7;

int dp[110][4][4][4];
const int A=0,G=1,C=2,T=3;
signed main(){
  int n;
  cin>>n;
  rep(i,4){
    rep(j,4){
      rep(k,4){
        if(i==A&&j==G&&k==C)continue; //AGC
        if(i==G&&j==A&&k==C)continue; //GAC
        if(i==A&&j==C&&k==G)continue; //ACG
        dp[3][i][j][k]=1;
      }
    }
  }
  for(int i=4;i<=n;++i){
    rep(c3,4){
      rep(c2,4){
        rep(c1,4){
          rep(c0,4){
            if(c3==A&&c2==G&&c1==C)continue; //AGC?
            if(c2==A&&c1==G&&c0==C)continue; //?AGC
            if(c3==G&&c2==A&&c1==C)continue; //GAC?
            if(c2==G&&c1==A&&c0==C)continue; //?GAC
            if(c3==A&&c2==C&&c1==G)continue; //ACG?
            if(c2==A&&c1==C&&c0==G)continue; //?ACG
            if(c3==A&&c1==G&&c0==C)continue; //A?GC
            if(c3==A&&c2==G&&c0==C)continue; //AG?C
            dp[i][c2][c1][c0]+=dp[i-1][c3][c2][c1];
            dp[i][c2][c1][c0]%=MOD;
          }
        }
      }
    }
  }
  int ans=0;
  rep(i,4){
    rep(j,4){
      rep(k,4){
        ans+=dp[n][i][j][k];
        ans%=MOD;
      }
    }
  }
  out(ans);

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n;
	string l[50];
	double ans[50];
	int a[9];
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<n;i++){
		cin>>l[i];
		for(int j=0;j<9;j++)
			cin>>a[j];
		ans[i]=a[6]*a[7]*a[8]-a[0];
		ans[i]/=a[1]+a[2]+a[3]+(a[4]+a[5])*a[8];
	}
	for(int i=0;i<n-1;i++){
		for(int j=n-1;j>i;j--){
			if(ans[j]>ans[j-1]){
				double tmp=ans[j];
				ans[j]=ans[j-1];
				ans[j-1]=tmp;
				string smp=l[j];
				l[j]=l[j-1];
				l[j-1]=smp;
			}
			if(ans[j]==ans[j-1]){
				bool t=true;
				int i=0;
				while(true){
					if(i==l[j].size()&&i!=l[j-1].size()){
						t=false;
						break;
					}
					if(i==l[j-1].size()&&i!=l[j].size())
						break;
					if(l[j][i]<l[j-1][i]){
						t=false;
						break;
					}
					if(l[j][i]>l[j-1][i])
						break;
					i++;
				}
				if(t==false){
					double tmp=ans[j];
				    ans[j]=ans[j-1];
				    ans[j-1]=tmp;
				    string smp=l[j];
				    l[j]=l[j-1];
				    l[j-1]=smp;
				}
			}
		}
	}
	for(int i=0;i<n;i++)
		cout<<l[i]<<endl;
	cout<<"#"<<endl;
	}
	return 0;
}

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

struct Data{
  
  string name;
  int reply;
  int depth;
  
};

vector<Data> v; 
int N;

void print_dot(int n){
  for(int i=0 ; i < n ; i++)cout <<".";
}

void out(int n){
  
  print_dot(v[n].depth);
  cout <<v[n].name<<endl;
  
  for(int i=1 ; i <= v.size() ; i++){
    if(v[i].reply ==  n){
      out(i);
    }
  }
  
}

int main(){
  
  cin >>N;
  
  v.push_back((Data){"null",-1,-1});
  
  int k;
  string str;
  
  cin >>k;
  cin >>str;
  
  v.push_back((Data){str,k,0});
  
  for(int i=0 ; i < N-1 ; i++){
    cin >>k;
    cin >>str;
    v.push_back((Data){str,k,v[k].depth+1});
  }

  /*test*/
  
  //for(int i=0 ; i <= n ; i++){
  // cout <<v[i].name<<" "<<v[i].reply<<" "<<v[i].depth<<endl;
  //}

  out(1);
  
  return 0;
}

Measured memory_bytes: 1364
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

template <typename T>
struct Vec2;

template <typename T>
T SqrMagnitude(const Vec2<T>& v);

template <typename T>
T Magnitude(const Vec2<T>& v);

template <typename T>
T Dot(const Vec2<T>& v1, const Vec2<T>& v2);


template <typename T>
struct Vec2 {
    T x, y;
    Vec2() = default;
    Vec2(T in_x, T in_y)
        : x {in_x}, y {in_y} {};
    Vec2(const Vec2&) = default;
    Vec2(Vec2&&) = default;

    Vec2 normalized() const{
        T mag = Magnitude(*this);
        return {x / mag, y / mag};
    }

    Vec2 normalize() {
        T mag = Magnitude(*this);
        return {x /= mag, y /= mag};
    }

    Vec2 operator-() {
        return {-x, -y};
    }

    Vec2 operator+(const Vec2& rhs) const{
        return {x + rhs.x, y + rhs.y};
    }

    Vec2 operator-(const Vec2& rhs) const{
        return {x - rhs.x, y - rhs.y};
    }

    Vec2 operator*(T rhs) const{
        return {x * rhs, y * rhs};
    }

    Vec2 operator/(T rhs) const{
        return {x / rhs, y / rhs};
    }

    Vec2& operator+=(const Vec2& rhs) {
        x += rhs.x;
        y += rhs.y;
        return *this;
    }

    Vec2& operator-=(const Vec2& rhs) {
        x -= rhs.x;
        y -= rhs.y;
        return *this;
    }

    Vec2& operator*=(T rhs) {
        x *= rhs;
        y *= rhs;
        return *this;
    }

    Vec2& operator/=(T rhs) {
        x /= rhs;
        y /= rhs;
        return *this;
    }
};

template <typename T>
inline Vec2<T> operator*(T s, const Vec2<T>& v) {
    return {s * v.x, s * v.y};
}


template <typename T>
inline T SqrMagnitude(const Vec2<T>& v) {
    return Dot(v, v);
}

template <typename T>
inline T Magnitude(const Vec2<T>& v) {
    return sqrt(SqrMagnitude(v));
}

template <typename T>
inline T Dot(const Vec2<T>& v1, const Vec2<T>& v2) {
    return v1.x * v2.x + v1.y * v2.y;
}

template <typename T>
inline T Cross(const Vec2<T>& v1, const Vec2<T>& v2) {
    return v1.x * v2.y - v1.y *v2.x;
}

int main() {
    Vec2<double> p0, p1, p2, q;


    while(cin >> p0.x >> p0.y >> p1.x >> p1.y >> p2.x >> p2.y >> q.x >> q.y) {
        auto v_qp0 = p0 - q;
        auto v_qp1 = p1 - q;
        auto v_qp2 = p2 - q;

        double c0 = Cross(v_qp0, v_qp1);
        double c1 = Cross(v_qp1, v_qp2);
        double c2 = Cross(v_qp2, v_qp0);

        cout << ((c0 > 0 && c1 > 0 && c2 > 0) || (c0 < 0 && c1 < 0 && c2 < 0) ? "YES" : "NO") << endl;
    }
        
        
    

    return 0;
}

Measured memory_bytes: 3044
#include <bits/stdc++.h>
#define int long long

using namespace std;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n,m;
    cin>>n>>m;

    int s[10]={0,2,5,5,4,5,6,3,7,6};
    int a[m+1];
    for (int i = 1; i <=m ; ++i) {
        cin>>a[i];
    }

    string dp[11000];
    fill_n(dp,11000,"");

    for (int j = 1; j <=m ; ++j) {
        int len1=dp[s[a[j]]].length();
        int len2=dp[0].length();

        if(len1-1==len2)
        {
            dp[s[a[j]]]=max(dp[s[a[j]]],dp[0]+to_string(a[j]));
        }
        else if(len1-1<len2)
        {
            dp[s[a[j]]]=dp[0]+to_string(a[j]);
        }
    }

//    for (int i = 1; i <=20 ; ++i) {
//        cout<<dp[i]<<"\n";
//    }

    for (int i = 1; i <=n ; ++i) {
        for (int j = 1; j <=m ; ++j) {
            int len1=dp[i+s[a[j]]].length();
            int len2=dp[i].length();
            if(len2==0)
                continue;
            if(len1-1==len2)
            {
                dp[i+s[a[j]]]=max(dp[i+s[a[j]]],dp[i]+to_string(a[j]));
            }
            else if(len1-1<len2)
            {
                dp[i+s[a[j]]]=dp[i]+to_string(a[j]);
            }
        }
    }
    cout<<dp[n];
}

Measured memory_bytes: 33024
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

const int MOD = 998244353;
const int N = 100007;

int n, d[N], cnt[N], max_d, ans = 1;

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

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

    ++cnt[d[i]];
    max_d = max(max_d, d[i]);
  }

  if(d[1]!=0) {
    cout<<0<<endl;
    
    return 0;
  }

  if(cnt[0]>1) {
    cout<<0<<endl;

    return 0;
  }

  for(i=1;i<=max_d;i++) {
    for(j=1;j<=cnt[i];j++) {
      ans = ans * 1ll * cnt[i - 1] % MOD;
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1024
import numpy as np
A, B, K = map(int, input().split(" "))
n_list = [A, B]
N = np.min(n_list)
for i in range(N, 0, -1):
    if (A % i == 0) & (B % i == 0):
        K -= 1
        if K == 0:
            print(i)



Measured memory_bytes: 12488
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int x[] = new int[4];
		for(int i=0; i<4; i++){
			x[i] = n % 10;
			n = n / 10;
		}

		
		if ((x[3] + x[2] + x[1] + x[0]) == 7){
			System.out.println(x[3]+"+"+x[2]+"+"+x[1]+"+"+x[0]+"=7");
		}
		else if ((x[3] + x[2] + x[1] - x[0]) == 7){
			System.out.println(x[3]+"+"+x[2]+"+"+x[1]+"-"+x[0]+"=7");
		}
		else if ((x[3] + x[2] - x[1] + x[0]) == 7){
			System.out.println(x[3]+"+"+x[2]+"-"+x[1]+"+"+x[0]+"=7");
		}
		else if ((x[3] - x[2] + x[1] + x[0]) == 7){
			System.out.println(x[3]+"-"+x[2]+"+"+x[1]+"+"+x[0]+"=7");
		}
		else if ((x[3] + x[2] - x[1] - x[0]) == 7){
			System.out.println(x[3]+"+"+x[2]+"-"+x[1]+"-"+x[0]+"=7");
		}
		else if ((x[3] - x[2] - x[1] + x[0]) == 7){
			System.out.println(x[3]+"-"+x[2]+"-"+x[1]+"+"+x[0]+"=7");
		}
		else if ((x[3] - x[2] + x[1] - x[0]) == 7){
			System.out.println(x[3]+"-"+x[2]+"+"+x[1]+"-"+x[0]+"=7");
		}
		else if ((x[3] - x[2] - x[1] - x[0]) == 7){
			System.out.println(x[3]+"-"+x[2]+"-"+x[1]+"-"+x[0]+"=7");
		}
	}

}


Measured memory_bytes: 22996
#include<stdio.h>

int main(void) {
  int N, M, X;
  scanf("%d %d %d", &N, &M, &X);
  int A[M];
  for (int i = 0; i < M; i++) {
    scanf("%d", &A[i]);
  }
  
  int j = 0;
  int sum1 = 0;
  int sum2 = 0;
  while (A[j] < X) {
    sum1++;
    j++;
  }
  while (j < M) {
    sum2++;
    j++;
  }
  
  if (sum1 < sum2) printf("%d", sum1);
  else printf("%d\n", sum2);
  
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <math.h>

using namespace std;
using ll = long long int;

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  vector<int> p(n);
  for(int i = 0; i < n; i++)
  {
    cin >> p[i];
  }
  vector<int> first, second, third;
  for(int i = 0; i < n; i++)
  {
    if(p[i] <= a)
    {
      first.push_back(p[i]);
    }else if(p[i] <= b)
    {
      second.push_back(p[i]);
    }else{
      third.push_back(p[i]);
    }
  }
  int maxc = min(first.size(), second.size()); 
  maxc = min(maxc, int(third.size()));
  cout << maxc << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define FOR(i,j,n) for(int i=(j);i<=((int)n);++i)
#define N 1000005
#define MOD 1000000007
#define all(c) (c).begin(),(c).end()
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define pb push_back
typedef long long int ll;
typedef std::vector< int > vi;
typedef std::vector< vi > vvi;
typedef std::pair< int,int > ii;
using namespace std;

vector <int>g[N];
void init()
{
	for(int i = 0; i < N; i++) {
		g[i].clear();
	}
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b;
    cin>>a>>b;
    int x=(b-1)/(a-1);
    if ((b-1)%(a-1))
    x++;
    cout<<x<<endl;
}





Measured memory_bytes: 23680
from collections import defaultdict, Counter

h, w, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

d = defaultdict(int)

for a, b in ab:
    for hi in range(a - 2, a + 1):
        for wi in range(b - 2, b + 1):
            if 1 <= hi <= h - 2 and 1 <= wi <= w - 2:
                d[(hi, wi)] += 1

c = Counter(d.values())

print((h - 2) * (w - 2) - sum(c.values()))

for i in range(1, 10):
    print(c[i])


Measured memory_bytes: 176428
#include <stdio.h>

int main() {
  int N, i, max = 0, total = 0;
  scanf("%d", &N);
  int price[10];
  for(i = 0; i < N; i++) {
    scanf("%d", &price[i]);
    total += price[i];
    if(max < price[i]) {
      max = price[i];
    }
  }
  printf("%d\n", total - max / 2);
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(void){
 int a[5];
 int i;
 for(i = 0; i < 5; i++){
  scanf("%d",&a[i]);
  if(a[i] < 40) a[i] = 40;
 }
 printf("%d\n",(a[0]+a[1]+a[2]+a[3]+a[4])/5);
 return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#include <utility>
#include <climits>
#include <cstring>

typedef long long ll;

using namespace std;

void solve(){
    int r, c;
    cin >> r >> c;
    int x[r+1][c+1];

    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cin >> x[i][j];
        }
    }

    for(int i = 0; i <= r; i++){
        for(int j = 0; j <= c; j++){
            if(i == r){
                x[i][j] = 0;
                for(int k = i; k > 0; k--){
                    x[i][j] += x[i-k][j];
                }
                cout << x[i][j];
                if(j != c) {
                    cout << " ";
                }
            }else if(j == c){
                x[i][j] = 0;
                for(int k = j; k > 0; k--){
                    x[i][j] += x[i][j-k];
                }
                cout << x[i][j];
            }else{
                cout << x[i][j] << " ";
            }
        }
        cout << endl;
    }
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define scl(a) scanf("%lld", &a)
#define scl2(a, b) scanf("%lld%lld", &a, &b)
#define ss(a) scanf("%s", a)
#define mem(a, b) memset(a, b, sizeof(a))
#define PII pair<int, int>
using namespace std;
LL dis(LL a,LL b){
    return a*a+b*b;
}
int main(){
    int n,cnt=0;
    LL d;
    sc(n);scl(d);
    while(n--){
        LL x,y;
        scl2(x,y);
        if(dis(x,y)<=d*d)cnt++;
    }
    cout<<cnt<<endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 3748
using System;
using System.Collections.Generic;

class Program
{
	static void Main(string[] args)
	{
		int n = int.Parse(Console.ReadLine());

		List<bool> hash = new List<bool>();

		int max = getKey("TTTTTTTTTTTT");
		for (int i = 0; i < max; i++)
		{
			hash.Add(false);
		}
		
		for (int i = 0; i < n; i++)
		{
			string[] input = Console.ReadLine().Split(' ');

			int key = getKey(input[1]);

			switch (input[0])
			{
				case "insert":
					hash[key] = true;
					break;

				case "find":
					Console.WriteLine(hash[key] ? "yes" : "no");
					break;
			}
		}
	}

	static int getKey(string str)
	{
		int p = 1;
		int sum = 0;
		for (int i = 0; i < str.Length; i++)
		{
			int a = 0;
			switch (str.Substring(i, 1))
			{
				case "A":
					a = 1;
					break;
				case "C":
					a = 2;
					break;
				case "G":
					a = 3;
					break;
				case "T":
					a = 4;
					break;
			}
			sum += p * a;
			p *= 5;
		}
		return sum;
	}
}



Measured memory_bytes: 453728
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INF = 1e16;

void solve(long long A, long long B) {
  if (A >= 13) {
    print(B);
  } else if (A >= 6 && A <= 12) {
    print(B / 2);
  } else {
    print(0);
  }
}

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


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

using namespace std;

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

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  int a, b, c;
  cin >> a >> b >> c;
  cout << (a <= c && c <= b ? "Yes" : "No") << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

using ll = long long;
int N,Weight;
ll w[101],v[101];
ll dp[101][100001];

int main() {
    cin >> N >> Weight;
    for(int i = 1; i <= N; ++i)
        cin >> w[i] >> v[i];
    for(int i = 1; i <= N; ++i)
        for(int j = 1; j <= Weight; ++j)
            if(j >= w[i])
                dp[i][j] = max(dp[i - 1][j],dp[i - 1][j - w[i]] + v[i]);
            else
                dp[i][j] = max(dp[i][j - 1],dp[i - 1][j]);
    cout << dp[N][Weight];
    return 0;
}


Measured memory_bytes: 78336
while True:
    n = int(raw_input())
    if n == 0: break
    for i in range(n):
        data = map(int, raw_input().split())
        if 100 in data or 90 <= float(sum(data[:2]))/2:
            print 'A'
        elif 80 <= float(sum(data))/3:
            print 'A'
        elif 70 <= float(sum(data))/3:
            print 'B'
        elif 50 <= float(sum(data))/3 and (80 <= data[0] or 80 <= data[1]):
            print 'B'
        else:
            print 'C'

Measured memory_bytes: 4228
#include<iostream>
using namespace std;
int main()
{
	int n,r;
	while(cin>>n>>r,n) 
	{
		int deck[n];
		for(int i = 0; i < n; ++i)
		{
			deck[i]=n-i;
		}
		for(int i = 0; i < r; ++i)
		{
			int p,c; cin>>p>>c;
			int tmp[n],now=0;
			for(int j = p-1; j < p-1+c; ++j)
			{
				tmp[now++]=deck[j];	
			}
			for(int j = 0; j < p-1; ++j)
			{
				tmp[now++]=deck[j];	
			}
			for(int j = p-1+c; j < n; ++j)
			{
				tmp[now++]=deck[j];
			}
			for(int i = 0; i < n; ++i)
			{
				deck[i]=tmp[i];
				//cout<<deck[i];
			}
			//cout<<endl;
		}
		cout<<deck[0]<<endl;
	}
  return 0;
}

Measured memory_bytes: 1160
import java.util.*;
import java.io.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n= sc.nextInt();
        int k= sc.nextInt();
        double ans= 0.0;
        ans+=Math.max(0.0,(double)(n-k)/n);

        for (int i=1; i<=Math.min(n,k); i++)
        {
            int tmp=i;
            int count=0;
            while(tmp<k)
            {
                tmp*=2;
                count++;
            }
            ans+=(Math.pow(0.5,(double)count)*(double)1/n);

        }
        System.out.println(String.format("%.10f", ans));


    }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define out(a) cout<<fixed<<setprecision((a))


int main(){
	ll A,B,C,D;
	cin >> A >> B >> C >> D;
	ll Cd = (B/C)-((A-1)/C);
	ll Dd = (B/D)-((A-1)/D);
	ll CD = lcm(C,D);
	ll CDd = (B/CD)-((A-1)/CD);
	cout << (B-A+1)-Cd-Dd+CDd << endl;
}

Measured memory_bytes: 256
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
long long a[200007];
int n;
long long k;
bool check(long long x){
    long long sum=0;
    for(int i=1;i<=n;++i){
        if(a[i]!=0){
            long long flag=x/a[i];
            if(x%a[i]){
                if(x>0&&a[i]<0){
                    sum+=n+1-(lower_bound(a+1,a+1+n,flag)-a);
                    if(a[i]>=flag)
                        --sum;
                }
                else if(x>0&&a[i]>0){
                    sum+=(lower_bound(a+1,a+1+n,flag+1)-a)-1;
                    if(a[i]<=flag)
                        --sum;
                }
                else if(x<0&&a[i]<0)
                    sum+=n+1-(upper_bound(a+1,a+1+n,flag)-a);
                else if(x<0&&a[i]>0)
                    sum+=(lower_bound(a+1,a+1+n,flag)-a)-1;
            }
            else{
                if(x>0&&a[i]<0){
                    sum+=n+1-(upper_bound(a+1,a+1+n,flag)-a);
                    if(a[i]>flag)
                        --sum;
                }
                else if(x>0&&a[i]>0){
                    sum+=(lower_bound(a+1,a+1+n,flag)-a)-1;
                    if(a[i]<flag)
                        --sum;
                }
                else if(x<0&&a[i]<0)
                    sum+=n+1-(upper_bound(a+1,a+1+n,flag)-a);
                else if(x<0&&a[i]>0)
                    sum+=(lower_bound(a+1,a+1+n,flag)-a)-1;
                else if(x==0&&a[i]<0)
                    sum+=n+1-(upper_bound(a+1,a+1+n,0)-a);
                else if(x==0&&a[i]>0)
                    sum+=(lower_bound(a+1,a+1+n,0)-a)-1;
            }
        }
        else if(a[i]==0&&x>0)
            sum+=n-1;
    }
    sum>>=1;
    return sum<k;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>k;
    for(int i=1;i<=n;++i)
        cin>>a[i];
    sort(a+1,a+1+n);
    long long l=-1e18,r=1e18;
    long long ans=0;
    while(l<=r){
        long long mid=(l+r)>>1;
        if(check(mid)){
            ans=mid;
            l=mid+1;
        }
        else
            r=mid-1;
    }
    cout<<ans;
    return 0;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

constexpr int INF = 1001001001;
int N, M;
std::vector<int> G[100100];
std::queue<int> que;
int pointer[100100];

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

  std::cin >> N >> M;

  for(int i=0;i<M;++i){
      int a, b;
      std::cin >> a >> b;

      G[a].emplace_back(b);
      G[b].emplace_back(a);
  }

  pointer[1] = -1;
  que.emplace(1);

  until(que.empty()){
      int v = que.front();
      que.pop();

      for(int w : G[v]){
          if(pointer[w] != 0){continue;}

          pointer[w] = v;
          que.emplace(w);
      }
  }

  std::cout << "Yes" << std::endl;

  for(int i=2;i<=N;++i){
      std::cout << pointer[i] << std::endl;
  }
}


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

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

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	vvi sum(n + 1, vi(n + 1));
	rep(i, m) {
		int l, r;
		cin >> l >> r;

		sum[l][r]++;
	}

	rep(i, n) rep(j, n) {
		sum[i + 1][j + 1] += sum[i][j + 1] + sum[i + 1][j] - sum[i][j];
	}

	rep(i, q) {
		int l, r;
		cin >> l >> r;

		cout << sum[r][r] - sum[l - 1][r] - sum[r][l - 1] + sum[l - 1][l - 1] << endl;
	}
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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 (b<a) { a=b; return true; } return false; }

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    ll a,b,k;
    cin>>a>>b>>k;
    if(k>a){
        if(k>a+b){
            cout<<0<<" "<<0<<endl;
        }else{
            cout<<0<<" "<<a+b-k<<endl;
        }
    }else{
        cout<<a-k<<" "<<b<<endl;
    }
    return  0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <climits>
using namespace std;
 
#define MOD 1000000009LL
 
typedef long long LL;
typedef pair<LL,LL> pLL;
typedef vector<LL> vLL;
typedef vector<vLL> vvLL;
 
vvLL make(int n){
	return vvLL(n, vLL(n));
}
 
void mulmm(vvLL &x, const vvLL &y){
	int n = x.size();
	vvLL z = make(n);
	for(int i = 0; i < n; ++i)
	for(int j = 0; j < n; ++j)
	for(int k = 0; k < n; ++k){
		z[i][j] = (z[i][j] + x[i][k] * y[k][j]) % MOD;
	}
	x.swap(z);
}

void mulvm(vLL &x, const vvLL &y){
	int n = x.size();
	vLL z(n);
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < n; ++j){
			z[i] = (z[i] + x[j] * y[j][i]) % MOD;
		}
	}
	x.swap(z);
}

void powmul(vLL &a, vvLL x, LL y){
	int n = x.size();
	vvLL z = make(n);
	for(int i = 0; i < n; ++i){
		z[i][i] = 1;
	}
	while(y){
		if(y & 1){ mulvm(a, x); }
		mulmm(x, x);
		y >>= 1;
	}
	z.swap(x);
}
 
int main(){
	LL w, h, n;
	int T = 0;
	while(scanf("%lld%lld%lld", &w, &h, &n), w){
		vector<pLL> v(n + 1);
		vLL ys;
		LL x, y;
		for(int i = 0; i < n; ++i){
			scanf("%lld%lld", &x, &y);
			v[i] = pLL(y, x);
			if(y > 1 && y < h){
				ys.push_back(y);
			}
		}
		v[n] = pLL(LLONG_MAX, LLONG_MAX);
		sort(v.begin(), v.end());
		ys.push_back(1);
		ys.push_back(h);
		sort(ys.begin(), ys.end());
		ys.erase(unique(ys.begin(), ys.end()), ys.end());
		vvLL s = make(w);
		for(int i = 0; i < w; ++i){
			s[i][i] = 1;
			if(i != 0){ s[i][i - 1] = 1; }
			if(i != w - 1){ s[i][i + 1] = 1; }
		}
		vLL a(w);
		a[0] = 1;

		int k = 0;
		while(v[k].first <= 1){ ++k; }
		for(int i = 1; i < ys.size(); ++i){
			powmul(a, s, ys[i] - ys[i - 1]);

			while(v[k].first == ys[i]){
				x = v[k].second - 1;
				if(x >= 0 && x < w){
					a[x] = 0;
				}
				++k;
			}
		}
		 
		printf("Case %d: %lld\n", ++T, a[w - 1]);
	}
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;
#ifdef ONLINE_JUDGE
#define D(...)
#else
#define D(...)cerr<<__LINE__<<":"<<"["<<#__VA_ARGS__<<"]->",P(__VA_ARGS__)
#endif
void P(){cerr<<endl;} 
template<typename H,typename...T>void P(H h,T...t){cerr<<h<<" ";P(t...);}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n;cin>>n;
    int flag=0;
    string s;
    char mark;
    unordered_set<string>st;
    while(cin>>s){
        if(flag==0){
            mark=s.back();
            flag=1;
        }
        else
        {
            if(s.front()!=mark){
                return cout<<"No",0;
            }
            mark=s.back();
        }
        st.insert(s);
    }
    if(int(st.size())==n){
        cout<<"Yes";
    }
    else cout<<"No";
    
}

Measured memory_bytes: 3668
<?php

fscanf(STDIN,"%d",$n);
$p = explode(" ",trim(fgets(STDIN)));

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

echo $count;


Measured memory_bytes: 3828
import sys

INFTY=sys.maxsize
WHITE=0
GRAY=1
BLACK=2

def readinput():
    n=int(input())
    nMap=[]
    for _ in range(n):
        nMap.append([INFTY]*n)

    for _i in range(n):
        l=list(map(int,input().split()))
        i=l[0]
        for jj in range(l[1]):
            j=l[2+jj*2]
            w=l[2+jj*2+1]
            nMap[i][j]=w
    return n, nMap

color=[]
d=[]
p=[]

def dijkstra(s,n,nMap):
    global color
    global d
    global p
    
    color=[WHITE]*n
    d=[INFTY]*n
    p=[-1]*n

    d[s]=0
    p[s]=-1

    while True:
        mincost=INFTY
        for i in range(n):
            if color[i]!=BLACK and d[i] < mincost:
                mincost=d[i]
                u=i
        if mincost==INFTY:
            break
        color[u]=BLACK

        for v in range(n):
            if color[v]!=BLACK and nMap[u][v]!=INFTY:
                if d[u]+nMap[u][v] < d[v]:
                    d[v]=d[u]+nMap[u][v]
                    p[v]=u
                    color[v]=GRAY

def main(n,nMap):

    dijkstra(0,n,nMap)
    for i in range(n):
        print('{} {}'.format(i,d[i]))

if __name__=='__main__':
    n,nMap=readinput()
    main(n,nMap)
    





Measured memory_bytes: 5716
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector <int> P(N);
  for(int i=0;i<N;i++){
    cin>>P.at(i);
  }
  vector <int> m(N);
  m.at(0)=P.at(0);
  for(int i=1;i<N;i++){
  if(m.at(i-1)>P.at(i))
    m.at(i)=P.at(i);
    else
      m.at(i)=m.at(i-1);
  }
  int sum=0;
  for(int i=0;i<N;i++){
  if(P.at(i)==m.at(i))
    sum++;
  
  } cout<<sum<<endl;
  
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
#include <climits>
using namespace std;
int main() {
  int n; cin >> n;
  n = n%10;
  if(n==2 || n==4 || n==5 || n==7 || n==9) cout << "hon" << endl;
  else if(n==0 || n==1 || n==6 || n==8) cout << "pon" << endl;
  else cout << "bon" << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

struct Point {
    double x, y, z;
};

Point operator+(Point a, Point b) {
    return Point{a.x+b.x, a.y+b.y, a.z+b.z};
}

Point operator-(Point a, Point b) {
    return Point{a.x-b.x, a.y-b.y, a.z-b.z};
}

Point operator*(double a, Point b) {
    return Point{a*b.x, a*b.y, a*b.z};
}

double abs(Point a) {
    return sqrt(a.x*a.x + a.y*a.y + a.z*a.z);
}

double cross(Point a, Point b) {
    double ra = a.y * b.z - a.z * b.y;
    double rb = a.z * b.x - a.x * b.z;
    double rc = a.x * b.y - a.y * b.x;
    return sqrt(ra*ra + rb*rb + rc*rc);
}

double dot(Point a, Point b) {
    return a.x*b.x + a.y*b.y + a.z*b.z;
}

signed main() {
    const double EPS = 1e-8;
    int N, Q; cin >> N >> Q;
    Point p[100];
    double r[100];
    int l[100];

    rep(i,0,N) {
        double x, y, z;
        cin >> x >> y >> z >> r[i] >> l[i];
        p[i] = Point{x, y, z};
    }
    while(Q--) {
        double sx, sy, sz, dx, dy, dz;
        cin >> sx >> sy >> sz >> dx >> dy >> dz;
        Point s{sx, sy, sz}, t{dx, dy, dz};

        int ans = 0;
        rep(i,0,N) {
            double A = dot(s-p[i], t-s);
            double B = dot(t-s, t-s);
            double T = - A / B;

            if(-EPS >= T || T >= 1.0 + EPS) continue;
            Point d = (s-p[i]) + T * (t-s);
            if(abs(d) - r[i] < EPS) ans += l[i];
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3236