akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
#define INF           1e16
#define REP(i,n)      for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)     for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)     for(lint i=n-1;i>=0;--i)
#define REPR1(i,n)    for(lint i=n;i>0;--i)
#define REPI(i,ini,n) for(lint i=(ini),i##_len=(n);i<i##_len;++i)
#define REPC(i,obj)   for(auto i:obj)
#define R_UP(a,b)     (((a)+(b)-1)/(b))
#define ALL(obj)      (obj).begin(),(obj).end()
signed main()
{
	int n; scanf("%d", &n);
	list<int>l;
	REP(i, n)
	{
		char cmd[12]; scanf("%s", cmd);
		if (!strcmp(cmd, "insert"))
		{
			int num; scanf("%d", &num);
			l.push_front(num);
		}
		else if (!strcmp(cmd, "delete"))
		{
			int num; scanf("%d", &num);
			auto itr = find_if(l.begin(), l.end(), [num](int n) {return n == num; });
			if (itr != l.end())l.erase(itr);
		}
		else if (!strcmp(cmd, "deleteFirst"))l.pop_front();
		else l.pop_back();
	}
	REP(i, l.size())
	{
		static auto itr = l.begin();
		if (i != 0)printf(" ");
		printf("%d", *itr++);
	}
	printf("\n");
}


Measured memory_bytes: 34448
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	ll n,m,mod=1e9+7;
	cin>>n>>m;
	if(abs(n-m)>1){
		return cout<<"0\n",0;
	}
	ll res=1;
	for(ll i=1;i<=n;++i) res=res*i%mod;
	for(ll i=1;i<=m;++i) res=res*i%mod;
	if(n==m) res=res*2LL%mod;
	cout<<res<<'\n';
}



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

ll n,a[55],ind1,ind2,m1,m2;

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

    cin>>n;
    for(ll i=0;i<n;i++)
        cin>>a[i];

    for(ll i=0;i<n;i++)
        if(a[i]>0)
        {
            ind1=1;
            if(a[i]>=a[m1])
                m1=i;
        }
    for(ll i=0;i<n;i++)
        if(a[i]<0)
        {
            ind2=1;
            if(a[i]<=a[m2])
                m2=i;
        }
    if(ind1==1&&ind2==0)
    {
        cout<<n-1<<endl;
        for(int i=1;i<n;i++)
            cout<<i<<" "<<i+1<<endl;
        return 0;
    }
    if(ind1==0&&ind2==1)
    {
        cout<<n-1<<endl;
        for(int i=n-1;i>0;i--)
            cout<<i+1<<" "<<i<<endl;
        return 0;
    }
    if(ind1==0&&ind2==0)
    {
        cout<<0<<endl;
        return 0;
    }
    ll m=a[m2],M=a[m1];

    //cout<<M<<m<<endl;
    m1++; m2++;

    if(M>=(-1)*m)
    {
        cout<<2*n-1<<endl;
        for(ll i=1;i<=n;i++)
            if(i!=m1)
                cout<<m1<<" "<<i<<endl;
        cout<<m1<<" "<<m1<<endl;
        for(int i=1;i<n;i++)
            cout<<i<<" "<<i+1<<endl;
        return 0;
    }
    else
    {
        cout<<2*n-1<<endl;
        for(ll i=1;i<=n;i++)
            if(i!=m2)
                cout<<m2<<" "<<i<<endl;
        cout<<m2<<" "<<m2<<endl;
        for(int i=n-1;i>0;i--)
            cout<<i+1<<" "<<i<<endl;
        return 0;
    }

    return 0;
}


Measured memory_bytes: 3656
/// You just can't beat the person who never gives up
/// ICPC next year

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
using namespace std ;
const int N = 2e5+5 ;

int n ,k ,a[N] ;
long long cum[N] ,pos[N] ;
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;++i){
        scanf("%d",a+i);
        if(a[i]>0) pos[i] = a[i] + pos[i-1] ;
        else pos[i] = pos[i-1] ;
        cum[i] = a[i] + cum[i-1] ;
    }
    long long ans = 0 ;
    for(int i=1;i+k-1<=n;++i){
        long long curpos = pos[i+k-1] - pos[i-1] ;
        long long allpos = pos[n] ;
        long long cursum = cum[i+k-1] - cum[i-1] ;
       // cout << i << " " << i+k-1 << " " << allpos << " " << curpos << " " << cursum << endl ;
        ans = max(ans ,allpos-curpos);
        ans = max(ans ,cursum + allpos-curpos);
    }
    printf("%lld\n",ans);
    return 0;
}


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

typedef long long ll;

vector<int> denom;
int dp[1000001];

void idk(){
    denom.push_back(1);
    int x=6;
    while(x<100000){
        denom.push_back(x);
        x*=6;
    }
    x=9;
    while(x<100000){
        denom.push_back(x);
        x*=9;
    }
    sort(denom.begin(), denom.end());
    for(x=0; x<1000001; x++) dp[x]=-1;
}

int findMin(int i) {
    if(dp[i] == -1) {
        if(i == 0) dp[i] = 0;
            else {
            int best = 1000000;
            for(int d : denom){
                if(i - d >= 0){
                    best = min(best, 1+findMin(i - d));
                    dp[i] = best;
                }
            }
        }
    }
    return dp[i];
}

int main(){
    idk();
    int n, i; cin>>n;
    cout<<findMin(n);
}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    long long int a_sum[n] = {};
    cin >> a_sum[0];
    for(int i = 1;i < n;i++)
    {
        long long int a;
        cin >> a;
        a_sum[i] = a_sum[i - 1] + a;
    }
    long long int mini = LLONG_MAX;
    for(int i = 0;i < n - 1;i++)
    {
        if(fabs(a_sum[n - 1] - 2 * a_sum[i]) < mini)
        {
            mini = fabs(a_sum[n - 1] - 2 * a_sum[i]);
        }
    }
    cout << mini;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, const char* argv[]) {

    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    int ans;
    string S;
    cin >> S;
    bool p = S[0] == 'R';
    bool q = S[1] == 'R';
    bool r = S[2] == 'R';

    if (p && q && r) {
        cout << 3 << endl;
    }
    else if ((p && q) || (q && r)) {
        cout << 2 << endl;
    }
    else if (p || q || r) {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }

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

    return 0;
}

Measured memory_bytes: 3588
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    let mut s: String = read();
    let mut c = 'C';
    while !s.is_empty() {
        let char = s.pop().unwrap();
        if c == char {
            if c == 'C' {
                c = 'A';
                continue;
            } else {
                println!("Yes");
                return;
            }
        }
        c = 'C';
    }
    println!("No")
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
using namespace std;
string S; bool jdg = true;
int main() {
    cin >> S;
    for(int i = 0; i < S.length(); ++i) {
        if((i%2==0 && S[i]=='L') || i%2==1 && S[i]=='R') {
            jdg = false;
            break;
        }
    }
    cout << (jdg?"Yes":"No");
}

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

int main() {
  int a,b;
  cin>>a>>b;
  vector<int> vec{1,3,5,7,8,10,12};
  vector<int> pax{4,6,9,11};
  vector<int> tax{2};
  int cou=0;int pau=0;int tau=0;
  rep(i,7){
    if(vec.at(i)==a||vec.at(i)==b){
      cou++;
    }
  }
  rep(i,4){
    if(pax.at(i)==a||pax.at(i)==b){
      pau++;
    }
  }
  if(cou==2||pau==2){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<string,int>;
using T = tuple<string,int,int>;

int main(){
  int n; cin >> n;
  vector<int> p(n);
  for(int i = 0; i < n; i++) cin >> p[i];
  int ans = 0;
  for(int i = 1; i < n-1; i++){
    if(p[i-1] < p[i] && p[i] < p[i+1]) ans++;
    else if(p[i-1] > p[i] && p[i] > p[i+1]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <string>
using namespace std;
int main(void){
    string a,b,c;
    cin >> a >>b;
    c=a+b;
    int d=stoi(c);
    int s=0,i=0;
    while(d>s){
        s+=2*i+1;
        i++;
        if(d==s){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

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

#if DEBUG && !ONLINE_JUDGE
  #include "header.h"
#else
  #define debug(args...)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long lli;
typedef long double ld;

#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(auto i=(a);i<b;i++)

#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
void preprocess(void) {
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  preprocess();
  int n; cin>>n;
  vi a(n), b(n), c(n-1);
  rep(i,0,n) cin>>a[i];
  rep(i,0,n) cin>>b[i];
  rep(i,0,n-1) cin>>c[i];
  int ans = 0;
  rep(i,0,n) {
    if(i == n-1) {
      ans += b[a[i]-1];
      //debug(b[a[i]-1]);
    }
    else {
      ans += b[a[i]-1];
      //debug(b[a[i]-1]);
      if(a[i]+1 == a[i+1]) {
        ans += c[a[i]-1];
      }
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
     int n;
     cin >> n;int count=0;int ans=0;int a[100];int b[100];
     if(n>=1 && n<=100)
     {
         for(int i=0;i<n;i++)
         {
             cin >> a[i];
             if(a[i]>=1 && a[i]<=1000)
             {
                 if(a[i]%2==0)
                 {
                     
                    b[count]=a[i];
                    count++;
                 }
             }
             
         }
         for(int j=0;j<count;j++)
         {
             if(b[j]%3==0 || b[j]%5==0)
             {
                 ans++;
             }
         }
         if(ans==count)
         {
             cout << "APPROVED" << endl;
         }
         else
         {
             cout << "DENIED" << endl;
         }
     }
     
     
  
    
     
}

Measured memory_bytes: 256
if __name__ == '__main__':
    N = int(input())
    L = sorted(map(int, input().split()))
    ret = 0
    for adx in range(N):
        cdx = adx
        for bdx in range(adx + 1, N):
            while cdx < N and L[cdx] < L[bdx] + L[adx]: cdx += 1
            ret += cdx - (bdx + 1)
    print(ret)

Measured memory_bytes: 42460
x, k, d = map(int, input().split())

lo = 0
hi = k

while (lo < hi) :
  mid = lo + (hi - lo) // 2 + 1
  if (x >= 0) :
    if (x - mid * d >= 0) : 
      lo = mid;
    else :
      hi = mid - 1
  else :
    if (x + mid * d <= 0) :
      lo = mid;
    else :
      hi = mid - 1;

if (x >= 0) :
  x -= d * hi
else :
  x += d * hi

k -= hi;

if ( (k % 2) == 0):
  print(abs(x))
else :
  print(min(abs(x - d), abs(x + d)))


Measured memory_bytes: 61924
#include<iostream>

using namespace std;
int main(){
	int n = 0;
	int m = 0;
	int A [105][105];
	int B [105];
	int s = 0;
	cin >> n >> m;
	
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			cin >> A[i][j];
		}
	}
	for (int j = 0; j < m; j++){
		cin >> B[j];
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			s = A[i][j] * B[j] + s;
		}
		cout << s << endl;
		s = 0;
	}
}

Measured memory_bytes: 3112
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>

const int N = 1e5 + 100 ;

using std::cin ;
using std::cout ;

char s[N] ;
int n , ans , v[N] , cnt ;

int main () {
  	std::ios::sync_with_stdio(false);
  	cin >> n >> s ;
  	for (int i = n - 1 ; ~ i ; -- i) s[i+1] = s[i] ;
  	for (int i = 1 ; i <= n ; ++ i)
      	if ( s[i] == s[i-1] ) v[i] = cnt ;
  		else v[i] = ++ cnt ;
  	ans = std::unique ( v + 1 , v + n + 1 ) - v - 1 ;
  	cout << ans << "\n" ;
  	return 0 ;
}

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

const int inf = (1 << 28);

struct Network {
    struct Arc {
        int from, to, cap, cost, rev;
        Arc() {}
        Arc(int from, int to, int cap, int cost, int rev) :
            from(from), to(to), cap(cap), cost(cost), rev(rev) {}
    };

    int n;
    vector<vector<Arc>> graph;

    Network(int n = 0) : n(n), graph(n) {}

    void addArc(int from, int to, int cap) {
        graph[from].emplace_back(from, to, cap, 0, graph[to].size());
        graph[to].emplace_back(to, from, 0, 0, graph[from].size() - 1);
    }

    int findBlockingFlow(vector<Arc*>& hist, int s, int t) {
        vector<int> dist(n, inf), limit(n, inf);
        fill(hist.begin(), hist.end(), nullptr);

        queue<int> que;
        dist[s] = 0;
        que.push(s);

        while (!que.empty()) {
            int u = que.front(); que.pop();

            for (Arc& arc : graph[u]) {
                if (dist[arc.to] > dist[u] + 1 and arc.cap > 0) {
                    dist[arc.to] = dist[u] + 1;
                    hist[arc.to] = &arc;
                    limit[arc.to] = min(limit[u], arc.cap);
                    que.push(arc.to);

                    if (arc.to == t) break;
                }
            }
        }
        return limit[t];
    }

    int findMaximumFlow(int s, int t) {
        vector<Arc*> hist(n, nullptr);
        int sumFlow = 0, flow;

        while (flow = findBlockingFlow(hist, s, t), hist[t] != nullptr) {
            Arc* flowPtr = hist[t];
            while (flowPtr != nullptr) {
                flowPtr->cap -= flow;
                graph[flowPtr->to][flowPtr->rev].cap += flow;
                flowPtr = hist[flowPtr->from];
            }
            sumFlow += flow;
        }
        return sumFlow;
    }

    int findMinimumCut(int s, int t) {
        return findMaximumFlow(s, t);
    }

};

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

    int n, m;
    cin >> n >> m;

    Network network(n);
    for (int i = 0; i < m; i++) {
        int u, v, c;
        cin >> u >> v >> c;
        network.addArc(u, v, c);
    }
    cout << network.findMaximumFlow(0, n - 1) << endl;

    return 0;
}


Measured memory_bytes: 3200
#include <cstdio>

using namespace std;

bool side(double a, double b, double c, double d) {
  return a * d - b * c >= 0;
}

int main() {
  double x1, y1, x2, y2, x3, y3, xp, yp;
  while (scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3, &xp, &yp) == 8) {
    if (side(x2-x1, y2-y1, x3-x1, y3-y1) == side(x2-x1, y2-y1, xp-x1, yp-y1) &&
        side(x3-x2, y3-y2, x1-x2, y1-y2) == side(x3-x2, y3-y2, xp-x2, yp-y2) &&
        side(x1-x3, y1-y3, x2-x3, y2-y3) == side(x1-x3, y1-y3, xp-x3, yp-y3))
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}

Measured memory_bytes: 0
f(int*a,int*b){return*a-*b;}
a[1<<17];buf[300000];char*p=buf;
i;
s=1e9;
l,r;
main(){
	read(0,buf,1100000);
	for(;*p;p+=1)
	{
		if(*p=='-')r=1;
		else if(*p<48)a[i]=r?-a[i]:a[i],i++,r=0;
		else a[i]=a[i]*10+*p-48;
	}
	qsort(a+2,a[0],4,f);
	for(i=0;i<=a[0]-a[1];i+=1)
	{
		l=a[i+2]>0?0:-a[i+2];
		r=a[i+a[1]+1]<0?0:a[i+a[1]+1];
		r+=r<l?r:l;
		s=s<r+l?s:r+l;
	}
	printf("%d",s);
}


Measured memory_bytes: 1660
W, H = map(int, input().split())
a = []
for i in range(W):
    a.append(list(input()))
ans = "Yes"
for j in range(W):
  for k in range(H):
    if a[j][k] == "#":
       if j == 0:
          if k == 0:
           if a[j][k+1]  == "#":
              continue
           elif a[j+1][k]  == "#":
              continue
           else:
              ans = "No"
              break 
          elif  k == H-1:
           if a[j][k-1] == "#":
              continue
           elif a[j+1][k]  == "#":
              continue
           else:
              ans = "No"
              break 
       elif j == W-1:
          if k == 0:
           if a[j][k+1]  == "#":
              continue
           elif a[j-1][k]  == "#":
              continue
           else:
              ans = "No"
              break 
          elif  k == H-1:
           if a[j][k-1] == "#":
              continue
           elif a[j-1][k]  == "#":
              continue
           else:
              ans = "No"
              break 
          else:
           if a[j][k-1] == "#":
              continue
           elif a[j][k+1]  == "#":
              continue
           elif a[j-1][k]  == "#":
              continue
           else:
              ans = "No"
              break
       elif k == 0:
         if a[j][k+1]  == "#":
            continue
         elif a[j-1][k]  == "#":
            continue
         elif a[j+1][k]  == "#":
            continue
         else:
            ans = "No"
            break 
       elif k == H-1:
         if a[j][k-1] == "#":
            continue
         elif a[j-1][k]  == "#":
            continue
         elif a[j+1][k]  == "#":
            continue
         else:
            ans = "No"
            break           
       else:
           if a[j][k-1] == "#":
              continue
           elif a[j][k+1]  == "#":
              continue
           elif a[j-1][k]  == "#":
              continue
           elif a[j+1][k]  == "#":
              continue
           else:
              ans = "No"
              break 
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) {
        cin >> A[i];
    }
    SORT(A);
    vector<P> res;
    REP(i, N - 2) {
        if (A[i + 1] < 0) {
            res.emplace_back(A.back(), A[i]);
            A.back() -= A[i];
        } else {
            res.emplace_back(A[i], A[i + 1]);
            A[i + 1] = A[i] - A[i + 1];
        }
    }
    res.emplace_back(A.back(), A[N - 2]);
    A.back() -= A[N - 2];
    cout << A.back() << endl;
    REP(i, N - 1) {
        cout << res[i].first << " " << res[i].second << endl;
    }

    return 0;
}


Measured memory_bytes: 4672
module Main where
import Data.List

int = read::String -> Int
main = interact $ printer . solver . parser

printer = unlines . (:[]) . show
parser = words

solver :: [String] -> Int
solver [ns, (s11:s1s), (s21:s2s)] = result
  where
    n = int ns
    result = 
      if s11==s21 
      then sweep (s11:s1s) (s21:s2s) 3
      else sweep (s1s) (s2s) 6

sweep (s11:[]) (s21:[]) pattern = pattern
sweep (s11:s12:s1s) (s21:s22:s2s) pattern
  | s11 == s21 && s12 == s22 = sweep (s12:s1s) (s22:s2s) (mod (2*pattern) 1000000007 )
  | s11 == s21 && s12 /= s22 = sweep (s1s) (s2s) (mod (2*pattern) 1000000007 )
  | s11 /= s21 && s12 == s22 = sweep (s12:s1s) (s22:s2s) (pattern)
  | s11 /= s21 && s12 /= s22 = sweep (s1s) (s2s) (mod (3*pattern) 1000000007 )
  


Measured memory_bytes: 508
#include <iostream>
#include <vector>
#include <set>
#include <queue>
using namespace std;

// incomplete

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

	int n;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; ++i) cin >> s[i];

	int res = 0;

	for (int i = 0; i < n; ++i) {
		vector<int> set_id(n, 0);
		bool failed = false;

		queue<int> q;
		q.push(i);
		set_id[i] = 1;
		int cres = 1;

		while (!q.empty()) {
			int curr = q.front();
			q.pop();

			for (int i = 0; i < n; ++i) {
				if (s[curr][i] == '1') {
					if (set_id[i] == 0) {
						set_id[i] = set_id[curr] + 1;
						cres = max(cres, set_id[i]);
						q.push(i);
					} else {
						for (int j = 0; j < n; ++j) {
							if (s[i][j] == '1') {
								if ((set_id[j] != 0) && (abs(set_id[i] - set_id[j]) != 1)) {
									failed = true;
									break;
								}
							}
						}
						if (failed) break;
					}
				}
			}
		}

		if (failed) continue;
		res = max(res, cres);
	}


	if (res == 0)
		cout << "-1\n";
	else
		cout << res << "\n";

	return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int k = Integer.parseInt(in.next());
            int x[] = new int[n];
            for (int i = 0; i < n; i++) {
                x[i] = Integer.parseInt(in.next());
            }
            int ans = 0;

            for (int i = 0; i < n; i++) {
                int tmp = Math.min(x[i] * 2, Math.abs(k - x[i]) * 2);
                ans += tmp;
            }
            // 出力
            out.println(ans);

        }

    }
}



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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for (int i = 0; i < n; i++) cin >> p[i];
  sort(p.begin(), p.end());
  int gokei = 0;
  for (int i = 0; i < k; i++) gokei += p[i];
  cout << gokei;
}

Measured memory_bytes: 3600
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  int n;
  string s,t;
  cin >> n>>s>>t;
  
  vector<string> p={t};
  repo(i,n+1){
    string x=s.substr(0,i)+t;
    p.pb(x);
  }
  
  for(auto x : p){
    if(x.substr(0,n)==s) {
    cout << x.size() << endl;
    return 0;
    }
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
constexpr int P = 1000000007;
void increase(int &a, int b) {(a += b) >= P ? a -= P : 0;}
void decrease(int &a, int b) {(a -= b) < 0 ? a += P : 0;}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> match(2 * n, -1), g(2 * n + 1), s(2 * n + 1, 1);
    s[0] = 0;
    g[0] = 1;
    for (int i = 2; i <= 2 * n; i += 2)
        g[i] = 1LL * g[i - 2] * (i - 1) % P;
    int k;
    cin >> k;
    for (int i = 0; i < k; ++i) {
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        match[x] = y;
        match[y] = x;
        s[x + 1] = s[y + 1] = 0;
    }
    for (int i = 1; i <= 2 * n; ++i)
        s[i] += s[i - 1];
    int ans = 0;
    vector<int> dp(2 * n);
    for (int i = 0; i < 2 * n; ++i) {
        fill(dp.begin(), dp.end(), 0);
        for (int j = i, mx = -1; j < 2 * n; ++j) {
            if (match[j] != -1) {
                if (match[j] < i)
                    break;
                mx = max(mx, match[j]);
            }
            if (j < mx)
                continue;
            int x = s[j + 1] - s[i];
            int y = 2 * (n - k) - x;
            if (x % 2 == 1)
                continue;
            dp[j] = g[x];
            for (int k = i; k < j; ++k)
                decrease(dp[j], 1LL * dp[k] * g[s[j + 1] - s[k + 1]] % P);
            increase(ans, 1LL * dp[j] * g[y] % P);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
  int i, n, k, begin, end, mid;
  int *a;
  char buf[12];
  fscanf(stdin, "%d\n", &n);
  a = (int*)malloc(sizeof(int)*n);
  for (i=0; i<n; i++)
    fscanf(stdin, "%d", &a[i]);
  fgets(buf, 12, stdin);
  fgets(buf, 12, stdin);
  while (fgets(buf, 12, stdin)) {
    k = atoi(buf);
    begin = 0;
    end = n-1;
    while (begin<=end) {
      mid = (begin+end)/2;
      if (a[mid]==k) {
        putc_unlocked('1', stdout);
        putc_unlocked('\n', stdout);
        goto next;
      }
      if (k<a[mid])  end = mid - 1;
      else  begin = mid + 1;
    }
    putc_unlocked('0', stdout);
    putc_unlocked('\n', stdout);
  next:
    ;
  }
  return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int n;
    long double a,ans=0;
    cin >> n;
    rep(i,n){
        cin >> a;
        ans+=(1/a);
    }
    
    cout << fixed << setprecision(12) << (long double)1/ans;
    
	return 0;
}

Measured memory_bytes: 3788
//B - Theater: 
//Assunto: 
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n, l, r, ans = 0;
    cin >> n;
    while(n--) {
        cin >> l >> r;
        ans += (r - l) + 1;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
/*
string subs(string s,int a,int b)
{
    string s1="";

    for(int i = a; i < b; i++)
        s1 = s1 + s[i];

    return s1;
}
vector<string> palindromic(string s)
{
    vector<string> v ;

    for (float i = 0; i < s.length();
                                 i += .5)
    {
        float Radius = i -(int)i;
        while ((i + Radius)
         < s.length() && (i - Radius)
         >= 0 && s[((int)(i - Radius))]
             == s[((int)(i + Radius))])
        {

    v.push_back(subs(s,(int)(i -Radius), (int)(i + Radius + 1)));

         Radius++;
        }
    }

    return v;
}
int main(){

        string g;
         char str[100000];
           cin>>str;

         for(int i=0;str[i]!='\0';i++)
             g.append(1,str[i]);

       vector<string> vect = palindromic(g);

         cout<<vect.size();
}*/
int main(){

      int n;
       cin>>n;

       ll arr[n];
        for(int i=0;i<n;i++)
          cin>>arr[i];

          vector<int>vect;

          for(int i=0;i<n;i++)
          {
             if(i==0)
             vect.push_back(0);

             else
             {
                int prev_total = vect[i-1] + arr[i-1];

                  if(arr[i] >= prev_total)
                  vect.push_back(0);

                  else
                  vect.push_back(prev_total - arr[i]);
             }
          }
           ll sum = 0;
           for(int i=0;i<vect.size();i++)
             sum+=vect[i];

            cout<<sum;
}

Measured memory_bytes: 5800
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,a,b;
  cin>>n>>a>>b;
  if(n<3){
    cout<<(n==1&&a!=b?0:1)<<endl;
    return 0;
  }
  n-=2;
  cout<<(a>b?0:n*b-n*a+1)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!


void solve(){
    int n;
    cin>>n;
    int d,r;
    cin>>d>>r;
    
    int ans=r;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        ans+=ceil((double)d /x);
        // cout<<x<<" "<<ceil(d/x)<<" "<<ceil((double)d /x)<<endl;
    }
    cout<<ans<<endl;
}

int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>

int main(){
	int j,s_length = 0;
	char s[101],p[101];
	scanf("%s",s);
	scanf("%s",p);

	for(int i = 0; s[i] != '\0';i++) s_length++;

	for(int left = 0;s[left] != '\0';left++){
		for(j = 0;p[j] != '\0' && p[j] == s[(left+j)%s_length];j++);
		if(p[j] == '\0'){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 2700
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int MAXN=100010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans;
int A[MAXN];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for (int i=1; i<=n; i++) cin>>A[i];
	sort(A+1, A+n+1);
	if (A[1]==A[n]){
		if (A[1]==n-1 || A[1]<=n/2) kill("Yes")
		kill("No")
	}
	if (A[1]+1!=A[n]) kill("No")
	
	for (int i=1; i<=n; i++) x+=(A[1]==A[i]);
	if (A[1]<x || x+(n-x)/2<A[n]) kill("No")
	kill("Yes")
	
	return 0;
}


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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
//   cout<<std::setprecision(12)<<
int par[300000];
int siz[300000];
int fin[300000];
int _findp(int x)
{
    if(x == par[x])return x;

    return par[x] = _findp(par[x]);
}
void _union(int u,int v)
{
    int a,b;
    a = _findp(u);
    b = _findp(v);

    if(a == b)return;

    if(siz[a] < siz[b])swap(a,b);

    par[b] = a;
    siz[a] += siz[b];

    return;
}
int main()
{
    int i,j,k,l,m,u,v,n;



    cin >> n >> m >> k;

    set<int>st[n+10];
    for(i=1;i<=n;i++)par[i] = i,siz[i]=1;

    while(m--)
    {
        cin >> u >> v;

        _union(u,v);

        st[u].insert(v);
        st[v].insert(u);
    }

    for(i=1;i<=n;i++)
    {
        l = _findp(i);

        fin[i] = siz[l] - 1  - st[i].size();
    }

    while(k--)
    {
        cin >> u >> v;

        if(_findp(u) == _findp(v))
        {
            fin[u]--;
            fin[v]--;
        }
    }

    for(i=1;i<=n;i++)
    {
       cout<<fin[i]<<" ";
    }

    cout<<endl;
}


Measured memory_bytes: 16000
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
if a[0]>=x:
    ans+=a[0]-x
    a[0]=x
for i in range(n-1):
    if a[i]+a[i+1]>=x:
        ans+=a[i]+a[i+1]-x
        a[i+1]=x-a[i]
    # print(a)
print(ans)

Measured memory_bytes: 63856
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N);
    for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  
  if (N < 3) {
  	cout << 0 << endl;
    return 0;
  } else {
  	int count = 0;
    
    for (int i = 0; i < N; i++) {
      for (int j = i+1; j < N; j++) {
      	for (int k = j+1; k < N; k++) {
        	int one = vec.at(i);
          	int two = vec.at(j);
          	int three = vec.at(k);
          
         	if (one == two || one == three || two == three) {
            	continue;
            } else {
            	if (one + two > three) {
                	count++;
                }
            }
        }
      }
    }
    
    cout << count << endl;
    return 0;
  }

}

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

int main() {

  long long int n;
  cin >> n;

  vector< long long int > v;

  for ( long long int i = 0; i < n; i++ ) {

    long long int in;
    cin >> in;
    v.push_back( in );

  }

  long long int k = 0;
  vector< long long int > p, q;

  for ( long long int i = 0; i < n; i++ ) {

    if ( v[i] > k ) {
      p.push_back( k );
      q.push_back( v[i] );
      k = v[i];
    }else {
      p.push_back( -1 );
      q.push_back( -1 );
    }

  }

  v.push_back( 1145141919 );
  sort( v.begin(), v.end() );

  long long int cnt = 0;

  for ( long long int i = 0; i < n; i++ ) {

    if ( p[i] == -1 ) {
      cout << 0 << endl;
    }else {

      long long int ans = 0;
      while( true ) {
	if ( v[ cnt ] > q[i] ) break;
	ans += v[cnt] - p[i];
	cnt++;
      }
      ans += ( n - cnt ) * ( q[i] - p[i] );
      cout << ans << endl;

    }

  }

  return 0;

}


Measured memory_bytes: 3612
n = int(input())
s = []

for i in range(n):
  s.append(input())
  
#共通して出てくる文字を見つける 
temp_set = {}
for i in range(n):
  if i == 0:
    temp_set = set(list(s[i]))
  else:
    temp_set = temp_set.intersection(s[i])

    
#各文字について、各文字列に出てくる最小回数を探す
counter_moji = []
for _, moji in enumerate(temp_set):
  num_count = 500
  for i in range(len(s)):
    current_count = s[i].count(moji)
    if num_count > current_count:
      num_count = current_count
  counter_moji.append(num_count)
  
ans = []
for i, moji in enumerate(temp_set):
  for _ in range(counter_moji[i]):
    ans.append(moji)   

ans.sort()
print("".join(ans))


Measured memory_bytes: 3064
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        long[] aArr = new long[n];

        for (int i = 0; i < n; i++) {
            aArr[i] = sc.nextLong();
        }

        long absMin = Integer.MAX_VALUE;
        long sum = 0;
        for (int i = 0; i < n; i++) {
            absMin = Math.min(absMin, Math.abs(aArr[i]));
            sum += Math.abs(aArr[i]);
        }

        System.out.println(condition(aArr, n) ? sum : sum - 2 * absMin);
    }

    boolean condition(long[] aArr, int n) {
        // 全部+にできればtrue
        int plusCount = 0;
        for (int i = 0; i < n; i++) {
            if (aArr[i] > 0) plusCount++;
        }
        return (n % 2 == 0 && plusCount % 2 == 0) || (n % 2 != 0 && plusCount % 2 != 0);
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


Measured memory_bytes: 52272
/*
	* ernestvw
	* C++
	* May 2020
*/

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

#define int long long

#define x first
#define y second
#define pb push_back
#define pii pair<int, int>
#define veci vector<int>
#define vecs vector<string>
#define amax(x, v) x = max(x, (v))
#define amin(x, v) x = min(x, (v))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) (int)(v.size())
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define nl '\n'

using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

const int oo = 1e9; // INT_MAX
const long long OO = 1e18; // LLONG_MAX
const double eps = 1e-9;
const double pi = 4.0 * atan(1.0);
const int p197 = 1000000007;
const int p998 = 998244353;
const int p103 = 1000003;

#define TEST_CASES 0

void solve(int test_case);

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

	int T = 1;
	if(TEST_CASES) cin >> T;
	for(int t = 1; t <= T; t++)
		solve(t);

	return 0;
}

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

int h1, m1, h2, m2, k;

void solve(int test_case) {
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	if(h1 > h2 || (h1 == h2 && m1 >= m2)) {
		cout << 0 << endl;
	}
	int nb1 = h1 * 60 + m1;
	int nb2 = h2 * 60 + m2;
	cout << max(0LL, nb2 - nb1-k) << endl;
}



















































Measured memory_bytes: 3652
#%%
s = int(input())

count = 2
a = s
a_list = [a]
while True:
    if a % 2 == 0:
        an = a // 2
    else:
        an = 3 * a + 1

    if an in a_list:
        break
    else:
        count += 1
        a_list.append(an)
        a = an

print(count)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define li long int
#define ll long long int
#define vec(x) vector<x> 
#define st(x) set<x> 
#define mpp(x,y) map<x,y> 
#define pi(x,y) pair<x,y>
#define forf(i,x,y) for(ll i=x;i<y;i++)
#define forl(i,x) for(ll i=x-1;i>=0;i--)
#define rev(x) reverse(x.begin(),x.end())
#define mem(x,a) memset(x,a,sizeof(x))
#define mod 1000000007
#define nxt_per(x) next_permutation(x.begin(),x.end())
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define vp(x,y) vec(pi(x,y) )
#define all(x) x.begin(),x.end()

using namespace std;

int main()
{
	string s,t,p;
	cin>>s>>t;
	p="";
	char f=t[0];
	vec(int) v;
	forf(i,0,s.size())
		if(s[i]==f)
			v.pb(i);
	int c=0;
	while(!v.empty())
	{	int x=v.back();
		forf(i,x,s.size())
			p+=s[i];
		forf(i,0,x)
			p+=s[i];
		if(t.compare(p)==0)
		{	c=1;
			break;
		}	
		else
			v.pop_back();
		p="";
	}
	if(c==1)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {


	char S[4];
	bool flag=true;

	cin >> S;
	
	for (int i=0; i < 3; i++) {
		if (S[i] == S[i + 1]) {
			flag = false;
		}
	}

	if (flag == true) {
		cout << "Good" << endl;
	}
	else {
		cout << "Bad" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import sys

def main():

	input = sys.stdin.readline
	N = int(input().strip())
	S = list(input().strip())

	maxlen = 0

	for i in range(N):
		SS = S[i:N]
		Z = [0]*len(SS)
		Z[0] = len(SS)
		ZA = [0]*len(SS)
		ZA[0] = min(0,Z[0])
		rt = 0
		lt = 0

		for k in range(1,len(SS)):
			if k>rt:
				n = 0
				while n+k<len(SS) and SS[n]==SS[n+k]:
					n += 1
				Z[k] = n
				ZA[k] = min(k,Z[k])
				if n>0:
					lt = k
					rt = k+n-1
			else:
				p = k-lt
				rlen = rt-k+1

				if Z[p]<rlen:
					Z[k] = Z[p]
					ZA[k] = min(k,Z[k])
				else:
					i = rt+1
					while i<len(SS) and SS[i]==SS[i-k]:
						i += 1
					Z[k] = i-k
					ZA[k] = min(k,Z[k])
					lt = k
					rt = i-1
		
		maxlen = max(maxlen,max(ZA))

	print(maxlen)

if __name__ == "__main__":
    main()

Measured memory_bytes: 57308
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n;
	cin >> n;
	ll yakusuX = 0;
	ll yakusuY = LINF;
	for (ll i = 1; i <= sqrt(n); i++)
	{
		if (n % i == 0)
		{
			yakusuX = max(yakusuX, i);
			yakusuY = min(yakusuY, n / i);
		}
	}
	cout << yakusuX + yakusuY - 2 << endl;
	return 0;
}

Measured memory_bytes: 256
program B176
implicit none
character(200000) :: N
integer(8) :: i, j, sum, len


read(5,*) N
len = len_trim(N)
sum = 0
do i = 1, len
    read(N(i:i),*) j
    sum = sum + j

end do

if (mod(sum,9) == 0) then
    write(6,*) "Yes"
else
    write(6,*) "No"
end if



end program B176

Measured memory_bytes: 3296
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A9x9 solver = new A9x9();
        solver.solve(1, in, out);
        out.close();
    }

    static class A9x9 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            if (a > 9 || b > 9)
                out.println(-1);
            else
                out.println(a * b);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



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

#define ll long long
#define ld long double
#define db double
#define str string
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define rall(v) rbegin(v),rend(v)
#define see(x) cout<<(#x)<<" -> "<<(x)<<"\n"
#define selp(a) for(auto i:a)cout<<i<<" ";cout<<nl;
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const db pi=2*acos(0.0);

int main(){
    nimble;
    int tt=1;//cin>>tt;
    while(tt--){
      int n;
      cin>>n;
      vector<vector<int>> a(n,vector<int>(3));
      rep(i,0,n){
        cin>>a[i][0];
        cin>>a[i][1];
        cin>>a[i][2];
      }
      ll x=a[0][0],y=a[0][1],z=a[0][2];
      if(n==1){
        cout<<max({x,y,z})<<nl;
        continue;
      }
      rep(i,1,n){
        ll x1=x,y1=y,z1=z;
        x=a[i][0]+max(y1,z1);
        y=a[i][1]+max(x1,z1);
        z=a[i][2]+max(x1,y1);
      }
      cout<<max({x,y,z})<<nl;
    }
    return 0;
}



Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1010;
int main()
{
    int n , m , a;
    while (~scanf("%d%d%d",&n,&m,&a)){
        if (m == n)  cout << a << endl;
        else if (m == a)  cout << n << endl;
        else  cout << m << endl;
    }
    return 0;
}

Measured memory_bytes: 256
'''
Created on 2020/03/28

@author: fanta
'''
X,Y,A,B,C = map(int,input().split())
RED = [int(x) for x in input().split()]
GREEN = [int(x) for x in input().split()]
WHITE = [int(x) for x in input().split()]
out = 0
apples = []

RED.sort(key=None, reverse=True)
GREEN.sort(key=None, reverse=True)
WHITE.sort(key=None, reverse=True)

apples = RED[:X] + GREEN[:Y] + WHITE
apples.sort(key=None, reverse=True)


print(sum(apples[:X+Y]))




Measured memory_bytes: 23340
w_str = str(input())

letter = 'abcdefghijklmnopqrstuvwxyz'
alphabet_count = [0]*len(letter)

for i in range(len(w_str)):
  for k in range(len(letter)):
    if letter[k] == w_str[i]:
      alphabet_count[k] += 1

count = 0
for j in range(len(alphabet_count)):
  if alphabet_count[j] % 2 == 0:
    count += 1

if count == 26:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include<queue>
#include<cstdio>

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

using namespace std;

const int INF=1<<29;

class edge{
public:
	int v,cost;
	edge(int v,int cost):v(v),cost(cost){}
};

int main(){
	for(int n,m,k;scanf("%d%d%d",&n,&m,&k),n;){
		vector<edge> G[100];
		int d[100][100];
		rep(u,n) rep(v,n) d[u][v]=(u==v?0:INF);
		rep(_,m){
			int u,v,cost; scanf("%d%d%d",&u,&v,&cost);
			d[u][v]=d[v][u]=cost;
			G[u].push_back(edge(v,cost));
			G[v].push_back(edge(u,cost));
		}

		rep(w,n) rep(u,n) rep(v,n) d[u][v]=min(d[u][v],d[u][w]+d[w][v]);

		double dp[100][100]={}; // dp[u][v] := ( u->v 間の最短経路の個数 )
		// 謎の魔法によって Floyd で最短経路の個数が計算できる
		// rep(u,n) rep(i,G[u].size()) {
			// int v=G[u][i].v,cost=G[u][i].cost;
			// if(d[0][u]+cost+d[v][n-1]==d[0][n-1]) dp[u][v]=1; // 最初は dp には最短経路 DAG の隣接行列が入っている
		// }
		// rep(w,n) rep(u,n) rep(v,n) dp[u][v]+=dp[u][w]*dp[w][v];

		// まじめに Dijkstra してもよい
		rep(u,n){
			dp[u][u]=1;
			int d2[100];
			rep(v,n) d2[v]=(v==u?0:INF);
			priority_queue< pair<int,int> > Q; Q.push(make_pair(0,u));
			while(!Q.empty()){
				int d_now=-Q.top().first,v=Q.top().second; Q.pop();
				rep(i,G[v].size()){
					int w=G[v][i].v,cost=G[v][i].cost;
					if(d[0][v]+cost+d[w][n-1]==d[0][n-1]){ // 最短経路 DAG の辺であるかどうか
						if(d2[w]>=d2[v]+cost){
							if(d2[w]>d2[v]+cost){
								d2[w]=d2[v]+cost;
								Q.push(make_pair(-d2[w],w));
							}
							dp[u][w]+=dp[u][v];
						}
					}
				}
			}
		}

		rep(_,k){
			int c; scanf("%d",&c);
			printf("%.9f\n",dp[0][c]*dp[c][n-1]/dp[0][n-1]);
		}
		puts("");
	}

	return 0;
}

Measured memory_bytes: 1316
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	string s;
	cin >> s;

	if(s[2]==s[3] && s[4]==s[5]) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}



Measured memory_bytes: 256