akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

ll n;
V<ll> a;
V<V<ll>> dp;
V<V<bool>> seen;

ll rec(ll l=0,ll r=n){
    if(r-l==0){
        if(n%2==0) return INF;
        return -INF;
    }
    if(r-l==1){
        if(n%2==1){
            dp[l][r]=a[l];
        }else{
            dp[l][r]=-a[l];
        }
        return dp[l][r];
    }

    ll oe=n-(r-l);
    ll& ret=dp[l][r];
    if(seen[l][r]) return ret;
    seen[l][r]=1;
    if(oe%2==0) ret=max(a[l]+rec(l+1,r),a[r-1]+rec(l,r-1));
    else ret=min(-a[l]+rec(l+1,r),-a[r-1]+rec(l,r-1));
    return ret;
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n;
    a.resize(n);
    rep(i,n) cin>>a[i];
    dp.resize(n+1,V<ll>(n+1,0));
    seen.resize(n+1,V<bool>(n+1,0));
    ll tmp=rec(0,n);
    cout<<dp[0][n]<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

Measured memory_bytes: 74968
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
typedef long long ll;
using namespace std;
const int maxn=101000;
int n,k;
int num[maxn];
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&num[i]);
    int pos=0;
    for(int i=1;i<=n;i++){
        if(num[i]==1){
            pos=i;
            break;
        }
    }
    int ans=(pos-1)/(k-1)+(n-pos)/(k-1);
    int ff=(pos-1)%(k-1)+(n-pos)%(k-1);
    if(ff>0){
        if(ff<=k-1) ans++;
        else ans+=2;
    }
    printf("%d\n",ans);
    return 0;
}

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

int main()
{
    int N;
    int a[200000] = {0};
    long long sum = 0LL;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
        sum += (long long)a[i];
    }

    long long snuke = (long long)a[0];
    long long araiguma = sum - a[0];
    long long ans = abs(snuke - araiguma);
    for (int i = 1; i < N - 1; i++)
    {
        snuke += a[i];
        araiguma -= a[i];
        ans = min(ans, abs(snuke - araiguma));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = Integer.parseInt(in.nextLine());
        final int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
            arr[i] -= i + 1;
        }
        in.nextLine();
        Arrays.sort(arr);
        System.out.println(f(arr, arr[n / 2]));
    }

    private static long f(int[] arr, int median) {
        long res = 0;
        for (int value : arr) {
            res += Math.abs(value - median);
        }
        return res;
    }
}


Measured memory_bytes: 60448
#include <bits/stdc++.h>
using namespace std;
 
#define F first
#define S second 
#define mp make_pair
#define pb push_back
#define pf push_front
#define speed_up ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define debug cerr << "OK\n";
#define ub upper_bound
#define lb lower_bound
#define treap_pair pair<treap*, treap*>
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef set <int> si;
typedef set <ll> sll;
typedef multiset <int> msi;
typedef multiset <ll> msll;

typedef map <int, int> mi;
typedef map <ll, int> mll;
 
const int N = 1e5 + 2;
const int M = 1e5 + 2;
const ll mod = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e16;
 
void data() {
	#ifdef PC
		freopen("main.in", "r", stdin);
		freopen("main.out", "w", stdout);
	#endif
}

int n;
ll dp[2][N];
vi g[N];

ll mul(ll a, ll b) {
	return (a * b) % mod;
}

ll add(ll a, ll b) {
	return (a + b) % mod;
}

void dfs(int v = 1, int p = -1) {
	dp[0][v] = dp[1][v] = 1LL;
	for (auto to : g[v]) {
		if (to == p)
			continue;
		dfs(to, v);
		dp[0][v] = mul(dp[0][v], dp[1][to]);
		dp[1][v] = mul(dp[1][v], add(dp[1][to], dp[0][to]));
	}
}
 
int main() {
	data();
	scanf("%d", &n);
	for (int i = 1; i < n; ++i) {
		int x, y;
		scanf("%d %d", &x, &y);
		g[x].pb(y);
		g[y].pb(x);			
	}
	dfs();
	printf("%lld", add(dp[1][1], dp[0][1]));
}
 
/*
	Timus: 288481RF
	CodeForces: fractal
*/


Measured memory_bytes: 14208
#include<bits/stdc++.h>
using namespace std;
vector<long long >v;
int main()
{
    long long t,n,c,x,p,k;
    double d;
    cin>>n>>k;
    if(n==k)
        cout<<0;
    else if(n<k)
    {
        d=k/2.0;
        if(n<d)
            cout<<n;
        else
            cout<<k%n;
    }
    else
    {
        n=n%k;
        d=k/2.0;
        if(n<d)
            cout<<n;
        else
            cout<<k%n;
    }


}


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

#define fi first
#define se second
#define FO(x, n) for (int x = 0; x < n; ++x)
#define FOR(x, a, b) for (int x = a; x < b; ++x)
#define RFO(x, n) for (int x = n - 1; x >= 0; --x)
#define RFOR(x, a, b) for (int x = b - 1; x >= a; --x)
#define FOR_ITER(x, a) for(auto x = a.begin(); x != a.end(); ++x)

using namespace std;

typedef unsigned char byte;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;
typedef pair<ll, ll> pll;
inline bool feq(const double& a, const double& b) { return fabs(a - b) < 1e-10; }
inline int gcd(int a, int b) {
    if (b == 0) return a;
    return a < b? gcd(b, a) : gcd(b, a % b);
}



int main(){
//    int n, l;
//    cin >> n >> k;
//    vector<bool> dislike(10, false);
//
//    FOR(i, 0, k) {
//        int t;
//        cin >> t;
//        dislike[t] = true;
//    }


    string a, b;

    cin >> a >> b;

    int sz1 = a.size();
    int sz2 = b.size();
    if (sz1 > sz2) {
        cout << "GREATER" << endl;
    } else if (sz1 < sz2) {
        cout << "LESS" << endl;
    } else {
        if (a == b) {
            cout << "EQUAL" << endl;
        } else if (a < b) {
            cout << "LESS" << endl;
        } else {
            cout << "GREATER" << endl;
        }
    }

    return 0;
}


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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
/* 4方向への隣接頂点への移動を表すベクトル */
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const long long INF = 1LL << 60;

int main(){
    long long N;
    cin >> N;
    int bit = 0;
    long long t;

    for(int i = 0; i < N; ++i){
        cin >> t;
        bit ^= t; 
    }
    if(bit == 0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
using System;

namespace ABC134
{
    class Program
    {
        static int Main(string[] args)
        {
            problemB();
            return 0;
        }

        static void problemB()
        {
            string[] input = Console.ReadLine().Split(' ');

            double n = double.Parse(input[0]);
            double d = double.Parse(input[1]);

            double ans = Math.Ceiling(n / (2 * d + 1));

            Console.WriteLine(ans);
        }
    }
}

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

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vstr;

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define asd cout << "ok" << endl;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define trav(it, m) for(auto it = m.begin(); it it!= m.end(); it++)

const char nl = '\n';
const int MOD = 1e9 +7;
const ll INF = 1e19;
const ld PI = acos((ld)-1);
const int MX = 2e5 + 5;

int main(){

  ios_base::sync_with_stdio(0); cin.tie(0);
  int n; cin >> n;
  cout << setprecision(9);
  cout << fixed;
  ld sum = 0;
  for(int i = 0; i < n; i++){
    ld x; string s;
    cin >> x >> s;
    if(s == "JPY")
      sum+=x;
    else
      sum += x*380000;
  }
  cout << sum << nl;





  return 0;
}



Measured memory_bytes: 3848
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int MAX_N = 55555;

VI wantPrime;
bool is_prime[MAX_N+1];

void sieve(int n)
{
    int p = 0;
    REP(i,MAX_N+1) is_prime[i] = true;
    is_prime[0] = false; is_prime[1] = false;
    for(int i = 2; i <= n; i++)
    {
        if(is_prime[i])
        {
            if(i % 5 == 1) 
            {
                wantPrime.pb(i);  
                p++;
            }
            for(int j = 2 * i; j <= n; j += i)
            {
                is_prime[j] = false;
            }
        }
    }

}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int N; cin >> N; 
    sieve(55555);
    REP(i,N)
    {
        cout << wantPrime[i] << " ";
    }
    cout << endl;

}


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

int main(){
  int N,W;
  cin >> N >> W;
  vector<int> w(N),v(N);
  for (int i = 0; i < N; i++)
  {
    cin >> w[i] >> v[i];
  }

  // 配るDP
  vector<vector<long long>>dp(N+1,vector<long long>(W+1));
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j <= W; j++)
    {
      if(j>=w[i]) dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]]+v[i]);
      else dp[i+1][j] = dp[i][j];
    }
  }
  cout << dp[N][W] << endl;  
}

Measured memory_bytes: 80256
A,B,C,D,E = input().split()
A = int(A)
B = int(B)
C = int(C)
D = int(D)
E = int(E)

if A == 0:
  print(1)
elif B == 0:
  print(2)
elif C == 0:
  print(3)
elif D == 0:
  print(4)
elif E == 0:
  print(5)

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

int main()
{
    long long n;
    cin>>n;
    long long a[n],x=0,y=0,t=0,i,d1,d2;
    for(i=0;i<n;i++) cin>>a[i],t+=a[i];y=t;d2=y;
    for(i=0;i<n-1;i++)
    {
        x+=a[i];
        y-=a[i];
        d1=abs(y-x);
        //cout<<d2<<" "<<d1<<endl;
        if(d1<=d2) {d2=d1;}
        else break;
    }
    cout<<d2<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N,Answer;
  	Answer = 3;
  	cin >> N;
  
  	string S;
  	for(int i = 0; i < N; i++){
    	cin >> S;
      	if(S == "Y"){
          Answer = 4;
        }
    }
  if(Answer == 4){
    cout << "Four" << endl;
  }else{
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define N 100

using namespace std;

int w, h, s, t;
bool data[N][N];

void init(){
  for(int i=0; i<N; ++i){
    for(int j=0; j<N; ++j){
      data[i][j]=false;
    }
  }
}
int get(int k){
  int x=0;
  for(int i=0; i<s; ++i){
    for(int j=0; j<t; ++j){
      x += data[k+i][j];
    }
  }
  return x;
}
int move(int x, int k, int l){
  for(int i=0; i<s; ++i){
    x -= data[i+k][l];
    x += data[i+k][l+t];
  }
  return x;
}
int solve(){
  int ans=0, tmp=0;
  for(int i=0; i<=h-s; ++i){
    tmp=get(i);
    ans=max(ans, tmp);
    for(int j=0; j<w-t; ++j){
      tmp=move(tmp, i, j);
      ans=max(ans, tmp);
    }
  }
  return ans;
}

int main(){
  int n, x, y;
  while(1){
    cin >> n;
    if(!n) break;
    init();
    cin >> h >> w;
    for(int i=0; i<n; ++i){
      cin >> x >> y;
      data[x-1][y-1]=true;
    }
    cin >> s >> t;
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)

int main(){
    int A,B,K;
    int index = 0;
    cin >> A >> B >> K;
    int N = max(A,B);
    rep(i,0,N){
        if(A%(N-i)==0 && B%(N-i)==0){
            index++;
            if(index == K) cout << (N-i) << endl;
        }
    }

}

Measured memory_bytes: 256
#include <stdio.h>

#define MIN(A,B) ((A)<(B)?(A):(B))

int main(){
    int facterCnt2=0;
    int facterCnt5=0;
    int n;
    
    while (scanf("%d",&n)!=EOF){
        if (n==0) break;
        facterCnt2 = facterCnt5 = 0;
        for (int skip=2; skip<20000; skip *=2){
            facterCnt2 += n/skip;
        }
        for (int skip=5; skip<20000; skip *=5){
            facterCnt5 += n/skip;
        }
        printf("%d\n", MIN(facterCnt2,facterCnt5));
    }
    
    
    return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
#include <cstdlib>
#include <ctime>
using namespace std;
#define pi acos(-1)
#define mod 1000000007
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))
#define cio ios::sync_with_stdio(false);
int s[200010];    // 结果
vector<int>v[200010]; // 建图
int main()
{   	
	int n, m;
	cin >> n >> m;
	int a, b;
	for(int i = 1; i <= m; i++){
		cin >> a >> b;
	v[a].push_back(b);
	v[b].push_back(a);
	}
	queue<int>q; // 队列用于搜索路径
	s[1] = 0; // 从1开始
	for(int i = 0; i < v[1].size(); i++){ // 将和1直接相连得点进去队列
		q.push(v[1][i]);
		s[v[1][i]] = 1; // 前一个点为1
	}
	while(!q.empty()){
		int p = q.front(); // 取队首元素
		q.pop(); // 移除队列
		for(int i = 0; i < v[p].size(); i++){ // 将与队首元素直接相连的点进入队列
			if(s[v[p][i]]==0&&v[p][i]!=1){ // 如果该点未走过，进入队列
				q.push(v[p][i]);
				s[v[p][i]] = p; // 该点前一个点即为队首元素p
			}
		}
	}
	int flag = 1;
	for(int i = 2; i <= n; i++){ // 判断是否每个点都可到达1
		if(s[i]==0){
			flag = 0;
			break;
		}
	}
	// 输出结果
	if(!flag){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
		for(int i = 2; i <= n; i++){
			cout << s[i] << endl;
		}
	}
    return 0;
}


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

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

int d, n;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> d >> n;
    if(n == 100) n = 101;
    int ans = 1;
    REP(i, d) ans *= 100;
    ans *= n;
    cout << ans << endl;

}


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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;g
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;
const static ll MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
    ll n, m;
    cin >> n >> m;

    if (m == 0) {
        n == 1 ? cout << 0 << endl : cout << pow(10, n - 1) << endl;
        exit(0);
    }

    char ans[n];

    NREP() {
        ans[i] = 'X';
    }

    REP(i, m) {
        ll s;
        char c;
        cin >> s >> c;
        if (ans[n - s] != 'X' && ans[n - s] != c) {
            cout << -1 << endl;
            exit(0);
        }
        ans[n - s] = c;
    }

    if (ans[n - 1] == '0' && n != 1) {
        cout << -1 << endl;
        exit(0);
    }

    NREP() {
        if (ans[n - i - 1] == 'X') {
            i == 0 ? ans[n - i - 1] = '1' : ans[n - i - 1] = '0';
        }
    }

    ll ret = 0;
    NREP() {
        ll pwd = pow(10, n - i - 1);
        ll dig = ans[n - i - 1] - '0';
        ret += pwd * dig;
    }
    cout << ret << endl;
}


Measured memory_bytes: 256
N,A,B,C,D = map(int, input().split())
S = [""] + list(input()) + [""]

def can(start, end):
    for i in range(start, end):
        if S[i] == S[i + 1] == "#":
            return False
    return True

def main():
    if not (can(A, C) and can(B, D)):
        return False

    if C < D:
        return True
    elif C > D:
        for i in range(B, D + 1):
            if S[i - 1] == S[i] == S[i + 1] == ".":
                return True
        return False

if __name__ == "__main__":
    if main():
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 6284
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

ll divpow(ll a, ll b, ll div) {
    ll ret = 1;
    a %= div;
    for (ll i = 0; i < b; i++) {
        ret *= a;
        ret %= div;
    }
    return ret;
}

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

    ll div = 998244353;
    map<ll, ll> tree;
    for (int i = 0; i < N; i++) {
        ll tmp;
        cin >> tmp;
        if (i == 0 && tmp != 0) {
            cout << 0 << endl;
            return 0;
        }
        tree[tmp]++;
    }
    if (tree[0] != 1) {
        cout << 0 << endl;
        return 0;
    }
    ll output = 1;
    pair<ll, ll> before = make_pair(0, tree[0]);
    for (auto t : tree) {
        if (t.first == 0) continue;
        if (t.first != before.first + 1) {
            output = 0;
            break;
        }
        output *= divpow(before.second, t.second, div);
        output %= div;
        before = t;
    }
    cout << output << endl;

    return 0;
}


Measured memory_bytes: 9816
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

using Graph = map<int,vector<pair<int,int>>>;
Graph rec(int L) {
  if(L==2) {
    map<int,vector<pair<int,int>>> G;
    G[1].push_back(make_pair(2,0));
    G[1].push_back(make_pair(2,1));
    return G;
  }
  if(L%2==0) {
    auto G = rec(L/2);
    Graph newG;
    int n = G.size();
    repeat(u,1,n+1) {
      for(auto vw : G[u]) {
        int v = vw.first;
        int w = vw.second;
        newG[u].push_back(make_pair(v,2*w));
      }
    }
    newG[n+1].push_back(make_pair(n+2,0));
    newG[n+1].push_back(make_pair(n+2,1));
    return newG;
  } else {
    auto G = rec(L-1);
    int n = G.size()+1;
    G[1].push_back(make_pair(n,L-1));
    return G;
  }
}

void printGraph(Graph G) {
  int n = G.size()+1;
  int m = 0;
  repeat(i,1,n+1) {
    m+=G[i].size();
  }
  cout << n << " " << m<<endl;
  repeat(v,1,n+1) {
    for(auto& uw : G[v]) {
      cout << v << " " << uw.first << " " << uw.second << endl;
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int L;
  cin>>L;
  auto G = rec(L);
  printGraph(G);
  return 0;
}


Measured memory_bytes: 256
N, M, Q = map(int, raw_input().split())

train = []
for i in range(0, N):
	train.append([])
for i in range(0, M):
	L, R = map(int, raw_input().split())
	train[L-1].append(R)
for i in range(0, N):
	train[i-1].sort()

counter = []
for i in range(0, N):
	lst = []
	for j in range(0, N):
		lst.append(0)
	for j in range(0, len(train[i])):
		lst[train[i][j]-1] = lst[train[i][j]-1] + 1
	for j in range(1, len(lst)):
		lst[j] = lst[j-1] + lst[j]
	counter.append(lst)
for i in range(1, N):
	for j in range(0, N):
		counter[N-1-i][j] = counter[N-1-i][j] + counter[N-i][j]

for i in range(0, Q):
	p, q = map(int, raw_input().split())
	print counter[p-1][q-1]

Measured memory_bytes: 17256
s = input()
k = int(input())

l = []
for i in range(len(s)):
    for j in range(1, 6):
        if i + j > len(s): break
        l.append(s[i : i + j])
l.sort()
cnt = 0
idx = 0
for i in range(len(l)):
    sub = 0
    while idx + sub < len(l) and l[idx] == l[idx + sub]: sub += 1
    cnt += 1
    if cnt == k:
        print(l[idx])
        break
    idx += sub

Measured memory_bytes: 4340
import itertools

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

list = [i+1 for i in range(n)]

per = itertools.permutations(list, n)

cnt = 0
for i in per:
	now = [i[j] for j in range(n)]
	if now == p:
		a = cnt
	if now == q:
		b = cnt
	cnt += 1

print(abs(a-b))


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    public static class AtCoder
    {
        public static void Main()
        {
            var input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);
            int x = int.Parse(input[2]);
            var ar = new int[n, m + 1];

            var book = new List<int>();
            for (int i = 0; i < n; i++)
            {
                book.Add(i);
                input = Console.ReadLine().Split(' ');
                for (int j = 0; j <= m; j++) { ar[i, j] = int.Parse(input[j]); }
            }

            // すべての組み合わせを調査
            int answer = 0;
            for (int i = 1; i <= n; i++)
            {
                var combi = Enumerate<int>(book, i, false);
                foreach (var c in combi)
                {
                    var check = new int[m];
                    int price = 0;
                    foreach (var j in c)
                    {
                        for (int k = 1; k <= m; k++)
                        {
                            check[k - 1] += ar[j, k];
                        }
                        price += ar[j, 0];
                    }

                    bool ok = true;
                    for (int k = 1; k <= m; k++)
                    {
                        if (check[k - 1] < x)
                        {
                            ok = false;
                            break;
                        }
                    }

                    if (ok)
                    {
                        if(answer == 0) { answer = price; }
                        else
                        {
                            answer = Math.Min(answer, price);
                        }
                    }
                }
            }

            if (answer == 0) { Console.WriteLine("-1"); }
            else { Console.WriteLine(answer); }
        }

        private static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items, int k, bool withRepetition)
        {
            if (k == 1)
            {
                foreach (var item in items)
                    yield return new T[] { item };
                yield break;
            }
            foreach (var item in items)
            {
                var leftside = new T[] { item };

                // item よりも前のものを除く （順列と組み合わせの違い)
                // 重複を許さないので、unusedから item そのものも取り除く
                var unused = withRepetition ? items : items.SkipWhile(e => !e.Equals(item)).Skip(1).ToList();

                foreach (var rightside in Enumerate(unused, k - 1, withRepetition))
                {
                    yield return leftside.Concat(rightside).ToArray();
                }
            }
        }
    }
}

Measured memory_bytes: 44472
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;

int board[10][10];
int memo[7][7][7][10][10];
int h,w;

struct State {
    int x,y,top,south,east,cost;
    State(int x,int y,int top,int south,int east,int cost) :
        x(x), y(y), top(top), south(south), east(east), cost(cost) {;}
};

const bool operator<(const State &s,const State &t) {
    return s.cost > t.cost;
}

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

State roll(State s,int k) {
    int nx = s.x + dx[k], ny = s.y + dy[k];
    if(nx < 0 || nx > w-1 || ny < 0 || ny > h-1)
        return State(-1,0,0,0,0,0);

    int ntop,nsouth,neast;
    if(k == 0) {
        nsouth = s.south;
        neast = s.top;
        ntop = 7 - s.east;
    }else if(k == 1) {
        neast = s.east;
        nsouth = s.top;
        ntop = 7 - s.south;
    }else if(k == 2) {
        nsouth = s.south;
        neast = 7 - s.top;
        ntop = s.east;
    }else if(k == 3) {
        neast = s.east;
        nsouth = 7 - s.top;
        ntop = s.south;
    }
    return State(nx,ny,ntop,nsouth,neast,0);
}

inline int dist(State s) {
    return memo[s.top][s.south][s.east][s.y][s.x];
}

int main() {
    while(cin>>h>>w, h|w) {
        for(int i=0; i<h; ++i)
            for(int j=0; j<w; ++j) cin>>board[i][j];

        int sx,sy,gx,gy;
        cin>>sy>>sx>>gy>>gx;

        priority_queue<State> q;
        memset(memo, -1, sizeof(memo));
        memo[1][2][3][sy][sx] = 0;
        q.push(State(sx,sy,1,2,3,0));
        while(!q.empty()) {
            State s = q.top(); q.pop();
            for(int k=0; k<4; ++k) {
                State ns = roll(s,k);
                if(ns.x == -1) continue;
                int nc = dist(s) + (7-ns.top)*board[ns.y][ns.x];
                if(dist(ns) != -1/* && nc > dist(ns)*/) continue;
                memo[ns.top][ns.south][ns.east][ns.y][ns.x] = nc;
                ns.cost = nc;
                q.push(ns);
            }
        }

        int ans = 1<<29;
        for(int i=1; i<=6; ++i)
            for(int j=1; j<=6; ++j)
                for(int k=1; k<=6; ++k) {
                    if(memo[i][j][k][gy][gx] == -1) continue;
                    ans = min(ans, memo[i][j][k][gy][gx]);
                }

        cout<<ans<<endl;
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

int A[1000];
int main(){
    int N;
    cin >> N;
    int sum = 0;
    REP(i,N){
        int a;
        cin >> a;
        A[i] = a;
        sum += a;
    }

    double ave = (double)sum / N;
    //cout << ave << endl;

    int idx = -1;
    double min = 1000000;
    REP(i,N){
        double diff = fabs(ave - A[i]);
        //cout << diff << endl;
        if(diff < min){
            min = diff;
            idx = i;
        }
    }

    cout << idx << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while (true) {

			int n = Integer.parseInt(br.readLine());

			if (n == 0)
				break;

			ArrayList<Product> products = new ArrayList<>();
			for (int i = 0; i < n; i++) {
				String str[] = br.readLine().split(" ");
				int p = Integer.parseInt(str[1]);
				int a = Integer.parseInt(str[2]);
				int b = Integer.parseInt(str[3]);
				int c = Integer.parseInt(str[4]);
				int d = Integer.parseInt(str[5]);
				int e = Integer.parseInt(str[6]);
				int time[] = { a, b, c, d, e };
				int f = Integer.parseInt(str[7]);
				int s = Integer.parseInt(str[8]);
				int m = Integer.parseInt(str[9]);
				products.add(new Product(str[0], p, time, f, s, m));
				products.get(i).setEfficiency();
			}
			Collections.sort(products);
			for (int i = 0; i < n; i++) {
				System.out.println(products.get(i).name);
			}
			System.out.println("#");
		}
	}
}

class Product implements Comparable<Product> {

	String name;
	int p;
	int time[] = new int[5];
	int f;
	int s;
	int m;

	double efficiency;

	public Product(String name, int p, int time[], int f, int s, int m) {
		this.name = name;
		this.p = p;
		this.time = time;
		this.f = f;
		this.s = s;
		this.m = m;
		efficiency = 0.0;
	}

	public void setEfficiency() {
		int money = ((f * s) * m) - p;
		int t = (time[3] + time[4]) * m;
		t += time[0] + time[1] + time[2];
		efficiency = money / (double) t;
	}

	@Override
	public int compareTo(Product pro) {
		if (this.efficiency > pro.efficiency) {
			return -1;
		} else if (this.efficiency < pro.efficiency) {
			return 1;
		} else {
			return this.name.compareTo(pro.name);
		}
	}
}


Measured memory_bytes: 29516
import java.util.*;
public class Main{
	public static void main(String args[]){
		
		Scanner ob = new Scanner(System.in);
		int N = ob.nextInt();
		int count = 0;
		int num;
		/*String con;

		con = Integer.toString(N);

		for(int i = 0; i < con.length(); i++){
			if(con.charAt(i) == 7){
				++count;
			}
		}
		if(count > 0){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}*/

		for(int i = 1; i <= N; i++ ){
			num = N % 10;
			if(num == 7){
				++count;
			}

			N /= 10;
		}
		if(count > 0){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 35768
n=int(input())
a=list(map(int,input().split()))
x = True
for i in range(len(a)):
  if a[i]%2==1:
    continue
  else:
    if (a[i]%3!=0)&(a[i]%5!=0):
      x = False
if x == False:
  print("DENIED")
else:
  print("APPROVED")

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

int main(){
  int N;
  cin>>N;
  int s=0;
  for(int i=0;i<N;i++){
    int l,r;
    cin>>l>>r;
    s+=(r-l+1);
  }
  cout<<s<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1000000007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }


template <class X>
class SegmentTree {
    int n;
    vector<X> dat;
    X identity;

    X query_sub(int a, int b, int i, int l, int r) {
        if (r <= a || b <= l) return identity;
        if (a <= l && r <= b)
            return dat[i];
        else {
            X vl = query_sub(a, b, i * 2 + 1, l, (l + r) / 2);
            X vr = query_sub(a, b, i * 2 + 2, (l + r) / 2, r);
            return op(vl, vr);
        }
    }

    X get_identity(){
        return 0; // Range Sum Query
    }
    X op(X x, X y){
        return x + y; // Range Sum Query
    }
public:
    SegmentTree(int n_) {
        n = 1;
        while (n < n_) n *= 2;

        identity = get_identity();
        dat = vector<X>(2 * n - 1, identity);

    }
    void update(int i, X x) {
        i += n - 1;
        dat[i] = x;
        while (i > 0) {
            i = (i - 1) / 2;
            dat[i] = op(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }
    // [a, b)
    X query(int a, int b) { return query_sub(a, b, 0, 0, n); }
    X at(int i) { return dat[i + n - 1]; }
};

int main(){
    int N;
    string S;
    int Q;
    cin >> N >> S >> Q;
    vector<SegmentTree<int>> st(26, SegmentTree<int>(N+1));
    REP(i, N)
        st[S[i]-'a'].update(i, 1);


    REP(i, Q){
        int kind;
        cin >> kind;
        if(kind == 1){
            int i;
            char c, c_old;
            cin >> i >> c;
            i--;
            c_old = S[i];
            S[i] = c;
            st[c_old-'a'].update(i, 0);
            st[c-'a'].update(i, 1);
        }else{
            int l, r;
            cin >> l >> r;
            l--; r--;
            int tot = 0;
            REP(i, 26)
                if(st[i].query(l, r+1) > 0) tot++;
            cout << tot << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 111620
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
double dp[3001][3001];

int main()
{
    int n;
    cin>>n;
    double a[n+5];
    for(int i=0; i<n; i++)
        cin>>a[i];

    memset(dp,0.0,sizeof(dp));

    for(int i=0; i<=n; i++)
    {
        double heads_prob=a[i-1];
        double tails_prob=1-heads_prob;
        for(int j=0; j<=i; j++)
        {
            if(i==0 && j==0)
                dp[i][j]=1.0;
            else if(j==0)
                dp[i][j]=dp[i-1][j]*tails_prob;
            else
                dp[i][j]=(dp[i-1][j]*tails_prob)+(dp[i-1][j-1]*heads_prob);
        }
    }

    double prob=0.0;
    for(int i=(n/2)+1; i<=n; i++)
        prob+=dp[n][i];
    cout<<setprecision(10)<<fixed<<prob<<endl;
    return 0;
}


Measured memory_bytes: 74148
//============================================================================
// Name        : hoba.cpp :)
// Author      : (O_O Diab) (Why_not) (el 3AQ)
// Version     :
// Copyright   : please, Don't touch me :(
// Description : problem in C++
// MAIN IDEA   : combinatorics NCR
//============================================================================
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define rw freopen("graphs_as_a_service.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define EPS 1e-6
// to convert string to number use int a = stoi(string);
// to convert number to string use string s = to_string(int);
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace __gnu_pbds;
using namespace std;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int N = 2e2 + 10, mod = (int) 1e9 + 7, INF = 0x3f3f3f3f;
int SP[11][11] = { };
int main() {
#ifdef ONLINE_JUDGE
	FAST
#endif
	int h, w;
	cin >> h >> w;
	lp(i,0,9)
		lp(j,0,9)
			cin >> SP[i][j];
	lp(k,0,9)
		lp(i,0,9)
			lp(j,0,9)
				SP[i][j] = min(SP[i][j], SP[i][k] + SP[k][j]);
	int ans = 0;
	lp(i,1,h)
		lp(j,1,w)
		{
			int x;
			cin >> x;
			if (abs(x) == 1)
				continue;
			ans += SP[x][1];
		}
	f(ans);
	return 0;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline

def main():
    ans = 0
    n, m ,x = map(int, input().split())
    a = list(map(int, input().split()))
    l = [0]*(n+1)
    for ai in a:
        l[ai] = 1
    ans = min(sum(l[:x]), sum(l[x:]))
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
 
int main() {
	ios::sync_with_stdio(false);
	int a,b;
	cin >> a >> b;
	if (a==1 && a!=b) cout << "Alice";
	else if (b==1 && a!=b) cout << "Bob";
	else if (a>b) cout << "Alice";
	else if (a<b) cout << "Bob";
	else cout << "Draw";
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
int ans,n,t;
char s[110]; 
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	fo(i,1,n){
		t=0;
		fo(j,i,n){
			if (s[j]!='A'&&s[j]!='T'&&s[j]!='C'&&s[j]!='G') break;
			t++;
			if (t>ans) ans=t;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
string A, B, C;
ll dp[51][20];
const int MOD = 1000000007;

void show() {
    int N = A.size();
    for (int i = 0; i <= N; ++i) {
        for (int j = 0; j < 19; ++j) {
            printf("%d ", dp[i][j]);
        }
        cout << endl;
    }
    cout << endl;
}

void solve() {
    int N = A.size();
    dp[0][0] = 1;
    for (int i = 0; i <= N; ++i) {
        char a = A[N - 1 - i];
        int a_ini = a != '?' ? a - '0' : N - 1 - i == 0 ? 1 : 0;
        int a_end = a != '?' ? 1 + a_ini : 10;
        char b = B[N - 1 - i];
        int b_ini = b != '?' ? b - '0' : N - 1 - i == 0 ? 1 : 0;
        int b_end = b != '?' ? 1 + b_ini : 10;
        char c = C[N - 1 - i];
        int c_ans = c != '?' ? c - '0' : -1;

        for (int l = 0; l <= 19; ++l) {
            ll past = dp[i][l];
            if (past == 0)  continue;
            for (int j = a_ini; j < a_end; ++j) {
                for (int k = b_ini; k < b_end; ++k) {
                    int ab = 10 <= l ? 1 + j + k : j + k;
                    if (c_ans == -1 || ab % 10 == c_ans) {
                        dp[i+1][ab] += past % MOD;
                    }
                }
            }
        }
    }
    if (C[0] != '?') cout << dp[N][C[0] - '0'] << endl;
    else {
        ll sum = 0;
        for (int i = 1; i < 10; ++i) {
            sum += dp[N][i] % MOD;
        }
        cout << sum % MOD << endl;
    }
}

int main() {
    while(true) {
        cin >> A;
        cin >> B;
        cin >> C;
        if (A == "0") break;
        memset(dp, 0, sizeof(dp));
        solve();
    }
    return 0;
}



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

using namespace std;

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

    string s;
    cin >> s;
    cout << (s[0] == '7' || s[1] == '7' || s[2] == '7' ? "Yes\n" : "No\n");

    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>

int
main(int argc, char *argv[])
{
  int n, a, cnt4 = 0, cnto = 0, cnte = 0;
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%d", &a);
    if((a & 3) == 0) cnt4++;
    if((a & 1) == 1) cnto++;
    if((a & 3) != 0 && (a & 1) == 0) cnte++;
  }
  if(cnte == 0){
    if(cnto <= cnt4 + 1) printf("Yes\n");
    else printf("No\n");
  }else{
    if(cnto <= cnt4) printf("Yes\n");
    else printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int a,b;
  cin >> a >> b;
  int s=0;
  int t=0;
  
  for(int i=0; i<b ; i++){
    s +=pow(10,i);
  }
  
  
  for(int i=0; i<a ; i++){
    t +=pow(10,i);
  }
  
  int A = s*a;
  int B = t*b;
  
  if(a<b){
    cout << A << endl;
  }
  
  else{
    cout << B <<endl;
  }
  
}

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

int main(){
    int a,b,c;
    int cnt = 0;

    cin >> a >> b >> c ;

    for ( int i=a ; i<=b ; i++){
        if ( c%i == 0){
            cnt++;
        }
    }
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 3096
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N, M;
ll arr[100005];
vector<pair<ll, ll>> V;
ll B, C;

int main() {
	scanf("%lld %lld", &N, &M);
	for(int i = 0; i < N; i++) {
		scanf("%lld", &arr[i]);
	}
	sort(arr, arr + N);
	ll X = M;
	while(X--) {
		scanf("%lld %lld", &B, &C);
		V.push_back(make_pair(C, B));
	}
	sort(V.begin(), V.end(), greater<pair<ll, ll>>());
	ll sum = 0;
	vector<ll> temp(N);
	for(int i = 0, k = 0; i < M && k < N; i++) {
			// cout << "tjos";
		int len = V[i].second;
		while(len--) {
			if(k >= N) {
				break;
			}
			temp[k++] = V[i].first;
			// cout << temp[k]
		}
	}

	ll ans = 0;
	for(int i = 0; i < N; i++) {
		// cout << arr[i] << " " << temp[i] << "\n";
		ans += max(arr[i], temp[i]);
	}
	printf("%lld\n", ans);
	return 0;

}
/*
	Powered by Buggy Plugin
*/


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

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    int common_divisors[101];
    for (int i = 0; i < 101; i++) {
        common_divisors[i] = 0;
    }
    for (int i = 1; i < 101; i++) {
        if (A % i == 0 && B % i == 0) {
            common_divisors[i] = 1;
        }
    }
    int j = 0;
    int Kth_divisor;
    for (int i = 100; i > 0; i--) {
        if (common_divisors[i]) {
            j++;
            if (j == K) {
                Kth_divisor = i;
                break;
            }
        }
    }
    cout << Kth_divisor << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll d,t,s;
  cin>>d>>t>>s;
  cout<<(d<=s*t?"Yes":"No")<<endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
char s[100010];
int w[26],v[26],f[26],g[26];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    scanf("%s",s+1);
    int n=strlen(s+1);
    ++w[s[1]-'a'];
    for(int i=2;i<=n;i++) {
	++w[s[i]-'a'];
	for(int j=0;j<26;j++)
	    if(2*w[j]-i>f[j]) return cout<<g[j]+1<<' '<<i,0;
	++v[s[i-1]-'a'];
	for(int j=0;j<26;j++)
	    if(2*v[j]-i+1<f[j]) f[j]=2*v[j]-i+1,g[j]=i-1;
    }
    puts("-1 -1");
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll; ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);
ll fac(ll x){if(x==0) return 1;  return x*fac(x-1);}

int main(){
    set<ll> t, y;
    ll h, w; cin>>h>>w;
    vector<vector<char>>a(h, vector<char>(w));
    rep(i,h){
        ll cnt=0;
        rep(j,w){
            cin>>a[i][j];
            if(a[i][j]=='#') cnt++;
        }
        if(cnt==0) y.insert(i);
    }
    rep(i,w){
        ll cnt=0;
        rep(j,h){
            if(a[j][i]=='#') cnt++;
        }
        if(cnt==0) t.insert(i);
    }

    rep(i,h){
        if(y.count(i)) continue;
        rep(j,w){
            if(t.count(j)) continue;
            cout<<a[i][j];
        }
        cout<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9+7;


int main(){

    int h,w,n;
    cin >> h >> w >> n;
    vector<int> a(n);

    int mp[h][w];
    

    for(int i = 0;i < n;i++){
        cin >> a[i];
    }

    int index = 0;
    for(int i = 0;i < h;i++){
        if(i % 2 == 0){
            for(int j = 0;j < w;j++){
                //if(a[index] > 0){
                    mp[i][j] = index+1;
                    a[index]--;
                    if(a[index] == 0){
                        index++;
                    }
                //}
            }
        }else{
            for(int j = w-1;j >= 0;j--){
                mp[i][j] = index+1;
                a[index]--;
                if(a[index] == 0){
                    index++;
                }
            }
        }
    }

    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            if(j == 0){
                cout << mp[i][j];
            }else{
                cout << " " << mp[i][j];
            }
        }
        cout << endl;
    }


    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include <sstream>
#include<map>
#include<cmath>
#include<queue>

using namespace std;

int main() {

	int X, A;
	cin >> X >> A;

	int result = (X < A) ? 0 : 10 ;


	cout << result << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,a[100101]={};
	int c4=0,c2=0;
	cin>>n;
	FOR(i,0,n){
		cin>>a[i];
		if(a[i]%4==0){
			a[i]=2;
			c4++;
		}else if(a[i]%2==0){
			a[i]=1;
			c2++;
		}else{
			a[i]=0;
		}
	}
	n-=(c2+c4);
	if(c2!=0){
		if(n<=c4)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}else{
		if(n-1<=c4)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
    return 0;
}


Measured memory_bytes: 640