akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, m, n) for (int i = m; i < n; ++i)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
// vvi data(n, vi(m));
using vll = vector<long long>;
using vvll = vector<vll>;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
  int x, y;
  cin >> x >> y;
  cout << x + y / 2 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(c,itr) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	string s;
	cin>>s;
	string t=s;
	reverse(all(t));
	int cnt=0;
	rep(i,s.size()){
		if(s[i]!=t[i]){
			cnt++;
		}
	}
	cout<<cnt/2;
	re 0;
}

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

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		//BufferedReader in = new BufferedReader(new FileReader(new File("input.txt")));
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] line = in.readLine().split(" ");
		int a = Integer.valueOf(line[0]);
		int b = Integer.valueOf(line[1]);
		if(a <= 5) {
			System.out.println("0");
		}else if(a <= 12) {
			System.out.println(b/2);
		}else {
			System.out.println(b);
		}
	}
}

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

typedef long long int ll;

const int MOD = 1e9 + 7;
const int INF = 2e9;

ll dp[55][55][2550];

int main() {
    int n, a;
    scanf("%d %d",&n,&a);
    int x[n];
    for(int i=0;i<n;i++) scanf("%d",&x[i]);

    dp[0][0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            for (int k = 0; k <= 2500; k++) {
                if (dp[i][j][k] == 0) continue;
                dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
                dp[i + 1][j][k] += dp[i][j][k];
            }
        }
    }

    ll ans = 0;
    for(int i=1;i<=n;i++) ans += dp[n][i][i * a];
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 55552
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
int a[MAXN][3];
int dp[MAXN][3];

int main()
{
    int n;
    ni(n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d %d", a[i]+0,a[i]+1,a[i]+2);
        if (i == 0) {
            dp[i][0] = a[i][0];
            dp[i][1] = a[i][1];
            dp[i][2] = a[i][2];
        } else {
            for (int j = 0; j < 3; j++)
                for (int k = 0; k < 3; k++)
                    if (k != j)
                        dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][j]);
        }
    }
    pri(max(dp[n-1][0], max(dp[n-1][1],dp[n-1][2])));
    return 0;
}


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

int compare_int(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

int main() {
  int i, n, m, ans = 0;
  scanf("%d %d", &n, &m);
  int p[n];
  
  for(i = 0; i < n; i++)
	scanf("%d", &p[i]);
  qsort(p, n, sizeof(int), compare_int);
  
  for(i = 0; i < m; i++)
   ans += p[i];
  
  printf("%d", ans);
  return(0);
}

Measured memory_bytes: 1712
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import re
import math
import collections
import itertools
import functools

DEBUG = True
DEBUG = False

def dbg(*args):
    if DEBUG:
        print("DBG: ", file=sys.stderr, end="")
        print(*args, file=sys.stderr)

def dist(a, b):
    return abs(a[0]-b[0]) + abs(a[1]-b[1])

def main():
    N, M = map(int, input().split())
    A = []
    for _ in range(N):
        a, b = map(int, input().split())
        A.append((a,b))
    B = []
    for _ in range(M):
        c, d = map(int, input().split())
        B.append((c,d))

    for i, a in enumerate(A):
        argmin = 0
        dmin = dist(a, B[0])
        for j, b in enumerate(B):
            d = dist(a, b)
            if d < dmin:
                argmin = j
                dmin   = d
        print(argmin+1)

if __name__ == "__main__": main()


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

int main(){
    string s;cin>>s;
    bool judge = false;
    for (int i=0;i<s.size() - 1;i++){
        if (s[i] == 'A' && s[i+1] == 'C'){
            judge = true;
            break;
        }
    }
    if (judge){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1e18 + 10;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n; cin >> n;
    vector<vector<int>> G(n);
    rep(i, n-1){
        int a, b; cin >> a >> b; a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<ll> C(n); ll sum = 0;
    rep(i, n){
        cin >> C[i];
        sum += C[i];
    }
    sort(all(C), greater<ll>());
    sum -= C[0];
    vector<int> res(n, INF);
    queue<int> que; que.push(0);
    res[0] = C[0]; int index = 1;
    while(!que.empty()){
        int v = que.front(); que.pop();
        for(int g: G[v]){
            if(res[g] != INF) continue;
            res[g] = C[index];
            index++;
            que.push(g);
        }
    }
    cout << sum << ln;
    rep(i, n) cout << res[i] << " ";
    cout << ln;
}


Measured memory_bytes: 4012
#include<iostream>

using namespace std;

int main()
{
	int i, j, n, q, count = 0, key;
	int s[10001];
	cin >> n;
	for (i = 0; i < n; i++)cin >> s[i];
	cin >> q;
	for (i = 0; i < q; i++)
	{
		cin >> key;
		j = 0;
		s[n] = key;
		while (s[j] != key)j++;
		if (j != n)count++;
	}
	cout << count << endl;
    return 0;
}

Measured memory_bytes: 1196
#include<stdio.h>
int main(void) {
	int SUM = 0, N, X, a = 0, Y, b = 0, Z, c = 0, are = 0, AA[101] = { 0 }, BB[100] = { 0 }, CC[100] = { 0 }, hanbetu = 0;
	scanf("%d", &N);
	for (are = 0; are < N; are++) {
		AA[are] = 1;
		if (are == 99) {
			break;
		}
	}
	are = 0;
	scanf("%d", &X);
	for (are = 0; are < X; are++) {
		scanf("%d", &a);
		AA[a-1] = 2;
		if (a == 100) {
			AA[a] = 1;
			a = a - 1;
			AA[a] = 2;
		}
	}
	are = 0;
	scanf("%d", &Y);
	for (are = 0; are < Y; are++) {
		scanf("%d", &b);
		BB[b-1] = 1;
	}
	are = 0;
	scanf("%d", &Z);
	for (are = 0; are < Z; are++) {
		scanf("%d", &c);
		CC[c-1] = 1;
	}
	for (hanbetu = 0; hanbetu < 100; hanbetu++) {
		if (AA[hanbetu] == 1 && CC[hanbetu] == 1) {
			SUM = SUM + 1;
		}
	}
	hanbetu = 0;
	for (hanbetu = 0; hanbetu < 100; hanbetu++) {
		if (BB[hanbetu] == 1 && CC[hanbetu] == 1) {
			SUM = SUM + 1;
			if (AA[hanbetu] == 1 && CC[hanbetu] == 1) {
				SUM = SUM - 1;
			}
		}
	}
	printf("%d\n", SUM);
	return 0;
}


Measured memory_bytes: 2732
'use strict'
const main = (input: string) => {
    const [n, l] = input.split(' ').map(Number)
    const al: number[] = [...Array(n)].fill(l).map((v, i) => v+i)
    const minAbs: number = al.reduce((p,c) => Math.min(Math.abs(p), Math.abs(c)))
    al.splice(al.indexOf(minAbs),1)
    console.log(al.reduce((p,c) => p+c,0))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim())

Measured memory_bytes: 7500
#include <bits/stdc++.h>
#define int long long
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
const int INF = 10000000000;
using namespace std;

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

  vector<int> numToUR(1000000, -1), numToUC(1000000, -1), countUR(N), countUC(N);
  vector<int> numToNR(1000000, -1), numToNC(1000000, -1), countNR(N), countNC(N);
  int countUDO = 0, countUDI = 0, countNDO = 0, countNDI = 0;

  rep(i, N) rep(j, N) {
    int x;
    cin >> x;
    --x;
    numToUR[x] = i, numToUC[x] = j;
  }
  rep(i, N) rep(j, N) {
    int x;
    cin >> x;
    --x;
    numToNR[x] = i, numToNC[x] = j;
  }
  int usagi = 0, neko = 0;
  rep(i, M) {
    int t;
    cin >> t;
    --t;
    if (~numToUR[t]) {
      if (++countUR[numToUR[t]] == N) usagi++, countUR[numToUR[t]] = -1;
      if (++countUC[numToUC[t]] == N) usagi++, countUC[numToUC[t]] = -1;
      if (numToUR[t] == numToUC[t]) {
        if (++countUDO == N) usagi++, countUDO = -1;
      }
      if (numToUR[t] == N - 1 - numToUC[t]) {
        if (++countUDI == N) usagi++, countUDI = -1;
      }
    }
    if (~numToNR[t]) {
      if (++countNR[numToNR[t]] == N) neko++, countNR[numToNR[t]] = -1;
      if (++countNC[numToNC[t]] == N) neko++, countNC[numToNC[t]] = -1;
      if (numToNR[t] == numToNC[t]) {
        if (++countNDO == N) neko++, countNDO = -1;
      }
      if (numToNR[t] == N - 1 - numToNC[t]) {
        if (++countNDI == N) neko++, countNDI = -1;
      }
    }
    if (N == 1) {
      if ((usagi >= 1 && U == 1) || (neko >= 1 && V == 1)) {
        if (usagi >= 1 && U == 1 && neko >= 1 && V == 1) {
          return cout << "DRAW" << endl, 0;
        } else if (usagi >= 1 && U == 1) {
          return cout << "USAGI" << endl, 0;
        } else if (neko >= 1 && V == 1) {
          return cout << "NEKO" << endl, 0;
        } else {
          return cout << "DRAW" << endl, 0;
        }
      }
    } else if (U <= usagi && neko < V) {
      return cout << "USAGI" << endl, 0;
    } else if (usagi < U && V <= neko) {
      return cout << "NEKO" << endl, 0;
    } else if (U <= usagi && V <= neko) {
      return cout << "DRAW" << endl, 0;
    }
  }
  cout << "DRAW" << endl;
}



Measured memory_bytes: 33988
#include <string>
#include <iostream>
using namespace std;
string s, t; int n, a, b;
int main() {
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> s >> t;
		if(s > t) a += 3;
		if(s < t) b += 3;
		if(s == t) a++, b++;
	}
	printf("%d %d\n", a, b);
	return 0;
}

Measured memory_bytes: 3336
#include <cstdio>
#include <iostream>
#include <cstring>
#define MN 201000
#define mod 1000000007

int Min[MN]; 
int cnt[MN];
int id1 = -1, id2 = -1; 
int c[MN], w[MN];
int fac[MN], inv[MN];

int C(int a, int b) {return 1ll * fac[a] * inv[b] % mod * inv[a - b] % mod;}

int main()
{
	memset(Min, 0x3f, sizeof(Min));
	int n, x, y; scanf("%d%d%d", &n, &x, &y);
	
	fac[0] = inv[0] = inv[1] = 1;
	for(int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
	for(int i = 2; i <= n; i++) inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
	for(int i = 1; i <= n; i++) inv[i] = 1ll * inv[i] * inv[i - 1] % mod;
	 
	for(int i = 1; i <= n; i++)
	{
		scanf("%d%d", &c[i], &w[i]);
		Min[c[i]] = std::min(Min[c[i]], w[i]);
	}
	
	for(int i = 1; i <= n; i++)
	{
		if(id1 == -1) id1 = i;
		else if(Min[i] <= Min[id1]) {id2 = id1; id1 = i;}
		else if(id2 == -1 || Min[i] <= Min[id2]) id2 = i;
	}
	
	for(int i = 1; i <= n; i++)
	{
		if(w[i] + Min[c[i]] <= x || (id1 == c[i] ? w[i] + Min[id2] : w[i] + Min[id1]) <= y)
			cnt[c[i]]++;
	}
	
	int tot = 0, ans = 1;
	for(int i = 1; i <= n; i++) if(Min[i] + Min[id1] <= y) tot += cnt[i];
	for(int i = 1; i <= n; i++) if(Min[i] + Min[id1] <= y) ans = 1ll * ans * C(tot, cnt[i]) % mod, tot -= cnt[i];
	printf("%d\n", ans);
}

Measured memory_bytes: 4992
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int n;
   cin >> n;
   vector<int> d(n, 0);
   for (int i = 0; i < n; i++)
      cin >> d[i];
   sort(d.begin(), d.end());
   cout << d[n / 2] - d[n / 2 - 1] << endl;
   return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n;
    m=n%10;
    if(m==2||m==4||m==5||m==7||m==9)
        cout<<"hon";
    else if(m==3)
cout<<"bon";
else
   cout<<"pon";
return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int h = sc.nextInt();
			int w = sc.nextInt();
			
			if(h == 0 && w == 0) {
				break;
			}else {
				for(int i1 = 0; i1 < h; i1++) {
					for(int i2 = 0; i2 < w; i2++) {
						System.out.print("#");
					}
					System.out.println();
				}
				System.out.println();
			}
		}
	}
}



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

int main() {
	int m, d;
	cin >> m >> d;
	ll ans = 0;
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= d; j++) {
			if (j % 10 >= 2 && j / 10 >= 2 && (j % 10) * (j / 10) == i)ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class QuestionC
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var inputLongArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            double a = inputLongArray[0];
            double b = inputLongArray[1];
            double h = inputLongArray[2];
            double m = inputLongArray[3];

            var hth = (h / 6 + m / 360) * Math.PI;
            var mth = (m / 30) * Math.PI;
            var hx = a * Math.Cos(hth);
            var hy = a * Math.Sin(hth);
            var mx = b * Math.Cos(mth);
            var my = b * Math.Sin(mth);

            var result = Math.Sqrt((hx - mx) * (hx - mx) + (hy - my) * (hy - my));

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}

Measured memory_bytes: 28664
#include<bits/stdc++.h>
using namespace std;
int i, p;
#define f(i, p) for( i = 0 ; i < p ; i++)
int main()
{
  int n, t;
  double k;
  cin>>n>>t>>k;
  vector<double> a ;
  f(i,n)
  { 
    int y;
    double g;
    cin>>y;
    g = t-(y*0.006);
    a.push_back(g);
  }
  double min = INT_MAX; 
  int minin;
  f(i,n)
  {
      //cout<<abs(a[i]-k)<<endl;
      
      if(abs((double)(a[i]-k))<min)
      { //cout<<abs(a[i]-k)<<endl;
          min = (double)abs(a[i]-k); minin = i; }
  }
  cout<<minin+1<<endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int i=N;
  int sum=0;
   
  while(i > 0){
    sum += i % 10;
    i /= 10;
  }
  
  if(N%sum == 0){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    int p[a],q[b],r[c];
    for(int i=0;i<a;i++)cin>>p[i];
    for(int i=0;i<b;i++)cin>>q[i];
    for(int i=0;i<c;i++)cin>>r[i];
    sort(p,p+a,greater<int>());
    sort(q,q+b,greater<int>());
    int d=x+y+c;
    int s[d];
    for(int i=0;i<x;i++)s[i]=p[i];
    for(int i=x;i<x+y;i++)s[i]=q[i-x];
    for(int i=x+y;i<d;i++)s[i]=r[i-x-y];
    sort(s,s+d,greater<int>());
    long long sum=0;
    for(int i=0;i<x+y;i++)sum+=s[i];
    cout<<sum<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define REP(i, FN) for (int i = 0; i < FN; i++)
const int INF = 0x3f3f3f3f;

int a[55][26];

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

  REP(i, n) {
    string s;
    cin >> s;
    REP(j, s.size()) a[i][s[j] - 'a']++;
  }

  REP(j, 26) {
    int mn = INF;
    REP(i, n) mn = min(mn, a[i][j]);
    REP(i, mn) cout << (char)('a' + j);
  }
  cout << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>

using namespace std;

int main(){
    string s1, s2;
    getline(cin, s1);
    getline(cin, s2);
    string ring = s1 + s1;
    // cout << "ring: " << ring << endl;
    // cout << ring.find(s2) << endl;
    if(ring.find(s2) != string::npos){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3224
#include <stdio.h>
int main () 
{
int n,x,tmp,i,j=0;
int count = 1;
int d[110];

scanf("%d",&n);
for(i=0;i<n;i++)
{
    scanf("%d",&d[i]);
}

while(1)
{
    int max = 0;
    for(i=j;i<n;i++)
    {    
        if(max<d[i])
        {
            max = d[i];
            x = i;
        }
    }
    tmp = d[j];
    d[j] = d[x];
    d[x] = tmp;
    if(j == n-1)
    break;
    j++;
}

for(i=0;i<n-1;i++)
{
    if(d[i]!=d[i+1])
    {
        count++;
    }
}
printf("%d",count);
return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
def main():
    R, C,K = map(int, input().split())
    dp = [[[0]*(C+1) for k in range(R+1)] for _ in range(4)]
    # dp[r][c][j] :=r index c columns already j cnt
    dp[0][0][0] = 0
    D = [[0 for i in range(C+1)] for j in range(R+1)]
    import random
    for i in range(K):
        r, c, v = map(int,input().split())
        D[r][c] = v
    
    for i in range(R+1):
        for j in range(C+1):
            if D[i][j] > 0:
                v = D[i][j]
                M = max(dp[k][i-1][j] for k in range(4))
                dp[0][i][j] = max(dp[0][i][j-1], M)
                dp[1][i][j] = max(dp[0][i][j-1]+v, dp[1][i][j-1], M+v)
                dp[2][i][j] = max(dp[1][i][j-1]+v, dp[2][i][j-1])
                dp[3][i][j] = max(dp[2][i][j-1]+v, dp[3][i][j-1])
    
            else:
                M = max(dp[k][i-1][j] for k in range(4))
                dp[0][i][j] = max(dp[0][i][j-1], M)
                dp[1][i][j] = dp[1][i][j-1]
                dp[2][i][j] = dp[2][i][j-1]
                dp[3][i][j] = dp[3][i][j-1]
    
    ans = 0
    for i in range(4):
        ans = max(ans, dp[i][-1][-1])
    print(ans)
main()

Measured memory_bytes: 446712
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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



int main(){
	
    int n,ans = 0;
    cin >> n;
    rep(i,0,n){
        int l,r;
        cin >> l >> r;
        ans += r -l+1;
    }
    P(ans);
	return  0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<char,int> pi;
int main(){
	//ios_base::sync_with_stdio(false);
	int len;
	string s;
	cin>>len>>s;
	set<int>red;
	set<int>white; 
	set<int>::iterator it;
	
	for(int i=0; s[i]; i++){
		if(s[i]=='R') red.insert(i);
		else white.insert(i);
	}
	vector<int>order;
	int counter = 0;
	char curr = s[0];
	for(int i=0; s[i]; i++){
		if(s[i]==curr) counter++;
		else{
			order.push_back(counter);
			counter = 1;
			curr = s[i];
		}
	}
	order.push_back(counter);
	if(red.empty() || white.empty()) cout<<0;
	else if(order.size()==2 && s[0]=='R') cout<<0;
	else{
		int minchange = 0;
		for(int i=0; s[i]; i++){		
			if(s[i]=='R'){
				if(red.size()==0) break;
				else red.erase(red.begin());
			}
			else{
				white.erase(white.begin());
				if(red.size()){
					it = red.end();
					it--;
					int point = *it;
					minchange++;
					s[point] = 'W';
					white.insert(point);
					red.erase(it);
				}
				else break; 
			}
		}
		cout<<minchange;
	}
}

Measured memory_bytes: 13408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  int n,k;
  cin >> n >> k;
  map<int,int> mp;
  rep(i,n){
    int x;
    cin >> x;
    mp[x]++;
  }
  vector<int> v;
  int ans = 0;
  for (auto q:mp){
    v.push_back(q.second);
  }
  sort(v.begin(),v.end());
  int tmp;
  tmp = int(v.size()) - k;
  if (tmp > 0){
    //cout << v.size() << "-" << k << "=" << tmp << endl;
    for (int j = 0;j < tmp;j++){
      ans += v[j];
    }
  }
  cout << ans << endl;
  return 0;
  
}


Measured memory_bytes: 13572
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>
#include <algorithm>
#include <complex>
#define FIXED_FLOAT(x)  std::fixed <<std::setprecision(7)<<(x)
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace  std;

using ll = long long;
const ll mod = 1e9 + 7;
typedef pair<ll ,ll > pairs;
typedef complex<ll> G;
const int N=2e5+5;

const ll INF = 1e18;

void done() {
    int n, k;
    cin >> n>> k;
    vector<int>a(n+1);
    for(int i = 1;i <= n;i++) {
        cin >> a[i];
    }
    for(int i=2; i<= n;i++) {
        a[i] += a[i-1];
    }
    int best = 0;
    a[0] = 0;
    for(int i =k;i <=n;i++) {
        best = max(best, a[i]-a[i-k]);
    }
    cout << FIXED_FLOAT((best+k)*.5);
}
void solve() {

    int n;
    cin >>n;
    vector<int>a(n);
    vector<int>b(n);
    vector<long double>c;
    for(int i=0;i < n;i++) {
        cin >> a[i];
    }
    int r = 0;
    for(int i=0;i < n;i++) {
        cin >> b[i];
        if(a[i]!=0) {
            c.push_back(b[i]/a[i]*1.0);
        }else if(b[i]=='0') {
            r++;
            c.push_back(-999999999);
        }
        else {
            c.push_back(-999999999);
        }
    }
    int sum = 1;
    int best = 0;
    sort(c.begin(), c.end());
    for(int i=1;i < n;i++) {
        if(c[i]==c[i-1] && c[i-1]!=-999999999) {
                sum++;
        }
        else {
            if(sum > best && c[i-1]!=-999999999) {
                best = sum;
                sum = 1;
            }
        }
    }
    if(sum > best && c[n-1]!=-999999999) {
        best = sum;
    }
    cout << best+r << '\n';
}
void another() {
    int n;cin >> n;
    vector<int>a(n);
    for(int i=0;i < n;i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int p = a[n-1];
    int ans = 0;


}
void test_case() {
    int t;
    cin >> t;
    while(t--)done();
}
int main() {

    fast;
    done();

}



Measured memory_bytes: 3976
class Dice:
    def __init__(self):
        self.faces=[]

    def rotate(self, direction):
        tmp = self.faces.copy()

        if direction =="N":
            self.faces[5-1] = tmp[1-1]
            self.faces[1-1] = tmp[2-1]
            self.faces[2-1] = tmp[6-1]
            self.faces[6-1] = tmp[5-1]
        if direction =="S":
            self.faces[5-1] = tmp[6-1]
            self.faces[1-1] = tmp[5-1]
            self.faces[2-1] = tmp[1-1]
            self.faces[6-1] = tmp[2-1]
        if direction =="W":
            self.faces[4-1] = tmp[1-1]
            self.faces[1-1] = tmp[3-1]
            self.faces[3-1] = tmp[6-1]
            self.faces[6-1] = tmp[4-1]
        if direction =="E":
            self.faces[3-1] = tmp[1-1]
            self.faces[1-1] = tmp[4-1]
            self.faces[4-1] = tmp[6-1]
            self.faces[6-1] = tmp[3-1]
        return 0

    def spin(self):
        self.faces[4-1], self.faces[2-1],self.faces[5-1],self.faces[3-1] =\
        self.faces[2-1], self.faces[3-1],self.faces[4-1],self.faces[5-1]

        return 0

d1 = Dice()
d1.faces=[int(x) for x in input().split(" ")]
lines = int(input())
for i in range(lines):
    up, front = map(int, input().split(" "))
    #set up side
    for _ in range(3):
        if d1.faces[0] == up:
            break
        d1.rotate("N")

    for _ in range(3):
        if d1.faces[0] == up:
            break
        d1.rotate("W")

    #set front side
    for _ in range(3):
        if d1.faces[1] == front:
            break
        d1.spin()

    print(d1.faces[2])

Measured memory_bytes: 7764
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


int main() {
	int A, B;
	cin >> A >> B;
	vector<string> g(100, string(100, '.'));
	for (int i = 0; i < 100; i++) {
		g[i][0] = '#';
	}
	for (int i = 0; i < 100; i++) {
		for (int j = 1; j < 99; j++) {
			if (i % 2 == 0)g[i][j] = '#';
		}
	}

	int a = 1, b = 1;
	for (int i = 1; i < 100 && a < A; i += 2) {
		for (int j = 2; j < 98 && a < A; j += 2) {
			g[i][j] = '#';
			a++;
		}
	}
	for (int i = 98; i >= 0 && b < B; i -= 2) {
		for (int j = 97; j >= 1 && b < B; j -= 2) {
			g[i][j] = '.';
			b++;
		}
	}

	cout << "100 100" << endl;
	for (int i = 0; i < 100; i++) {
		cout << g[i] << endl;
	}

	
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a,d,r;
	double b,f;
	scanf("%d %lf",&a,&b);
	d=a/b;
	r=a%(int)b;
	f=a/b;
	printf("%d %d %lf\n",d,r,f);
	return 0;
}


Measured memory_bytes: 2104
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32)::i,ans
    integer(int32), allocatable::a(:)
    character(3):: n

    read*, n

    do i=1,3
        if (n(i:i) == '7') then
            print*, 'Yes'
            stop
        end if
    end do
    print*, 'No'

    
end program name

Measured memory_bytes: 2820
#include <iostream>
#include <vector>
#include <algorithm>
#include<stdio.h>
#include<functional>
using namespace std;
typedef long long ll;
int main() {
    int A;
    int B;
    cin >> A >> B;
    int ans;
    if ((A-B)>=1){
        ans=2*A-1;
    }
    else if((B-A)>=1){
        ans=2*B-1;
    }
    else{
        ans=2*B;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define REP(i, n) FOR(i, 1, ll(n) + 1)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template <typename T> inline bool chmax(T &a, const T b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> inline bool chmin(T &a, const T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

int N, K, Q;
vector<int> A;

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

    cin >> N >> K >> Q;
    A.resize(N);
    rep(i, N) cin >> A[i];

    int ret = 1 << 30;
    rep(i, N) {
        vector<int> P, V;
        rep(j, N) {
            if(A[j] < A[i]) {
                if(V.size() >= K) {
                    sort(ALL(V));
                    rep(x, V.size() - K + 1) P.push_back(V[x]);
                }
                V.clear();
            } else
                V.push_back(A[j]);
        }
        if(V.size() >= K) {
            sort(ALL(V));
            rep(x, V.size() - K + 1) P.push_back(V[x]);
        }
        if(P.size() < Q) continue;
        sort(ALL(P));
        chmin(ret, P[Q - 1] - P[0]);
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll i,j,k,n,m,c,t,mn,l,r;
    scanf("%lld",&n);
    ll a[n+4];
    for(i=0;i<n;i++){
        scanf("%lld",&a[i]);
    } ll ans=0;
    while(1){
        mn=LLONG_MAX;l=0;r=n-1;
        bool flag=0;
        for(i=0;i<n;i++){
            if(a[i]==0&&flag){r=i-1;break;}
            if(a[i]&&!flag){flag=1;l=i;}
            if(a[i]) mn=min(mn,a[i]);
        } if(flag==0) break;
        ans+=mn;
        for(i=l;i<=r;i++) a[i]-=mn;
    }
    printf("%lld\n",ans);
}



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

int main() {
  int t_H,t_P,A_H,A_P;
  cin >>t_H >> t_P >> A_H >> A_P;
  while(true){
  A_H -= t_P;
  if(A_H <= 0){
  cout << "Yes" << endl;
  break;
  }
  t_H -= A_P;
  if(t_H <= 0){
  cout << "No" << endl;
  break;
  }
  }
}


Measured memory_bytes: 3636
/*
3 3
1 1 4
2 3 1
連続したものの和と同じものがあるとうれしい

*/

#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

int h[1600], w[1600];

int main(void)
{
	int n, m;
	while (cin >> n >> m, n && m){
		for (int i = 0; i < n; i++){
			cin >> h[i];
		}
		for (int i = 0; i < m; i++){
			cin >> w[i];
		}

		map <int, int> hdata, wdata;

		int sum = 0;
		for (int i = 0; i < n; i++){
			sum += h[i];
			int tmp = sum;
			for (int j = 0; j <= i; j++){
				hdata[tmp]++;
				tmp -= h[j];
			}
		}
		sum = 0;
		for (int i = 0; i < m; i++){
			sum += w[i];
			int tmp = sum;
			for (int j = 0; j <= i; j++){
				wdata[tmp]++;
				tmp -= w[j];
			}
		}

		/*
		puts("**debug**");
		for (int i = 0; i < n*m; i++){
			cout << i << " " << hdata[i] << " " << wdata[i] << endl;
		}
		*/

		int ret = 0;
		map <int, int>::iterator hit = hdata.begin(), wit = wdata.begin();
		while (hit != hdata.end() && wit != wdata.end()){
			if (hit->first == wit->first){
				ret += hit->second * wit->second;
				hit++;
				wit++;
			}
			else if (hit->first < wit->first){
				hit++;
			}
			else {
				wit++;
			}
		}

		cout << ret << endl;

	}
}

Measured memory_bytes: 27988
n = int(input())
lst = list(map(int, input().split()))
total = sum(lst)
cnt = 0
for i in range(n):
    if cnt < total/2:
        cnt += lst[i]
    else:
        cnt2 = cnt - lst[i-1]
        break
print(min((abs(total-2*cnt), abs(total-2*cnt2))))

Measured memory_bytes: 3060
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;


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

	while (cin >> N >> M, N) {
		vector<char>c(N);
		vector<int>v(N);
		int ans = 0;
		int idx = 0;
		vector<int>odd;
		vector<int>even;
		int oddl = 0, oddr = 0, evenl = 0, evenr = 0;
		for (int i = 0; i < N; i++) {
			cin >> c[i] >> v[i];
			if (v[i] & 1) {
				odd.push_back(i);
				if (c[i] == 'L')oddl++;
				else oddr++;
			}
			else {
				even.push_back(i);
				if (c[i] == 'L')evenl++;
				else evenr++;
			}
			if (c[i] == 'L') {
				if (ans <= v[i]) {
					ans = v[i];
					idx = i;
				}
			}
			else {
				if (ans < M - v[i]) {
					ans = M - v[i];
					idx = i;
				}
			}
		}
		cout << ans << " ";
		if (v[idx] & 1) {
			if (c[idx] == 'L')cout << odd[oddl - 1] + 1 << endl;
			else cout << odd[oddl] + 1 << endl;
		}
		else {
			if (c[idx] == 'L')cout << even[evenl - 1] + 1 << endl;
			else cout << even[evenl] + 1 << endl;
		}
	}
}


Measured memory_bytes: 3112
#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 x;
  cin >> x;
  ll count = 0;
  count += 2*(x / 11);
  if(x%11<=6&&0<x%11){
    count++;
  }
  else if(x%11==0){
  }
  else{
    count += 2;
  }
  print(count);
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
struct job{
	int c;//cost
	int d;//deadline
	bool operator < (const job t){
		return d<t.d;
	}
};
static const int maxn=2e5+9;
job j[maxn];
int n;
void input(){
	scanf("%d",&n);
	for(int i=0;i<n;++i)scanf("%d%d",&j[i].c,&j[i].d);
	sort(j+0,j+n);
}
int solve(){
	int tk=0;
	for(int i=0;i<n;++i){
		tk+=j[i].c;
		if(tk>j[i].d){
			printf("No");
			return 0;
		}
	}
	printf("Yes");
	return 1;
}
int main(){
	input();
	solve();
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(long long x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<long long,long long> P;
typedef pair<long long,P> PP;
long long n;
long long wa;
long long waa;
long long ans;
long long a[200005];
int main()
{
	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n)waa+=a[i];
	rep(i,n-1)
	{
		wa+=a[i];
		waa-=a[i];
		if(i==0)ans=abs(wa-waa);
		else ans=min(ans,abs(wa-waa));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using longlong=long long;

[[maybe_unused]]auto cmn=[](auto&& a,auto b){if(a>b){a=b;return true;}return false;};
[[maybe_unused]]auto cmx=[](auto&& a,auto b){if(a<b){a=b;return true;}return false;};

int main(){
    std::cin.tie(nullptr);std::cin.sync_with_stdio(false);
    int n;std::cin>>n;
    int ans=1;
    for(int i=2;i<=n;i++){
        for(int j=i*i;j<=n;j*=i){
            cmx(ans,j);
        }
    }
    std::cout<<ans<<std::endl;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;

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

	cin >> N;
	vector<vector<int>>v(N, vector<int>(N));
	for (auto &i : v) {
		for (auto &j : i)cin >> j;
	}
	vector<long long int>dp(1 << N);
	dp[0] = 1;
	vector < vector<int>>box(N);
	for (int i = 0; i <(1<< N)-1; i++) {
		int bag = i;
		int cnt = 0;
		while (bag) {
			cnt += bag & 1;
			bag >>= 1;
		}
		box[cnt].push_back(i);
	}
	for (int i = 0; i < N; i++) {
		for (auto j : box[i]) {
			dp[j] %= MOD;
			for (int k = 0; k < N; k++) {
				if ((j >> k) & 1)continue;
				if(v[i][k])				dp[j | (1 << k)] += dp[j];
			}
		}
	}
	cout << dp.back() % MOD << endl;
	return 0;
}

Measured memory_bytes: 26560
#include<bits/stdc++.h>
using namespace std;
#pragma region Macros
#define ios\
    ios::sync_with_stdio(false);\
    cin.tie(nullptr);
#define VEC(type, name, size)\
    V<type> name(size);\
    IN(name)
#define VVEC(type, name, h, w)\
    VV<type> name(h, V<type>(w));\
    IN(name)
#define INT(...)\
    int __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LL(...)\
    ll __VA_ARGS__;\
    IN(__VA_ARGS__)
#define STR(...)\
    string __VA_ARGS__;\
    IN(__VA_ARGS__)
#define CHAR(...)\
    char __VA_ARGS__;\
    IN(__VA_ARGS__)
#define DOUBLE(...)\
    DOUBLE __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LD(...)\
    LD __VA_ARGS__;\
    IN(__VA_ARGS__)
template <class T> void scan(T &a) { cin >> a; }
template <class T> void scan(vector<T> &a) { for(auto &i : a) scan(i); }
template <class T, class L> void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &... tail) { scan(head); IN(tail...); }
template <class T> inline void print(T x){ cout << x << '\n';}
#define ll long long
#define ld long double
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
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; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
template <typename T> T pow(T a, long long n, T e = 1) {T ret = e; while (n) {if (n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
const ll INF = 1e18;
#pragma endregion

int main(){
    ios;
    INT(n);
    VEC(int, h, n);
    REP(i, n - 1){
        if(h[i + 1] > h[i]) h[i + 1]--;
        if(h[i] > h[i + 1]){
            print("No");
            return 0;
        }
    }
    print("Yes");
}


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

int main() {
  
  string n;
  cin >> n;
  int size = n.size();
  int total = 0;
  
  for (int i = 0; i < size; i++){
    
    int x;
    x = n.at(i) - '0';
    total = total + x;
    
  }
  
  if(total % 9 == 0){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
 
  
}



Measured memory_bytes: 3752
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;

template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}
template <class _T> static _T tp_pow(int base, int exp)
{
	_T ans = 1;

	for (int i = 0; i < exp; i++) {
		ans *= base;
	}
	return ans;
}

static const long long MOD_NUM = 1000000007LL;

static void D_task();

int main()
{
	D_task();
	fflush(stdout);
	return 0;
}


static void D_getStartEnd(int N, int& stt, int& end) {
	stt = N % 10;
	
	int tmp = N;
	while (tmp) {
		end = tmp % 10;
		tmp /= 10;
	}
}
static void D_task()
{
	int N;
	get1int(N);

	int start = 0;
	int end = 0;

	LLONG count = 0;
	for (int i = 1; i <= N; i++) {
		D_getStartEnd(i, start, end);

		if (start == 0) {
			continue;
		}
		if (start == end) {
			count++;
		}

		for (int d = 1; d <= 5; d++) {
			int num = tp_pow<int>(10, d) * start + end;
			if (num <= N) {
				count++;

				int ptnd = tp_pow<int>(10, (d - 1));
				for (int n = 1; n < ptnd; n++) {
					if ((num + (n * 10)) <= N) {
						count++;
					}
				}
			}
		}
	}
	printf("%lld\n", count);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#define inf 1e9+7
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl;
 
using namespace std;
 
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

typedef pair<ll,ll> Pair;

ll n,k;

void solve(){
    if(k>(n-1)*(n-2)/2) {
        kaku(-1);
    }
    else{
        ll edge=(n-1)*(n-2)/2-k;
        kaku(edge+(n-1));
        for(ll i=2;i<=n;i++) cout << 1 << " " << i << endl;
        for(ll i=2;i<=n-1 && edge;i++){
            for(ll j=i+1;j<=n && edge;j++){
                cout << i << " " << j << endl;
                edge--;
            }
        }
    }
}

int main(){
    cin >> n >> k;
    solve();
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long

int main(){
  int N;
  cin >> N;
  vector<int> L(N);
  for(int i=0; i<N; i++){
    cin >> L[i];
  }
  sort(L.begin(), L.end());
  int count=0;
  for(int i=0; i<N;i++){
    for(int j=i+1; j<N; j++){
      for(int k=j+1; k<N; k++){
        if(L[k] < L[i]+L[j]){
          count++;
        }else{
          break;
        }
      }
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;
int main(){
  char joi[1000001];
  int ans = 0;
  cin >> joi;
  for(char *p = joi; *p != 0; ){
      char joi_c[3] = {'J','O','I'};
      int cnt[3] = {0};
      for(int j = 0 ; j < 3 ; j++){
	while(*p == joi_c[j] && *p != 0 ){
	  cnt[j]++;
	  *p++;
	}
      }
      if( cnt[0] >= cnt[1] && cnt[1] <= cnt[2] )ans = max(cnt[1],ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2116
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>
#include <sys/time.h>
#include <fstream>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define REP(i,n)  FOR(i,0,n)
#define each(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define deb(x) cerr << #x << " = " << (x) << " , ";
#define debl cerr << " (L" << __LINE__ << ")"<< endl;
#define sz(s) (int)((s).size())


#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(x,y) make_pair((x),(y))

double pi=3.14159265358979323846;

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& z){
	os << "[ ";
	REP(i,z.size())os << z[i] << ", " ;
	return ( os << "]" << endl);
}

template<typename T> std::ostream& operator<<(std::ostream& os, const set<T>& z){
	os << "set( ";
	EACH(p,z)os << (*p) << ", " ;
	return ( os << ")" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const map<T,U>& z){
	os << "{ ";
	EACH(p,z)os << (p->first) << ": " << (p->second) << ", " ;
	return ( os << "}" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const pair<T,U>& z){
	return ( os << "(" << z.first << ", " << z.second << ",)" );
}

double get_time(){
	struct timeval tv;
	gettimeofday(&tv, NULL);
	return tv.tv_sec + tv.tv_usec*1e-6;
}

typedef unsigned int uint32_t;
struct RND{
	uint32_t x;
	uint32_t y;
	uint32_t z;
	uint32_t w;
	RND(){
		x=123456789;
		y=362436069;
		z=521288629;
		w=88675123;
	}
	void init(int seed){
		x=123456789;
		y=362436069;
		z=521288629;
		w=seed+100;
		REP(i,10)get();
	}
	uint32_t get(){
		uint32_t t;
		t=x^(x<<11);
		x=y;y=z;z=w;
		w=(w^(w>>19))^(t^(t>>8));
		return w;
	}
};
RND rnd;

void _main(istream &inp){
	ll N,x;
	inp >> N >> x;
	vl a(N);
	rep(i,N) inp >> a[i];
	sort(a.begin(), a.end());
	ll ret = 0;
	rep(i,a.size()){
		if(i+1!=a.size() && x>=a[i]){
			ret += 1;
			x-=a[i];
		}
		if(i+1==a.size() && x==a[i]){
			ret += 1;
		}
	}
	cout << ret << endl;

}

int main(){
	if(0){
		ifstream ifs("test.txt");
		_main(ifs);
	}
	else{
		_main(cin);
	}
	return 0;
}


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

using ll=long long;
using P=pair<int,int>;

const int MOD=1e9+7;
const int INF=1<<30;
const int MAX=1e5;

ll n;

template<class T>
inline void xmin(T &a, T b){a=(a<b)?a:b;}
template<class T>
inline void xmax(T &a, T b){a=(a>b)?a:b;}



void solve(){
    ll mini=1LL<<60;
    cin>>n;
    for(ll i=1; i*i<=n; i++){
        if(n%i==0)xmin(mini, i+n/i-2);
    }
    cout<<mini<<endl;
}

signed main(){
    //while(1)
    solve();
}


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

int main() {
    long long int num = 0, ans = 0, keta = 1;
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    int a[2019] = {0};
    a[0]++;
    for(int i = 0; i < s.size(); ++i) {
        num = num + (s[i] - '0')*keta;
        num %= 2019;
        a[num]++;
        keta *= 10;
        keta %= 2019;
    }
    for(int i = 0; i < 2019; ++i) ans += a[i]*(a[i] - 1)/2;
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3680