akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return ('0' <= c && c <= '9')?(c - '0'):-1;}

double kitai[1001];
void initKitai(){
  int tmp = 0;
  rep(i,1001){
    tmp += i;
    if(i){
      kitai[i] = (double)(i+1) / 2;
    }
  }
}
// TODO: write
int main() {
  int k,n;cin>>n>>k;
  vector<int> a(n);rep(i,n)cin>>a[i];
  initKitai();
  vector<double> b(n+1);

  b[0] = 0;
  rep(i,n)b[i+1] = b[i] + kitai[a[i]];
  
  double ans = 0;
  for(int i = k;i <= n;++i){
    ans = max(ans,b[i] - b[i-k]);
  }
  
  printf("%.10lf\n",ans);
  return 0;
}



Measured memory_bytes: 2560
S = list(input())
K = int(input())

for i, s in enumerate(S):
    if s == "a":
        pass
    elif ord('z') - ord(s) + 1 <= K:
        S[i] = 'a'
        K -= ord('z') - ord(s) + 1

K %= 26
S[-1] = chr((ord(S[-1]) - ord('a') + K) % 26 + ord('a'))

print("".join(S))


Measured memory_bytes: 10040
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	string s;cin >> s;
	int k;cin >> k;
	int i;
	k--;
	for(i = 0;i < s.size() && k && s[i] == '1';k--,i++);
	cout << s[i] << endl;
	return 0;
}

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

int main(){
    using namespace std;
    string S;
    cin >> S;
    for(unsigned long i = 0; i < S.size(); ++i){
        if(~i & 1){
            if(S[i] == 'L')return 0 & puts("No");
        }else{
            if(S[i] == 'R')return 0 & puts("No");
        }
    }
    puts("Yes");
    return 0;
}

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

int fetch_card()
{
  int card;
  cin >> card;
  if (card == 1)
  {
    card += 13;
  }
  return card;
}

int main()
{
  int a = fetch_card();
  int b = fetch_card();

  if (a > b)
  {
    cout << "Alice" << endl;
  }
  else if (a < b)
  {
    cout << "Bob" << endl;
  }
  else
  {
    cout << "Draw" << endl;
  }
}


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

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9 + 7;
const int inf = 1e8;

int main() {
	int N,M,X;
	cin>>N>>M>>X;
	vector<int> A(M);
	int c1=0,c2=0;
	rep(i,M){
		cin>>A[i];
		if(A[i]>X)c1++;
		else if(A[i]<X)c2++;
	}
	cout<<min(c1,c2)<<endl;
}

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

using namespace std;

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

#define abs(a) ((a) < (0)? -(a):(a))
#define rep(i, n) REP(i, 0, (n))
#define REP(i, a, n) for(int i=(a); i<(n); i++)
#define pb push_back

int T, D, L;

int main() {
    while(cin>>T>>D>>L, T+D+L) {
        int ans = 0, d = 0;
        rep(i, T) {
            int x; cin >> x;
            if(x >= L) d = D;
            else d = max(d-1, 0);
            if(d > 0) ans++;
        }
        cout << max(ans-1, 0) << endl;
    }
}


Measured memory_bytes: 3016
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<math.h>
#include<map>
#include<unordered_map> 
#include<vector>
#include<queue>
#include<set>
#include<bits/stdc++.h>
#include<deque> 
#include<bitset>
#include<string>
#define N 40
#define K 300005
#define MOD 1e9+7
#define int long long 
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
 
int max(int a, int b){
    if(a>b)
        return a;
    return b;
}
int min(int a, int b){
    if(a<b)
        return a;
    return b;
}
 
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
 
bool isPrime(int n) 
{ 
    // Corner case 
    if (n <= 1) 
        return false; 
  
    // Check from 2 to n-1 
    for (int i = 2; i < n; i++) 
        if (n % i == 0) 
            return false; 
  
    return true; 
} 
int mod = 1e9 + 7;
int black[100005];
int white[100005];
int vis[100005];
void dfs(int ro, vector<int> g[]){

	vis[ro] = 1;
	white[ro] = 1;
	black[ro] = 1;
	int ans1 =1, ans2 = 1;
	//ans1 is for white root
	//ans2 is for black root
	for(int x: g[ro]){
        if(vis[x])
            continue;
		dfs(x, g);
		ans2 = ans2 * (white[x]);
		ans1 = ans1 * (white[x] + black[x]);
		if(ans1 >= mod){
			ans1 %= mod;
		}
		if(ans2 >= mod){
			ans2 %= mod;
		}
	}
	white[ro] = ans1;
	black[ro] = ans2;
}



int32_t main(){
	int n;
	cin>>n;
    //if(n == 1){
      //  cout<<2<<endl;
       //return 0;
    //}
	vector<int> g[n+1];
	int x, y;
	for(int i=0;i<n-1;i++){
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
    //cout<<g[1].size()<<endl;
    
	dfs(1, g);
	cout<<(black[1] + white[1])%mod<<endl;
 
	
 
	 
}



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

void solve() {
    int n; cin >> n;
    int a[n][3];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }
    vector<vector<int>> dp(n, vector<int>(3, 0));
    dp[0][0] = a[0][0]; dp[0][1] = a[0][1]; dp[0][2] = a[0][2];
    for (int i = 1; i < n; i++) {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i][0];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + a[i][1];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + a[i][2];
    }

    cout << *max_element(dp.back().begin(), dp.back().end());



}

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

}

Measured memory_bytes: 9732
import itertools


def main():
    a = 'abcdefghijklmnopqrstuvwxyz'
    s = input()

    if len(s) < 26:
        for v in s:
            a = a.replace(v, '')
        print(s + a[0])
    elif s == a[::-1]:
        print(-1)
    else:
        for i in (range(25))[::-1]:
            if s[i] < s[i+1]:
                for j in range(i+1, len(s))[::-1]:
                    if s[i] < s[j]:
                        print(s[:i]+s[j])
                        exit()


def input_list():
    return list(map(int, input().split()))

if __name__ == "__main__":
    main()

Measured memory_bytes: 61972
using System;
class SS
{
 static void Main()
 {
   var n=Console.ReadLine().Split(" ");
   int day=int.Parse(n[0]);
   int m=int.Parse(n[1]);
   var lines=Console.ReadLine().Split(" ");
   int sum=0;
  for(int i=0;i<m;i++)
  {
    sum+=int.Parse(lines[i]);
  }
   if(sum<=day)
   {
     Console.WriteLine(day-sum);
   }
   else
     Console.WriteLine("-1");
 }
}


Measured memory_bytes: 28468
#include<iostream>
#include<string>
using namespace std;
int main(){
	int k,c,s;
	while(true){
		cin>>k;
		if(k==0)
			break;
		s=0;
		for(int i=0;i<k*(k-1)/2;i++){
			cin>>c;
			s+=c;
		}
		cout<<s/(k-1)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define ll long long int
#include<list>
#include<algorithm>
#define ld long double
#define pb push_back
#define FF first
#define SS second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repr(a,b,c) for(a=b-1;a>=c;a--)
#define PLL pair<ll, ll>
#define inf 100000001
#define mod 1000000007
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define PQ priority_queue
#define rep1 for(i=1;i<=n;i++)
#define VLL vector<ll>
#define EF else if
const double pi  =3.141592653589793238463;
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define UMP unordered_map
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define test4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define test5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define test6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
using namespace std;
/*
    //string with spaces
    std::string str;
    std::getline(std::cin >> std::ws, str);
*/
ll myXOR(unsigned long long int x, unsigned long long int y)
{
    return (x|y)&(~x|~y);   
}
ll powerLL(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    }
    return result; 
}
int main()
{
    // fastio
    ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r, t,u,w,x,y,z;
    string str, ss, str1;
    // cin>>t;
    t=1;
    while(t--){
        cin>>n>>d; 
        ll res =0;
        rep(i,0,n){
            double a, b;
            cin>>a>>b;
            double ok = (double)sqrt((double)a*(double)a + (double)b*(double)b);
            // test1(ok);
            if((double)ok <= (double)d){
                res +=1 ;
            }
            // test1(res);
        }
        cout<<res<<endl;
    }
}

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

const int MOD = 1000000000;
const int MAX =200000;

int main() {
  ll n, a, b, loop, rest;
  ll ans = 0;
  cin >> n >> a >> b;
  loop = n / (a + b);
  rest = (n % (a + b));
  if(a == 0) {
    cout << 0 << endl;
    return 0;
  }else {
    if(rest < a) {
      ans = a * loop + rest;
    }else {
      ans = a * loop + a;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int a, b, c; cin >> a >> b >> c;
    if ((b-a) == (c-b)) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
n = int(input())
s = input()
n1 = []
for i in range(n):
    s1 = set()
    for j in range(i+1):
        for k in range(i+1, n):
            # print(i, j, k, s[j], s[k])
            if s[j] == s[k] and set(s[j]).issubset(s1) is False:
                s1.add(s[j])
            # print('len', len(s1))
    n1.append(len(s1))
print(max(n1))


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
bool cmp(char a,char b)
{
	return a>b;
}
int main()
{
	string s,t;
	cin>>s>>t;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end(),cmp);
	if(s<t)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

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

// priceをキーに降順でソート
//sort(fruits.begin(), fruits.end(),
//     [](const fruit& x, const fruit& y) { return x.price > y.price;});

int main() {
    string S;
    std::cin >> S;
    int N=S.length();
    S= S + 'E';
    int a[N];
    int odd_check;
    int tmp_cnt, tmp_pnt;
    for(int i=0; i<N; i++){
        tmp_cnt=0;
        while(S[i+1]=='R'){
            a[i]=0;
            tmp_cnt++;
            i++;
        }
        tmp_pnt=i;
        tmp_cnt++;
        if(tmp_cnt%2==1){
            odd_check=1;
        }
        else{
            odd_check=-1;
        }
        i++;
        while(S[i+1]=='L'){
            a[i+1]=0;
            tmp_cnt++;
            i++;
        }
        tmp_cnt++;
        if(odd_check==1) {
            a[tmp_pnt + 1] = tmp_cnt / 2;
            a[tmp_pnt] = tmp_cnt - a[tmp_pnt + 1];
        }
        else{
            a[tmp_pnt] = tmp_cnt / 2;
            a[tmp_pnt+1] = tmp_cnt - a[tmp_pnt];
        }
    }
    for(int i=0; i<N; i++){
        std::cout << a[i] << std::endl;
    }

    return 0;
}


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

int main() {
  int N, K;
  string S;
  cin >> N >> K >> S;
  for (int i = 0; i < N; i++)
  {
    if (i + 1 == K && S.at(i) == 'A')
    {
      S.at(i) = 'a';
    }
    else if (i + 1 == K && S.at(i) == 'B')
    {
      S.at(i) = 'b';
    }
    else if (i + 1 == K && S.at(i) == 'C')
    {
      S.at(i) = 'c';
    }
  }
  cout << S << endl;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
ll mod=1e9+7;

int main() {
  string s;
  cin >> s;
  if(s=="KIHBR"||s=="AKIHBR"||s=="KIHABR"||s=="KIHBAR"||s=="KIHBRA"||s=="AKIHABR"||s=="AKIHBAR"||s=="AKIHBRA"||s=="KIHABAR"||s=="KIHABRA"||s=="KIHBARA"||s=="AKIHABAR"||s=="AKIHABRA"||s=="AKIHBARA"||s=="KIHABARA"||s=="AKIHABARA") cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
import itertools
n = int(input())
def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table
d = divisor(n)
l = float('inf')
for i in range(len(d)):
    l = min(n // d[i] + d[i] - 2,l)
print(l)

Measured memory_bytes: 3904
#include<iostream>
#include<string>
using namespace std;
int main(){
string a,b,c;
cin>>a>>b;
if(a.size()==b.size()){
	for(int i=0;i<a.size();i++){
		c=c+a[i];
		c=c+b[i];
	}
}
if(a.size()!=b.size()){
	for(int i=0;i<b.size();i++){
		c=c+a[i];
		c=c+b[i];
	}
	c=c+a[a.size()-1];
}
	cout<<c<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if(a == 1) a = 14;
	if(b == 1) b = 14;
	if(a < b) {
		cout << "Bob" << endl;
	} else if(a == b) {
		cout << "Draw" << endl;
	} else {
		cout << "Alice" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    NI = lambda : int(sys.stdin.readline())

    N = NI()

    d = [2] * (N+1)
    d[1] = 1
    for i in range(2,N//2+1):
        j = 2
        while i * j <= N:
            d[i*j] += 1
            j += 1

    ans = 0
    for i in range(1,N+1):
        ans += i * d[i]

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 148252
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const int mod=1000000007;
#define ll long long
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
int _,a,b,n,k,m;
int main() {
	#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    bool flag=false;
    int x,n,k,diff,mini=INT_MAX,maxi=INT_MIN,mini1=INT_MAX,mini2=INT_MAX;
    cin>>x>>n;
    int freq[101];
    memset(freq,0,sizeof(freq));
    std::vector<int> arr;
    rep(i,0,n){
    	cin>>a;
    	mini=min(mini,a);
    	maxi=max(maxi,a);
    	freq[a]=1;
    }
    if(n>=1){
    rep(i,1,101){
    	if(freq[i]==0){
    		arr.pb(i);
    	}
    }
    rep(i,0,arr.size()){
    	flag=true;
    	diff=abs(x-arr[i]);
    	if(diff<mini1){
    		mini1=diff;
    		k=arr[i];
    	}
    }
    int g=(maxi+1)-x;
 	int e=x;
   	if(mini1<g){
   		mini2=min(mini2,k);
   	}
   	else{
   		if(mini1==g){
   			mini2=min(mini2,(maxi+1));
   			mini2=min(mini2,k);
   		}
   		if(e<=g){
   			mini2=min(mini2,0);
   		}
   		else{
   			mini2=min(mini2,maxi+1);
   		}
   	}
   	cout<<mini2<<endl;
    }
	else{
		cout<<x<<endl;
	}
    return 0;
}

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

using namespace std;

#define ll long long

int main(){

    int a,b,c,d,e;

    cin>>a>>b>>c>>d>>e;

    if(a == 0) cout<<1<<endl;

    if(b == 0) cout<<2<<endl;
    if(c == 0) cout<<3<<endl;
    if(d == 0) cout<<4<<endl;
    if(e == 0) cout<<5<<endl;

    return 0;

}


Measured memory_bytes: 3588
#include <stdio.h>
#include <math.h>

int main(void){
	int N, M, i, j;
	scanf("%d %d", &N, &M);
	double a[N], b[N], c[M], d[M];
	for(i = 0; i < N; i++){
			scanf("%lf %lf", &a[i], &b[i]);
	}
	for(i = 0; i < M; i++){
			scanf("%lf %lf", &c[i], &d[i]);
	}
	int min_j = 0;
	double min_d = 0;
	for(i = 0; i < N; i++){
		min_j = 0;
		min_d = fabs(a[i] - c[0]) + fabs(b[i] - d[0]);
		for(j = 0; j < M; j++){
			if(min_d > (fabs(a[i] - c[j]) + fabs(b[i] - d[j]))){
				min_d = (fabs(a[i] - c[j]) + fabs(b[i] - d[j]));
				min_j = j;
			}
		}
		printf("%d\n", min_j+1);
	}
 	return 0;
}

Measured memory_bytes: 128
S = input()

flag = False

if S[0] == 'A':
    S = S.strip('A')
    if S[1:-1].count('C') == 1:    # countメソッド
        S = S.replace('C', '')
        if S == S.lower():
            flag = True

if flag:
    print('AC')
else:
    print('WA')

Measured memory_bytes: 3060
h, w = [int(x) for x in input().split()]

if h==1:
  print(1)
  quit()
if w==1:
  print(1)
  quit()

if h%2==0 and w%2==0:
  print(h*w//2)
elif h%2==0 and w%2==1:
  print(h*w//2)

elif h%2==1 and w%2==0:
  print((h*w)//2)
else:
  print((h*w)//2+1)

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

int main(){
  ll x,a,b;
  cin >> x >> a >> b;
  int c = b-a;
  if(c <= 0){
    puts("delicious");
  }
  else if(x >= c){
    puts("safe");
  }
  else{
    puts("dangerous");
  }
  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 pp pair<int,int>
#define ll long long
int inf=100000000;
ll INF=100000000000000000;
ll MOD=1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> a(n+1),b(n+1);
    for (int i=1;i<n+1;i++) {cin >> a.at(i);b.at(i)=a.at(i);}
    b.at(0)=0;
    sort(b.begin(),b.end());
    int t=0;
    for (int i=1;i<n+1;i++){
        if (a.at(i)==b.at(i)) t++;
        //cout << "aaaa" <<b.at(i) << endl;
    }
    if (t==n) {cout << 0 << endl;return 0;}
    int q=0;
    cin >> q;
    int u,y;
    rep(i,q){
        cin >> u >> y;
        if (a.at(u)==b.at(u)) t--;
        if (a.at(y)==b.at(y)) t--;
        if (a.at(u)==b.at(y)) t++;
        if (a.at(y)==b.at(u)) t++;
        //cout <<  "uuuu" << a.at(u) << " " << a.at(y) << endl;
        swap(a.at(u),a.at(y));
        if (t==n) {cout << i+1 << endl;return 0;}
        //cout << t << endl;
    }
    cout << -1 << endl;
}



Measured memory_bytes: 5196
*s, = input()
_q = int(input())
rev = 0
l, r = [], []
for _ in range(_q):
    *q, = map(str, input().split())

    if q[0] == "1":
        rev += 1
        continue

    t = q[0]
    f = q[1]
    c = q[2]

    if rev%2 == 0:
        if f == "1":
            l.append(c)
        else:
            r.append(c)
    else:
        if f == "1":
            r.append(c)
        else:
            l.append(c)

*l, = reversed(l)

s = l + s + r

if rev%2 == 1:
    *s, = reversed(s)

print("".join(s))


Measured memory_bytes: 92732
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,d;
  cin>>n>>d;
  double x[n][2];
  for(int i=0;i<n;i++){
    for(int j=0;j<2;j++){
      cin>>x[i][j];
    }
  }
  int ans=0;
  for(int i=0;i<n;i++){
    if(sqrt(x[i][0]*x[i][0]+x[i][1]*x[i][1])<=d){
      ans++;
    }
  }
  cout<<ans<<endl;
  
}

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

typedef long long ll;

const ll N = 55, inf = 1e17;

ll cost[N], n;

string str[N];


bool is_pallindrome(string s) {
	string t = s;
	reverse(t.begin(), t.end());
	return t == s;
}


ll dp[52][21][2][2][10001];




ll go(ll idx, ll len, ll pref, ll suff, ll dep) {
	if (len <= 1)return 0;
	string tm = str[idx].substr(0, len);
	if (pref && is_pallindrome(tm))
		return 0;
	tm = str[idx].substr(str[idx].size() - len, len);
	if (suff && is_pallindrome(tm))
		return 0;
	if (dep > 10000)return inf;
	ll &ret = dp[idx][len][pref][suff][dep];
	if (~ret)return ret;
	ret = inf;
	for (ll i = 1; i <= n; i++) {
		if (pref) {
			ll k = min(len, (ll)str[i].size());
			if (is_pallindrome(str[i].substr(0, k) + str[idx].substr(len - k, k))) {
				if (k < (int) str[i].size()) {
					ret = min(ret, cost[i] + go(i, str[i].size() - k, 0, 1, dep + 1));
				} else {
					ret = min(ret, cost[i] + go(idx, len - k, 1, 0, dep + 1));
				}
			}
		}
		 else {
			ll k = min(len, (ll)str[i].size()), pos = str[idx].size() - len;
			if (is_pallindrome(str[idx].substr(pos, k) + str[i].substr(str[i].size() - k, k))) {
				if (k < (int) str[i].size()) {
					ret = min(ret, cost[i] + go(i, str[i].size() - k, 1, 0, dep + 1));
				} else {
					ret = min(ret, cost[i] + go(idx, len - k, 0, 1, dep + 1));
				}
			}
		}
	}
	return ret;
}

int32_t main() {
	///*
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
	//*/

	cin >> n;
	ll ans = inf;
	for (ll i = 1; i <= n; i++) {
		cin >> str[i] >> cost[i];
		if (is_pallindrome(str[i])) {
			ans = min(ans, cost[i]);
		}
	}
	memset(dp, -1, sizeof dp);
	for (ll i = 1; i <= n; i++) {
		for (ll j = 1; j <= n; j++) {
			ll n = str[i].size(), m = str[j].size();
			if (n <= m) {
				if (is_pallindrome(str[i] + str[j].substr(m - n, n))) {
					ans = min(ans, cost[i] + cost[j] + go(j, m - n, 1, 0, 1));
				}
			} else {
				if (is_pallindrome(str[i].substr(0, m) + str[j])) {
					ans = min(ans, cost[i] + cost[j] + go(i, n - m, 0, 1, 1));
				}
			}
		}
	}
	if (ans >= inf) ans = -1;
	cout << ans << endl;
}

Measured memory_bytes: 348136
import java.util.*;

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

	int MAX = 1000000;
	int[] p = new int[MAX];
	for(int i=2; i<p.length; i++)p[i] = 1;
	for(int i=2; i<Math.sqrt(MAX)+1; i++){
	    for(int j=i*2; j<MAX; j+=i){
		p[j] = 0;
	    }
	}

	int n = sc.nextInt();

	while(n!=0){
	    int count = 0;
	    int s = 0;
	    for(int i=0; i<MAX; i++){
		if(p[i]==1){
		    s += i;
		    count++;
		}
		if(count==n){break;}
	    }

	    System.out.println(s);

	    n = sc.nextInt();
	}
    }
}

Measured memory_bytes: 16000
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
typedef long long ll;

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

	int M[100][100];
	int d[100], p[100];
	int color[100];
	
	rep(i,n)
	{
		rep(j,n)
		{
			cin >> M[i][j];
		}
	}

	rep(i,n)
	{
		color[i]=0;
		d[i]  = INT_MAX;
	}


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

	while(1)
	{
		
		int u;
		int mincost = INT_MAX;
		rep(i,n)
		{
			if(color[i]!=2&&d[i]<mincost)
			{
				mincost = d[i];
				u = i;
			}
		}

		if(mincost==INT_MAX)break;
		//cout<<mincost<<endl;
		color[u] = 2;

		rep(v,n)
		{
			if(color[v] != 2 && M[u][v]!= -1)
			{
				if(M[u][v] < d[v])
				{
					//cout<<M[u][v]<<endl;
					
					d[v] = M[u][v];
					p[v] = u;
					color[v]=1;
				}
			}
		}
	}
	int sum = 0;
	rep(i,n)
	sum+= d[i];
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 3108
#include<iostream>
using namespace std;
int n, x[20000000], two, one;
int main() {
	while (true) {
		cin >> n;
		if (!n) { break; }
		two = 0; one = 0;
		for (int i = 0; i < n; i++) {
			cin >> x[i];
			if (x[i] >= 2) { two++; }
			if (x[i] >= 1) { one++; }
		}
		if (two == 0) { cout << "NA" << endl; }
		else { cout << 1 + one << endl; }
	}
}

Measured memory_bytes: 1204
from collections import deque
N,M=map(int,input().split())
Table=[[] for i in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    Table[a-1].append(b-1)
    Table[b-1].append(a-1)
visit=[False]*N
iro=[-1]*N
kei=deque()
def nibu():
    kei.append(0)
    iro[0]=0
    while kei:
        x = kei.pop()
        visit[x]=True
        for i in Table[x]:
            if visit[i] and iro[i] == iro[x]:
                return False
            elif not visit[i]:
                kei.append(i)
                iro[i]=(iro[x]+1)%2
    return True
if nibu():
    B = iro.count(0)
    W = iro.count(1)
    ans = B*W-M
else:
    ans = (N*(N-1))//2 -M
print(ans)

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

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

int main(){
  int N,ans=0,min=200000;
  cin >> N;
  vector<int> P(N);
  rep(i,N)
    cin >> P[i];
  for(int i = 0; i < N; i++){
     if(min>=P[i])
      min=P[i];
     if(P[i]<=min)
       ans++;
    }
  
   cout << ans;
}

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

int main(){
int N , f, total[10005];
cin>>N;
for(int i=0;i<=N;i++){
f=i/10000;
if(i%3==0&&i!=0) total[i]=i;
else if((i-10000*f)/1000==3)total[i]=i;
else if(i/100%10==3)total[i]=i;
else if(i/10%10==3)total[i]=i;
else if(i%10==3)total[i]=i;
else total[i]=0;
}
for(int i=0;i<=N;i++){
if(total[i]!=0)cout<<" "<<total[i];

}
cout<<endl;

  return 0;
}



Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {


    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt(),b=s.nextInt();
        if(a%b==0) System.out.println(0);
        else System.out.println(1);
        

    }




}


class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25404
import Data.Maybe
import Data.List

main = interact $ unlines . map (show' . whenCanWeMeet) . read' . lines
 where
  read' ("0 0":_) = []
  read' (nq:xs) = (q, map (map read . tail . words) dates) : read' xs'
   where
    [n,q] = (map read . words) nq
    (dates,xs') = splitAt n xs
  show' = maybe "0" show

whenCanWeMeet :: (Int, [[Int]]) -> Maybe Int
whenCanWeMeet (q,dates) = fmap head $ listToMaybe $ sort $ filter ((== max_attend) . length) ands
 where
  ands = filter ((>= q) . length) $ group $ sort $ concat dates
  max_attend = maximum (map length ands)

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

vector<int> v(100005);
int n,k,m;
string s,t;

int main() {
  cin >> s;
  ll ans=0,cnt=0;
  for(auto c:s) c=='B' ? cnt++ : ans+=cnt;
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = (1LL<<31) - 1;
const long long int base1 = 48271;
const long long int base2 = 69621;

vector<int> match;

void contain(vector<long long int> a, vector<long long int> b, long long int BASE){// find a from b
    if(a.size() > b.size()) return ;

    long long int powB = 1;
    for(int i=0; i<a.size(); i++){
        powB *= BASE;
        powB %= MOD;
    }

    // Hash
    long long int hash_a = 0;// a[0] * BASE^(la-1) + ... + a[la-2] * BASE + a[la-1] 
    long long int hash_b = 0;
    for(int i=0; i<a.size(); i++){
        hash_a = hash_a * BASE + a[i];
        hash_b = hash_b * BASE + b[i];// hash of b.substr(0, a.length())

        hash_a %= MOD;
        hash_b %= MOD;
    }

    // Roll
    for(int i=0; i+a.size()<=b.size(); i++){
        if(hash_a == hash_b){// b.substr(i,la) == a
            match[i] += 1;
        }
        if(i + a.size() < b.size()){
            hash_b = hash_b * BASE + b[i+a.size()] - b[i] * powB;
            hash_b = (hash_b % MOD + MOD) % MOD;
        }
    }
    return ;// i + a.length() == b.length() : coudln't find
}

int main(){
    int n;
    cin >> n;
    match.resize(n);

    vector<long long int> a(n+1), b(n+1);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    for(int i=0; i<n; i++){
        cin >> b[i];
    }
    a[n] = a[0];
    b[n] = b[0];

    vector<long long int> xa(2*n-1), xb(n);
    for(int i=0; i<n; i++){
        xa[i] = (a[i] ^ a[i+1]);
        if(i == n-1) break;
        xa[n+i] = xa[i];
    }
    for(int i=0; i<n; i++){
        xb[i] = (b[i] ^ b[i+1]);
    }

    //for(int i=0; i<2*n-1; i++) cout << xa[i] << " ";
    //cout << endl;
    //for(int i=0; i<n; i++) cout << xb[i] << " ";
    //cout << endl;

    contain(xb, xa, base1);
    contain(xb, xa, base2);

    for(int k=0; k<n; k++){
        if(match[k] == 2){
            int x = a[k] ^ b[0];
            cout << k << " " << x << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 16940
#include<stdio.h>
#include<string.h>
#define max 1000000
void merge(int [],int ,int ,int );
void mergeSort(int [],int ,int );
int count = 0,newA[max];
int main(){
  int i,j,A[max],left,right,n;

  scanf("%d",&n);
  
  for(i = 0;i < n;i++){
    scanf("%d",&A[i]);
  }
  left = 0;
  right = n;
  mergeSort(A,left,right);
  
   for(i = 0;i < n-1;i++){
    printf("%d ",A[i]);
  }
   printf("%d\n",A[n-1]);
   printf("%d\n",count);
  return 0;
}

void mergeSort(int A[],int left, int right){
  int mid = 0;

  if((left + 1) < right){
    mid = (left + right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}

void merge(int A[],int left,int mid,int right){
  int n1,n2,i,j,k;
  
  n1 = mid - left;
  n2 = right - mid;

  int L[n1+1],R[n2+1];

  for(i = 0;i < n1;i++){
    L[i] = A[left+i];
  }

  for(i = 0;i < n2;i++){
    R[i] = A[mid+i];
  }
  L[n1] = 1000000000;
  R[n2] = 1000000000;
  i = 0;
  j = 0;
  
  for(k = left;k < right;k++){
    if(L[i] <= R[j]){
     A[k] = L[i];
     i++;
    }
    else{
      A[k] = R[j];
      j++;
    }
    count++;
  }
}

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



using namespace std;
int first [30] , last [30] ;
int n;
char tmp[10001] ;
int main ()
{
    while (cin>>n)
    {
        int ans =0;
        cin>>tmp ;
        fill (first , first +26 , 0 ) ;
        fill (last ,last +26, 0) ;
        first [tmp [0]-'a' ] ++ ;
        for (int i =1; i<n ; i++)
        {
            last [tmp [i] -'a' ] ++ ;
        }

        for (int i=1;i<n-1;i++)
        {
            int t =0;
            for (int j=0;j<26;j++)
            {
                if (first [j] && last [j] ) t++ ;
            }
            ans = max (ans , t) ;
            first [tmp [i] -'a' ] ++;
            last [tmp [i] -'a' ] -- ;

        }
        cout<<ans<<endl ;
    }

    return  0;
}


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

using namespace std;

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

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main() {
  int n, ct[10010], wt[10010];  
  
  while(1) {
    cin >> n;
    if(!n) break;

    REP(i, n) cin >> ct[i];
    sort(ct, ct+n);
    wt[0] = 0;
    FOR(i, 1, n) wt[i] = ct[i-1] + wt[i-1];

    LL ans = 0;
    REP(i, n) ans += wt[i];
    cout << ans << endl;
  }
}

Measured memory_bytes: 1248
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iostream>
#include <deque>
#include <math.h>
#include <cstdio>
#include <functional>
#include <set>
#include <iomanip>
#include <tuple>
typedef  long long ll;
using namespace std;

int main(void) {
	ll a, b, k;
	cin >> a >> b >> k;
	for (int i = a; i <= b; i++)
	{
		if (i <= a + k -1 || b - k + 1 <= i )
		{
			cout << i << endl;
		}
	}
	

	return 0;
}

Measured memory_bytes: 256
n, m = gets.chomp.split(' ').map(&:to_i)

results = {}
m.times do
  p, s = gets.chomp.split(' ')
  p = p.to_i

  current_p = results[p]

  if current_p.nil?
    hash = { AC: 0, WA: 0 }
    hash[s.to_sym] +=1
    results[p] = hash
  elsif current_p[:AC] > 0
    next
  else
    current_p[s.to_sym] +=1
  end
end

acs = results.select { |k, v| v[:AC] > 0 }
ac_count = acs.count
wa_sum = acs.reduce(0) { |sum, (k, v)| sum + v[:WA] }
puts "#{ac_count} #{wa_sum}"

Measured memory_bytes: 43516
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

struct tree{
	int lr[2];
	int degree;
	int parent;
};

void Preorder(vector<struct tree> node, int x){
	cout<<" "<<x;
	for(int i=0;i<2;i++)
		if(node[x].lr[i] != -1)
			Preorder(node, node[x].lr[i]);
}

void Inorder(vector<struct tree>node, int x){
	if(node[x].lr[0] != -1)
		Inorder(node, node[x].lr[0]);

	cout<<" "<<x;

	if(node[x].lr[1] != -1)
		Inorder(node, node[x].lr[1]);
}

void Postorder(vector<struct tree> node, int x){
	for(int i=0;i<2;i++)
		if(node[x].lr[i] != -1)
			Postorder(node, node[x].lr[i]);

	cout<<" "<<x;
}

int main(){
	int n, id, d[2], x;
	vector<struct tree> node(25);
	
	cin>>n;

	for(int i=0;i<n;i++)
		node[i].parent = -1;

	for(int i=0;i<n;i++){
		cin>>id>>d[0]>>d[1];
		for(int j=0;j<2;j++){
			node[id].lr[j] = d[j];
			if(d[j] != -1)
				node[d[j]].parent = id;
		}
	}

	for(int i=0;i<n;i++)
		if(node[i].parent == -1)
			x = i;

	cout<<"Preorder"<<endl;
	Preorder(node, x);
	cout<<endl<<"Inorder"<<endl;
	Inorder(node, x);
	cout<<endl<<"Postorder"<<endl;
	Postorder(node, x);
	cout<<endl;

	return 0;
}

Measured memory_bytes: 1224
class height():

    def __init__(self):
        self.human = 0
        self.step = 0

    def Sum(self):
        return self.human + self.step
N = int(input())
A = [height() for i in range(N)]

s = str(input()).split()

for i,v in enumerate(s):
    A[i].human = int(v)
    # print(i,v)

sum, tmp = 0,0
for i in range(len(A)-1):
    if A[i+1].human >= A[i].Sum():
        continue
    tmp = A[i].Sum() - A[i+1].human
    A[i+1].step = tmp
    sum += tmp

print(sum)
# for a in A:
#     print("human",a.human)

Measured memory_bytes: 69012
x,k,d=map(int,input().split())
if x == 0:
  print((k%2) * d)
elif k - abs(x//d) < 0:
  if x > 0:
    print(x - k*d)
  else:
    print(abs(x + k*d))
elif (k - abs(x//d))%2:
  print(abs(x%d-d))
else:
  print(x%d)

Measured memory_bytes: 9180
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e6)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
#define PI (acos(-1))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}
LL exp(int a, int b){
    LL res = 1;
    LL sum = a;
    while(b){
        if(b&1)res = (res * sum) % MOD;
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}
int N;
vector<string> bytes;
vector<int> dp;
LL count(string a, string b){
    bool check=false;
    for(auto i:b)if(i=='y'){
        check=true;
        break;
    }
    if(check){
        bool flag = false;
        int xc = 0;
        int yc = 0;
        REP(i, a.size()){
            if(b[i]=='1'){
                if(a[i]=='0')return 0;
            }
            if(b[i]=='0'){
                if(a[i]=='1')return 0;
            }
            if(b[i]=='x'){
                if(a[i]=='x')++xc;
            }
            if(b[i]=='y'){
                if(a[i]=='1')flag=true;
                if(a[i]=='x')++yc;
            }
        }
        if(flag){
            return exp(2, xc + yc);
        }else{
            if(yc==0)return 0;
            return (exp(2, yc) - 1) * exp(2, xc);
        }
    }else{
        int count = 0;
        REP(i, a.size()){
            if(b[i]=='x'){
                if(a[i]=='x')++count;
            }else{
                if((a[i]!='x') and (a[i] != b[i]))return 0;
            }
        }
        return exp(2, count);
    }
} 

LL func(int place){
    if(place == N){
        return 1;
    }
    if(dp[place]>=0)return dp[place];
    LL res = (LL)func(place+1) * count(bytes[place], "0xxxxxxx");
    res %= MOD;
    if(place+2 <= N){
        res += (LL)func(place+2) * count(bytes[place]+bytes[place+1], "110yyyyx10xxxxxx");
        res %= MOD;
    }
    if(place+3 <= N){
        string str="";
        for(int i=0;i<3;++i)str += bytes[place+i];
        res += (LL)func(place+3) * count(str, "1110yyyy10yxxxxx10xxxxxx");
        res %= MOD;
    }
    if(place+4 <= N){
        string str="";
        for(int i=0;i<4;++i)str += bytes[place+i];
        res += (LL)func(place+4) * count(str, "11110yyy10yyxxxx10xxxxxx10xxxxxx");
        res %= MOD;
    }
    return dp[place] = res;
}

int main(){
    while(cin >> N && N){
        bytes = vector<string>(N);
        for(auto &i:bytes)cin >> i;
        dp = vector<int>(N, -1);
        cout << func(0) << endl;
    }
    return 0;
}



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

int N, K, A[100005], B[100005];

int main() {
	scanf("%d%d", &N, &K);
	for (int i = 0; i < N; i++) scanf("%d%d", &A[i], &B[i]);
	long long ans = 0;
	for (int b = 0; b < 31; b++) {
		int tk = K;
		if (b >= 0) {
			K >>= b;
			K <<= b;
			if (b > 0) K += (1 << (b - 1)) - 1;
		}
		if (K <= tk) {
			long long cur = 0;
			for (int i = 0; i < N; i++) {
				if ((A[i] | K) == K) cur += B[i];
			}
			ans = max(ans, cur);
		}
		K = tk;
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
int main(void){
    // Your code here!
 ll i,k,n;
 cin >> n >> k;
 ll a[n];
 for(i=0;i<n;i++)
 cin >> a[i];
 vector<string> v;
 for(i=k;i<n;i++)
 v.pb((a[i]>a[i-k]) ? "Yes" : "No");
 for(auto p:v)
 cout << p << '\n';
 return 0;
}

Measured memory_bytes: 13200
#include<stdio.h>
#include<math.h>

int n;
double Koch(int n,double lx,double ly,double rx,double ry)
{
  if(n!=0)
  {
    double p[3][2];
    p[0][0]=(2*lx+rx)/3;
    p[0][1]=(2*ly+ry)/3;
    p[2][0]=(lx+2*rx)/3;
    p[2][1]=(ly+2*ry)/3;

    p[1][0]=(p[2][0]-p[0][0])/2-(p[2][1]-p[0][1])*sqrt(3)/2+p[0][0];
    p[1][1]=(p[2][0]-p[0][0])*sqrt(3)/2+(p[2][1]-p[0][1])/2+p[0][1];
  
    Koch(n-1,lx,ly,p[0][0],p[0][1]);
    printf("%.8f %.8f\n",p[0][0],p[0][1]);
    Koch(n-1,p[0][0],p[0][1],p[1][0],p[1][1]);
    printf("%.8f %.8f\n",p[1][0],p[1][1]);
    Koch(n-1,p[1][0],p[1][1],p[2][0],p[2][1]); 
    printf("%.8f %.8f\n",p[2][0],p[2][1]);
    Koch(n-1,p[2][0],p[2][1],rx,ry); 
  }
  if(n==0)
      return 0;
  
}
int main()
{
  scanf("%d",&n);
  printf("%.8f %.8f\n",0.0,0.0);
  Koch(n,0,0,100,0);
  printf("%.8f %.8f\n",100.0,0.0);
  return 0;
}



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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// 結果を入れたmapを返します
map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i <= sqrt(n); i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  // 2以上で割り切れなかったら
  if (n != 1) ret[n] = 1;
  return ret;
}

// ====================================================================

int main() {
  ll n;
  cin >> n;
  map<ll, int> m;  // nの階乗を素因数分解した結果を入れます

  for (ll i = 1; i <= n; i++) {
    map<ll, int> ret = prime_factor(i);
    for (auto x : ret)
      m[x.first] += x.second;
  }

  // 計算用のvectorを作る
  vector<int> v;
  for (auto x : m) {
    v.push_back(x.second + 1);
    // cout << x.first << " " << x.second << endl;
  }

  int dp[v.size() + 1][80];  // iまで考えて、掛けてjになる組み合わせ
  memset(dp, 0, sizeof(dp));
  dp[0][1] = 1;
  for (int i = 0; i < v.size(); i++) {  // i番目まで見ていく
    for (int j = 1; j <= 75; j++) {     // jに1~kを掛けて遷移する
      for (int k = 1; k <= v[i]; k++) {
        if (j * k <= 75)
          dp[i + 1][j * k] += dp[i][j];
      }
    }
  }

  cout << dp[v.size()][75] << endl;
}


Measured memory_bytes: 256
def main():
    n, c = map(int, input().split())
    xv = [None]*n
    for i in range(n):
        xv[i] = list(map(int, input().split()))
    v, left_max, right_max = 0, 0, 0
    gl = [None]*n
    gr = [None]*n
    _2oas = [None]*(n+1)
    _2obs = [None]*(n+1)
    _2oas[0], _2obs[0] = 0, 0
    ans = 0
    for i, (xi, vi) in enumerate(xv, 1):
        v = v + vi
        left = v - xi
        if left_max < left:
            left_max = left
        gl[n-i] = left_max
        _2oas[i] = v - 2*xi
    v = 0
    for i, (xi, vi) in enumerate(xv[::-1], 1):
        v = v + vi
        right = v - c + xi
        if right_max < right:
            right_max = right
        gr[n-i] = right_max
        _2obs[i] = v - 2*(c - xi)
    for oa, _2ob, ob, _2oa in zip(gl, _2obs[:n], gr, _2oas[:n]):
        ans = max(ans, _2oa+ob, _2ob+oa)
    print(ans)
        
if __name__ == "__main__":
    main()

Measured memory_bytes: 69208
tmp=input()
l1=[]
l2=[]
Asum=0
Area=[]

for i in range(len(tmp)):
	if tmp[i] is "\\":
		l1.append(i)
	elif tmp[i] is "/" and len(l1) is not 0:
		a1=l1.pop()
		sum=i-a1
		Asum+=sum
		while len(l2)>0:
			if l2[-1]>a1:
				l2.pop()
				sum+=Area.pop()
			else:
				break

		Area.append(sum)
		l2.append(i)
print(Asum)
print(len(Area),*Area)


Measured memory_bytes: 6380
#coding: UTF-8

#a~b??????????´???°????????°

l = map(int, raw_input().split())
a = l[0]
b = l[1]
c = l[2]

ans = 0
x = a

while x <= b:
	y = c % x
	x += 1
	if y == 0:
		ans += 1

print "%d" %ans

Measured memory_bytes: 6456
#include <bits/stdc++.h>
#define ll long long
using namespace std;
template<class T>inline void read(T &res)
{
    char c;
    T flag=1;
    while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;
    res=c-'0';
    while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';
    res*=flag;
}
void gcd(ll a,ll b,ll &d,ll &x,ll &y)
{
    if(!b)
    {
        d=a;
        x=1;
        y=0;
    }
    else
    {
        gcd(b,a%b,d,y,x);
        y-=x*(a/b);
    }
}
ll in(ll a,ll mod)
{
    ll d,x,y;
    gcd(a,mod,d,x,y);
    return d==1?(x+mod)%mod:-1;
}

ll qp(ll a,ll x,ll mod)
{
    ll ans=1;
    while(x)
    {
        if(x%2==1)
            ans=(ans*a)%mod;
        a=(a*a)%mod;
        x/=2;
    }
    return ans;
}
int cmp(ll a,ll b)
{
    return a<b;
}

int main()
{
    string s;
    cin>>s;
    int len=s.length();
    int f=0;
    ll sum=0;
    for(int i=0;i<len;i++)
        sum+=s[i]-'0';
    if(sum%9==0)
        printf("Yes\n");
    else 
        printf("No\n");
    return 0;

}




Measured memory_bytes: 3676