akhauriyash/Code-Regression huggingface dataset:
while True:
    N=input()
    if N==0:break
    L=map(int,raw_input().split())
    P=[]
    cnt=0
    while (P<>L) and (cnt<10000):
        P=L[:]
        L=map(lambda x:x-1,L)
        L.append(len(L))
        L=[i for i in L if i<>0]
        cnt+=1
    print cnt-1	if cnt<>10000 else -1

Measured memory_bytes: 4336
#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;


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

	
	int a, b;
	cin >> a >> b;
	cout << a * (a - 1) / 2 + b * (b - 1) / 2;
}

Measured memory_bytes: 256
import numpy as np
def eratosthenes(n):
    is_prime = np.ones((n+1,), dtype=bool)
    is_prime[:2] = False
    for i in range(2,n+1):
        if is_prime[i]:
            is_prime[i*2::i]=False
    return np.arange(n+1)[is_prime]
Ps = eratosthenes(1000007)
def divisor(n):
    for p in Ps:
        if p*p>n:return -1
        if n%p==0:return p
def prime_division(n):
    d={}
    while n>1:
        p=divisor(n)
        if p==-1:d[n]=d.get(n,0)+1;break
        else:d[p]=d.get(p,0)+1;n//=p
    return d

def z(n,k,v):
    if len(k)==1:
        return [n*k[0]**i for i in range(v[0]+1)]
    else:
        r=[]
        for i in range(v[0]+1):
             r+=z(n*k[0]**i,k[1:],v[1:])
        return r
def y(n):
    pd=prime_division(n)
    KV=[[k,v] for k,v in pd.items()]
    K=[k for k,v in KV]; V=[v for k,v in KV]
    return z(1,K,V)

N=int(input())
if N==1:print(0);exit()
r=0
#print(y(N))
for yk in y(N):
    if yk>1 and N//(yk-1) == N%(yk-1):
        r+=yk-1
print(r)

Measured memory_bytes: 30736
n, x = map(int, raw_input().split())
a = map(int, raw_input().split())
a.sort()
give = a[::]

for i in range(n):
    if i == n-1:
        give[i] = x
    else:
        give[i] = min(x, a[i])
        x -= give[i]

print sum([give[i] == a[i] for i in range(n)])
    

Measured memory_bytes: 2692
#include <stdio.h>


int main (void){
    
   int r;
   
   scanf("%d", &r);
   
   int one = r%10;
   int ten = r%100 - one;
   int hun = r-ten-one;

   int sum = one+ten/10+hun/100;
   printf("%d",sum);
    
    
    return 0;
    
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef double lld;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define pb push_back
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
template <typename T, typename U>ostream &operator<<(ostream &out, const pair<T, U> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>void print(const ContainerType<ValueType, Args...> &c){for (const auto &v : c)cout << v << ' ';cout << '\n';} void print(){cout<<'\n';}
template <typename T, typename... Args>void print(T a, Args... args){cout << a << " ";print(args...);}
lli llipower(lli x, lli y, lli p = LLONG_MAX){lli res = 1;x = x % p;while (y > 0){if (y & 1)res = (res * x) % p;y = y >> 1;x = (x * x) % p;}return res;}

//8====================================D
int main(){
    int a;
    cin>>a;
    print(a+a*a+a*a*a);
}

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

max=0
max_i=0
max2=0
for i in range(n):
    x=int(input())
    if max<x:
        max = x
        max_i = i
    elif max2<x:
        max2 = x


for i in range(n):
    if i==max_i:
        print(max2)
    else:
        print(max)

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


int main() {
    int r; cin >> r;
    cout << r*r << endl;
    return 0;
}


Measured memory_bytes: 256
/*map,set,priority_queue,stack,queue*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define el "\n"
#define pb push_back
#define F first
#define S second
#define fo(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
typedef vector<int> vi;
const int inf = (1e18)+7;
const int neginf = -1*((int)1e18 ) + 7 ;
const int mod = (int)1e9 + 7;
const int N = 500007;
/*int arr[N];
vector<int> adj[N];

void dfs(int x,int par)
{
    arr[x]+=par;
    arr[par] = 0;
    for(auto child:adj[x])
    {
        if(child==par)
            continue;
        dfs(child,x);
    }
}
*/

int32_t main() 
{
fastio
    
  int a,b;
    cin>>a>>b;
    b = 2*b;
    
    cout<<max(0LL,a-b);
    
    
    
    return 0;
}


Measured memory_bytes: 256
from collections import deque

n = int(input())
tree = {i:[] for i in range(1, n+1)}
for _ in range(n-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)
c = list(map(int, input().split()))

c = sorted(c, reverse = True)
d = [-1]*(n+1)
que = deque([1])
ic = 0
while len(que) > 0:
    x = que.popleft()
    d[x] = c[ic]
    ic += 1
    for y in tree[x]:
        if d[y] < 0:
            que.append(y)
print(sum(c[1:]))
print(*d[1:])


Measured memory_bytes: 7068
/*
            _ _  ___            __ _ _  _       _     
 _   _  ___| | |/ _ \__      __/ _| | || |  ___| |__  
| | | |/ _ \ | | | | \ \ /\ / / |_| | || |_/ __| '_ \ 
| |_| |  __/ | | |_| |\ V  V /|  _| |__   _\__ \ | | |
 \__, |\___|_|_|\___/  \_/\_/ |_| |_|  |_| |___/_| |_|
 |___/                 

*/

#include <bits/stdc++.h>
using namespace std;
#define sz(x) (ll)(x).size()
#define trav(x) for(auto& it: x)
#define all(x) x.begin(), x.end()
#define stp fixed<<setprecision(20)
#define db(x) cout<<#x<<": "<<x<<endl
#define tc ll tt; cin>>tt; while(tt--)
#define For(i, st, en) for(ll i=st; i<en; i++)
#define rFor(i, st, en) for(ll i=st; i>=en; i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define printv(x) For(i, 0, sz(x)){cout<<x[i]<<" ";} cout<<endl;
#define print2v(x) For(i, 0, sz(x)){For(j, 0, sz(x[i])){cout<<x[i][j]<<" ";} cout<<endl;}
#define ll long long
#define int long long
#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
#define endl '\n'
#define MAXN 300005
#define MOD 1000000007
#define INF 1000000000000000007
#define bitc __builtin_popcountll

int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (double)(clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n";

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

void splitx(string s, char c, vector<string> &v){
    int i=0, j;
    while(i<sz(s)){
        j=i; string temp;
        while(j<sz(s) && s[j]!=c){temp+=s[j]; j++;}
        v.pb(temp); i=j+1;
    }
}

/*################################ ¯\_(ツ)_/¯ ################################*/

// #define MAXN 200
// #define INF 1000

signed main(){
	fast
	int n, wt;
	cin>>n>>wt;

	vi w(n), v(n);
	For(i, 0, n){
		cin>>w[i]>>v[i];
	}

	vvi dp(n, vi(MAXN, INF));

	For(i, 0, n){
		if(i==0){
			dp[i][v[i]] = w[i];
			continue;
		}
		dp[i][v[i]] = min(dp[i][v[i]], w[i]);
		For(j, 0, MAXN){
			dp[i][j] = min(dp[i][j], dp[i-1][j]);
			if(dp[i-1][j]!=INF){
				dp[i][j+v[i]] = min(dp[i][j+v[i]], dp[i-1][j]+w[i]);
			}
		}
	}
	int ans=0;
	// For(i, 0, n){
	int i = n-1;
	For(j, 0, MAXN){
		// if(dp[i][j]!=1000){
		// 	cout<<" "<<dp[i][j]<<" ";
		// }else{
		// 	cout<<".";
		// }
		if(dp[i][j]<=wt){
			ans = max(ans, j);
		}
	}
	// 	cout<<endl;
	// }
	cout<<ans<<endl;
    // print2v(dp);
    // end_routine()
    return 0;
}



Measured memory_bytes: 237056
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;cin>>s;
  bool ans=false;
  string t(s);reverse(t.begin(),t.end());
  if(s==t) {
    ll l=s.length();
    string a=s.substr(0,(l-1)/2);
    string b(a);
    reverse(b.begin(),b.end());
    if(a==b) {
      string c=s.substr((l+1)/2,(l-1)/2);
      string d(c);
      reverse(d.begin(),d.end());
      if(c==d) ans=true;
    }
  }
  if(ans) print("Yes");else print("No");
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    string S;
    cin >> S;
    int year=0, month=0, day=0;
    for(int i=0; i<4;i++){
        year *= 10;
        year += S[i] - '0';
    }
    for(int i=5; i<7; i++){
        month *= 10;
        month += S[i] - '0';
    }
    for(int i=8; i<10; i++){
        day *= 10;
        day += S[i] - '0';
    }

    if(year == 2019){
        if(month <= 4){
            cout << "Heisei" << endl;
        }else{
            cout << "TBD" << endl;
        }
    }else if(year < 2019){
        cout << "Heisei" << endl;
    }else{
        cout << "TBD" << endl;
    }
    return 0;
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

const int MAX_N = 200000;
int n;
int a[MAX_N];
multiset<int,greater<int>> c;

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> n;
  forn(i,n) {
    cin >> a[i];
    c.insert(a[i]);
  }

  forn(i,n) {
    c.erase(c.find(a[i]));
    cout << *c.begin() << endl;
    c.insert(a[i]);
  }


  return 0;
}


Measured memory_bytes: 13568
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
while 1:
    n = input()
    if not n:
        break
    s = [(0, 0)]
    for i in xrange(n-1):
        p, d = map(int, raw_input().split())
        x, y = s[p]
        dx, dy = dd[d]
        s.append((x + dx, y + dy))
    xs = [e[0] for e in s]
    ys = [e[1] for e in s]
    print max(xs)-min(xs)+1, max(ys)-min(ys)+1

Measured memory_bytes: 6252
N=int(input())
c=input()

flag=True


while(flag):
  flag=False
  c_new=''
  for i in range(len(c)-1):
    if c[i]==c[i+1]:
      flag=True
      #del c[i-minus]
      #minus+=1
    else:
      c_new+=c[i]
  c_new+=c[len(c)-1]
  c=c_new
print(len(c))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int n, m;
  cin >> n >> m;
  vector<string> a(n);
  vector<string> b(m);
  REP(i, n) cin >> a[i];
  REP(i, m) cin >> b[i];
  REP(y, n-m+1) REP(x, n-m+1){
    bool ok = true;
    REP(i, m) REP(j, m){
      if(a[y+i][x+j] != b[i][j]) ok = false;
    }
    if(!ok) continue;
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define REP(i, n) for(int i=0; i<n; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll mod = 1e9+7;

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    int a, b, m; cin >> a >> b >> m;
    vector<int> A(a+1, 1e9);
    vector<int> B(b+1, 1e9);
    REP(i, a){
        cin >> A[i+1];
    }
    REP(i, b){
        cin >> B[i+1];
    }
    int x, y, c;
    int ans = 1e9;
    REP(i, m){
        cin >> x >> y >> c;
        ans = min(A[x] + B[y] - c, ans);
    }
    sort(ALL(A));
    sort(ALL(B));
    ans = min(A[0] + B[0], ans);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
#define MAX 100100
//#define NIL -1

LL pow(LL x, LL n){
    LL ans = 1;
    while(n>0){
        if((n&1)==1){
            ans = ans * x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

vector<LL> factorize_gen(LL n){
    vector<LL> out;
    for(LL i=2; i*i<=n; i++){
        if(n%i!=0){
            continue;
        }
        while(n%i==0){
            out.push_back(i);
            n/=i;
        }
    }
    if(n!=1){
        out.push_back(n);
    }

    return out;
}

int main() {
    LL n;
    cin >> n;
    vector<LL> num_list=factorize_gen(n);

    LL num_pat=pow(2, num_list.size());
    LL a;
    LL b;
    LL keta_a;
    LL keta_b;
    LL ans=MAX;
    LL idx;
    for(int i=0; i<num_pat; i++){
        int tmp=i;
        a=1;
        b=n;
        idx=0;
        while(tmp>0){
            if(tmp&1==1){
                a*=num_list[idx];
                b/=num_list[idx];
            }
            tmp/=2;
            idx++;
        }
        //cout << a << " " << b << endl;
        keta_a=0;
        keta_b=0;
        while(a>0){
            keta_a++;
            a/=10;
        }
         while(b>0){
            keta_b++;
            b/=10;
        }
        ans=min(ans, max(keta_a, keta_b));
    }

    cout << ans << endl;    


    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use std::cmp::{min, max};
use smallvec::alloc::collections::VecDeque;

#[fastout]
fn main() {
    input! {
    h: usize,
    w: usize,
    s: [Chars; h]
    }
    let mut ans = 0;
    let dx = [0, -1, 0, 1];
    let dy = [1, 0, -1, 0];
    let mut q = VecDeque::new();
    for si in 0..h {
        for sj in 0..w {
            let mut map = vec![vec![-1; w]; h];
            map[si][sj] = 0;
            if s[si][sj] == '#' {continue}
            q.push_back((si, sj));
            if si == 2 && sj == 4 {
                print!("")
            }
            while !q.is_empty() {
                let (x, y) = q.pop_front().unwrap();
                for i in 0..4 {
                    let (nx, ny) = (x as i64 + dx[i], y as i64 + dy[i]);
                    if nx >= 0 && nx < h as i64 && ny >= 0 && ny < w as i64 {
                        let (nx, ny) = (nx as usize, ny as usize);
                        if s[nx][ny] == '#' || map[nx][ny] >= 0 {continue}
                        map[nx][ny] = map[x][y] + 1;
                        ans = max(map[nx][ny], ans);
                        q.push_back((nx, ny))
                    }
                }
            }
        }
    }
    println!("{}", ans);
}


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

int main()
{
	int N;
	cin >> N;
	string res = "Yes";
	int fX = 0;
	int M = N;
	while (N > 0) {
		fX += N % 10;
		N /= 10;
	}
	if (M%fX == 0) {
		res = "Yes";
	}
	else {
		res = "No";
	}

	cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
//C++11
#if __cplusplus == 201103L
#include <tuple>
#endif

using namespace std;

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

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
typedef vector<int> vi;

int main(){
  string s;
  while(cin >> s && s != ""){
    vector<int> v;
    REP(i, s.size()){
      if(s[i]=='c'){
        v.push_back(0);
        i += string("chicken").size() - 1;
      }else{
        assert(s[i] == 'e');
        v.push_back(1);
        i += string("egg").size() - 1;
      }
    }
    vector<vi> vs;
    vi tmp;
    REP(i, v.size()){
      if(tmp.size() > 0 && tmp.back() == v[i]){
        vs.push_back(tmp);
        tmp.clear();
      }
      tmp.push_back(v[i]);
    }
    vs.push_back(tmp);
    int maxlen = 0;
    REP(i, vs.size())maxlen = max(maxlen, (int)vs[i].size());
    int ans = -1;
    for(int i = vs.size() - 1; i >= 0; i--)if(vs[i].size() == maxlen){
      ans = vs[i].back();
    }
    if(ans == 0)cout<<"chicken"<<endl;
    else cout<<"egg"<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#-*-coding:utf-8-*-

import sys

def main():
    maps=[]
    n = int(input())
    count=0
    maps=list(map(int,input().split()))
    for idx,value in enumerate(maps,1):
        if idx % 2 != 0 and value %2 !=0:
            count+=1
    print(count)            

if __name__ == "__main__":
    main()

Measured memory_bytes: 9140
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n, a, b, c, d, sum = 0, num = 0;
	cin >> n >> a >> b >> c >> d;
	if (n % a == 0) {
		sum = n / a * b;
	}
	else {
		sum = (n / a + 1) * b;
	}
	if (n % c == 0) {
		num = n / c * d;
	}
	else {
		num = (n / c + 1) * d;
	}
	cout << min(sum, num) << endl;
	cin >> n;
}


Measured memory_bytes: 3112
#include <iostream>
#include <queue>

using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	priority_queue<long long> q;
	for (int i = 0; i < N; ++i) {
		int A;
		cin >> A;
		q.push(A);
	}

	for (int i = 0; i < M; ++i) {
		auto x = q.top();
		q.pop();
		q.push(x / 2);
	}
	long long ans = 0;
	while (!q.empty()) {
		ans += q.top();
		q.pop();
	}
	cout << ans << endl;
}


Measured memory_bytes: 1400
#import
#import math
#import numpy as np
N = int(input())
#= input()
#= map(int, input().split())
a = list(map(int, input().split()))
#= [input(), input()]
#= [list(map(int, input().split())) for _ in range(N)]
#= {i:[] for i in range(N)}

alen = N
two = 0
four = 0

for aa in a:
    if aa % 4 == 0:
        four += 1
    elif aa % 2 == 0:
        two += 1

other = alen - two - four

res = False

if other > four + 1:
    pass
elif other == four + 1:
    if two == 0:
        res = True
else:
    res = True

if res:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 19964
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

//0-1 Knapsack: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_B
void printDP(const int n, const int c, vector<vector<int> >& dp){
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= c; j++) {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
}

int solve_a(const int n, const int c, const vector<int>& v, const vector<int>& w) {
    
    vector<vector<int>> dp(n + 1, vector<int>(c + 1, 0));
    
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= c; j++) {
            dp[i][j] = dp[i - 1][j];
            if (j >= w[i - 1]) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
            }
        }
    }
    //printDP(n, c, dp);
    return dp[n][c];
}

int solve_a_1(const int n, const int c, const vector<int>& v, const vector<int>& w) {
    vector<int> dp(c + 1, 0);
    for (int i = 0; i < n; i++) {
        for (int j = c; j > 0; j--) {
            if (j >= w[i]) {
                dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
            }
        }
    }
    return dp[c];
}

int solve_b(const int n, const int c, const vector<int>& v, const vector<int>& w) {
    
    vector<vector<int>> dp(n + 1, vector<int>(c + 1, 0));
    
    for (int i = n - 1; i >= 0; i--) {
        for (int j = 0; j <= c; j++) {
            dp[i][j] = dp[i + 1][j];
            if (j >= w[i]) {
                dp[i][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
            }
        }
    }
    //printDP(n, c, dp);
    return dp[0][c];
}

int solve_c_rec(int i, int j, vector<vector<int>>& dp,
        const vector<int>& v, const vector<int>& w) {
    if (i == 0 || j == 0) {
        return 0;
    }
    if (dp[i][j] != -1) {
        return dp[i][j];
    }
    int result = solve_c_rec(i - 1, j, dp, v, w);
    if (j >= w[i - 1]) {
        result = max(result, solve_c_rec(i - 1, j - w[i - 1], dp, v, w) + v[i - 1]);
    }
    dp[i][j] = result;
    return result;   
}

int solve_c(const int n, const int c, const vector<int>& v, const vector<int>& w) {
    vector<vector<int>> dp(n + 1, vector<int>(c + 1, -1));
    return solve_c_rec(n, c, dp, v, w);
}

int solve_d_rec(int i, int j, vector<vector<int>>& dp, const int n,
        const vector<int>& v, const vector<int>& w) {
    if (i == n || j == 0) {
        return 0;
    }
    if (dp[i][j] != -1) {
        return dp[i][j];
    }
    int result = solve_d_rec(i + 1, j, dp, n, v, w);
    if (j >= w[i]) {
        result = max(result, solve_d_rec(i + 1, j - w[i], dp, n, v, w) + v[i]);
    }
    dp[i][j] = result;
    return result;   
}

int solve_d(const int n, const int c, const vector<int>& v, const vector<int>& w) {
    vector<vector<int>> dp(n + 1, vector<int>(c + 1, -1));
    return solve_d_rec(0, c, dp, n, v, w);
}

int main() {
    int n, c;
    cin >> n >> c;
    vector<int> v(n, 0);
    vector<int> w(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> v[i] >> w[i];
    }
    int ans = solve_a_1(n, c, v, w);
    cout << ans << endl;
}

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

using namespace std;

int main(void){
	
	char Tar[16];
	
	while( scanf("%s", Tar) != EOF ){
		int n;
		int size = strlen(Tar);
		int ans = 0;
		
		scanf("%d", &n);
		for(int i = 0; i < n; i++){
			char str[32];
			scanf("%s", str);
			for(int j = 0;j < 10; j++){
				str[j+10] = str[j];
			}
			
			str[20] = '\0';
			
			
			int count=0;
			for(int j = 0; j < 21; j++){
				if(str[j] == Tar[count]){
					count++;
				}
				else {
					if(count != 0)j--;
					count = 0;
					continue;
				}
				if(count == size)break;
			}
			if(count == size){
			//	printf("find\n");
				ans++;
			}
		}
		
		printf("%d\n", ans);
	}
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int sx,sy,tx,ty; cin>>sx>>sy>>tx>>ty;
    int x = tx-sx;
    int y = ty-sy;
    rep(i,x) cout<<"R";
    rep(i,y) cout<<"U";
    rep(i,x) cout<<"L";
    rep(i,y) cout<<"D";
    cout<<"D";
    rep(i,x+1) cout<<"R";
    rep(i,y+1) cout<<"U";
    cout<<"L";
    cout<<"U";
    rep(i,x+1) cout<<"L";
    rep(i,y+1) cout<<"D";
    cout<<"R\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
const int ddx[4] = {1,1,-1, -1};
const int ddy[4] = {1,-1,-1,1};
//////////////////////////////////

int main(){
  int n; cin >> n;
  string s; cin >> s;
  vector<int> r(n+1, 0);
  vector<int> g(n+1, 0);
  vector<int> b(n+1, 0);
  for(int i=0; i<n; i++) {
    if (s[i] == 'R') r[i]++;
    if (s[i] == 'G') g[i]++;
    if (s[i] == 'B') b[i]++;
    if (i != 0) {
      r[i] += r[i-1];
      g[i] += g[i-1];
      b[i] += b[i-1];
    }
  }

  long long cnt = 0;
  for(int i=0; i<n; i++) {
    for(int j=i+1; j<n; j++) {
      if (s[i] == s[j]) continue;
      if ((s[i] == 'B' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'B')) {
        cnt += r[n-1] - r[j];
        if (j+j-i < n && s[j + j - i] == 'R') cnt--;
      }
      if ((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R')) {
        cnt += g[n-1] - g[j];
        if (j+j-i < n && s[j + j - i] == 'G') cnt--;        
      }
      if ((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')) {
        cnt += b[n-1] - b[j];
        if (j+j-i < n && s[j + j - i] == 'B') cnt--;
      }
    }
  }
  cout << cnt << endl;

}

// EOF


Measured memory_bytes: 3580
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void){
    
    int N;
    cin >> N;
    
    while(N != 0){
        if(N % 10 == 7){
            cout << "Yes" << endl;
            return 0;
        }
        N /= 10;
    }
    
    cout << "No" << endl;
}


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

typedef pair<int, int> P;
const int NO = -1;

int main() {
    int h, w;
    scanf("%d %d", &h, &w);

    char s[52][52];

    for (int i = 0; i < h; ++i) scanf("%s", s[i]);

    int d[52][52];

    for (int i = 0; i < 52; ++i) 
        for (int j = 0; j < 52; ++j) d[i][j] = NO;

    queue<P> que;
    que.push(P(0, 0));

    d[0][0] = 0;

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

    while (que.size() != 0) {
        P p = que.front();
        que.pop();
        for (int i = 0; i < 4; ++i) {
            int ni = p.first  + dy[i];
            int nj = p.second + dx[i];
            if (ni >= 0 && ni < h && nj >= 0 && nj < w && s[ni][nj] != '#' && d[ni][nj] == NO) {
                que.push(P(ni, nj));
                d[ni][nj] = d[p.first][p.second] + 1;
            }
        }
    }


    // for (int i = 0; i < 50; ++i) { 
    //     for (int j = 0; j < 50; ++j) { 
    //         printf("%3d", d[i][j]);
    //     }
    //     cout << endl;
    // }
    // cout << d[h-1][w-1] << endl;
    int r = d[h-1][w-1];
   if (r == -1) {
       cout << r << endl;
   } else {
       int count = 0;
       for (int i = 0; i < h; ++i) {
           for (int j = 0; j < w; ++j) {
               if (s[i][j] == '#') {
                   count += 1;
               }
           }
       }
       cout << h*w - count - r - 1 << endl;
   }
   return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        // for (int i = 0; i < n; i++) {
        // a[i] = 0;
        // }
        int[] b = new int[n - 1];
        for (int i = 0; i < n - 1; i++) {
            b[i] = sc.nextInt();
        }

        int ans = 0;
        a[0] = b[0];
        for (int i = 0; i < n - 1; i++) {
            a[i + 1] = Math.max(a[i], b[i]);
            if (i < n - 2) {
                a[i + 1] = Math.min(a[i + 1], b[i + 1]);// point
            }

        }

        for (int i = 0; i < n; i++) {
            ans += a[i];
        }
        System.out.println(ans);
        sc.close();
    }

}


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

int main()
{
  int a,b,c,k;
  scanf("%d %d %d %d",&a,&b,&c,&k);

  int res=0;
  res+=std::min(a,k);
  k-=a;
  if(k>0) k-=b;
  if(k>0) res-=std::min(k,c);
  printf("%d",res);
  return 0;
}

Measured memory_bytes: 3816
import sys
s=input()
k=int(input())
if(len(s)==1):
    print(s[0])
    sys.exit()
if(k==1):
    print(s[0])
    sys.exit()
c=0
for i in range(k):
    if(s[i]=='1'):c+=1
    else:break
if(c==k):
    print(1)
else:
    print(s[c])

Measured memory_bytes: 3064
import fractions
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
m=A[-1]
if m<K:
    print("IMPOSSIBLE")
else:
    ans=A[0]
    for i in range(1,N):
        ans=fractions.gcd(ans,A[i])
    if fractions.gcd(K,ans)==ans:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

Measured memory_bytes: 88172
s = input()
n = len(s)

ans = n
b = 1
for i in range(1, n):
    if s[i-1] == s[i]:
        b += 1
    else:
        ans -= (b+1) // 3
        if b % 3 == 2:
            b = 0
        else:
            b = 1
    # print(i,ans,b)

ans -= (b+1) // 3

print(ans)


Measured memory_bytes: 40304
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iterator>

int main(int argc, char const *argv[])
{
	int k, x;
	std::cin >> k >> x;

	if (500 * k >= x)
		std::cout << "Yes" << std::endl;
	else
		std::cout << "No" << std::endl;

	return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int pa = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'p') pa++;
    }
    cout << n / 2 - pa << endl;
}

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

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

const int N = (int) 1e5;
const int INF = (int) 1e9 + 7;

int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

	int a;
	sf("%d", &a);
	printf("%d\n", a + a * a + a * a * a);

	return 0;
}


Measured memory_bytes: 3824
#include <iostream>
#include <vector>
using namespace std;

void print(vector<int> a,int n){
  	for(int i=0;i<n;i++){
      if(i!=n-1) cout<<a.at(i)<<" ";
      if(i==n-1) cout<<a.at(i)<<endl;;      
    }
}

void insertsort(vector<int> a,int n){
	int target,hikaku;
  	for(int i=1;i<n;i++){
    	target=a.at(i);
      	hikaku=i-1;
      while(hikaku>=0 && a.at(hikaku)>target){
      	a.at(hikaku+1)=a.at(hikaku);
        hikaku--;
        a.at(hikaku+1)=target;
      }
       print(a,n);
    }
}

int main(){
	int n;cin>>n;
  	vector<int> a(n);
  	for(int i=0;i<n;i++) cin>>a.at(i);
  	print(a,n);
  	insertsort(a,n);
}


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

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long K = sc.nextLong();
		long[] input = new long[(int) N];
		for (int i = 0; i < N; i++) {
			input[i] = sc.nextLong();
		}
		Arrays.sort(input);
		long sum = 0;
		for (int i = 0; i < K; i++) {
			sum += input[i];
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 39104
#include <bits/stdc++.h>
using namespace std;
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }



int main() {
    const double PI = acos(-1.0);
    double a, b, x;
    cin >> a >> b >> x;
    x /= a;
    auto f = [&](double t) {
        // 前者
        if (tan(t) <= b/a) return a*b - a*(a*tan(t))/2;
        // 後者
        else return b*(b/tan(t))/2;
    };
    double left = 0, right = PI/2;
    for (int iter = 0; iter < 100; ++iter) {
        double theta = (left + right) / 2;
        if (f(theta) >= x) left = theta;
        else right = theta;
    }
    cout << fixed << setprecision(10) << left*180/PI << endl;
}

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

map<ll, ll> Prime(ll n)
{
  map<ll, ll> ret;
  if (n == 1)
  {
    ret[1]++;
    return ret;
  }
  ll a = 2;
  while (n >= a * a)
  {
    if (n % a == 0)
    {
      ret[a]++;
      n /= a;
    }
    else
    {
      a++;
    }
  }
  ret[n]++;
  return ret;
}




int main()
{
  int n;cin>>n;
  cout << n << ":";
  auto m = Prime(n);
  for (auto && a : m) {
    while (a.second--) {
      cout << " " << a.first ;
    }
  }
  cout << endl;
}



Measured memory_bytes: 3108
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

ll p2(ll i) {
  if (i == 0) return 1;
  if (i == 1) return 2;
  else {
    ll tmp = p2(i/2);
    if (i%2==1) return tmp*tmp*2;
    return tmp*tmp;
  }
}

int main() {
  ll a, b, c; cin >> a >> b >> c;
  if (a == b && b == c) {
    if (a % 2 == 0) cout << -1 << endl;
    else cout << 0 << endl;
    return 0;
  }
  ll tmp=a;
  ll ai=0, bi=0, ci=0;
  while (true) {
    if (tmp % 2 == 0) {
      tmp /= 2; ai++;
    } else break;
  }
  tmp = b;
  while (true) {
    if (tmp % 2 == 0) {
      tmp /= 2; bi++;
    } else break;
  }
  tmp = c;
  while (true) {
    if (tmp % 2 == 0) {
      tmp /= 2; ci++;
    } else break;
  }
  ll mini = min({ai, bi, ci});
  ll div = p2(mini);
  a /= div; b /= div; c /= div;
  if ((a+b)%2==0 && (a+c)%2==0 && (c+b)%2==0) mini++;
  cout << mini << endl;
  return 0;
}


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

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

const long long INF = 1LL << 60;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));

  int cnt = 0;
  REP(i, 0, n-3){
    REP(j, i+1, n-2 ){
      if(a[i] == a[j]) continue;
      REP(k, j+1, n-1){
        if(a[j] == a[k]) continue;
        if(a[i] + a[j] > a[k]) cnt++;
      }
    }
  }
  
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#define REP(i, a, b) for (auto i = (a); i < (b); ++i)
using namespace std;

const long long inf = 1e18;

struct edge {
	int a, b;
	long long cost;
};

signed main() {
	long long n, m, p; cin >> n >> m >> p;

	vector<edge> e(m);
	REP(i, 0, m) {
		long long a, b, c; cin >> a >> b >> c;
		e[i].a = a - 1;
		e[i].b = b - 1;
		e[i].cost = - c + p;
	}

	vector<long long> d(n, inf);
	d[0] = 0;
	for (int i = 0; i < 2 * n; ++i) {
		for (int j = 0; j < m; ++j)
            if (d[e[j].a] < inf) {
                if (d[e[j].b] > d[e[j].a] + e[j].cost) {
                    if (i < n)
                        d[e[j].b] = max(-inf, min(inf, d[e[j].a] + e[j].cost));
                    else
                        d[e[j].b] = -inf;
                }
        }
	}

	if (d[n - 1] == -inf) cout <<  -1;
	else cout << max(0LL, -d[n - 1]);
}


Measured memory_bytes: 764
A = list(map(int, input().split()))
A.sort()

def solve(a, b):
    if (b - a) % 2 == 0:
        return (b - a) // 2
    else:
        return (b - a + 1) // 2 + 1

ans = 0
if (A[2] - A[0]) % 2 == 1 and (A[2] - A[1]) % 2 == 1:
    A[2] -= 1
    ans += 1
ans += solve(A[0], A[2]) + solve(A[1], A[2])
print(ans)


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

int main()
{
	int a, b;
	char op;

	while (true)
	{
		cin >> a >> op >> b;
		if (op == '?') break;
		switch (op)
		{
		case '+':
			cout << a + b;
			break;
		case '-':
			cout << a - b;
			break;
		case '*':
			cout << a * b;
			break;
		case '/':
			cout << a / b;
			break;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3100
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <cmath>
#include <bits/stdc++.h> 
using namespace std;
int main(){
  string m1,m2,w;
  int N;
  getline(cin,m1);
  istringstream ss1(m1);
  ss1>>w;
  N=stoi(w);
  getline(cin,m2);
  istringstream ss(m2);
  do { 
        string word; 
        ss >> word; 
        if(word!="")
         N-=stoi(word); 
    } while (ss); 
  if(N<0){
    cout<<"-1"<<endl;}
  else{
    cout<<N<<endl;}
}

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

int main() {
  string s, t;
  cin >> s >> t;
  string t1, t2;

  for (int k = 0; k < (int)s.size(); k++) {
    if (s == t) {
      cout << "Yes" << endl;
      return 0;
    }
    t1 = s[(int)s.size() - 1];
    t2 = s.substr(0, (int)s.size() - 1);
    s = t1 + t2;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	for ( int i = 0; i < 3; i++ ) {

	    int fromH = stdin.nextInt();
	    int fromM = stdin.nextInt();
	    int fromS = stdin.nextInt();

	    int toH = stdin.nextInt();
	    int toM = stdin.nextInt();
	    int toS = stdin.nextInt();

	    int s = 0;
	    int m = 0;
	    int h = 0;
	    
	    if ( toS < fromS ) {
		toM -= 1;
		toS += 60;
	    }
	    s = toS - fromS;

	    if ( toM < fromM ) {
		toH -= 1;
		toM += 60;
	    }
	    m = toM - fromM;
	    h = toH - fromH;

	    System.out.printf( "%d %d %d\n", h, m, s );	    
	}	
    }    
}

Measured memory_bytes: 17192
N = int(input())
p = list(map(int, input().split()))
s = sorted(p)
cnt = 0
ans = 'YES'

for (pi, si) in zip(p, s):
    if pi != si:
        cnt += 1

if cnt != 0 and cnt != 2:
    ans = 'NO'

print(ans)


Measured memory_bytes: 38384
i = gets.chomp.to_i
arr = gets.chomp.split(" ").map(&:to_i)
ans = 0
(i-2).times{|t|
if arr[t] > arr[t+1] and arr[t+1] > arr[t+2] then
    ans += 1
elsif arr[t] < arr[t+1] and arr[t+1] < arr[t+2] then
    ans += 1
end
}
print ans

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

const int MAX_N = 1 << 18;
const int INF = 1 << 25;
const ll def = -(1LL << 62);

struct MaxSegTree{
	int n;
	ll dat[2 * MAX_N - 1];
	void init(int n_){
		n = 1;
		while(n < n_) n *= 2;
		for(int i = 0; i < 2 * n - 1; i++) dat[i] = -def;
	}

	void update(int k, ll a){
		k += n - 1;
		dat[k] = a;
		while(k > 0) k = (k - 1) / 2, dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
	}

	ll query(int a, int b){ return query(a, b, 0, 0, n); }

	ll query(int a, int b, int k, int l, int r){
		if(r <= a || b <= l) return def;
		if(a <= l && r <= b) return dat[k];
		ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return max(vl, vr);
	}

	void show(){
		for(int i = 0; i < n; i++) cout << dat[i + n - 1] << " ";
		cout << endl;
	}
} st;

ll x[200000];
ll s[200010];
ll sum[200010];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int N;
	cin >> N;

	st.init(N);
	for(int i = 0; i < N; i++){
		cin >> x[i] >> s[i];
		sum[i + 1] = sum[i] + s[i];
		ll a = sum[i + 1] - x[i];
		//cout << a << endl;
		st.update(i, a);
	}

	ll ans = 0;
	for(int i = 0; i < N; i++){
		ll r = st.query(i, N) + x[i] - sum[i];
		ans = max(ans, r);
	}
	cout << ans << endl;
}


Measured memory_bytes: 9088
#include<stdio.h>
int n, s, tmp;
int main(){
  scanf("%d", &n);
  s=0;
  for (int i=0;i<n;i++){
    scanf("%d", &tmp);
    s += (tmp & 1);
  }
  if (s&1){
    printf("NO\n");
  }
  else{
    printf("YES\n");
  }
  return 0;
}

Measured memory_bytes: 1636
function Main(input)
{
	input = parseInt(input);
	var canBeCaluculated = "No";
	var calucResultNumbers = new Set();

	for (i = 1; i <= 9; i++)
	{
		for (j = 1; j <= 9; j++)
		{
			calucResultNumbers.add(i*j)
		}
	}

	if (calucResultNumbers.has(input))
	{
		canBeCaluculated = "Yes";
	}

	console.log(canBeCaluculated)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define PI 3.1415926535

int main() {
    ll a, b;
    cin >> a >> b;
    ll i = 0;
    while(1){
        if(i * (a - 1) + 1 >= b){
            cout << i << endl;
            break;
        }
        i++;
    }

    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

struct UnionFind {
    // par[i]:iの親の番号　(例) par[3] = 99 : 3の親が99
    vector<int> par;

    UnionFind(int N) : par(N) {  // 初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    void print(){
       for (int i = 0; i < par.size(); i++)
            printf("par[%d] = %d\n",i, par[i]);
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {  // xとyの木を併合
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(){
        int N = par.size();
        set<int> s;
        for (int i = 0; i < N; i++) {
            s.insert(root(i));
        }
        return s.size();
    }
};

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

    UnionFind uf(N);
    
    vec<int> p(N);
    rep(i, N) {
        cin >> p[i];
        --p[i];
    }
    
    vec<int> x(M), y(M);
    rep(i, M) {
        cin >> x[i] >> y[i];
        --x[i],--y[i];
        uf.unite(x[i],y[i]);
    }

    int ans = 0;
    rep(i,N){
        uf.same(i,p[i]) && ++ans;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 4848
#include<bits/stdc++.h>
#define LL long long
#define INF 1e10

using namespace std;

LL ans, N, A, B;
vector<LL> h;

bool f(LL K){
    LL res = 0;
    for(int i = 0; i < N; ++i){
        LL remain = h[i] - B * K;
        if(remain > 0) res += (remain + A - B - 1) / (A - B);
    }
    return res <= K;
}

LL meguru_search(LL ok, LL ng){
    while(abs(ok - ng) > 1){
        LL mid = (ok + ng) / 2;
        if(f(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main(){
    cin >> N >> A >> B;
    h = vector<LL>(N);
    for(int i = 0; i < N; ++i) cin >> h[i];
    ans = meguru_search(INF, 0);
    cout << ans << endl;
}

Measured memory_bytes: 1024
H,W = map(int,input().split())

if H%3 == 0 or W%3 == 0:
    print(0)
else:
    if H<W:H,W = W,H
    ans = W
    S1 = 0
    for i in range(1,H+1):
        S1 += W
        S2 = (H-i) * (W//2)
        S3 = (H-i) * (W-W//2)
        tmp = max(S1,S2,S3)-min(S1,S2,S3)
        ans = min(ans,tmp)
        
    H,W = W,H
    ans = min(ans,H)
    S1 = 0
    for i in range(1,H+1):
        S1 += W
        S2 = (H-i) * (W//2)
        S3 = (H-i) * (W-W//2)
        tmp = max(S1,S2,S3)-min(S1,S2,S3)
        ans = min(ans,tmp)
    
    
    print(ans)

Measured memory_bytes: 40432
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1)/*v1の後ろにv2を入れる*/)
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);



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

	int a, b, c;
	cin >> a >> b >> c;
	if (a + b + c == 17)cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
from itertools import permutations
import math


def submit():
    n = int(input())
    positions = {i: tuple(map(int, input().split())) for i in range(n)}
    cities = [i for i in range(n)]
    
    dists = {}
    for i in cities[:-1]:
        for j in cities[i + 1:]:
            pi = positions[i]
            pj = positions[j]
            d = math.sqrt((pi[0] - pj[0]) ** 2 + (pi[1] - pj[1]) ** 2)
            dists[(i, j)] = d
            dists[(j, i)] = d

    path_count = 0
    path_sum = 0
    for p in permutations(cities):
        d = 0
        for i in range(n - 1):
            d += dists[(p[i], p[i + 1])]
        path_sum += d
        path_count += 1

    print(path_sum / path_count)


if __name__ == "__main__":
    submit()

Measured memory_bytes: 3064
/*
 * main.c
 *
 *  Created on: 2020/07/28
 *      Author: 113896
 */
#include <stdio.h>
#include <string.h>

#define BSIZE 2000

int main() {

	char buffer[BSIZE];

	int total = 0;
	while (1) {
		fgets(buffer, BSIZE, stdin);
		int length = 0;
		while (buffer[length] != '\0') {
			length++;
		}
		char num[length+1];
		strncpy(num, buffer, length+1);
		if (strcmp(num, "0\n\0") == 0) break;
		total = 0;
		char c;
		for (int i = 0; i < length; i++) {
			c = num[i];
			if (c >= '0' && c <= '9') {
				total += num[i] - '0';
			}
		}
		printf("%d\n", total);
		memset(buffer, '\0', BSIZE * sizeof(char));
	}

	return 0;
}




Measured memory_bytes: 2136