akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void){

  long n,k,c;
  scanf("%ld %ld %ld", &n, &k, &c);

	char s[n];
	scanf("%s", s);

  long first[k];
  long last[k];
  long work = 0;
  long day;

  for (day = 0; work < k; day++) {
    if (s[day] == 'o') {
      first[work] = day;
      day += c;
      work++;
    }
  }

  work = 0;
  for (day = n-1; work < k; day--) {
    if (s[day] == 'o') {
      last[work] = day;
      day -= c;
      work++;
    }
  }

  for (long i = 0; i < k; i++) {
    if (first[i] == last[k-i-1]) {
      printf("%ld\n", first[i]+1);
    }
  }

  return 0;
}

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

int main() {
	string s,forward,back;
	forward = "";
	back = "";
	bool flag = false;
	int t, f,q;
	char c;
	cin >> s>>q;
	
	for (int i = 0;i < q;i++) {
		cin >> t;
		if (t == 1)flag = !flag;
		if (t == 2) {
			cin >> f >> c;
			if ((f == 1 && !flag) || (f == 2 && flag)) {
				//s = c + s;
				forward = c + forward;
			}
			else {
				//s = s + c;
				back = back + c;
			}
		}
	}
	s = forward + s + back;

	if (flag) reverse(s.begin(), s.end());
	
	cout << s << "\n";

	return 0;
}


Measured memory_bytes: 1512
N=int(input())
T=[list(map(int,input().split())) for i in range(N)]
X=0
c=1
for i in range(N):
  for j in range(N):
    X=X+((abs(T[i][0]-T[j][0]))**2+(abs(T[i][1]-T[j][1]))**2)**0.5
print(X/N)

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

int main() {
	int n, x;
	int mina = INT_MAX;
	int maxa = -INT_MAX;
	cin>>n;
	long long s = 0 ;
	
	for(int i=0; i<n; i++)
	{
		cin>>x;
		if(x > maxa) {  maxa = x ; }
		if(x < mina) {  mina = x ; }
		s += x;
	}

	cout<<mina << " " << maxa << " " <<s <<endl;
	return 0;
}



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

int main()
{
  const int dx[8]={1, 1, 1, 0,  0, -1, -1, -1};
  const int dy[8]={1, 0,-1, 1, -1,  1,  0, -1};
  int H, W;
  char s[51][51];
  int res=0;
  cin >> H >> W;

  rep(i,H) cin >> s[i];

  rep(i,H){
    rep(j,W){
      if(s[i][j]=='.'){
        int cnt=0;
        rep(k,8){
          int x=j+dx[k];
          int y=i+dy[k];
          if(x<0||y<0||x>=W||y>=H) continue;
          if(s[y][x]=='#') cnt++;
        }
        s[i][j]=cnt+48;
      }
    }
  }

  rep(i,H){
    cout << s[i] << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>

using namespace std;

using ll = long long int;

int main(){
    
    ll N;
    string S;
    
    cin >> N >> S;
 
    for(ll i = 0; i < S.size(); ++i){
        ll cnt = 0;
        for(ll j = 0; j < S.size(); ++j){
            if(S[j] == '('){
                cnt += 1;
            }else{
                cnt -= 1;
            }
            if(cnt < 0){
                break;
            }
        }
        if(cnt < 0){
            S.insert(i, 1, '(');
        }
    }
    ll cnt = 0;
    for(ll j = 0; j < S.size(); ++j){
        if(S[j] == '('){
            cnt += 1;
        }else{
            cnt -= 1;
        }
    }
    while(cnt-- > 0){
        S.push_back(')');
    }
    
    cout << S << endl;
    
    return 0;
}

Measured memory_bytes: 256
H, W, M = map(int, input().split())

B = [list(map(int, input().split())) for _ in range(M)]

bombs_row = [0] * H
bombs_col = [0] * W

for b in B:
    bombs_row[b[0] - 1] += 1
    bombs_col[b[1] - 1] += 1

row_max = max(bombs_row)
col_max = max(bombs_col)

row_max_count = bombs_row.count(row_max)
col_max_count = bombs_col.count(col_max)

ans = row_max + col_max

possible_point = row_max_count * col_max_count

bombed_point = 0

for b in B:
    if bombs_row[b[0] - 1] == row_max and bombs_col[b[1] - 1] == col_max:
        bombed_point += 1

if bombed_point == possible_point:
    ans -= 1

print(ans)


Measured memory_bytes: 68388
#include<stdio.h>
#include<bits/stdc++.h>
#include<string>
#include<math.h>
#include<vector>
#include <iostream>
#include <algorithm>

using namespace std;
const long long int INF=1e9+5;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long N;
    cin>>N;
    long long K;
    cin>>K;
    vector<long long>h(N);
    for(long long i=0;i<N;i++)
        cin>>h[i];
    vector<long long> dp(N,INF);
    dp[0]=0;
    for(long long i=0;i<N;i++){
        for(long long j=i+1;j<=i+K;j++){
            if(j<N){
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
            }
        }
    }
    cout<<dp[N-1];
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int N; cin >>N;
  vector<string>s(N);
  rep(i,N)cin>>s.at(i);
  int M;cin>>M;
  vector<string>t(M);
  rep(i,M)cin>>t.at(i);
  int kotae=0;
  map<string,int>mp;
  for(string x:s){
    mp[x]++;
  }
  for(string x:t){
    mp[x]--;
  }
  for(auto x:mp){
    kotae=max(kotae,x.second);
  }
  cout<<kotae<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
 		int k = sc.nextInt();
      	String s = sc.next();
      	String result = "";
      	if(s.length() <= k){
          result = s;
        }else{
          result = s.substring(0,k) + "...";
        }
      System.out.println(result);
}
}



Measured memory_bytes: 38672
#define rep(i, n) for(int i = 0; i < n; i++)
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
	ll N;
	cin >> N;
	vector<ll> a(N);
	rep(i,N) cin >> a[i];
	sort(a.begin(), a.end());

	ll ans = 0;

	for (int k=0;k<=N-2;k++) ans += a[N-1-((k+1)/2)];

	cout << ans << endl;
	

	return 0;
}


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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;

int main() {
    double t, x;
    cin >> t >> x;
    cout << fixed << setprecision(10) << t / x << endl;
    return 0;
}

Measured memory_bytes: 3772
n = gets.to_i

res = n
(0..n).each do |i|
  cc = 0
  t = i
  while t > 0
    cc += t % 6
    t /= 6
  end
  t = n - i
  while t > 0
    cc += t % 9
    t /= 9
  end

  res = cc if res > cc
end

puts res

Measured memory_bytes: 1788
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <algorithm>

using namespace std;

#define fir first
#define sec second

typedef pair<int, int> PI;

namespace io
{
	const int maxb = 1 << 15;
	char b[maxb], *s = b, *t = b;
	bool Getchar(char &ch)
	{
		return ch = s == t && (t = (s = b) + fread(b, 1, maxb, stdin)) == b ? 0 : *s ++;
	}
}

int Getint()
{
	using namespace io;
	char ch;
	while (Getchar(ch) && (ch < '0' || ch > '9'));
	int s = ch - '0';
	while (Getchar(ch) && ch >= '0' && ch <= '9')
		s = s * 10 + ch - '0';
	return s;
}

const int maxn = 1e5 + 10;

set<int> adj[maxn];
map<int, int> cnt[maxn];

int main()
{
	int n = Getint(), m = n - 1 << 1;
	for (int i = 1; i <= m; ++ i)
	{
		int x = Getint(), y = Getint();
		if (x > y) swap(x, y);
		adj[x].insert(y);
		adj[y].insert(x);
		++ cnt[x][y];
	}
	queue<PI> Q;
	for (int i = 1; i <= n; ++ i)
	{
		for (set<int> :: iterator it = adj[i].begin(); it != adj[i].end(); ++ it)
		{
			if (*it > i) break;
			if (cnt[*it][i] > 1) Q.push(PI(*it, i));
		}
	}
	int count = 0;
	while (!Q.empty())
	{
		int x = Q.front().fir, y = Q.front().sec;
		Q.pop();
		if (adj[x].empty() || adj[y].empty()) continue;
		++ count;
		adj[x].erase(y);
		adj[y].erase(x);
		if (adj[x].size() < adj[y].size()) swap(x, y);
		for (set<int> :: iterator it = adj[y].begin(); it != adj[y].end(); ++ it)
		{
			adj[*it].erase(y);
			adj[*it].insert(x);
			adj[x].insert(*it);
			int p = min(x, *it), q = max(x, *it);
			if ((cnt[p][q] += cnt[min(y, *it)][max(y, *it)]) == 2) Q.push(PI(p, q));
		}
		adj[y].clear();
	}
	if (count == n - 1) puts("YES"); else puts("NO");
	return 0;
}


Measured memory_bytes: 37888
#include <cstdio>
using namespace std;

#define MAX 500000

struct Node
{
	int key;
	Node *parent, *left, *right;
public:
	Node() { parent = left = right = NULL; }
};

Node *root;

void insert(int u)
{
	Node *y = NULL;
	Node *x = root;
	Node *z = new Node();
	z->key = u;
	//?????????????????§?§????
	while (x != NULL) {
		y = x;
		if (z->key < x->key)
			x = x->left;
		else x = x->right;
	}
	z->parent = y;

	//?????????????????????????????\
	if (y == NULL) root = z;
	else if (z->key < y->key) y->left = z;
	else y->right = z;
}

void Preorder(Node *u)
{
	printf(" %d", u->key);
	if (u->left != NULL) Preorder(u->left);
	if (u->right != NULL) Preorder(u->right);
}

void Inorder(Node *u)
{
	if (u->left != NULL) Inorder(u->left);
	printf(" %d", u->key);
	if (u->right != NULL) Inorder(u->right);
}

int main()
{
	int n;
	scanf("%d", &n);

	char order[20];
	int z;
	for (int i = 0; i < n; i++) {
		scanf("%s", order);
		switch (order[0])
		{
		case 'i':
			scanf("%d", &z);
			insert(z);
			break;
		case 'p':
			Inorder(root);
			printf("\n");
			Preorder(root);
			printf("\n");
			break;
		default:
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 24468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


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

	string s,k;
	cin >> s;
	ll l = s.size();
	s += 'F';
	vector<string> v;
	FOR(i,0,l){
		if(s[i]=='A'){
			k += 'A';
		}else if(s[i]=='B'&&s[i+1]=='C'){
			k += "B";
			i++;
		}else{
			if(k.size()!=0){
				v.push_back(k);
				k = "";
			}
		}
	}
	if(k.size())v.push_back(k);
	ll ans = 0;
	for(auto S:v){
		ll Sl = S.size();
		vector<ll> BC(Sl+6,0),A(Sl+6,0);
		FORR(i,0,Sl){
			if(S[i]=='B')BC[i]++;
			BC[i] += BC[i+1];
		}
		FOR(i,0,Sl){
			if(S[i]=='A'){
				ans += BC[i];
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3988
#include <stdio.h>
#include <stdlib.h>
struct node{
  int key;
  struct node *left;
  struct node *right;
  struct node *parent;
};
typedef struct node* Node;
Node rootnode,NIL;


Node getMinimum(Node node){
  while(node->left!=NIL)
    node=node->left;
  return node;
}

Node getSuccessor(Node node){
  Node delete=node->parent;
  if(node->right!=NIL)
    return getMinimum(node->right);

  while(delete!=NIL && node==delete->right){
    node=delete;
    delete=delete->parent;
  }
  return delete;
}

Node Find(Node node,int key){
  while(node!=NIL && node->key!=key){
    if(node->key<key)
      node=node->right;
    else
      node=node->left;
  }
  return node;
}

void Insert(int key){
  Node node=rootnode,z,y=NIL;
  z=(Node)malloc(sizeof(struct node));
  z->key=key;
  z->left=NIL;
  z->right=NIL;

  while(node!=NIL){
    y=node;
    if(key>node->key)
      node=node->right;
    else
      node=node->left;
  }
  z->parent=y;
  if(y==NIL)rootnode=z;
  else{
    if(key>y->key)
      y->right=z;
    else
      y->left=z;
  }
}

void Preorder(Node node){
  if(node!=NIL){
    printf(" %d",node->key);
    Preorder(node->left);
    Preorder(node->right);
  }
}
void Inorder(Node node){
  if(node->left!=NIL)
    Inorder(node->left);
  printf(" %d",node->key);
  if(node->right!=NIL)
    Inorder(node->right);
}

void Delete(Node node){
  Node delete;
  Node child;

  if(node->left==NIL || node->right==NIL)
    delete=node;
  else
    delete=getSuccessor(node);
   
  
  //setting child
  if(delete->left!=NIL)
    child=delete->left;
  else
    child=delete->right;
  
  if(child!=NIL)
    child->parent=delete->parent;
  
  
  //if deletenode is rootnode
  if(delete->parent==NIL)
    rootnode=child;
  //deletenode is not rootnode
  else{
    if(delete->parent->left==delete)
      delete->parent->left=child;
    else
      delete->parent->right=child;
  }

  if(delete!=node)
    node->key=delete->key;
  free(delete);
}

int main(void){
  int n,i,key;
  char command[7];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",command);
    if(command[0]=='i'){
      scanf("%d",&key);
      Insert(key);
    }
    else if(command[0]=='p'){
      Inorder(rootnode);
      printf("\n");
      Preorder(rootnode);
      printf("\n");
    }
    else if(command[0]=='f'){
      scanf("%d",&key);
      if(Find(rootnode,key)!=NIL)
	printf("yes\n");
      else printf("no\n");
    }
    else if(command[0]=='d'){
      scanf("%d",&key);
      Delete(Find(rootnode,key));
    }
  }

  return 0;
}



Measured memory_bytes: 20436
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var u = xArray(1,n);
  var e = xArray("[]",n);
  for(var i = 1; i < n; i++){
    var t = o.l().map(a=>a-1);
    e[t[0]].push(t[1]);
    e[t[1]].push(t[0]);
  }
  return treeDia(e)%3 === 1 ? "Second":"First";
}

function treeDia(e){
  var v1 = 0, l;
  for(var i = 0; i < 2; i++){
    l = 0;
    var q = [[v1,-1]], q2 = [];
    while(q.length || q2.length){
      if(q.length === 0){
        l++;
        q = q2;
        q2 = [];
        v1 = q[0][0];
      }
      var t = q.pop(), v = t[0], p = t[1];
      for(var j = 0; j < e[v].length; j++){
        if(p === e[v][j])continue;
        q2.push([e[v][j],v]);
      }
    }
  }
  return l;
}

Measured memory_bytes: 115616
h,w = gets.split("\s").map(&:to_i)
lines = []
h.times do
	lines << gets.chomp.each_char.to_a
end

map = []
lines.each_with_index do |line, i|
	map << []
	line.each_with_index do |c, j|
		if c == "."
			map[i][j] = 0
		end
	end
end

lines.each_with_index do |line, i|
	line.each_with_index do |c, j|
		if c == "#"
			irange = ( (i>0 ? i-1 : 0)..( i==h-1 ? i : i+1 ) )
			jrange = ( (j>0 ? j-1 : 0)..( j==w-1 ? j : j+1 ) )
			
			irange.each do |i2|
				jrange.each do |j2|
					map[i2][j2] += 1 if map[i2][j2]
				end
			end
		end
	end
end

h.times do |i|
	w.times do |j|
		print map[i][j] || "#"
	end
	puts
end

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

#define ll long long 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()

int main(){

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
		
	ios::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	string s; cin >> s;
	int hash[n][3];
	memset(hash, 0, sizeof hash);

	for(int i = 0; i < n; i++) {
		if(s[i] == 'R') hash[i][0]++;
		if(s[i] == 'G') hash[i][1]++;
		if(s[i] == 'B') hash[i][2]++;
	}
	for(int i = 1; i < n; i++) {
		for(int j = 0; j < 3; j++) {
			hash[i][j] += hash[i - 1][j];
		}
	}
	ll ans = 0;
	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			if(s[i] == s[j]) continue;
			bool r, g, b;
			r = g = b = false;
			if(s[i] == 'R' || s[j] == 'R') r = true;
			if(s[i] == 'G' || s[j] == 'G') g = true;
			if(s[i] == 'B' || s[j] == 'B') b = true;

			if(!r) {
				ans += hash[n - 1][0] - hash[j][0];
				if(2 * j - i < n && s[2 * j - i] == 'R') ans--;
			}
			if(!g) {
				ans += hash[n - 1][1] - hash[j][1];
				if(2 * j - i < n && s[2 * j - i] == 'G') ans--;
			}
			if(!b) {
				ans += hash[n - 1][2] - hash[j][2];
				if(2 * j - i < n && s[2 * j - i] == 'B') ans--;
			}
			// cout << "i: " << i << " j: " << j << " ans: " << ans << "\n";
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3660
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> x(3);
    for(int i=0; i<n; ++i){
        int a;
        cin >> a;
        ++ x[a%3];
    }

    if(x[1] == 0 && x[2] == 0){
        cout << 1 << endl;
        return 0;
    }

    int ans = 0;
    for(int i=1; i<3; ++i){
        int sum = x[0];
        int mod = 0;
        int p = x[1];
        int q = x[2];
        if(i == 1){
            if(p == 0)
                continue;
            ++ sum;
            mod = 1;
            -- p;
        }
        else{
            if(q == 0)
                continue;
            ++ sum;
            mod = 2;
            -- q;
        }

        for(;;){
            if(mod == 1){
                if(p == 0){
                    sum += min(1, q);
                    break;
                }
                ++ sum;
                mod = 2;
                -- p;
            }
            else{
                if(q == 0){
                    sum += min(1, p);
                    break;
                }
                ++ sum;
                mod = 1;
                -- q;
            }
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int n,m;
    cin >> n >> m;
    vector<P> st(n);
    vector<P> ch(m);
    rep(i,n) cin >> st[i].first >> st[i].second;
    rep(i,m) cin >> ch[i].first >> ch[i].second;
    vector<int> ans(n);
    rep(i,n) {
        int dis = 1001001001;
        int num;
        rep(j,m) {
            int ndis = abs(st[i].first-ch[j].first)+abs(st[i].second-ch[j].second);
            if(ndis < dis) num = j;
            dis = min(ndis,dis);
        }
        ans[i] = num+1;
    }
    rep(i,n) cout << ans[i] << endl;
}

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

ll N;
ll A[210000];
ll MOD = 1000000007;


int main(void){

    ll sum = 0;

    cin >> N;
    for (int i = 1; i <= N;i++) {
        cin >> A[i];
        sum = (sum + A[i]) % MOD;
    }

    ll ans = 0;

    for (int i = 1; i < N;i++){
        if (A[i] > sum) sum = MOD + sum - A[i];
        else sum = sum - A[i];

        ans = (ans + sum * A[i]) % MOD;

    }

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 5188
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
string s;
int res;
int main() {
    DAU
    cin >> s;
    s = '0' + s;
    for (int i = (int)s.size() - 1; i > 0; --i) {
        if (s[i] <= '4' || (s[i] == '5' && s[i-1] < '5'))
            res += s[i] - '0';
        else {
            res += '9' + 1 - s[i];
            ++s[i-1];
        }
    }
    res += s[0] - '0';
    cout << res;
    PLEC
}


Measured memory_bytes: 2332
#include <stdio.h>

int	is_triangle(int a, int b, int c)
{
  int	blen_a;
  int	blen_b;
  int	blen_c;
  
  blen_a = (a < (b + c));
  blen_b = (b < (c + a));
  blen_c = (c < (a + b));
  
  return (blen_a && blen_b && blen_c);
}

int	main(void)
{
  int	n;
  int	*li;
  int	i;
  int	j;
  int	k;
  int	count;
  
  if (scanf("%d", &n) == NULL)
    return (-1);
  if (n < 3)
  {
    printf("0\n");
    return (0);
  }
  if (!(li = (int *)malloc(sizeof(int) * n)))
    return (-1);
  i = 0;
  while (i < n)
  {
    if (scanf("%d", &li[i++]) == NULL)
      return (-1);
  }
  i = 0;
  count = 0;
  while (i < n - 2)
  {
    j = i + 1;
    while (j < n - 1)
    {
      k = j + 1;
      while (k < n)
      {
        if (li[i] != li[j] && li[j] != li[k] && li[k] != li[i])
        {
          if (is_triangle(li[i], li[j], li[k]))
            count++;
        }
        k++;
      }
      j++;
    }
    i++;
  }
  printf("%d\n", count);
  free(li);
  return (0);
}

Measured memory_bytes: 1736
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)



signed main(){
	int A,B;
	cin>>A>>B;
	cout<<((A*3)+B)/2<<endl;
	return 0;
}


Measured memory_bytes: 256
/*
				GAURAV KUMAR
				 MNNIT
				  BTECH 3RD YEAR
*/

#include<bits/stdc++.h>
using namespace std;
#define debug1(x) cout << # x << " " << x << endl;
#define debug2(x,y) cout << #x << " " << x << " " << #y << " " << y << endl;
#define debug3(x,y,z) cout << #x << " " << x << " " << #y << " " << y << " " << #z << " " << z << endl;
#define debug4(x,y,z,w) cout << #x << " " << x << " " << #y << " " << y << " " << #z << " " << z <<  " " << #w << " "<<w <<endl;

typedef long long int ll;
const ll INF=1e12;
ll a[1001];
int n;
ll dp[401][401];
ll pre[401];
ll solve(int i,int j)
{
	ll ans=LONG_MAX;
	if(i==j)return 0;
	if(dp[i][j]!=-1)
		return dp[i][j];
	for(int k=i;k<j;k++)
	{
		ans=min(ans,pre[j]-pre[i-1]+solve(i,k)+solve(k+1,j));
	}
	return dp[i][j]=ans;

}
int main()
{
	

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t;
	
		
		
		cin>>n;
		for(int i=1;i<=n;i++)
			cin>>a[i];
		for(int i=0;i<=400;i++)
			for(int j=0;j<=400;j++)dp[i][j]=-1;
		for(int i=1;i<=n;i++)
			pre[i]=pre[i-1]+a[i];
		cout<<solve(1,n)<<endl;
	
	
}

Measured memory_bytes: 1536
public class Main {
	
		
		public static void main(String[] args) {
			java.util.Scanner scan = new java.util.Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();	
		
		if(1<=a  && b<=100){;
		System.out.print(a*b+" ");
		System.out.println(2*a+2*b);// TODO ?????????????????????????????????????????????
		}
		}	
			
		
	
	}

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

using namespace std;
typedef long long ll;

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

int main(){
// ここに処理を記述
    int N;
    cin >> N;

    double v[N];
    REP(i,N) cin >> v[i];

    sort(v,v+N);
    double ans = 0;

    ans = (v[0]+v[1])/2;

    FOR(i,2,N){
        ans = (ans + v[i])/2;
    }

    cout << ans << endl;


return 0;
}

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

int main(void) {
  int N;
  string S;
  cin >> N >> S;
  bool flag = N % 2 == 0;
  for (int i = 0; i < N / 2; i++) {
    if (S[i] != S[i + N / 2]) flag = false;
  }
  cout << (flag ? "Yes" : "No") << endl;
  return 0;
}

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

#ifdef DEBUG
#define debug(...) __VA_ARGS__
#else
#define endl '\n'
#define debug(...)
#endif
#define debugf(...) debug(printf(__VA_ARGS__))

const int N = 1e4 + 5;
using ll = long long;
const ll mod = 1e9 + 7;

int a[N];

ll pwr(ll x, ll e) {
    ll ans = 1;
    for (; e > 0; e >>= 1) {
        if (e & 1)
            ans = ans * x % mod;
        x = x * x % mod;
    }
    return ans;
}

ll inv(ll x) {
    return pwr(x, mod - 2);
}

const int K = 1e6 + 5;
int lp[K];

void sieve() {
    for (int x = 2; x < K; x++) {
        if (lp[x]) continue;
        for (int y = x; y < K; y += x)
            lp[y] = x;
    }
}

int cnt[K];

void add(int x) {
    while (lp[x]) {
        int f = 0;
        int y = lp[x];
        do {
            f++;
            x /= lp[x];
        } while (y == lp[x]);

        cnt[y] = max(cnt[y], f);
    }
}

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

    sieve();

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

    ll L = 1;
    for (int i = 2; i < K; i++) {
        L *= pwr(i, cnt[i]);
        L %= mod;
    }

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ans += L * inv(a[i]) % mod;
        if (ans >= mod) ans -= mod;
    }

    cout << ans << endl;


    return 0;
%>

Measured memory_bytes: 10084
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59
 
ll h,w;
ll s[70][70];

bool valid(ll a,ll b){
  if(s[a][b]==1&&a>=0&&a<h&&b>=0&&b<w) return 1;
  else return 0;
}
 
int main(){
  
  ll i,j;
  cin>>h>>w;
  ll white=0;
 
  char x;
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      cin>>x;
      if(x=='.') {
        s[i][j]=1;
        white++;
      }
      else s[i][j]=0;
    }
  }
  VVI used(h+10,VI(w+10,0));
 
  priority_queue <pair<ll,P>, vector<pair<ll,P> >, greater<pair<ll,P> > > p;
  p.push(make_pair(1,P(0,0)));
  used[0][0]=1;
 
  P d[4];
  d[0]=P(1,0);
  d[1]=P(0,1);
  d[2]=P(-1,0);
  d[3]=P(0,-1);
  
  ll v,vv;
 
  while(!p.empty()){
    auto x=p.top();
    p.pop();
    P z=x.se;
    for(ll k=0;k<4;k++){
      v=z.fi+d[k].fi;
      vv=z.se+d[k].se;
      if(valid(v,vv)&&used[v][vv]==0){
        if(v==h-1&&vv==w-1){
          cout<<white-(x.fi+1)<<endl;
          return 0;
        }
        p.push(make_pair(x.fi+1,P(v,vv)));
        used[v][vv]=1;
      }
    }
  }
  cout<<-1<<endl;
  return 0;
  
}

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

using namespace std;

#define ll long long

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

  int n;
  cin >> n;
  if (n % 1000 == 0)
    cout << "0\n";
  else
    cout << 1000 - n % 1000 << "\n";

  return 0;
}

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

#define int long long
#define ll long long
#define ffor(i,n) for(int i = 0;i < (n); ++i)
#define fro(i,j,n) for(int i = (j);i < (n); ++i)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pii>
#define ff first
#define ss second
const int mod = 1e9 + 7;
int add(int a,int b){
	return (a + b)%mod;
}
int sub(int a,int b){
	return add(a,mod - 1);
}
int mul(int a,int b){
	return (a*b)%mod;
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    int x,y;
    cin >> x >> y;
    cout << (y >= x ? "unsafe":"safe");
}

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

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> ans(n+1,0);
  for(int i = 0;i<m;i++){
    int a,b;
    cin>>a>>b;
    ans[a]++;
    ans[b]++;
  }
  for(int i = 0;i<n;i++){
    cout<<ans[i+1]<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
import collections

#https://note.nkmk.me/python-prime-factorization/
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def f(n):
    for i in range(1,20):
        if n<(i*(i+1))//2:
            return i-1

n = int(input())
c = collections.Counter(prime_factorize(n))
ans = 0
for i in c.keys():
    ans += f(c[i])
print(ans)

Measured memory_bytes: 9464
#include<map>
#include<set>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lb(x) x&-x
#define il inline
#define ll long long
#define llu unsigned long long
#define mem(x) memset(x,0,sizeof(x))
#define mem3(x) memset(x,0x3f,sizeof(x))
#define ccA() puts("耐心冷静查代码")
#define cc() puts("谁知盘中餐，粒粒皆辛苦")
#define fo(i,a,b) for(register int i=a;i<=b;++i)
#define fd(i,a,b) for(register int i=a;i>=b;--i)
#define fk(i,j) for(register int i=fir[j];i;i=nxt[i])
#define fv(i,q) for(int i=0;i<q.size();i++)
using namespace std;
inline ll read(){
    ll x=0,f=1;char c;
    for(c=getchar();c<'0'||c>'9';f=((c=='-')?-1:f),c=getchar());
    for(;c>='0'&&c<='9';x=x*10+c-'0',c=getchar());
    return x*f;
}
inline void write(ll a){
    if(a==0){putchar('0');return;}
    if(a<0)putchar('-'),a=-a;
    char c1[120];
    ll h=0;
    while(a)c1[++h]=a%10+'0',a/=10;
    fd(i,h,1)putchar(c1[i]);
    return;
}
inline void write_(ll a){write(a);putchar(' ');}
inline void writeln(ll a){write(a);putchar('\n');}
//------------------------------------------------------
const int N=100;
int n,k,ans,a[N],now[N],tot,bans=0;

int main(){
	n=read(),k=read();
	fo(i,1,n)a[i]=read();
	fo(i,0,n){
		fo(j,i+1,n+1){
			if(i+n-j+1<=k){
				tot=0;bans=0;
				fo(l,1,i)now[++tot]=a[l],bans+=a[l];
				fd(r,n,j)now[++tot]=a[r],bans+=a[r];
				sort(now+1,now+1+tot);
				fo(p,1,min(k-i-(n-j+1),tot)){
					if(now[p]<=0)bans-=now[p];
					else break;
				}
				ans=max(ans,bans);
			}
		}
	}
	writeln(ans);
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
signed main() {
  ios::sync_with_stdio(false);
  int N, X; cin >> N >> X;
  vector<int> A(N);
  REP(i,N) cin >> A[i];
  int ans = 0;
  REP(i,N-1) {
    if(A[i] + A[i + 1] > X) {
      int t = A[i] + A[i + 1] - X;
      ans += t;
      A[i + 1] -= min(t, A[i + 1]);
    }
  }
  cout << ans << endl;
}


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

int main(void){
    int a, b;
    cin >> a >> b;
    int m, n;
    if(a<b){
        n = a;
        m = b;
    }else{
        n = b;
        m = a;
    }
    for(int i=0; i<m; i++){
        cout << n;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

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

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

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

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

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

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

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

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

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

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

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	a := readInt()
	b := readInt()
	c := readInt()
	d := readInt()
	e := readInt()
	f := readInt()

	maxsw := 0
	maxsg := 0
	for p := 0; p*a*100 <= f; p++ {
		g1 := p * a * 100
		for q := 0; q*b*100 <= f-g1; q++ {
			g2 := g1 + q*b*100
			for r := 0; r*c <= f-g2; r++ {
				g3 := g2 + r*c
				for s := 0; s*d <= f-g3; s++ {
					sg := r*c + s*d
					sw := 100*p*a + 100*q*b + sg

					if (100+e)*sg > e*sw {
						continue
					}

					if maxsw == 0 && maxsg == 0 || sw*maxsg < sg*maxsw {
						maxsg = sg
						maxsw = sw
					}
				}
			}
		}
	}
	println(maxsw, maxsg)
}


Measured memory_bytes: 640
""" AtCoder """

N = int(input())
S = input()

e = S.count('E')
w = 0
ans = e

for s in S:
    ans = min(ans, w + e)
    if s == 'W':
        w += 1
    else:
        e -= 1

ans = min(ans, w + e)

print(ans)


Measured memory_bytes: 3672
K = int(input())

text = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'
textl = list(text.split(', '))

ans = textl[K - 1]
print(ans)

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    ll x, y, a, b, c; cin >> x >> y >> a >> b >> c;
    vector<ll> 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.begin(), p.end(), greater<ll>());
    sort(q.begin(), q.end(), greater<ll>());
    sort(r.begin(), r.end(), greater<ll>());
    priority_queue<ll, vector<ll>, greater<ll>> que;
    for(int i = 0; i < x; i++) que.push(p[i]);
    for(int i = 0; i < y; i++) que.push(q[i]);


    for(int i = 0; i < c; i++)
    {
        ll k = que.top();
        if(k > r[i]) break;
        que.pop();
        que.push(r[i]);
    }
    ll ans = 0;
    while(que.size())
    {
        ans += que.top(); que.pop();
    }
    cout << ans << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 4852
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	if (a >= k) cout << k << endl;
	else if (a + b >= k) cout << a << endl;
	else cout << (2 * a + b - k) << endl;
	return 0;
}

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

int main(){
    int h, w;
    cin >> h >> w;
    char c[1010][1010];
    for(int i = 0;i < h;i++){
        cin >> c[i];
    }

    char ans[1010][1010];
    int ap = 0;
    for(int i = 0;i < h;i++){
        bool flag = true;
        for(int j = 0;j < w;j++){
            if(c[i][j] != '.'){
                flag = false;
            }
        }
        if(!flag){
            for(int j = 0;j < w;j++){
                ans[ap][j] =c[i][j];
            }
            ap++;
        }
    }

    char ans2[1010][1010];
    int ap2 = 0;
    for(int i = 0;i < w;i++){
        bool flag = true;
        for(int j = 0;j < ap;j++){
            if(ans[j][i] != '.'){
                flag = false;
            }
        }
        if(!flag){
            for(int j = 0;j < ap;j++){
                ans2[j][ap2] =ans[j][i];
            }
            ap2++;
        }
    }

    for(int i = 0;i < ap;i++){
        for(int j = 0;j < ap2;j++){
            cout << ans2[i][j];
        }
        cout << endl;
    }

    return 0;
}


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

int main() {
    int N;
    cin >> N;
    int ac, wa, tle, re;
    ac = 0;
    wa = 0;
    tle = 0;
    re = 0;
    for (int i=0; i<N; i++) {
        string S;
        cin >> S;
        if (S == "AC") {
            ac ++;
        }
        else if (S == "WA") {
            wa ++;
        }
        else if (S == "TLE") {
            tle ++;
        }
        else if (S == "RE") {
            re ++;
        }
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}

Measured memory_bytes: 3600
// Contest: AtCoder Beginner Contest 154 (https://atcoder.jp/contests/abc154)
// Problem: E: Almost Everywhere Zero (https://atcoder.jp/contests/abc154/tasks/abc154_e)


// region {{{ boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cpp_lib_nonmember_container_access >= 201411
#   define sz(x) ((int)size(x))
#else
#   define sz(x) ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define all(a)         (a).begin(),(a).end()
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __has_cpp_attribute(maybe_unused) >= 201603
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18;
//endregion }}}

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

    string n; int ik; cin >> n >> ik;
    ll d = sz(n);

    string num(d, '0');
    ll res = 0;
    rep(i, d) reps(iv, 1, 10) {
        if (ik == 1) {
            num[i] = '0' + iv;
            res += num <= n;
            num[i] = '0';
            continue;
        }
        num[i] = ('0' + iv + 1);
        if (num <= n) {
            num[i] = '0';
            if (ik == 2)
                res += (d-i-1)*9;
            else
                res += (d-i-1)*(d-i-2)/2*9*9;
            continue;
        }
        num[i] = '0' + iv;
        reps(j, i+1, d) reps(jv, 1, 10) {
            if (ik == 2) {
                num[j] = '0' + jv;
                res += num <= n;
                num[j] = '0';
                continue;
            }
            num[j] = '0' + jv + 1;
            if (num <= n) {
                num[j] = '0';
                if (ik == 2)
                    ++res;
                else
                    res += (d-j-1) * 9;
                continue;
            }
            num[j] = '0' + jv;
            reps(k, j+1, d) reps(kv, 1, 10) {
                num[k] = '0' + kv;
                res += num <= n;
                num[k] = '0';
            }
            num[j] = '0';
        }
        num[i] = '0';
    }

    cout << res << '\n';
    return 0;
}

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

class Main{

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		while(true){

			String input = br.readLine();
			StringTokenizer st = new StringTokenizer(input, " ");
			int n = Integer.parseInt(st.nextToken());
			int x = Integer.parseInt(st.nextToken());
			int count = 0;

			if(n == 0 && x == 0){
				break;
			}

			for(int i = 1; i <= n; i++){
				for(int j = 1; j <= n; j++){

					if(j == i){
						break;
					}

					for(int k = 1; k <= n; k++){

						if(k == i || k == j){
							break;
						}

						if((i + j + k) == x){
							count++;
						}

					}

				}
			}

			sb.append(count + "\n");

		}

		System.out.print(sb);

	}
}

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

#define mod 1000000007

using namespace std;
 
int main(void){
	
	int A[3], count = 0;
	
	cin >> A[0] >> A[1] >> A[2];
	
	sort(A, A+3);
	
	//while(A[0] != A[1] && A[1] != A[2]){
		if(A[2]%2 == 0){
			if(A[0]%2 != 0 && A[1]%2 == 0){
				A[2]++;
				A[1]++;
				count++;
			}else if(A[1]%2 != 0 && A[0]%2 == 0){
				A[2]++;
				A[0]++;
				count++;
			}else if(A[0]%2 != 0 && A[1]%2 != 0){
				A[0]++;
				A[1]++;
				count++;
			}
		}else if(A[2]%2 != 0){
			if(A[0]%2 != 0 && A[1]%2 == 0){
				A[2]++;
				A[0]++;
				count++;
			}else if(A[1]%2 != 0 && A[0]%2 == 0){
				A[2]++;
				A[1]++;
				count++;
			}else if(A[0]%2 == 0 && A[1]%2 == 0){
				A[0]++;
				A[1]++;
				count++;
			}
		}
		while(A[1] != A[2]){
			A[1] += 2;
			count++;
		}
		while(A[0] != A[2]){
			A[0] += 2;
			count++;
		}
	//}
	
	cout << count;
	
	return 0;
}

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

int main()
{
    long long n,i;
    scanf("%lld",&n);
    double f=sqrt(n);
    i=f+1;
    for(;i>=1;i--){
        if(n%i==0){
            break;
        }
    }
    printf("%lld\n",i+n/i-2);

    return 0;
}


Measured memory_bytes: 3812
n, m = io.read("*n", "*n", "*l")
ac, wa = 0, 0
accepted = {}
wacand = {}
for i = 1, m do
  s = io.read()
  a, b = s:match("(%d+) (%w%w)")
  a = tonumber(a)
  if not accepted[a] then
    if b == "AC" then
      if wacand[a] then
        wa = wa + wacand[a]
      end
      ac = ac + 1
      accepted[a] = true
    else
      if not wacand[a] then
        wacand[a] = 1
      else
        wacand[a] = wacand[a] + 1
      end
    end
  end
end
print(ac .. " " .. wa)


Measured memory_bytes: 10796
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^8 -> 8回
// double pi = M_PI or acos(-1)
// printf("%.10f\n", ans);

int main() {
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];
    auto dist = [&](int i, int j) {
        double dx = x[i] - x[j];
        double dy = y[i] - y[j];
        return sqrt(dx * dx + dy * dy);
    };
    vector<int> p(n);
    rep(i, n) p.at(i) = i;
    double len = 0;
    int cnt = 0;
    do {
        rep(i, n - 1) {
            len += dist(p.at(i), p.at(i + 1));
        }
        cnt++;
    } while (next_permutation(p.begin(), p.end()));
    double ans = len / cnt;
    printf("%.10f\n", ans);

    return 0;
}


Measured memory_bytes: 3768
/*input
1000000000000000 9.99
*/ 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<ll,ll>;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define MP make_pair
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
const ll maxn=1e5+5;
const ll maxlg=__lg(maxn)+5;
int main(){
    ll a;
    ld b;
    cin>>a>>b;
    cout<<(ll)floor((ld)a*b);
}


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

int main() {
  int n;
  cin >> n;
  vector<int> h(n);

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

  int mx = 0;
  int temp = 0;
  for(int i = 0; i < n-1; i++){
    if(h[i] >= h[i+1]){
      temp++;
      mx = max(mx, temp);
    }
    else{
      temp = 0;
    }
  }

  cout << mx << endl;

  return 0;

}

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

using namespace std;

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

    long long x, k, d;
    cin >> x >> k >> d;

    x = abs(x);
    
    long long n = min(k, x / d);
    k -= n;
    x -= n * d;

    if (k % 2) cout << d - x;
    else cout << x;

    return 0;
}



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

int Z(int n){
  int sum = 0;
  while(n>0){
    sum += n%10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  int total = 0;
  
  for(int i=1; i<=N; i++){
    int sum = Z(i);
    if(A <= sum && sum <= B){
      total += i;
    }
  }
  cout << total <<endl;
}

Measured memory_bytes: 3548
s = input()

flag = 0
for i in range(len(s)-2):
  if s[i] == s[i+1]:
    print("{0} {1}".format(i+1, i+2))
    flag = 1
    break
  elif s[i] == s[i+2]:
    print("{0} {1}".format(i+1, i+3))
    flag = 1
    break
if s[-1] == s[-2] and flag == 0:
  print("{0} {1}".format(len(s)-1, len(s)))
  flag = 1
    
if flag == 0:
  print("{0} {1}".format(-1, -1))

Measured memory_bytes: 3188