akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
int calc(int x, int y, int z)
{
  switch (z){
  case 0: return (x + y);
  case 1: return (x - y);
  case 2: return (x * y);
  }
}
int hantei(int a, int b, int c, int d){
  int i,j,k;
  char en[3]={'+','-','*'};
    for(i=0;i<3;i++){
      for(j=0;j<3;j++){
	for(k=0;k<3;k++){
	  if (calc(calc(a, b, i), calc(c, d, j), k) == 10){
	    return printf("(%d%c%d)%c(%d%c%d)\n", a, en[i], b, en[k], c, en[j], d);
	  }
	  if (calc(calc(calc(a, b, i), c, j), d, k) == 10){
	      return printf("((%d%c%d)%c%d)%c%d\n", a, en[i], b, en[j], c, en[k], d);
	  }
	}
      }
    }
    return 0;
}
int main(void){
  int a, b, c, d;
  while (scanf("%d %d %d %d", &a, &b, &c, &d)&&a&&b&&c&&d){
    if(hantei(a, b, c, d)) continue;
    else if(hantei(a, b, d, c)) continue;
    else if(hantei(a, c, b, d)) continue;
    else if(hantei(a, c, d, b)) continue;
    else if(hantei(a, d, b, c)) continue;
    else if(hantei(a, d, c, b)) continue;
    else if(hantei(b, a, d, c)) continue;
    else if(hantei(b, a, c, d)) continue;
    else if(hantei(b, c, a, d)) continue;
    else if(hantei(b, c, d, a)) continue;
    else if(hantei(b, d, a, c)) continue;
    else if(hantei(b, d, c, a)) continue;
    else if(hantei(c, a, b, d)) continue;
    else if(hantei(c, a, d, b)) continue;
    else if(hantei(c, b, a, d)) continue;
    else if(hantei(c, b, d, a)) continue;
    else if(hantei(c, d, a, b)) continue;
    else if(hantei(c, d, b, a)) continue;
    else if(hantei(d, a, b, c)) continue;
    else if(hantei(d, a, c, b)) continue;
    else if(hantei(d, b, a, c)) continue;
    else if(hantei(d, b, c, a)) continue;
    else if(hantei(d, c, a, b)) continue;
    else if(hantei(d, c, b, a)) continue;
    printf("0\n");
  }
  return 0;
}
 

Measured memory_bytes: 1764
package main

import "fmt"

func main() {
	var S, T string
	var A, B int
	var U string
	fmt.Scan(&S, &T, &A, &B, &U)

	if S == U {
		A--
	}
	if T == U {
		B--
	}
	fmt.Println(A, B)
}


Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

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

const int dir[4][2] = { {-1, 0}, {0, -1}, {1, 0}, {0, 1} };
const int INF = 1e9;

int h, w, k;
vector<vector<char>> MP;
vector<vector<int>> dis;

bool outside(int x, int y) {
	return x < 0 or x >= h or y < 0 or y >= w;
}

bool bad(int x, int y, int nd) {
	return MP[x][y] == '@' or dis[x][y] < nd;
}

void bfs(int x1, int y1) {
	queue<pair<int, int>> que;
	que.push({ x1, y1 });
	dis[x1][y1] = 0;
	while (!que.empty()) {
		int x = que.front().first;
		int y = que.front().second;
		que.pop();
		for (int i = 0; i < 4; i++) {
			int nx = x, ny = y;
			int nd = dis[x][y] + 1;
			for (int j = 1; j <= k; j++) {
				nx += dir[i][0];
				ny += dir[i][1];
				if (outside(nx, ny) or bad(nx, ny, nd))
					break;
				if (dis[nx][ny] > nd) {
					que.push({ nx, ny });
					dis[nx][ny] = nd;
				}
			}
		}
	}
}

int main() {
	int x1, y1, x2, y2;
	cin >> h >> w >> k >> x1 >> y1 >> x2 >> y2;
	--x1, --y1, --x2, --y2;
	MP.resize(h, vector<char>(w));
	dis.resize(h, vector<int>(w));
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			cin >> MP[i][j], dis[i][j] = INF;
	bfs(x1, y1);
	cout << (dis[x2][y2] == INF ? -1 : dis[x2][y2]);
}

Measured memory_bytes: 11988
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Node {
  int key;
  struct Node *right, *left, *parent;
};
typedef struct Node Node;

Node *root, *NIL;

Node * treeMinimum(Node *x) {
  while(x->left != NIL)
    x = x->left;
  return x;
}

Node * find(Node *u, int k) {
  while(u != NIL && k != u->key) {
    if(k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}

Node * treeSuccessor(Node *x) {
  if(x->right != NIL) return treeMinimum(x->right);
  Node *y = x->parent;
  while(y != NIL && x == y->right) {
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node *z) {
  Node *y; // 削除する対象
  Node *x; // yの子

  // 削除する節点を決める
  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  // yの子xを決める
  if(y->left != NIL) {
    x = y->left;
  } else {
    x = y->right;
  }

  if(x != NIL) {
    x->parent = y->parent;
  }

  if(y->parent == NIL) {
    root = x;
  } else {
    if(y == y->parent->left) {
      y->parent->left = x;
    } else {
      y->parent->right = x;
    }
  }

  if(y != z) {
    z->key = y->key;
  }
}

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;
  
  z = (Node *)malloc(sizeof(Node));
  z->key   = k;
  z->left  = NIL;
  z->right = NIL;
  
  while(x != NIL) {
    y = x;
    if(z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  
  z->parent = y;
  if(y == NIL) {
    root = z;
  } else {
    if( z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node *u) {
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node *u) {
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}
  
int main(void) {
  int n, i, x;
  char com[16];
  scanf("%d",&n);
  
  for(i=0;i<n;i++) {
    scanf("%s",com);
    if(!strcmp(com,"find")) {
      scanf("%d",&x);
      Node *t = find(root,x);
      if(t != NIL) printf("yes\n");
      else printf("no\n");
    } else if(!strcmp(com,"insert")) {
      scanf("%d",&x);
      insert(x);
    } else if(!strcmp(com,"print")) {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if(!strcmp(com,"delete")) {
      scanf("%d",&x);
      treeDelete(find(root,x));
    }
  }

  return 0;
}


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

namespace ConsoleApplication1
{
    class Node
    {
        internal List<int> target;
        internal int inDegree;
        internal bool isVisit;

        public Node()
        {
            target = new List<int>();
        }
    }

    class SearchOrder
    {
        Node[] nodeList;
        List<int> result;

        public SearchOrder(int m)
        {
            nodeList = Enumerable.Range(0, m).Select(a => new Node()).ToArray();
            result = new List<int>();
        }

        public void MakeList(int s, int t)
        {
            nodeList[s].target.Add(t);
            nodeList[t].inDegree++;
        }

        public void Print()
        {
            TopologicalSort(nodeList);

            StringBuilder sb = new StringBuilder();

            foreach (int node in result)
            {
                sb.AppendLine((node + 1).ToString());
            }
            Console.Write(sb);
        }

        private void TopologicalSort(Node[] NL)
        {
            for (int i = 0; i < NL.Length; i++)
            {
                if (NL[i].inDegree == 0 && !NL[i].isVisit)
                {
                    BFS(NL, i);
                }
            }
        }

        private void BFS(Node[] NL, int s)
        {
            Queue<int> que = new Queue<int>();
            que.Enqueue(s);

            NL[s].isVisit = true;

            while (que.Count > 0)
            {
                int u = que.Dequeue();
                result.Add(u);

                for (int i = 0; i < NL[u].target.Count; i++)
                {
                    int v = NL[u].target[i];
                    NL[v].inDegree--;

                    if (NL[v].inDegree == 0 && !NL[v].isVisit)
                    {
                        NL[v].isVisit = true;
                        que.Enqueue(v);
                    }
                }
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            int m = int.Parse(Console.ReadLine());
            int n = int.Parse(Console.ReadLine());

            SearchOrder S = new SearchOrder(m);

            for (int i = 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                int x = int.Parse(input[0]) - 1;
                int y = int.Parse(input[1]) - 1;

                S.MakeList(x, y);
            }
            S.Print();
        }
    }
}

Measured memory_bytes: 10588
object Main extends App {
  import scala.io.StdIn._

  val n = readInt()
  val a = readLine.trim
  val b = readLine.trim
  val c = readLine.trim
  println((0 until n).map(i ⇒ List(a(i), b(i), c(i)).distinct.length - 1).sum)
}

Measured memory_bytes: 27312
import math
from collections import Counter

n = int(input())
prime_count = Counter()
def prime_c(m):
  for i in range(2, math.ceil(math.sqrt(m))+1):
    while m % i == 0:
      m /= i
      prime_count[i] += 1
  if m > 1:
    prime_count[int(m)] += 1  

for i in range(2, n+1):
  prime_c(i)

mod = 10**9+7
ans = 1
for v in prime_count.values():
  ans *= (v+1) 
  ans %= mod 
print(ans)

Measured memory_bytes: 40688
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
constexpr long long MMOD = 500000004;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))), end((c)))
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

LL n, a;

int main() {
	cin >> n >> a;
	if (n % 500 <= a) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
   string S;
   cin >> S;
   if(S == "abc" || S == "acb" || S == "bac" || S == "bca" || S == "cab" || S == "cba"){
       cout << "Yes" << endl;
   }
   else{
       cout << "No" << endl;
   }
    
}

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

int main() {
    string S, T ;
    cin >> S >> T ; //S and T are strings of length 3 each , S and T consist of 'S' , 'C', and 'R'.
    int X = 0 ;
    if ( S[0] == T[0]) X++ ;
    if ( S[1] == T[1]) X++ ;
    if ( S[2] == T[2]) X++ ;
    cout << X <<endl ;
	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <map>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <memory>
#include <iomanip>
using namespace std;

const int N = 3000;
double probabilites[N], dp[N][N];
int n;

double solve(int index, int count){
	if (index == n){
		if (count > n / 2)
			return 1.0;
		else
			return 0.0;
	}
	if (dp[index][count] != -1)
		return dp[index][count];
	double answer = 0;
	answer += probabilites[index] * solve(index + 1, count + 1);
	answer += (1.0 - probabilites[index]) * solve(index + 1, count);
	return dp[index][count] = answer;
}

int main() {
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++)
			dp[i][j] = -1.0;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> probabilites[i];
	cout << fixed << setprecision(10) << solve(0, 0) << '\n';
	return 0;
}

Measured memory_bytes: 70912
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define P3(a, b, c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    int N, mod=26;
    string S, alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    cin >> N >> S;
    
    REP(i,0,S.size()){
        REP(j,0,26){
            if(S[i] == alpha[j]){
                cout << alpha[(j+N)%mod];
                break;
            }
        }
    }
    
    cout << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Libraries --------------------------------//

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n, m, L;
    cin >> n >> m >> L;
    yukari<pair<int, i64>> g(n);
    yukari<i64> dp(n, akari<i64>(n, 1e15)), dp2(dp);
    while (m--)
    {
        int a, b, c;
        cin >> a >> b >> c;
        if (L < c)
        {
            continue;
        }
        a--, b--;
        g[a].push_back(make_pair(b, c));
        g[b].push_back(make_pair(a, c));
        dp[a][b] = dp[b][a] = c;
    }
    for (int k = 0; k < n; k++)
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
            {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
            }

    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
        {
            if (dp[i][j] <= L)
            {
                dp2[i][j] = 1;
            }
        }
    for (int k = 0; k < n; k++)
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
            {
                dp2[i][j] = min(dp2[i][j], dp2[i][k] + dp2[k][j]);
            }

    int q;
    cin >> q;
    while (q--)
    {
        int s, t;
        cin >> s >> t;
        s--, t--;
        cout << (dp2[s][t] == 1e15 ? -1 : dp2[s][t] - 1) << '\n';
    }
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
typedef long long l;
typedef string s;
int a1[5]={2,4,5,7,9};
int a2[4]={0,1,6,8};
int a3=3;
int main()
{
	int n;
	cin>>n;
	n=n%10;
	for(int i=0;i<5;i++)
		if(a1[i]==n)
			cout<<"hon"<<endl;
	for(int i=0;i<4;i++)
		if(a2[i]==n)
			cout<<"pon"<<endl;
	if(n==a3)
		cout<<"bon"<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue> 
using namespace std;
inline void _read(int &x)
{
	x = 0;
	char t = getchar();
	while (!isdigit(t)) t = getchar();
	while (isdigit(t))
	{
		x = x * 10 + t - '0';
		t = getchar();
	}
}
int n, k, lst = 0;
int main()
{
	_read(n), _read(k);
    for (register int i = 0, x; i < n; i++)
    {
    	_read(x);
    	if (i == 0)
		{
			lst = x;
			continue;
		}
    	if (lst + x >= k)
		{
			puts("Possible");
            for (int j = 1; j < i; j++)
                printf("%d", j), puts("");
            for (int j = n - 1; j >= i; j--)
                printf("%d", j), puts("");
            return 0;
        }
        lst = x;
	}
    puts("Impossible");
    return 0;
}

Measured memory_bytes: 768
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        List<Long> as = new ArrayList<>();
        List<Long> bs = new ArrayList<>();
        List<Long> cs = new ArrayList<>();

        for (int i = 0; i < N; i++) {
            as.add(sc.nextLong());
        }
        for (int i = 0; i < N; i++) {
            bs.add(sc.nextLong());
        }
        for (int i = 0; i < N; i++) {
            cs.add(sc.nextLong());
        }
        Collections.sort(as);
        Collections.sort(bs);
        Collections.sort(cs);

        long ans = 0;
        for (int i = 0; i < N; i++) {
            long b = bs.get(i);

            //lower_bound
            long lowerResult = Collections.binarySearch(as, b, (x, y) -> x.compareTo(y) >= 0 ? 1 : -1);
            lowerResult = (lowerResult >= 0)? lowerResult : ~lowerResult;

            // upper_bound
            long upperResult = Collections.binarySearch(cs, b, (x, y) -> x.compareTo(y) > 0 ? 1 : -1);
            upperResult = (upperResult >= 0)? upperResult : ~upperResult;

            ans += lowerResult * (N - upperResult);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 103592
n, m, Q = map(int, input().split())

imos = [[0 for i in range(n)] for j in range(n)]

for i in range(m):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    imos[l][r] += 1

for i in range(n):
    for j in range(n-1):
        imos[i][j+1] += imos[i][j]

for j in range(n):
    for i in range(n-1):
        imos[i+1][j] += imos[i][j]

for i in range(Q):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    if p == 0:
        print(imos[q][q])
    else:
        print(imos[q][q] - imos[p-1][q])


Measured memory_bytes: 14964
//#define TIMER_
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;

int main() {
  fastio;
  int k; string s;
  cin >> k; cin >> s;
  if (s.size() <= k) {
    cout << s << '\n'; return 0;
  } else {
    string res = s.substr(0, k) + "...";
    cout << res << endl;
    return 0;
  }
  
  #ifdef TIMER_
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  #endif
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long double LD;
char s[2];
int x[100005], y[100005], d[100005];
int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int main(){
    int n;
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%d%d%s", &x[i], &y[i], s);
        if(s[0] == 'R') d[i] = 0;
        else if(s[0] == 'L') d[i] = 1;
        else if(s[0] == 'U') d[i] = 2;
        else d[i] = 3;
    }
    LD ans = 1e18;
    LD lo = 0, hi = 1e9;
    for(int i=0;i<200;i++){

        LD mid1 = lo+(hi-lo)/3;
        LD mx_x = -1e9, mn_x = 1e9, mx_y = -1e9, mn_y = 1e9;
        for(int i=1;i<=n;i++){
            mx_x = max(mx_x, (LD)x[i]+mid1*dir[d[i]][0]);
            mn_x = min(mn_x, (LD)x[i]+mid1*dir[d[i]][0]);

            mx_y = max(mx_y, (LD)y[i]+mid1*dir[d[i]][1]);
            mn_y = min(mn_y, (LD)y[i]+mid1*dir[d[i]][1]);
        }
        LD res1 = abs((mx_x-mn_x)*(mx_y-mn_y));

        LD mid2 = lo+2*(hi-lo)/3;
        mx_x = -1e9, mn_x = 1e9, mx_y = -1e9, mn_y = 1e9;
        for(int i=1;i<=n;i++){
            mx_x = max(mx_x, (LD)x[i]+mid2*dir[d[i]][0]);
            mn_x = min(mn_x, (LD)x[i]+mid2*dir[d[i]][0]);

            mx_y = max(mx_y, (LD)y[i]+mid2*dir[d[i]][1]);
            mn_y = min(mn_y, (LD)y[i]+mid2*dir[d[i]][1]);
        }
        LD res2 = abs((mx_x-mn_x)*(mx_y-mn_y));

        if(res1 < res2){
            ans = min(ans, res1);
            hi = mid2;
        }
        else{
            ans = min(ans, res2);
            lo = mid1;
        }
    }
    printf("%.20Lf\n", ans);
}

Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main(void){
  int S;
  int h;
  int m;
  int s;
  int a;
  
  cin >> S;
  h=S/3600;
  a=S%3600;
  m=a/60;
  s=a%60;
  
  cout << h << ":" << m << ":" << s << endl;
  
  
}


Measured memory_bytes: 3084
#coding:utf-8

def main():
    a, b = map(int, input().split())
    c = []
    for i in range(2):
        if a > b or a == b:
            c.append(a)
            a = a - 1
        elif b > a:
            c.append(b)
            b = b - 1

    print(sum(c))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < int(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i))
#define REP_R(i, n) for (int i = int(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = int(n) - 1; (i) >= int(m); -- (i))
#define ALL(x) begin(x), end(x)
#define dump(x) cerr << #x " = " << x << endl
#define unittest_name_helper(counter) unittest_ ## counter
#define unittest_name(counter) unittest_name_helper(counter)
#define unittest __attribute__((constructor)) void unittest_name(__COUNTER__) ()
using ll = long long;
using namespace std;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
template <class T> inline void chmax(T & a, T const & b) { a = max(a, b); }
template <class T> inline void chmin(T & a, T const & b) { a = min(a, b); }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }
template <typename T> ostream & operator << (ostream & out, vector<T> const & xs) { REP (i, int(xs.size()) - 1) out << xs[i] << ' '; if (not xs.empty()) out << xs.back(); return out; }

int main() {
    // input
    int n; cin >> n;
    vector<int> a(1 << n);
    REP (i, 1 << n) cin >> a[i];

    // solve
    vector<pair<int, int> > choice(1 << n, make_pair(-1, -1));
    REP3 (k, 1, 1 << n) {
        vector<int> cands;
        cands.push_back(0);
        cands.push_back(k);
        REP (i, n) if (k & (1 << i)) {
            int l = k ^ (1 << i);
            if (l == 0) continue;
            cands.push_back(choice[l].first);
            cands.push_back(choice[l].second);
        }
        sort(ALL(cands), [&](int i, int j) { return a[i] > a[j]; });
        unique(ALL(cands));
        choice[k] = make_pair(cands[0], cands[1]);
    }
    vector<int> ans(1 << n);
    REP3 (k, 1, 1 << n) {
        int i, j; tie(i, j) = choice[k];
        ans[k] = a[i] + a[j];
        chmax(ans[k], ans[k - 1]);
    }

    // output
    REP3 (k, 1, 1 << n) {
        cout << ans[k] << endl;
    }
    return 0;
}


Measured memory_bytes: 7168
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
char ch[200];
int main(){
	scanf("%s",ch+1);
	int n=strlen(ch+1);
	for (int i=1;i<=n;i++)
		if (ch[i]=='C'){
			for (int j=i+1;j<=n;j++)
				if (ch[j]=='F'){
					printf("Yes\n"); return 0;
				}
		}
	printf("No\n"); return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
	"strings"
)

func main() {
	n := readString()
	n = n[len(n)-1:]

	hon := "24579"
	bon := "3"

	if strings.Contains(hon, n) {
		fmt.Println("hon")
	} else if strings.Contains(bon, n) {
		fmt.Println("bon")
	} else {
		fmt.Println("pon")
	}
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readInt() int {
	return int(readInt64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


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

typedef long long ll;
typedef vector<ll> v1;
typedef vector<v1> v2;

ll n,c;
v2 schedule;
v1 acm;

int main(){
  cin >> n >> c;
  schedule = v2(c+1,v1(100000*2+50));
  for(ll i = 0;i < n;i++){
    ll s,t,c;
    cin >> s >> t >> c;
    for(ll i = s*2-1;i <= t*2;i++){
      schedule[c][i] = 1;
    }
  }
  acm = v1(100000*2+50);
  for(ll i = 0;i <= c;i++){
    for(ll j = 0;j < 100000*2+50;j++){
      acm[j] += schedule[i][j];
    }
  }
  cout << *max_element(acm.begin(),acm.end()) << endl;

}


Measured memory_bytes: 50304
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <unordered_map>
using namespace std;

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

const int maxn = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

#define dbg(x1) cout<<#x1<<" = "<<(x1)<<endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<" "<<#x3<<" = "<<(x3)<<endl
int a[maxn];
int main() {
    //freopen(".in", "r", stdin);
    int n,t;scanf("%d%d",&n,&t);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    ll ans=t;
    ll pre=t;
    for(int i=1;i<=n;i++)
    {
        if(pre>a[i])
        {
            ans+=t;
            ans-=(pre-a[i]);
            pre=a[i]+t;
        }
        else
        {
            ans+=t;
            pre=a[i]+t;
        }
    }
    printf("%lld\n",ans);
    return 0;
}



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

# define ll long long
ll mod=pow(10,9)+7;

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

    ll n;
    cin>>n;
    ll ar[n];
    for(ll i=0;i<n;i++)
        cin>>ar[i];
    sort(ar,ar+n);
    ll ans=0;
    for(ll i=n-1;i>=n/2;i--)
        ans+=ar[i]*2;
    ans-=ar[n-1];
    if(n%2==1)
        ans-=ar[n/2];
    cout<<ans<<endl;
}


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

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

int main(){
  int H, W; cin >> H >> W;
  vector<vector<bool> > glid(H, vector<bool>(W, false));
  queue< pair<int, int> > nxt;
  for(int h = 0; h < H; h++){
    for(int w = 0; w < W; w++){
      char c; cin >> c;
      if(c == '#') {
        glid[h][w] = true;
        nxt.push(make_pair(h, w));
      }
    }
  }
  
  int ans = 0;
  while(!nxt.empty()){
    queue< pair<int, int> > que;
    que.swap(nxt);
    while(!que.empty()){
      auto now = que.front(); que.pop();
      int y = now.first, x = now.second;
      for(int i = 0; i < 4; i++){
        int ny = y + dy[i], nx = x + dx[i];
        if(ny >= 0 && ny < H && nx >= 0 && nx < W){
          if(!glid[ny][nx]){
            glid[ny][nx] = true;
            nxt.push(make_pair(ny, nx));
          }
        }
      }
    }
    ans++;
  }
  cout << ans - 1 << endl;
}

Measured memory_bytes: 8592
#include<bits/stdc++.h>
using namespace std;
int n;
int m;
int ans;
int v[5];
inline int calc(int x){
	int res=0;
	while(x){
		res++;
		x/=10;
	}
	return res;
}
inline void dfs(int x,long long sum,int mask){
	if(sum<=n&&mask==7) ans++;
	if(x==m+1){
		return;
	}
	dfs(x+1,sum*10+3,mask|1);
	dfs(x+1,sum*10+5,mask|2);
	dfs(x+1,sum*10+7,mask|4);
}
int main(){
	cin>>n;
	m=calc(n);
	dfs(1,0,0);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=200011;
typedef long long ll;
char a[N];
int main()
{
    scanf("%s",a);
    int len=strlen(a);
    int ans=0,p=0;
    for(int i=0;i<len;i++){
        if(a[i]=='S'){
            ans++;
        }
        else{
            if(ans){
                ans--;
                p++;
            }
        }
    }
    cout<<len-2*p<<endl;
    return 0;
}


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

using namespace std;

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

    vector<int> xs(m);
    for (auto& x : xs)
    {
        cin >> x;
    }

    if (n >= m)
    {
        cout << 0 << endl;
    }
    else
    {
        sort(xs.begin(), xs.end());

        vector<pair<int, int>> ds(m - 1);
        for (int i = 0; i < m - 1; i++)
        {
            ds[i].second = i + 1;
            ds[i].first = xs[i + 1] - xs[i];
        }
        sort(ds.begin(), ds.end());
        reverse(ds.begin(), ds.end());

        int accum = xs.back() - xs.front();
        for (int i = 0; i < n - 1; i++)
        {
            accum -= ds[i].first;
        }
        cout << accum << endl;
    }
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"

using namespace std;

#define pb push_back
#define mp make_pair
constexpr int INF = 1 << 29;
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;

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

int main() {
	int N, A;
	cin >> N >> A;
	vector<int> X(N);
	for (int i = 0; i < N; i++) {
		cin >> X[i];
		X[i] -= A;
	}
	// -1 1 0 1

	unordered_map<int, ll> dp[2];
	dp[0][0] = 1;
	for(int i = 0; i < N; i++) {
		dp[!(i % 2)].clear();
		for(auto &e : dp[i % 2]) {
			int j = e.first;
			dp[!(i % 2)][j] += dp[i % 2][j];
			dp[!(i % 2)][j + X[i]] += dp[i % 2][j];
		}
	}
	cout << dp[N % 2][0] - 1 << endl;
	return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};



int main(){

  int n,m;
  cin >> n >> m;
  vector<Pl> v(n);
  REP(i,n)cin >> v[i].first >> v[i].second;
  vector<Pl> c(m);
  REP(i,m)cin >> c[i].first >> c[i].second;
  vector<int> res(n,-1);
  REP(i,n){
    ll dist = INF;
    REP(j,m){
      ll r = abs(v[i].first-c[j].first)+abs(v[i].second-c[j].second);
      if(r < dist){
        res[i] = j;
        dist = r;
      }
    }
  }
  REP(i,n)cout << res[i]+1 << endl;





  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k,x,y,k1,total;
cin>>n>>k>>x>>y;
k1=n-k;
if(k>=n)
total=(n*x);
else
total=(k*x)+(k1*y);
cout<<total<<endl;
return 0;
}


Measured memory_bytes: 256
main = interact $ unlines . map (show . prime_gap . read) . init . lines

prime_gap n = if p == n then 0 else p - (last ps1)
 where (ps1,(p:_)) = span (<n) primes

primes = 2:3:[x | i<-[1..], j<-[-1,1], let x = 6*i+j, isPrime x]
 where isPrime n = null [i | i<-takeWhile (\x -> x*x <= n) primes, rem n i == 0]

Measured memory_bytes: 23644
#include <bits/stdc++.h>
using namespace std;
int n,p1,p2;
string s,s1,s2;
int main()
{
    scanf("%d\n",&n);
    p1=p2=0;
    for(int i=1;i<=n;i++)
    {
        s.clear();s1.clear();s2.clear();
        getline(cin,s);
        int j=0;
        while (s[j]!=' ') s1+=s[j++];
        j++;
        while (j<s.size()) s2+=s[j++];
        if (s1<s2) p2+=3;
        else
            if (s1==s2)
            {
                p1++;p2++;
            }
            else p1+=3;
    }
    printf("%d %d\n",p1,p2);
}



Measured memory_bytes: 3312
#include<iostream>

using namespace std;

int main(){
    int N;
    bool flag=true;
    int cnt=-1;

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

    while(flag){
        cnt += 1;
        for(int i=0;i<N;++i){
            if(A[i]%2!=0){
                flag = false;
                break;
            }else{
                A[i] /= 2;
                flag = true;
            }
        }
    }
     
    cout << cnt;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <utility>
using namespace std;
const int INF=0x3f3f3f3f;
typedef long long LL;
struct edge{
    int to,cap,cost,rev;
    edge(int to,int cap,int cost,int rev):to(to),cap(cap),cost(cost),rev(rev){}
};
const int MAX_V=10010;
int V,dist[MAX_V],prevv[MAX_V],preve[MAX_V];
vector<edge> G[MAX_V];
void add_edge(int from,int to,int cap,int cost){
    G[from].push_back(edge(to,cap,cost,G[to].size()));
    G[to].push_back(edge(from,0,-cost,G[from].size()-1));
}
int min_cost_flow(int s,int t,int f){
    int res=0;
    while(f>0){
        fill(dist,dist+V,INF);
        dist[s]=0;
        bool update=1;
        while(update){
            update=0;
            for(int v=0;v<V;v++){
                if(dist[v]==INF)continue;
                for(int i=0;i<G[v].size();i++){
                    edge &e=G[v][i];
                    if(e.cap>0&&dist[e.to]>dist[v]+e.cost){
                        dist[e.to]=dist[v]+e.cost;
                        prevv[e.to]=v;
                        preve[e.to]=i;
                        update=1;
                    }
                }
            }
        }
        if(dist[t]==INF)return -1;
        int d=f;
        for(int v=t;v!=s;v=prevv[v]){
            d=min(d,G[prevv[v]][preve[v]].cap);
        }f-=d;
        res+=d*dist[t];
        for(int v=t;v!=s;v=prevv[v]){
            edge &e=G[prevv[v]][preve[v]];
            e.cap-=d;
            G[v][e.rev].cap+=d;
        }
    }return res;
}
void clear(){for(int i=0;i<=V;i++)G[i].clear();}
const int MAX_N=10010;
int M,N,K,w[MAX_N],lst[MAX_N],a[MAX_N];
int solve(){
    for(int i=1;i<=N;i++)scanf("%d",&w[i]);
    for(int i=1;i<=K;i++)scanf("%d",&a[i]);
    int cnt=unique(a+1,a+K+1)-(a+1);
    int res=0;
    memset(lst,0,sizeof(lst));
    V=cnt+1; clear();
    for(int i=1;i<=cnt;i++){
        res+=w[a[i]];
        if(lst[a[i]])add_edge(lst[a[i]],i-1,1,-w[a[i]]);
        lst[a[i]]=i;
    }for(int i=1;i<cnt;i++)add_edge(i,i+1,INF,0);
    printf("%d\n",res+min_cost_flow(1,cnt,M-1));
}
int main(){
    while(~scanf("%d%d%d",&M,&N,&K))solve();
    return 0;
}

Measured memory_bytes: 4080
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
#define rep(i,N) for(ll i=0; i<N; i++)

int main(){
    ll N, M; cin >> N >> M;
    ll a[M]; rep(i,M) cin >> a[i];

    ll dp[N+1]; dp[0] = 1;
    ll m = 0;
  	if(a[m] == 1){
      dp[1] = 0;
      m++;
    }
  	else dp[1] = 1;
    for(ll i=2; i<=N; i++){
        dp[i] = (dp[i-1] + dp[i-2]) % MOD;
        if(a[m] == i){
            dp[i] = 0;
            m++;
        }
    }
    cout << dp[N] << endl;
}


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

using namespace std;

const int Nmax = 2e5 + 5;
const int Mod = 1e9 + 7;
const int oo = 1e9;

int n, m, q, mx;
int x[20];

struct Q
{
    int a, b, c, d;
}a[55];

void Back(int top)
{
    if(top > n)
    {
        int scor = 0;
        for(int i = 1; i <= q; i++)
            if(x[a[i].b] - x[a[i].a] == a[i].c) scor += a[i].d;

        mx = max(mx, scor);
        return ;
    }


    for(int i = x[top - 1]; i <= m; i++)
    {
        x[top] = i;
        Back(top + 1);
    }
}

int main()
{
/**
    #ifndef ONLINE_JUDGE

        ifstream cin("test.in");

    #endif // ONLINE_JUDGE
*/

    cin >> n >> m >> q;

    for(int i = 1; i <= q; i++)
        cin >> a[i].a >> a[i].b >> a[i].c >> a[i].d;
    
    x[0] = 1;
    Back(1);
    cout << mx;
    return 0;
}


Measured memory_bytes: 3588
N = int(input())
s  = input().strip()

cnt = 0
for key in range(1000):
    key = '{:0>3}'.format(str(key))    #; print(key)
    i0 = s.find(key[0])
    if 0 <= i0 < N-2:
        i1 = s.find(key[1], i0+1)
        if 0 < i1 < N-1:
            i2 = s.find(key[2], i1+1)
            if i2 != -1:
                cnt += 1                                 
print(cnt)      

Measured memory_bytes: 9256
#define LOCAL
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 1e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char c) {return to_string((string) &c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

struct query{
    ll v, d, c;
    query(){}
    query(ll v, ll d, ll c):v(v), d(d), c(c){}
};

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

vector<vector<ll>> graph(n_max);
vvl dp(n_max, vl(11, INF));
void dfs(ll pos, ll d, ll turn){
    if(dp[pos][d] != INF) return ;
    dp[pos][d] = turn;
    if(d == 0)return ;
    dfs(pos, d-1, turn);
    for(auto &to : graph[pos]){
        dfs(to, d-1, turn);
    }
}
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n,m; cin >> n >> m;
    
    rep(i,m) {
        ll a,b;cin >> a >> b;
        a--;b--;
        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }
    ll q; cin >> q;
    vector<query> que(q);
    rep(i,q){
        ll v,d,c; cin >> v >> d >> c;
        v--;
        que[i] = query(v,d,c);
    }
    reverse(all(que));
    

    rep(i,q){
        dfs(que[i].v, que[i].d, i);
    }
    rep(i,n){
        ll ans;
        if(dp[i][0] == INF)ans = 0;
        else{
            ans = que[dp[i][0]].c;
        }

        cout << ans << "\n";
    }
}

Measured memory_bytes: 28544
#include<bits/stdc++.h>
using namespace std;
using Int = long long int;
int main(){
  int N;
  cin >>N;
  Int current = 0;
  Int sum = 0;
  for(int i=0;i<N;i++){
	Int a;
    cin>>a;
    if (current==0||a>=current){
      current=a;
    }else{
        sum+=current-a;
    }
  }
  cout<<sum<<endl;
}
      

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    string str = "abcdefghijklmnopqrstuvwxyz";
    string str2;
    cin >> str2;
    int a = str2[0] - 'a';
    cout << str[a+1] << endl;

    return 0;
}

Measured memory_bytes: 3624
/******************************************
* AUTHOR : GURUTEJA *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second

void debug(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 

}

long long int sumof(string s){
   long long int count=0;
   int n=s.length();
   int i=0,x;
   while(i<n){
        
      x=s[i]-'0';
      
      count+=x;
      i++;
   }
   return count;
}

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


   string s;
    cin>>s;
    if((sumof(s))%9==0){
    	cout<<"Yes"<<endl;
    }else{
    	cout<<"No"<<endl;
    }

    return 0;
  }

Measured memory_bytes: 3764
from heapq import heappush, heappop

N, K = map(int, input().split())
P = [int(i) for i in input().split()]

dp = [0] * N
dp[0] = 1
for i in range(1, N) :
    if P[i] > P[i-1] :
        dp[i] = dp[i-1] + 1
    else :
        dp[i] = 1
        
ma = []
mi = []

for i in range(K) :
    heappush(ma, (-P[i], i))
    heappush(mi, (P[i], i))

if dp[K-1] == K :
    ret = 0
else :
    ret = 1
    
for i in range(K, N) :
    heappush(ma, (-P[i], i))
    heappush(mi, (P[i], i))
    
    while ma[0][1] < i - K :
        heappop(ma)
    while mi[0][1] < i - K :
        heappop(mi)
        
    if dp[i] < K and (P[i-K] != mi[0][0] or P[i] != -ma[0][0]) :
        ret += 1

if sum([dp[i] >= K for i in range(N)]) > 0 :
    ret += 1

print(ret)

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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == 0) {
        v.clear();
        return 0;
    }
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    return i;
}
void read_cr() {
    fgets(_buf, 256, stdin);
}

ll solve(int N, int M, vi& x) {
    if (N >= M) return 0;
    sort(ALL(x));
    vll ma(M-1);
    rep(i,M-1) ma[i] = x[i+1] - x[i];
    sort(ALL(ma));
    int cuts = N-1;
    return accumulate(ma.begin(), ma.end()-cuts, 0LL);
}

int main() {
    int N,M; scanf("%d%d", &N, &M); read_cr();
    vi x(M);
    loadvec(x,M);
    cout << solve(N,M,x) << endl;
    return 0;
}


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

#define int long long

using namespace std;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, d, ans = 0, x, y;
	cin >> n >> d;
	while(n--){
		cin >> x >> y;
		if(sqrt(double(x*x) + double(y*y)) <= double(d)){
			ans++;
		}
	}
	cout << ans << "\n";
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll MOD = 1e9+7;

class mint{
    ll n;
public:
    mint(ll m = 0){
        n = ((m % MOD) + MOD) % MOD;
    }
    bool operator==(const mint& m){
        return n == m.n;
    }
    mint operator-() const {
        return mint(-n);
    }
    mint& operator+=(const mint& m){
        n += m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator-=(const mint& m){
        n += MOD - m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& m){
        n *= m.n;
        n %= MOD;
        return *this;
    }
    mint operator+(const mint& m) const{
        mint res(*this);
        res += m;
        return res;
    }
    mint operator-(const mint& m) const{
        mint res(*this);
        res -= m;
        return res;
    }
    mint operator*(const mint& m) const{
        mint res(*this);
        res *= m;
        return res;
    }
    mint pow(ll t) const{
        if(t == 0) return mint(1);
        mint m = pow(t>>1);
        m *= m;
        if(t & 1 == 1) m *= *this;
        return m;
    }
    // for prime modulo
    mint inv() const{
        return pow(MOD-2);
    }
    mint& operator/=(const mint& m){
        (*this) *= m.inv();
        n %= MOD;
        return *this;
    }
    mint operator/(const mint& m) const{
        mint res(*this);
        res /= m;
        return res;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.n;
        return os;
    }
};

ll N,M;
vector<ll> A,B;

int main(){
    cin >> N >> M;
    for(int i=0;i<N;i++){
        ll tmp;
        cin >> tmp;
        A.push_back(tmp);
    }
    for(int j=0;j<M;j++){
        ll tmp;
        cin >> tmp;
        B.push_back(tmp);
    }
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    A.erase(unique(A.begin(),A.end()), A.end());
    B.erase(unique(B.begin(),B.end()), B.end());
    if(A.size() != N || B.size() != M){
        cout << 0 << endl;
        return 0;
    }
    mint ans(1);
    for(int i=N*M;i>=1;i--){
        if(binary_search(A.begin(),A.end(),i) && binary_search(B.begin(),B.end(),i)) continue;
        if(binary_search(A.begin(),A.end(),i)){
            ll ind = B.end() - upper_bound(B.begin(),B.end(),i);
            ans *= mint(ind);
            continue;
        }
        if(binary_search(B.begin(),B.end(),i)){
            ll ind = A.end() - upper_bound(A.begin(),A.end(),i);
            ans *= mint(ind);
            continue;
        }
        ll ind_a = A.end() - upper_bound(A.begin(),A.end(),i);
        ll ind_b = B.end() - upper_bound(B.begin(),B.end(),i);
        ans *= mint(ind_a) * mint(ind_b) - mint(N*M-i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
N = int(input())
moves=0
previous=0
exists=1
a = [0 for i in range(N)]
for i in range(N):
  a[i]=int(input())
if a[0]!=0:
  exists=0
for i in [N-j-1 for j in range(N)]:
  if a[i]>=previous:
    moves+=a[i]
  elif a[i]<previous-1:
    exists=0
  previous = a[i]
if exists==0:
  print(-1)
else:
  print(moves)

Measured memory_bytes: 18968