akhauriyash/Code-Regression huggingface dataset:
s=['AKIHABARA','KIHABARA','AKIHBARA','AKIHABRA','AKIHABAR','KIHBARA','KIHABRA','KIHABAR','AKIHBRA','AKIHBAR','AKIHABR','KIHBRA','KIHABR','KIHBAR','AKIHBR','KIHBR']
t=input()
if t in s:
    print('YES')
else:
    print('NO')


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("INP.txt", "r", stdin);
    //freopen("OUT.txt", "w", stdout);
    ll n;
    cin >> n;
    vector<ll> hold(n);
    for (ll i = 0; i < n; i++) {
        cin >> hold[i];
    }
    for (ll i = n - 2; i >= 0; i--) {
        if (hold[i] > hold[i + 1]) {
            if (hold[i] - 1 <= hold[i + 1]) {
                hold[i]--;
            }
            else {
                cout << "No" << '\n';
                return 0;
            }
        }
    }
    cout << "Yes" << '\n';
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{

   long long int i,N,sum,sum1=0,sum2=0,sum3=0,sum4=0;
   scanf("%lld",&N);
   for(i=1;i<=N;i++)
   {   sum4=sum4+i;
       if(i%3==0)
       sum1=sum1+i;
       else if(i%5==0)
       sum2=sum2+i;
       else if(i%15==0)
        sum3=sum3+i;

       sum=sum1+sum2+sum3;
   }
   printf("%lld",sum4-sum);

}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int N; cin >> N;
  vector<int> A(N), B(N);
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];
  vector<int> surpluses;
  ll deficit_sum = 0;
  int deficit_count = 0;
  rep(i, N) {
    if (A[i] - B[i] > 0) {
      surpluses.push_back(A[i] - B[i]);
    }
    if (A[i] - B[i] < 0) {
      deficit_count++;
      deficit_sum += B[i] - A[i];
    }
  }
  sort(surpluses.begin(), surpluses.end());
  int size = surpluses.size();
  int used_count = 0;
  rep(i, size) {
    if (deficit_sum > 0) {
      deficit_sum -= surpluses[size - 1 - i];
      used_count++;
    }
  }
  cout << (deficit_sum > 0 ? -1 : deficit_count + used_count) << "\n";
}


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

#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")

#define int long long
typedef pair <int, int> pii;

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	int h[n];
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	sort(h, h + n);
	reverse(h, h + n);
	int sum = 0;
	for (int i = k; i < n; i++)
		sum += h[i];
	cout << sum;
}



Measured memory_bytes: 1792
N = input()
nums = input().split()
num_list = [int(i) for i in nums]

mes = "APPROVED"
for num in num_list:
  if num % 2 ==0:
    if num % 3 == 0 or num % 5 == 0:
      pass
    else:
      mes = "DENIED"
print(mes)

Measured memory_bytes: 38384
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
int main(){
ll a,b,c,d,e,f;
cin>>a>>b>>c>>d>>e>>f;
V<ll> wat;
a*=100;b*=100;
for(ll i=0;i<=30;i++){
    for(ll j=0;j<=30;j++){
        if(a*i+b*j==0||a*i+b*j>f)continue;
        wat.push_back(a*i+b*j);
    }
}
set<ll> s;
for(ll i=0;i<=3000;i++){
    for(ll j=0;j<=3000;j++){
        if(c*i+d*j==0||c*i+d*j>f)continue;
        s.insert(c*i+d*j);
    }
}
int n=wat.size();
double ma=0.0;
ll w=0,su=0;
for(int i=0;i<n;i++){
    ll v=wat[i];
    ll m=v/100*e;
    if(m+v>f)m=f-v;
    auto ite=s.upper_bound(m);
    ll sug=0;
    if(ite!=s.begin()){
    ite--;
    sug=*ite;
    }
    if(ma<=double(sug)/double(v+sug)*100.0){
        w=v+sug;su=sug;
        ma=double(sug)/double(sug+v)*100.0;
    }
}
cout<<w<<" "<<su<<"\n";
}

Measured memory_bytes: 512
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        x: i64
    }
    let k = [99999, 1800, 1600, 1400, 1200, 1000, 800, 600, 400];
    for (i, &v) in (0..).zip(&k) {
        if x >= v {
            println!("{}", i);
            break;
        }
    }
}


Measured memory_bytes: 2172
import sys
a=[list(map(int,input().split())) for i in range(3)]
x1,x2=a[0][0]-a[0][1],a[0][0]-a[0][2]
for i in range(3):
    if a[i][0]-a[i][1]!=x1 or a[i][0]-a[i][2]!=x2: print("No"),sys.exit()

y1,y2=a[0][0]-a[1][0],a[0][0]-a[2][0]
for j in range(3):
    if a[0][j]-a[1][j]!=y1 or a[0][j]-a[2][j]!=y2: print("No"),sys.exit()

print("Yes")

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**6)

n = int(input())
edges = [[int(i) for i in input().split()] for _ in range(n - 1)]

BLACK = 1
WHITE = 0
UNKNOWN = -1

import sys
if n == 1:
    print(BLACK)
    sys.exit(0)

colors = [UNKNOWN] * (n + 1)

graph = [[] for _ in range(n + 1)]
for e in edges:
    graph[e[0]].append((e[1], e[2]))
    graph[e[1]].append((e[0], e[2]))

def dfs(graph, colors, current_point, current_color):
    colors[current_point] = current_color

    for next_point_info in graph[current_point]:
        if colors[next_point_info[0]] != UNKNOWN:
            continue
        if (next_point_info[1] % 2 == 0):
            next_color = current_color
        else:
            next_color = 1 - current_color
        dfs(graph, colors, next_point_info[0], next_color)

dfs(graph, colors, 1, BLACK)
for c in colors[1:]:
    print(c)


Measured memory_bytes: 90320
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
		ArrayList<Integer> one = nextIntArray();
		int A = one.get(0);
		int B = one.get(1);
		if(B == 1){
			myout(0);
			return;
		}
		if(B <= A){
			myout(1);
			return;
		}
		int mass = 1;
		int count = 0;
		while(B > mass){
			count++;
			mass += A - 1;
		}
		myout(count);
	}
	//Method addition frame start




	//Method addition frame end
}


Measured memory_bytes: 32932
S = str(input())
A= S[0]
B=S[1]
C=S[2]
L=list([A,B,C])
Rcount = S.count('R')
if Rcount ==0:
    print(0)
elif Rcount ==1:
    print(1)
elif Rcount == 3:
    print(3)
else:
    if B == 'R':
        print(2)
    else:
        print(1)

Measured memory_bytes: 9132
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)

int main() {
  string s; cin >> s;
  vector <ll> v(26, 0);
  rep(i, s.size()) {
    ll loc = s.at(i) - 'a';
    v.at(loc)++;
  }
  rep(i, 26) {
    if (!v.at(i)) {
      char c = 'a' + i;
      cout << c << endl;
      break;
    }
    if (i == 25) cout << "None" << endl;
  }
}

Measured memory_bytes: 3664
/// Kazuki Hoshino


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
//#define endl '\n'
typedef tree<
int,
null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update>
ordered_set;


int h,w,n,mx[202020],x,y,ans;
map<pi,int> mp;
vpi v;

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

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

cin >> h >> w >> n;
for(int i=1;i<n+1;i++){
       cin >> x >> y;
       mp[{x,y}]=1;
       v.pb({x,y});
}
if(n==0){
       cout << h << endl;
       return 0;
}
x=1;y=1;
bool pre = false;
while(true){
       bool flag = false;
       if(x+1<=h && !mp[{x+1,y}]){
              x++;
              mx[x]=max(y,mx[x]);
              flag = true;
       }
       if(!flag){
              if(pre)
              ans = x;

              else {
                     ans = x;
              }
              //cout << x << " " << y << endl;
              break;
       }
       if(y+1<=w && !mp[{x,y+1}]){
              y++;
              pre = true;
              mx[x]=max(y,mx[x]);
       }
       else {
              pre=false;
       }

}
//v.pb({h,w});
sort(all(v));
for(auto t:v){
       if(mx[t.f]>t.ss){
              ans = min(t.f -1, ans);
              //cout << t.f << " " << t.ss << endl;
       }
}

cout << ans << endl;



return 0;}
///....


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

typedef long long ll;

int main()
{
    ll i,j;
    ll h,n;
    cin >> h >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i) >> b.at(i);
    }
    vector<vector<ll>> dp(n+1,vector<ll>(h+1,1e9));
    for(i = 0;i <= n;++i){
        dp.at(i).at(0) = 0;
    }
    for(i = 1;i <= n;++i){
        for(j = 1;j <= h;++j){
            ll tmp = i-1;
            ll tmp2 = min(dp.at(i-1).at(max(0LL, j - a.at(tmp))) +  + b.at(tmp), dp.at(i).at(max(0LL, j - a.at(tmp))) +  + b.at(tmp));
            dp.at(i).at(j) = min(tmp2, dp.at(i-1).at(j));
        }
    }
    cout << dp.at(n).at(h) << endl;
    return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
const int INF = 1001001001;
const ll mod = 1e9+7;

ll ans=0;

vector<int> A;
ll s;
string dfs (string x){
//  cout<<x<<endl;
//  cout<<A.size()<<endl;
  int keta;
  keta=x.size();
//  cout<<s<<'s'<<keta<<'k'<<endl;
  if (keta<=s){


    if(count(x.cbegin(),x.cend(),'3')>=1 & count(x.cbegin(),x.cend(),'5')>=1 & count(x.cbegin(),x.cend(),'7')>=1){
      A.push_back(stoi(x));
    }

    dfs(x+'3');
    dfs(x+'5');
    dfs(x+'7');


}
return x;
}


int main() {
  string n;
  cin>>n;
  s=n.size();
  //cout<<s<<'s'<<endl;
  if (s<3){
    cout<<0;return 0;
  }


//cout<<ans<<endl;
dfs("");

rep(i,A.size()){
  if (A[i]<=stoi(n)) ans++;
}

cout<<ans;

}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  cin>>n;
  while(n--){
    int a,b;
    cin>>a>>b;
    cout<<(a-1)%b+1<<endl;
  }


}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 10000
#define MAP 100
#define MAX_N 100000
#define Pair pair<int,int>
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int dist[MAP][MAP];
int h[MAX_N];
int dp[MAX_N];
int main(){
    int n,k; cin >> n >> k;
    int h[MAX_N];
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    for(int i = 0; i < n; i++){
        dp[i] = MM;
    }
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 1; j <= k; j++){
            if(i+j < n){
                dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]));
            }
        }
    }
    cout << dp[n-1] << endl;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    long long int answer = 0;
    for(int i =0; i < s.size(); i++){
        if(s[i] == '?'){
            s[i] = 'D';
        }
    }
    
    cout<<s<<"\n";
    return 0;
}

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

int main() {
  int N ,K ;
  cin >> N >> K ;
 
  int i , p , x , y , sum ;
  sum = 0;
  for(i=0; i<N ; i++){
    cin >> p;
    x=K-p;
    if(p<x){
      y=p*2;
    }
    else{
      y=x*2;
    }
    sum+=y;
  
  }
  
  cout << sum << endl;
    
    
}
    
  



Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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;

ll n, m, k, u, v, x, y, t, a, b, ans;
ll A[MAXN];
vector<ll> gauss;
string S;

inline void add(ll x){
	for (ll a:gauss) if (a&-a&x) x^=a;
	if (!x) return ;
	for (ll &a:gauss) if (x&-x&a) a^=x;
	gauss.pb(x);
}
inline bool get(ll x){
	for (ll a:gauss) if (a&-a&x) x^=a;
	return x==0;
}

int Solve(){
	gauss.clear();
	cin>>n;
	for (int i=1; i<=n; i++) cin>>A[i];
	cin>>S;
	for (int i=n; i; i--){
		if (S[i-1]=='0') add(A[i]);
		else if (!get(A[i])) kill("1")
	}
	kill("0")
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int T;
	cin>>T;
	while (T--) Solve();
	
	return 0;
}


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

using namespace std;

typedef long long int ll;
ll n,cost=0;
vector<ll> height(100005, INT_MAX);
ll memo[100005];
ll dp(int pos)
{
	if(pos>n-1)
		return INT_MAX;
	if(pos==n-1)
		return 0;
	if(memo[pos]!=-1)
		return memo[pos];
	ll ans = INT_MAX;
	for(int i = 1; i< 3; i++)
		ans = min(ans, dp(pos+i)+abs(height[pos]-height[pos+i]));
	return memo[pos] = ans;
}
int main()
{
	cin>>n;
	for(int i = 0 ; i < n; i++)
		cin>>height[i];
	memset(memo, -1, sizeof memo);
	cout<<dp(0)<<endl;
	return 0;
}

Measured memory_bytes: 8064
h,w=map(int,input().split())
if h==1 or w==1:
  print(1)
  exit()
if h%2==1 and w%2==1:
  a1=((h+1)//2)*(w+1)//2
  a2=(h//2)*(w//2)
  print(a1+a2)
else:
  print((h*w)//2)


Measured memory_bytes: 2940
import java.util.*;
import java.io.*;
public class Main {
 public static void main(String[] moo) throws Exception {
   Scanner file = new Scanner(System.in);
   int n = file.nextInt();
   Moo[] m = new Moo[n];
   for (int i = 0; i < n; i++) {
    m[i] = new Moo(i + 1, file.next(), file.nextInt()); 
   }
   Arrays.sort(m);
   for (int i = 0; i < n; i++) {
    System.out.println(m[i].id); 
   }
   file.close();
   System.exit(0);
 }
 public static class Moo implements Comparable<Moo> {
   int id, score;
   String name;
   public Moo(int id, String name, int score) {
    this.id = id;
    this.name = name;
    this.score = score;
   }
   public int compareTo(Moo o) {
    int c = name.compareTo(o.name);
    if (c == 0) {
     return -Integer.compare(score, o.score); 
    }
    return c;
   }
 }
}

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

#define ll long long int
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define finput ifstream cin;cin.open("in.txt")
#define foutput ofstream cout;cout.open("out.txt")  
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007

ll gcd(ll x, ll y){ 
	if(x<y) 
		swap(x,y); 
	if(x%y==0)
		return y;
	return gcd(y, x%y);
}

ll pwm(ll a, ll n){
	ll ans = 1;
	while(n>0){
		if(n%2==1){
			ans = (ans * a)%mod;
		}
		a = (a*a)%mod;
		n /= 2;
	}
	return ans%mod;
}

const int pwn = 100010;
ll pw[pwn];
void pwtwo(){
	pw[0] = 1;
	for(int i=1; i<pwn; i++){
		pw[i] = (pw[i-1]*2)%mod;
	}
}


ll gcdExtended(ll a, ll b, ll *x, ll *y); 
  
ll modInverse(ll a, ll m) 
{ 	
	if(a==1)
		return 1;
	//cout<<"mi "<<a<<" "<<m<<" ";
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
    if (g != 1){
        //cout << "Inverse doesn't exist"<<endl; 
        return -1;
    }
    else
    { 
        // m is added to handle negative x 
        ll res = (x%m + m) % m; 
        //cout<<res<<endl;
        return res;
        // cout << "modular multiplicative inverse is " << res; 
    } 
} 
  
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1;
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
} 

ll fact[1010];
ll init(){
	fact[0] = 1;
	for(int i=1; i<1010; i++)
		fact[i] = (fact[i-1]*i)%mod;
}

ll ncr(ll n, ll r){
	ll ans = fact[n];
	if(r>n)
		return 0;
	//if(r!=0)
	ans = (ans*modInverse(fact[r], mod))%mod;
	// if(n-r!=0)
	ans = (ans*modInverse(fact[n-r], mod))%mod;

	return ans;
}

int main(){
	// finput;
	// foutput;
	fast;

	ll n, k, i, j, x, m;
	// ll ans;
	// string s;
	cin>>n;

	// ll pre = n%10;
	ll mx = 0;
	// n /= 10;
	ll ans = 0;
	m = 0;
	// ll ans = 0;
	while(n>0ll){
		x = n%10ll;
		n /= 10ll;
		// if(x=0){

		// }

		m += x;
		if(x!=0ll){
			m = max(m, mx + x -1);
		}

		mx += 9;
	}

	cout<<m;

	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll H, W, h, w;
    cin >> H >> W >> h >> w;
    if(H%h == 0 && W%w == 0){
    	cout << "No" << endl;
    	return 0;
    }
    bool flag = true;
    if(W%w == 0){
    	flag = false;
    	swap(W, H);
    	swap(w, h);
    }
    cout << "Yes" << endl;
    vector<ll> res(W), ress(W+1, 1);
    REP(i, W+1){
    	if(i%w == 0) continue;
    	ll tmp = i - w;
	    while(tmp >= 0){
	    	ress[tmp] = ress[tmp+w] + 1;
	    	tmp -= w;
	    }
	}
	ress[0] = 0;
	ll ind = 0;
	while(ind+w < W){
		ress[ind+w] = ress[ind] - 1;
		ind += w; 
	}
	//cout << ress << endl;
	if(flag){
		REP(i, H){
			REP(j, W){
				cout << ress[j+1] - ress[j] << " ";
			}
			cout << endl;
		}
	}else{
		REP(i, W){
			REP(j, H){
				cout << ress[i+1] - ress[i] << " ";
			}
			cout << endl;
		}
	}
    return 0;
}

Measured memory_bytes: 1408
// https://atcoder.jp/contests/abc153/tasks/abc153_e

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll H, N;
  cin >> H >> N;

  struct Mg {
    ll h, m;
  };

  V<Mg> mgs(N);

  rep(i, N) {
    ll h, m;
    cin >> h >> m;

    mgs[i] = {h, m};
  }

  // dp[i][h] // i 番目の魔法までで h 減らすのに必要な m
  VVL dp(N + 1, VL(H + 1, INF));
  dp[0][0] = 0;

  rep(i, N) rep(h, H + 1) {
    auto mg = mgs[i];
    chmin(dp[i + 1][h], dp[i][h]);
    chmin(dp[i + 1][min(H, h + mg.h)], dp[i + 1][h] + mg.m);
    chmin(dp[i + 1][min(H, h + mg.h)], dp[i][h] + mg.m);
  }

  cout << dp[N][H] << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


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

using namespace std;

int main(){
    int A,B,X;
    cin >> A >> B >> X;
    if(A > X){
        cout << "NO" << endl;
        return 0;
    }
    if(A+B >= X){
        cout << "YES" << endl;
        return 0;
    }
    else{
        cout << "NO" << endl;
        return 0;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int r, c, n;
    cin >> r >> c >> n;
    vector<pair<int, int>> v;
    for (int i = 0; i < n; ++i) {
        int a, b, p, q;
        scanf("%d%d%d%d", &a, &b, &p, &q);
        if(((a == 0 || a == r) || (b == 0 || b == c)) && ((p == 0 || p == r) || (q == 0 || q == c))){
            int d = 0;
            if(b == 0) d = a;
            else if (a == r) d = r+b;
            else if (b == c) d = 2*r+c-a;
            else if (a == 0) d = 2*r+2*c-b;
            v.emplace_back(d, i);
            d = 0;
            if(q == 0) d = p;
            else if (p == r) d = r+q;
            else if (q == c) d = 2*r+c-p;
            else if (p == 0) d = 2*r+2*c-q;
            v.emplace_back(d, i);
        }
    }
    if(v.empty()) {
        puts("YES");
        return 0;
    }
    sort(v.begin(), v.end());
    deque<int> dq;
    for (auto &i : v) {
        if(!dq.empty() && dq.back() == i.second) dq.pop_back();
        else dq.emplace_back(i.second);
    }
    while(!dq.empty() && dq.front() == dq.back()){
        dq.pop_front(); dq.pop_back();
    }
    puts(dq.empty() ? "YES" : "NO");
    return 0;
}


Measured memory_bytes: 2420
/**
  *  Worg
  */
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>

int main() {
	int n; std::cin >> n;
	std::vector<double> p(n);
	for (auto& x: p) {
		std::cin >> x;
	}

	std::vector<std::vector<double>> dp(n, std::vector<double>(n + 1, 0));
	dp[0][0] = 1 - p[0]; dp[0][1] = p[0];

	for (int i = 1; i < n; i++) {
		dp[i][0] = dp[i - 1][0] * (1 - p[i]);
		for (int j = 1; j <= i + 1; j++) {
			dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]);
		}
	}

	double answer = 0;
	for (int i = 0; i <= n; i++) {
		if (i > n - i) {
			answer += dp[n - 1][i];
		}
	}

	std::cout << std::fixed << std::setprecision(10) << answer << "\n";
	return 0;
}

Measured memory_bytes: 70656
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include<list>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    int h1, h2; cin >> h1 >> h2;
    int k1, k2; cin >> k1 >> k2;
    int a, b, c, d; cin >> a >> b >> c >> d;
    int hir = 0, ken = 0;
    hir += h1*a + h2*b + h1/10*c + h2/20*d;
    ken += k1*a + k2*b + k1/10*c + k2/20*d;
    if(hir>ken) cout << "hiroshi" << endl;
    else if(hir<ken) cout << "kenjiro" << endl;
    else cout << "even" << endl;

    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    string s1,s2,s3;
    cin >> s1 >> s2 >> s3;
    cout << s1[0] << s2[1] << s3[2] << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)

signed main() {
    int H,W,A,B;
    cin >> H >> W >> A >> B;
    int ans[H][W] = {};
    REP(i,B) REP(j,A) ans[i][j] = 1;
    REPP(i,B,H) REPP(j,A,W) ans[i][j] = 1;
    REP(i,H){
        REP(j,W){
            cout << ans[i][j];
        }
        cout << endl;
    }
}

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

int main(){
	int N,M,X;
	cin >> N >> M >> X;
	long long ans=99999999999999999;
	
	vector<int> C(N);
	vector<vector<int>> A(N);
	for(int i=0;i<N;i++){
		cin >> C[i];
		for(int j=0;j<M;j++){
			int a;
			cin >> a;
			A[i].push_back(a);
		}
	}
	
	for(int k=0;k<(1<<N);k++){
		long long tmp=0;
		vector<int> B(M,0);
		for(int i=0;i<N;i++){
			if(k&(1<<i)){
				tmp+=C[i];
				for(int j=0;j<M;j++)B[j]+=A[i][j];
			}
		}
		bool flag=true;
		for(int j=0;j<M;j++)if(B[j]<X)flag=false;
		if(flag)ans=min(ans,tmp);
	}
	if(ans==99999999999999999)cout << "-1" << endl;
	else cout << ans << endl;
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define FILL(c, v) fill((c).begin(),(c).end(), v)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

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

typedef long long LL;
typedef unsigned long long ULL;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

bool isAC[10'0001];
int waOf[10'0001];

void solve()
{
  int N, M; cin >> N >> M;
  int n_ac = 0;
  int n_wa = 0;
  REP0(i, M)
  {
      int p; string S; cin >> p >> S;
      if (isAC[p]) continue;
      else if (S == "AC")  { n_ac += isAC[p] = true; n_wa += waOf[p]; } 
      else waOf[p]++;
  }
  cout << n_ac << ' ' << n_wa << endl;

}

int main(int argc, char const *argv[])
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout<<std::fixed<<std::setprecision(10);
  solve();
  return 0;
}

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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#define showvv(v)
#endif

using namespace std;

#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

int main(){
  int a,b,c,d; cin >> a >> b >> c >> d;
  cout << min(a,b)+min(c,d) << endl;
}


Measured memory_bytes: 256
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
    int n,x;
    cin>>n>>x;
    int g=0;
    for(int i=0;i<n;i++){
    	int a;
    	cin>>a;
    	g=__gcd(g,abs(a-x));
    }
    cout<<g<<endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
l = list(map(int, input().split()))

e = [0]*n

for i in range(n):
  e[i] = (l[i]+1)/2

from itertools import accumulate
a = [0] + e
b = list(accumulate(a))

ans = 0
for i in range(n-k+1):
  ans = max(ans, b[i+k]-b[i])
print(ans)

Measured memory_bytes: 86792
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0;i<(intl)(n);i++)
#define Rep1(i,n) for(intl i=1;i<(intl)(n)+1;i++)
#define vec vector
#define fi first
#define se second
#define pushb push_back
#define popb pop_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(), v.rend())
using intl = int64_t;
using vi = vec<intl>;
using vvi = vec<vi>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};

intl pow(intl a,intl n){
  intl ans=1;
  Rep(i,n) ans *=a;
  return ans;
}

int main(){
  int N,K;
  cin >> K>>N;
  vi A(N);
  vi distance(N);
  Rep(i,N) {cin >> A[i];}
  Rep(i,N-1) {distance[i+1]=A[i+1]-A[i];}
  distance[0]=A[0] + (K-A[N-1]);
  SortA(distance);
  cout << K- distance[N-1];
}

Measured memory_bytes: 3580
import math
mod = 10**9+7
n,m = map(int,input().split())
if n!=m and abs(n-m)!=1:
    print("0")
    exit()

if n==m:
    n=max(n,m)
    m=min(n,m)
    ans = math.factorial(n)*2*math.factorial(m)
    print(ans%mod)
else:
    ans = math.factorial(n)*math.factorial(m)
    print(ans%mod)



Measured memory_bytes: 5184
#include <bits/stdc++.h>
using namespace std;
#define int long long
char process(int x) {
    cout<<x<<endl;
    string s; 
	cin>>s;
    if(s[0]=='V') exit(0);
    return s[0];
}
signed main(){
    cin.tie(nullptr); ios::sync_with_stdio(false); cout.tie();
    int n; 
	cin>>n;
    vector<char> a(n+1);
    a[0]=a[n]=process(0);
    int l=0,r=n;
    for(;;){
        int m=(l+r)/2;
        a[m]=process(m);
        int cl=(m-l-1)%2;
        if(cl^(a[l]==a[m])) r=m;
        else l=m;
    }
    return 0;
}

Measured memory_bytes: 980
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE RecordWildCards       #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString.Char8       as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           Foreign.C.String
import           Text.Printf
import           Unsafe.Coerce

main :: IO ()
main = do
    [n, m] <- map read.words <$> getLine :: IO [Int]
    pys <- unfoldr parseInt2 <$> B.getContents
    solve pys

solve :: [(Int, Int)] -> IO ()
solve pys = putInts
    . map snd
    . sort
    . concat
    . IM.elems
    . IM.mapWithKey (\p yis -> map (\(j, (_, i)) -> (i, (p, j))) . zip [1 :: Int ..] $ sort yis)
    . foldl' (\acc (i, (p, y)) -> IM.insertWith (++) p [(y, i)] acc) IM.empty
    $ zip [0 :: Int ..] pys

show06d :: Int -> Int -> String
show06d x y = printf "%06d%06d" x y

foreign import ccall unsafe "stdio.h printf"
    c_printf :: CString -> Int -> Int -> IO ()

putInts :: [(Int, Int)] -> IO ()
putInts xs = B.unsafeUseAsCString "%06d%06d\n" $ \fmt ->
    foldr ((>>).uncurry (c_printf fmt)) (return ()) xs

-------------------------------------------------------------------------------
type Parser a = B.ByteString -> Maybe (a, B.ByteString)

parseInt :: Parser Int
parseInt = B.readInt . B.dropWhile isSpace

parseInt2 :: Parser (Int, Int)
parseInt2 = runStateT $
    (,) <$> StateT (B.readInt . B.dropWhile isSpace)
        <*> StateT (B.readInt . B.unsafeTail)



Measured memory_bytes: 53756
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<60;
const double eps=1e-9;
const ll MOD=1000000007LL;
template<typename T>void chmin(T &a,T b){a=min(a,b);};
template<typename T>void chmax(T &a,T b){a=max(a,b);};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
struct edge{int to;ll cap;int rev;};
struct Dinic{
    int n;
    vector<int> lev,itr;
    vector<vector<edge>> G;
    Dinic(int n):n(n){
        itr.resize(n);
        lev.resize(n);
        G.resize(n);
    }
    void add_edge(int from,int to,ll cap){
        G[from].push_back((edge){to,cap,(int)G[to].size()});
        G[to].push_back((edge){from,0LL,(int)G[from].size()-1});
    }

    void bfs(int s){
        lev.assign(n,-1);
        queue<int> q;
        lev[s]=0;
        q.push(s);
        while(!q.empty()){
            int v=q.front();q.pop();
            for(int i=0;i<G[v].size();i++){
                edge &e=G[v][i];
                if(e.cap>0&&lev[e.to]<0){
                    lev[e.to]=lev[v]+1;
                    q.push(e.to);
                }
            }
        }
    }
    ll dfs(int v,int t,ll f){
        if(v==t)return f;
        for(int &i=itr[v];i<G[v].size();i++){
            edge &e=G[v][i];
            if(e.cap>0&&lev[v]<lev[e.to]){
                ll d=dfs(e.to,t,min(f,e.cap));
                if(d>0){
                    e.cap-=d;
                    G[e.to][e.rev].cap+=d;
                    return d;
                }
            }
        }
        return 0;
    }
    ll max_flow(int s,int t){
        ll flow=0;
        for(;;){
            bfs(s);
            if(lev[t]<0)return flow;
            itr.assign(n,0);
            ll f;
            while((f=dfs(s,t,LINF))>0){
                flow+=f;
            }
        }
    }
};
int main(){
    int n;cin>>n;
    vector<ll> a(n+10);
    for(int i=1;i<=n;i++)cin>>a[i];
    Dinic d(n+2);
    int s=0,t=n+1;
    ll ans=0;
    for(int i=1;i<=n;i++){
        ans+=max(a[i],0LL);
        if(a[i]>=0){
            d.add_edge(s,i,a[i]);
            d.add_edge(i,t,0);
        }else{
            d.add_edge(s,i,0);
            d.add_edge(i,t,-a[i]);
        }
        for(int j=i+1;j<=n;j++){
            if(j%i==0){
                if(a[j]>=0){
                    d.add_edge(j,i,a[j]);
                }else{
                    d.add_edge(j,i,0);
                }
            }
        }
    }
    cout<<ans-d.max_flow(s,t)<<endl;
}

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

int main(){
  int N; cin >> N;
  for (int i=0, dt=0, dx=0, dy=0; i<N; i++){
    int t, x, y; cin >> t >> x >> y;
    int st=abs(t-dt), di=abs(x-dx)+abs(y-dy);
    if(di>st||(di+st)&1){
      cout << "No\n";
      return 0;
    }
    dt = t, dx = x, dy = y;
  }
  cout << "Yes";
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int main()
{
    int n, T, ans = 0;
    scanf("%d%d", &n, &T);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        if (i > 0) {
            ans += min(a[i] - a[i - 1], T);
        }
    }
    printf("%d\n", ans + T);
    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication40
{
    class Program
    {
        static void Main()
        {
          int  C = int.Parse(Console.ReadLine());
            for(int D = 0; D < C; D++)
            {
                int[] E = Console.ReadLine().Split().Select(int.Parse).ToArray();
                int[] S = { 0, 0 };
                for(int W = 0; W < 10; W++)
                {
                    Array.Sort(S);
                    if (S[1] < E[W]) S[1] = E[W];
                    else if (S[0] < E[W]) S[0] = E[W];
                    else { Console.WriteLine("NO");goto J; }
                }
                Console.WriteLine("YES");J:;
            }
        }
    }
}

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

int main() {
    int N, i;
    char s;
    char S1[52] = {};
    char S2[52] = {};
    cin >> N;
    for (i = 0; i < N; i++) {
        cin >> s;
        S1[i] = s;
    }

    for (i = 0; i < N; i++) {
        cin >> s;
        S2[i] = s;
    }

    long sum = 1;
    int pre = 0; //たて1横0
    for (i = 0; i < N; i++) {
        // たて
        if (S1[i] == S2[i]) {
            if (i == 0) {
                sum*=3;
                sum = sum%1000000007;
            } else {
                // 前回が横
                if (pre == 0) {
                    //何もしない
                } else {
                // 前回がたて
                    sum*=2;
                    sum = sum%1000000007;
                }
            }
            pre = 1;
        } else {
        // 横
            if (i == 0) {
                sum*=6;
            } else {
                // 前回が横
                if (pre == 0) {
                    //何もしない
                    sum*=3;
                    sum = sum%1000000007;
                } else {
                // 前回がたて
                    sum*=2;
                    sum = sum%1000000007;
                }
            }
            i++;
            pre = 0;
        }
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        int N = int.Parse(Console.ReadLine());
        long[] X = new long[N];
        long[] Y = new long[N];
        long maxY = 0;
        long minY = 1000000000;
        for(int i=0;i<N;i++){
            string[] str = Console.ReadLine().Split(' ');
            long x = int.Parse(str[0]);
            long y = int.Parse(str[1]);
            if(x > y){
                long t = y;
                y = x;
                x = t;
            }
            X[i] = x;
            Y[i] = y;
            maxY = Math.Max(maxY,y);
            minY = Math.Min(minY,y);
        }
        Array.Sort(X,Y);
        long count = (X[N-1]-X[0])*(maxY-minY);
        long M = X[N-1];
        long m = Y[0];
        for(int i=0;i<N;i++){
            count = Math.Min(count,(maxY-X[0])*(M-Math.Min(X[i],m)));
            m = Math.Min(m,Y[i]);
            M = Math.Max(M,Y[i]);
        }
        sb.Append(count+"\n");
    }
}

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

int main(){
  int N;
  cin >> N;
  long long A[N+1];
  long long B[N];
  long long cnt=0;
  for (int i=0;i<N+1;i++){
    cin>>A[i];
  }
  for (int i=0;i<N;i++){
    cin>>B[i];
    cnt=cnt+min(A[i]+A[i+1],B[i]);
    if(A[i]<B[i]){
      A[i+1]=A[i+1]-(B[i]-A[i]);
    }
    if(A[i+1]<0){
      A[i+1]=0;
    }
  }
  cout<<cnt<<endl;
  return 0;
}

  

Measured memory_bytes: 1792
<?php
$word = trim(fgets(STDIN));
$word_len = strlen($word);
$odd = [R,U,D];
$even = [L,U,D];
for($i = 0; $i < $word_len; $i++){
	$word_i = substr($word, $i, 1);
  	if($i%2 == 0 && in_array($word_i, $odd) == false){
    	echo "No";
        break;
    }elseif($i%2 == 1 && in_array($word_i, $even) == false){
        echo "No";
        break;	
    }elseif($i == $word_len - 1){
      	echo "Yes";
    }


}  
?>

Measured memory_bytes: 3576
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
using namespace std;

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

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int N, M, C;
int B[20];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> N >> M >> C;
  REP(i, M) {
    cin >> B[i];
  }

  int ans = 0;
  REP(i, N) {
    int sum = 0;
    REP(j, M) {
      int a;
      cin >> a;
      sum += a * B[j];
    }
    sum += C;
    if(sum > 0) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<set>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;


int main(){
    int N;
    cin >> N;
    int count = 0;
    vector<int> d(N);
    set<int> st;
    for(int i =0;i < N;i++){
        cin >> d.at(i);
        st.insert(d.at(i));
    }
 
    cout << st.size() << endl;
    




    
}


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

int x, y, z, k;
ll a[1111], b[1111], c[1111];

bool f(ll n) {
    int cnt = 0;
    for (int i = 0; i < x; i++) {
        for (int j = 0; j < y; j++) {
            for (int l = 0; l < z; l++) {
                if (a[i] + b[j] + c[l] < n) break;
                cnt++;
                if (cnt >= k) return true;
            }
        }
    }
    return false;
}

int main() {
    cin >> x >> y >> z >> k;
    for (int i = 0; i < x; i++) cin >> a[i];
    for (int i = 0; i < y; i++) cin >> b[i];
    for (int i = 0; i < z; i++) cin >> c[i];
    sort(a, a + x, greater<ll>());
    sort(b, b + y, greater<ll>());
    sort(c, c + z, greater<ll>());
    ll lb = -1, ub = 1001001001001;
    while (ub - lb > 1) {
        ll md = (ub + lb) / 2;
        if (f(md)) lb = md;
        else ub = md;
    }
    priority_queue<ll> que;
    for (int i = 0; i < x; i++) {
        for (int j = 0; j < y; j++) {
            for (int l = 0; l < z; l++) {
                if (a[i] + b[j] + c[l] < lb + 1) break;
                que.push(a[i] + b[j] + c[l]);
            }
        }
    }
    for (int i = 0; i < k; i++) {
        if (que.empty()) {
            cout << lb << endl;
        } else {
            cout << que.top() << endl;
            que.pop();
        }
    }
}

Measured memory_bytes: 3688
W,H,N = map(int,input().split())
a1 = []
a2 = []
a3 = []
a4 = []
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        a1.append(x)
    elif a == 2:
        a2.append(x)
    elif a == 3:
        a3.append(y)
    else:
        a4.append(y)
a1.sort(reverse=True)
a2.sort()
a3.sort(reverse=True)
a4.sort()
if a1:
    l = a1[0]
else:
    l = 0
if a2:
    r = a2[0]
else:
    r = W
if a3:
    d = a3[0]
else:
    d = 0
if a4:
    u = a4[0]
else:
    u = H
if r >= l and u >= d:
    print((r-l)*(u-d))
else:
    print(0)

Measured memory_bytes: 62720