akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    string s;
    cin >> s;
    int ans1 = 0, ans2 = 0;
    REP(i,s.length()){
        if (i % 2){
            if (s[i] == '0') ans1++;
            else ans2++;
        }else{
            if (s[i] == '0') ans2++;
            else ans1++;
        }
    }
    cout << min(ans1, ans2) << endl;
    return 0;
}


Measured memory_bytes: 512
N = int(input())
R = sorted([list(map(int, input().split())) for i in range(N)])
T = []
for i in range(N):
    T.append([R[i][0] + R[i][1], R[i][0] - R[i][1]])
T.sort(reverse=True)
while len(T) - 1 > 0:
    t = T.pop()
    i = 1
    while len(T) and t[0] > T[-1][1]:
        N -= 1
        i += 1
        T.pop()
print(N)

Measured memory_bytes: 41416
#include <algorithm>
#include <iostream>
#include <math.h>
#include <cstdio>
#include <string.h>
using namespace std;
int main(void){
	int w,a,b,ans;
	cin>>w>>a>>b;
	if(a>b)swap(a,b);
	ans=b-(a+w);
	if(ans<0)ans=0;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
from math import sqrt

N = int(input())
n = int(sqrt(N))
ans = 10 ** 25
for i in range(1, n + 1):
    if N % i == 0:
        j = N // i
        #print('i={}, j={}'.format(i, j))
        ans = min(ans, i + j - 2)

print(ans)

Measured memory_bytes: 40428
s = input()
t = input()
dic_s = {}
dic_t = {}
conv_s = []
conv_t = []
cnt_s = 0
cnt_t = 0
ans = "Yes"

for i in range(len(s)):
    if s[i] not in dic_s:
        dic_s[s[i]] = cnt_s
        conv_s.append(dic_s[s[i]])
        cnt_s += 1

    elif s[i] in dic_s:
        conv_s.append(dic_s[s[i]])

    if t[i] not in dic_t:
        dic_t[t[i]] = cnt_t
        conv_t.append(dic_t[t[i]])
        cnt_t += 1
    elif t[i] in dic_t:
        conv_t.append(dic_t[t[i]])
    if conv_s[i] != conv_t[i]:
        ans = "No"
        break
print(ans)

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

long long n, w;

int values[110], weights[110];

int sDP[101][301][101];

int saved;

int dp(short index, int weight, int cnt) {
	int &ret = sDP[index][weight][cnt];
	if (ret != -1) return ret;
	
	if (weight + cnt*saved > w) return -1000000000;
	
	if (index == n-1) {
		weight += weights[index];
		cnt++;
		if (weight + cnt*saved > w) {
			return ret = 0;
		} else {
			return ret = values[index];
		}
	}
	
	ret = max(dp(index+1, weight, cnt), dp(index+1, weight + weights[index], cnt+1) + values[index]);
	
	return ret;
}

int main() {
	memset(sDP, -1, sizeof(sDP));
	
	cin >> n >> w;
	cin >> weights[0] >> values[0];
	saved = weights[0];
	weights[0] = 0;
	for (int i = 1; i < n; i++) {
		cin >> weights[i] >> values[i];
		weights[i] -= saved;
	}
	cout << dp(0, 0, 0);
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;

const int N = (int)(1e6 + 5);
const int LOG = (int)(63);

lli n, m, k, ar[N], op[N], p[N][LOG], d[N], pp[N], t[N];

int main() {
	fast_io();
	// freopen("inp.in", "r", stdin);
	
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> ar[i];
	for(int i = 1; i < n; i++)
		d[i] = ar[i + 1] - ar[i];
	cin >> m >> k;
	for(int i = 1; i <= m; i++)
		cin >> op[i];
	for(int i = 1; i < n; i++)
		p[i][0] = i;
	for(int i = 1; i <= m; i++)
		swap(p[op[i]][0], p[op[i] - 1][0]);
	for(int i = 1; i < LOG; i++)
		for(int j = 1; j < n; j++)
			p[j][i] = p[p[j][i - 1]][i - 1];
	for(int i = 1; i <= n; i++)
		pp[i] = i;
	for(lli i = 0; i < LOG; i++)
		if((1ll << i) & k) {
			for(int j = 1; j < n; j++)
				t[j] = d[p[j][i]];
			for(int j = 1; j < n; j++)
				d[j] = t[j];
		}
	for(int i = 2; i < n; i++)
		ar[i] = ar[i - 1] + d[i - 1];
	for(int i = 1; i <= n; i++)
		cout << ar[i] << endl;
}

Measured memory_bytes: 67584
N, K = map(int,input().split())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int,input().split())

S = []
power = 2
while power <= K:
    if K & power != 0:
        S.append(K & ~power | (power - 1))
    power <<= 1
S.append(K)

ans = 0

for s in S:
    tmp = 0
    for i in range(N):
        if s & A[i] == A[i]:
            tmp += B[i]
    ans = max(ans, tmp)

print(ans)

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

struct Node{
  ll key;
  Node *p;
  Node *left;
  Node *right;
  Node(ll k){
    key = k;
    p = left = right = NULL;
  }
};

void fr(Node* n){
  if(n == NULL) return;
  fr(n->left);
  if(n->left != NULL)
    delete n->left;
  fr(n->right);
  if(n->right != NULL)
    delete n->right;
}

void inorder(Node* n){
  if(n == NULL){
    return;
  }
  inorder(n->left);
  cout << " " << n->key;
  inorder(n->right);
  return;
}

void preorder(Node* n){
  if(n == NULL){
    return;
  }
  cout << " " << n->key;
  preorder(n->left);
  preorder(n->right);
  return;
}

void insert(Node* &T, Node* z){
  Node* y = NULL;
  Node* x = T;
  while(x != NULL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }else{
      x = x->right;
    }
  }
  z->p = y;

  if(y == NULL){
    T = z;
  }else if(z->key < y->key){
    y->left = z;
  }else{
    y->right = z;
  }
}

Node* find(Node* T, ll k){
  Node* res = NULL;
  Node* x = T;
  while(x != NULL){
    if(x->key == k){
      res = x;
      break;
    }
    if(k < x->key){
      x = x->left;
    }else{
      x = x->right;
    }
  }
  return res;
}

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

  int m;
  Node* T = NULL;
  cin >> m;
  while(m--){
    string str; cin >> str;
    if(str == "print"){
      inorder(T);
      cout << endl;
      preorder(T);
      cout << endl;
    }else if(str == "find"){
      ll k;
      cin >> k;
      if(find(T, k) != NULL){
        cout << "yes" << endl;
      }else{
        cout << "no" << endl;
      }
    }else{
      ll k; cin >> k;
      Node* kn = new Node(k);
      insert(T, kn);
      /*
      if(kn->p != NULL) cout << kn->p->key << endl;
      else if(kn->left != NULL) cout << "LEFT " << kn->left->key << endl;
      else if(kn->right != NULL) cout << "RIGHT " << kn->right->key << endl;
      */
    }
  }
  fr(T);
  return 0;
}

Measured memory_bytes: 19980
#include <iostream>

using namespace std;

int func(int y,int z,int e){
	return y+z+e-y*y-z*z*z;
}

int main(){

	int e;

	while(cin>>e){
		if(e==0)break;

		int min=10000000;

		for(int y=0;y*y<=e;y++){
			for(int z=0;(z*z*z+y*y)<=e;z++){
				int ans = func(y,z,e);
				
			//	cout<<"y="<<y<<"z="<<z<<endl;
				if(ans<=0)break;

				if(min>=ans){
					min=ans;
				}

			}
		}

		cout<<min<<endl;

	}

	return 0;
}

Measured memory_bytes: 1160
import java.math.*;
import java.text.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		in.useDelimiter("\\n");
		while(in.hasNext()){
			String str = in.next();
			char[] s = str.toCharArray();
			for(int shift=0; shift<26; shift++){
				for(int i=0; i<s.length; i++){
					if(Character.isLowerCase(s[i])){
						s[i] = (char)(((int)s[i]-(int)'a'+1)%26 + (int)'a');
					}
				}
				str = new String(s);
				if(str.indexOf("the")!=-1
					|| str.indexOf("this")!=-1
					|| str.indexOf("that")!=-1)
					break;
			}
			System.out.println(new String(s));
		}
	}

}

Measured memory_bytes: 12000
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
   string a;
   int max=0,i,n,s=0;
   cin>>n>>a;
   for(i=0;i<n;i++){
   	   if(a[i]=='I'){
   	   	    s++;
   	   	      if(s>max){
   	   	      	max=s;
			}
		  }
		if(a[i]=='D'){
   	   	      s--;
   	   	      if(s>max){
   	   	      	max=s;
			}
		  }
   }
   cout<<max;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (void){



	char tmp ;				//?????£???????????????strS[0]?????????????????????????????°


	int i = 0 ;		//???????????°
	int j = 0 ;		//?????????s?????????
	int k = 0 ;		//???????????°
	int l = 0 ;
	int m = 0 ;

	int s = 0 ;		//?????£??????????????°





	while(1){	//???????????????????????¨????????????

		char strS[201] = {} ;		//100???????????§???????????????????´?????????????????????????
		scanf("%s", strS) ;				//?????????S???????????????
#ifdef DEBUG
		printf("?????????S???%s\n",strS);
#endif

		/*????????????*/
		if(strS[0] == '-'){
			break;
		}


		/*?????????strS?????????????????????(strS[j]???\0)*/
		for(i = 0 ; i < 202 ; i++){
			if(strS[i] == '\0'){
				j = i;
				break;
			}
		}
#ifdef DEBUG
		printf("?????????S?????????j???%d\n",j);
#endif


		/*?????£??????????????°????????????????????°???k???????´?*/
		scanf("%d" ,&k);
#ifdef DEBUG
		printf("k???%d\n",k);
#endif
		for(l = 1 ; l <= k ; l++){

			scanf("%d" ,&s);			//k???s???????????????
#ifdef DEBUG
		printf("s???%d\n",s);
#endif
			/*s????????£???????????????*/
			for(i = 1 ; i <= s ; i++){

				tmp = strS[0];			//tmp???????????????????????????

				for( m = 1 ; m < j ; m++){		//?????????????????\?????????????????????
					strS[m-1] = strS[m];
				}

				strS[j-1] = tmp;			//????????????????????????????°??????????
#ifdef DEBUG
				printf("????????????%s\n",strS);
#endif
			}//?????£?????????????????????????????§
		}

		/*??????????????°????????£?????????????????°?????£????????????????????¨???*/
		printf("%s\n",strS);

		s = 0 ;				//?????£??????????????°????????????????????????


	}//?????????????????????????????§



	return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1844674407370955161
typedef long long int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a * b / g;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}


class DisjointSet{
    public:
        vector<int> rank, p;

        DisjointSet(){
        }

        DisjointSet(int size){
            rank.resize(size, 0);
            p.resize(size, 0);
            for (int i = 0; i < size;i++){
                makeSet(i);
            }
        }
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }

        bool same(int x,int y){
            return findSet(x) == findSet(y);
        }
        void unite(int x,int y){
            link(findSet(x), findSet(y));
        }
        void link(int x,int y){
            if(rank[x]>rank[y]){
                p[y] = x;
            }else{
                p[x] = y;
                if(rank[x]==rank[y]){
                    rank[y]++;
                }
            }
        }
        int findSet(int x){
            if(x!=p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};

int main()
{
    int n;
    cin >> n;
    int p[n];
    REP(i,0,n){
        cin >> p[i];
    }
    int ans = 0;

    REP(i,1,n-1){
        if(p[i]>p[i-1]&&p[i]<p[i+1]){
            ans++;
        }

        if(p[i]<p[i-1]&&p[i]>p[i+1]){
            ans++;
        }
    }
    cout << ans << endl;
}

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

int main(){
	int n,k,x; cin>>n>>k;
	int cnt=0;
	rep(i,n){
		cin>>x;
		cnt+=min(x,abs(k-x));
	}
	cout<<cnt*2<<endl;
}

Measured memory_bytes: 3640
main = do
  [_,m,x] <- map read . words <$> getLine
  a <- map read . words <$> getLine
  let left =maximum $ 0 : [i+1 | i <- [0..m-1],a !! i < x]
      right = maximum $ 0 : [m-i | i <- [0..m-1],a !! i > x] 
  print $ min left right

Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
  ll n;
  cin >> n;
  ll a[n+1],b[n];
  for(int i=0;i<n+1;i++) cin >> a[i];
  for(int i=0;i<n;i++) cin >> b[i];
  ll ans=0;
  for(int i=0;i<n;i++){
    ll s=min(a[i],b[i]);
    ans+=s;
    a[i]-=s; b[i]-=s;
    if(b[i]){
      ll t=min(a[i+1],b[i]);
      ans+=t;
      a[i+1]-=t; b[i]-=t;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <sstream>

#define DEBUG 0
#define fi first
#define se second
#define pb push_back
#define fore(i, a, b) for (int i = (a), _b = (b); i < (_b); ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= (_b); ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= (_b); --i)

using namespace std;

typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

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

int main() {
    if (DEBUG) {
        freopen("CP.inp", "r", stdin);
        //freopen("CP.out", "w", stdout);
    }
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    cout << 3 * n * n << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int main() {
  while(1){
    int p,q;
    cin>>p>>q;
    if(!p)break;
    int prob[21][21][21];
    REP(i,21)REP(j,21)REP(k,21) prob[i][j][k] = 1;
    int sr = 0, sc = 0, ss = 0;
    REP(i,p) {
      string s;
      cin>>s;
      int ind = 0;
      while(s[ind] == '.') ++ind;
      REP(i,21)REP(j,21)REP(k,21) {
        int v = i * sr + j * sc + k * ss; 
        if (v != ind) prob[i][j][k] = 0;
      }
      REP(j,s.size()) {
        switch(s[j]) {
          case '(': ++sr; break;
          case ')': --sr; break;
          case '{': ++sc; break;
          case '}': --sc; break;
          case '[': ++ss; break;
          case ']': --ss; break;
        }
      }
    }
    sr=sc=ss=0;
    REP(i,q) {
      if (i) cout << ' ';
      string s;
      cin>>s;
      set<int> p;
      REP(i,21)REP(j,21)REP(k,21) {
        if (i&&j&&k&&prob[i][j][k]) {
          int v = i * sr + j * sc + k * ss; 
          p.insert(v);
        }
      }
      if (p.size() == 1) cout << *begin(p);
      else cout << -1;
      REP(j,s.size()) {
        switch(s[j]) {
          case '(': ++sr; break;
          case ')': --sr; break;
          case '{': ++sc; break;
          case '}': --sc; break;
          case '[': ++ss; break;
          case ']': --ss; break;
        }
      }
    }
    cout << endl;
  }
  return 0;
}

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

int main() {
	string S;
	int min = 1000;
	cin >> S;
	for (int i = 0; i < S.size() - 2; i++) {
		int x = abs(753 - stoi(S.substr(i, 3)));
		if (min > x) min = x;
	}
	cout << min << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int A, B;
    cin >> A >> B;
    if (A + B == 3) {
        cout << 3 << endl;
    }
    else if (A + B == 4) {
        cout << 2 << endl;
    } 
    else {
        cout << 1 << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.math.BigInteger;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			String str = scan.nextLine().replace("+"," ").replace("="," ");
			boolean sw = true;
			for(int i = 9;i >= 0;i--){
				String[] a = str.replaceAll("X",String.valueOf(i)).split(" ");
				if(i == 0){
					for(int j = 0;j < 3;j++){
						if(a[j].length() > 1 && a[j].charAt(0) == '0'){
							sw = false;
							break;
						}
					}
					if(!sw){
						sw = true;
						continue;
					}
				}
				BigInteger b1 = new BigInteger(a[0]);
				BigInteger b2 = new BigInteger(a[1]);
				BigInteger b3 = new BigInteger(a[2]);
				if(b3.equals(b1.add(b2))){
					sw = false;
					System.out.println(i);
					break;
				}
			}
			if(sw){
				System.out.println("NA");
			}
		}
	}
}

Measured memory_bytes: 23840
#include <iostream>
#include <functional>
#include <algorithm>
#include <math.h>
#include <ctype.h>
#include <vector>
#include <regex>
#include <locale>
#include <stack>
#include <queue>
#include <bitset>
#include <map>
#include <iterator>
#include <set>
#include <climits>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#define FASTIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define MOD 1000000007

using namespace std;

std::string ltrim(const std::string& s) {
	return std::regex_replace(s, std::regex("^\\s+"), std::string(""));
}

std::string rtrim(const std::string& s) {
	return std::regex_replace(s, std::regex("\\s+$"), std::string(""));
}

std::string trim(const std::string& s) {
	return ltrim(rtrim(s));
}

void helper (ll A, string& result) {
	if (A > 1)
        helper (A / 2, result);
    result += to_string (A % 2);
}

string dec_to_bin (ll A) {
    string result;
    helper (A, result);
    return result;
}

void print_matrix_vector (vector<vector<int>> &mat) {
    for_each (mat.begin (), mat.end (), [](auto x) {for_each (x.begin (), x.end (), [](int x){cout << x << ' ';});cout << '\n';});
    cout << '\n';
}

void print_vector (vector<int> &vec) {
    for_each (vec.begin (), vec.end (), [](int x){cout << x << ' ';});
    cout << '\n';
}

void replace (string &s, const char search, const char key) {
    replace(s.begin(), s.end(), search, key);
}

void int_vector_to_string (vector<int>& vec, string& ans, int start = 0, int end = 0) {
    for_each (vec.begin () + start, vec.end () - end, [&ans](int x){ans += to_string (x);});
}

string multiply (string a, string b) {
    int a_len = a.size (), b_len = b.size ();
    vector<int> vals((a_len + b_len + 1), 0);
    for (int i = b_len - 1; i >= 0; --i) {
        for (int j = a_len - 1; j >= 0; --j) {
            int num1 = b[i] - '0', num2 = a[j] - '0';
            int mul = num1 * num2;
            if (mul > 9) {
                vals[i + j + 1] += mul % 10;
                vals[i + j ] += mul / 10;
            } else {
                vals[i + j + 1] += mul;
            }
            if (vals[i + j + 1] > 9) {
                mul = vals[i + j + 1];
                vals[i + j + 1] = mul % 10;
                vals[i + j] += mul / 10;
            }
        }
    }
    int i = 0;
    while (vals[i] == 0) {
        i++;
    }
    string ans = "";
    int_vector_to_string (vals, ans, i, 1);
    return ans;
}

void leftrotate(string &s, int d) {
    reverse(s.begin(), s.begin()+d); 
    reverse(s.begin()+d, s.end()); 
    reverse(s.begin(), s.end()); 
}

void rightrotate(string &s, int d) {
    leftrotate(s, s.length()-d); 
} 

int main () {
    FASTIO
    ll num, ans = 0;
    cin >> num;
    for (long long i = 1; i <= num; ++i) {
        if (i % 3 == 0 && i % 5 == 0) {
            continue;
        } else if (i % 3 == 0) {
            continue;
        } else if (i % 5 == 0) {
            continue;
        } else {
            ans += i;
        }
    }
    cout << ans << '\n';
    return 0;
}


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

const int N=1e5+5;
int n,m,x,y;
int a[N],b[N];

int main()
{
	int i;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;++i) b[i]=1;a[1]=1;
	for(i=1;i<=m;++i)
	{
		scanf("%d%d",&x,&y);
		if(a[x]) a[y]=1;
		if(b[x]==1) a[x]=0;
		--b[x],++b[y];
	}
	int ans=0;
	for(i=1;i<=n;++i) ans+=a[i];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1024
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<P<<endl
#define OUT2(P1,P2) cout<<P1<<" "<<P2<<endl
#define OUT3(P1,P2,P3) cout<<P1<<" "<<P2<<" "<<P3<<endl
#define OUTS(I,N,V) REP(I,N) cout<<V[i]<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
typedef unsigned long ul;
typedef unsigned int ui;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
long N,M,i,res;

long fact(long n){
  res=1;
  UP(i,1,n){
    res*=i;
    res%=(long)(1e9+7);
  }
  return res;
}

inline void solve(){
  IN2(N,M);
  if(abs(N-M)>1)OUT(0);
  else if(abs(N-M)==1)OUT((fact(N)*fact(M))%(long)(1e9+7));
  else OUT((2*fact(N)*fact(M))%(long)(1e9+7));
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
//is there any case of -1 or any special corner cases ?
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define zeros(arr) memset(arr,0,sizeof(arr));
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
#define nl cout<<"\n";
#define test int t;cin>>t;while(t--) 
const int maxx  = 1e6+2 , limit = 9*1e18 , MOD=1e9+7;
int32_t main(){
    // boost;
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    
    double pie  = 3.14159265359;
    double ang1 = (360/12)*h + (m/60)*(30);
    
    double ang2 = (360/60)*m;
    
    // cout<<ang1<<" "<<ang2<<endl;
    
    double diff = abs(ang1-ang2);
    
    // diff = 90;
    if(diff > 180){
        diff = 360-diff;
    }
    
    // cout<<diff<<endl;
    diff = ((diff*(pie/180.0)));
    
    
    
    
    double res = a*a + b*b - 2*a*b*(cos(diff));
    // cout<<diff<<endl;
    // cout<<cos(diff)<<endl;
    res = sqrt(res);
    
    precise(10);
    cout<<res<<endl;
    
    
    
    
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}

int main(){
    ll N, M; cin >> N >> M;
    if(N == 1 && M == 1) {
        cout << 1 << endl;
    } else if(N == 1 || M == 1) {
        if(N == 1) cout << M - 2 << endl;
        if(M == 1) cout << N - 2 << endl;
    } else {
        ll res = (N - 2) * (M - 2);
        cout << res << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
#define N 1000001
bool prime[N];
int cnt[N];
int main() {
	for (int i = 0; i < N ; i++)prime[i] = true;
	int n = sqrt(N);
	prime[0] = prime[1] = false;
	for (int i = 2; i <= n; i++) {
		if (prime[i]) {
			for (int j = i + i; j <= N; j += i)prime[j] = false;
		}
	}
	cnt[0] = cnt[1] = 0;
	for (int i = 2; i < N; i++) {
		if (prime[i])cnt[i] = cnt[i - 1] + 1;
		else cnt[i] = cnt[i - 1];
	}
	int x;
	while (cin >> x) {
		cout << cnt[x] << endl;
	}
	return 0;
}

Measured memory_bytes: 6044
package main
import (
  "fmt"
  "sort"
)
func main() {
  var n int
  fmt.Scan(&n)
  xs := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&xs[i])
  }
  
  sortedXs := make([]int, n)
  copy(sortedXs, xs)
  sort.Ints(sortedXs)
  smallB := sortedXs[len(sortedXs)/2 - 1]
  largeB := sortedXs[len(sortedXs)/2]

  for _, x := range xs {
    if x <= smallB {
      fmt.Println(largeB)
    } else {
      fmt.Println(smallB)
    }
  }
}

Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int l=s.length()-1;
	if(s[l]=='2' || s[l]=='4' || s[l]=='5' || s[l]=='7' || s[l]=='9')
		cout<<"hon";
	if(s[l]=='0' || s[l]=='1' || s[l]=='6' || s[l]=='8')
		cout<<"pon";
	if(s[l]=='3')
		cout<<"bon";
}

Measured memory_bytes: 3628
N = int(input())
*A, = map(int,input().split())
*B, = map(int,input().split())
*C, = map(int,input().split())

ans = sum(B)
p = -1
for i,a in enumerate(A):
    if p+1==a:ans += C[p-1]
    p = a
print(ans)

Measured memory_bytes: 3060
#include<iostream>
 #include<vector>
 using namespace std;
     
    int main() {
    	int A, B, C;
    	cin >> A;
    	cin >> B;
    	
        if (A*B==2){ 
          	C = 3;
    		cout << C << endl;
        }
      	else if (A*B==3){
          	C = 2;
    		cout << C << endl;
        }
      	else {
          	C = 1;
    		cout << C << endl;
        }      
    }

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var n=Arr.shift()-0;
   if(n==0)break;
   var first=Arr.shift().split(":");
   first=first[1].slice(0,-1).split(",");
   var F={};
   first.forEach(function(v){F[v]=true;});
   var obj={};
   for(var i=0;i<n-1;i++){
      var arr=Arr.shift().split(":");
      obj[arr[0]]=arr[1].slice(0,-1).split(",");
   }
   var L=0;
   while(true){
      if(L==Object.keys(F).length)break;
      L=Object.keys(F).length;
      for(var k in F){
         if(obj.hasOwnProperty(k)){
            obj[k].forEach(function(v){F[v]=true;});
         }
      }
   }
   var cnt=0;
   for(var k in F)if(obj.hasOwnProperty(k)==false)cnt++;
   console.log(cnt);
}

Measured memory_bytes: 11544
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3f;

struct node{
	LL id,lr,val;
	bool operator <(const node &nd)const{
		return nd.val > val;
	}
};
priority_queue <node> q;

node make_node(LL id,LL lr,LL val){
	node ret; ret.id = id; ret.lr = lr; ret.val = val; return ret;
}

LL n,l[500005],r[500005],sl = 0,sr = 0;
LL in[500005][2] = {0};
LL h[500005],hd[500005],sum = 0,ans = INF;

int main(){
    ios::sync_with_stdio(false);
	cin >> n;
	for(LL i = 1;i <= n;i ++){
		cin >> l[i] >> r[i]; sl += l[i]; sr += r[i];
		in[i][0] = 1; in[i][1] = 1;
		q.push(make_node(i,0,l[i]));
		if(q.size() > n){ in[q.top().id][q.top().lr] = 0; q.pop(); }
		q.push(make_node(i,1,r[i]));
		if(q.size() > n){ in[q.top().id][q.top().lr] = 0; q.pop(); }
	}
	for(LL i = 1;i <= n;i ++){
		h[i] = q.top().val; sum += h[i]; hd[i] = q.top().id;
		q.pop();
	}
	for(LL i = 1;i <= n;i ++){
		LL tmp = sum,tt = 0;
		if(!in[i][0] && !in[i][1]){
			tmp += l[i]; tmp += r[i];
			tmp -= h[1]; tmp -= h[2];
		}
		if(!in[i][0] && in[i][1]){
			tmp += l[i];
			tmp -= (hd[1] == i ? h[2] : h[1]);
		}
		if(!in[i][1] && in[i][0]){
			tmp += r[i];
			tmp -= (hd[1] == i ? h[2] : h[1]);
		}
		ans = min(ans,tmp);
	}
	ans = min(ans,min(sl,sr));
	cout << ans << endl;
	return 0;
}

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

int main(){
  int a;
  int b;
  while(cin >> a >> b){
    int c=a+b;
    int i;
    if(c==0) c=1;
    for(i=0; c>0; i++){
      c/=10;
    }
    cout << i << endl;
  }

  return 0;
}



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

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    int s1=0,s2=0;
    for(int i=n-1;i>=1;i--)
    {
        s1+=i;
    }
    for(int i=m-1;i>=1;i--)
    {
        s2+=i;
    }
    cout<<s1+s2;
}

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

int main(){
  int p,q,r;
  cin>>p>>q>>r;
  int ans=0;
  ans=min(p+q,q+r);
  ans=min(ans,r+p);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define RYO 10000
#define MA 500000
  
typedef struct edge {
  int f, top, cost;
} Hira;

int main()
{
  Hira tes[MA];
  int wasa, furu=0, unk,d[RYO],i, j, cic;
  scanf("%d", &wasa);
  
  for(i=0; i<wasa; i++) {
    scanf("%d", &cic);
    scanf("%d", &unk);
    for(j=1; j<=unk; j++) {
      tes[furu].f=cic;
      scanf("%d %d", &tes[furu].top, &tes[furu].cost);
      furu++;
    }
  }

  for(i=1; i<wasa; i++) d[i]=INT_MAX;
  j=1;
  while(j) {
    j=0;
    for(i=0; i<furu; i++) {
      if(d[tes[i].f] !=INT_MAX && d[tes[i].f]+tes[i].cost < d[tes[i].top]) {
	d[tes[i].top] = d[tes[i].f]+tes[i].cost;
	j++;
      }
    }
  }
  for(i=0; i<wasa; i++) {
    printf("%d %d\n", i, d[i]);
  }
  return 0;
}

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

// assume x is gcd => if unevenness can be vanish within K times operation, OK
// devede +1 part & -1 part

int make_gcd_x( int x, vector<int> &A, int N ){ // A must be sorted
    //now candidate x is devisor of sum(A)
    vector<int> r(N);
    rep(i,N) r[i] = A[i]%x;
    sort(r.begin(),r.end());
    int tot = 0;
    rep(i,N) tot += r[i]; // also multiple of x
    int partation = N - tot/x;
    int step = 0;
    rep( i, partation ) step += r[i];
    return step;
}

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    int sum = 0;
    rep(i,N) sum += A[i];
    set<int> devisor; // search all common devisor
    for( int i=1; i*i<=sum; i++ ){ // D = { a<gcd(n) | E(b) s.t. a*b = n } => n(D) <= sqrt(n) 
            if( sum%i==0 ){
            devisor.insert(i);
            devisor.insert(sum/i);
        }
    }
    int ans = 1;
    for( int x : devisor ){
        int step =  make_gcd_x( x, A, N );
        if( step <= K ) ans = max(ans,x);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3644
/*
======================
[     ___T_          ]
[    | 6=6 | =>HI :-)] 
[    |__o__|         ]
[ >===]__o[===<      ]
[     [o__]          ]
[      .".           ]
[      |_|           ]
[                    ]
======================
 */

#include<bits/stdc++.h>
using namespace std;
using lli = int64_t;
int main(){
	 ios::sync_with_stdio(false);
	 cin.tie(nullptr);
	 cout.tie(nullptr);
	 int T = 1;
	 for(int t = 1; t <= T; t++){
		 int n;
		 cin >> n;
		 int input[n + 1];
		 for(int i = 1; i <= n; i++){
			 cin >> input[i];
		 }
		 sort(input + 1,input + n + 1);
		 int count = 0;
		 for(int i = 1;i <= n; i++){
			 for(int j = i + 1; j <= n; j++){
				 for(int k = j + 1; k <= n; k++){
					 if(((input[i] + input[j] > input[k]) and (input[j] + input[k] > input[i]) and (input[i] + input[k] > input[j])) and (input[i] != input[j] and input[j] != input[k])){
						 count += 1;
					 }
				 }
			 }
		 }
		 cout << count;
	 }
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int A,B,C;
    cin >> A >>B>>C;
    bool ans=false;
    if(A*B*C==5*5*7&&A+B+C==17&&A*B+B*C+C*A==95){
        ans=true;
    }
    if(ans){
        cout << "YES" << endl;
    }else{
        cout << "NO" <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

#define int ll
void solve()
{
	ll d;
	cin>>d;
	vector<ll>c(26);
	rep(i,26)cin>>c[i];
	vector<vector<ll>>s(d,vector<ll>(26));
	rep(i,d)rep(j,26)cin>>s[i][j];
	vector<ll>t(d);
	rep(i,d)cin>>t[i];
	vector<ll>last(26);
	ll res=0;
	rep(i,d){
		ll maxv=0;
		t[i]--;
		int day=t[i];
		// rep(j,26){
		// 	if(chmax(maxv,s[i][j]))day=j;
		// }
		maxv=s[i][day];
		res+=maxv;
		last[day]=i+1;
		rep(j,26){
			res-=c[j]*(i+1-last[j]);
		}
		cout<<res<<"\n";
	}
}
#undef int
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


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

using namespace std;

const double PI = 2.0 * acos(0.0);

int main(int argc, char *argv[])
{
    
    
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    
    double a,b,c;
    double S,L,h;
    
    cin >> a >> b >> c;
    c = c / 180.0 * PI;
    S = a*b*sin(c)/2;
    L = sqrt(pow(a, 2)+pow(b, 2)-2*a*b*cos(c))+a+b;
    h = 2*S/a;
    
    cout << fixed << setprecision(8) << S << " " << L << " " << h << endl;
    
    return 0;
}



Measured memory_bytes: 3484
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
using ll =long long;
#define PI 3.14159265358979
using P = pair<ll , ll>;
//using map = map<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;

int main(){

    char s;
    cin >> s;

    if (isupper(s))
    {
        cout << "A" << endl;
    }
    else
    {
        cout << "a" << endl;
    }

    return 0;
}

Measured memory_bytes: 3672
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto abc = readints;
    abc.sort();
    writeln(abc[0] + abc[1] + 10 * abc[2]);
}


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

using namespace std;

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

    int max_l=1, min_r=N;
    for (int i=0; i<M; i++) {
        int l, r;
        cin >> l >> r;

        max_l = max(max_l, l);
        min_r = min(min_r, r);
    }


    int cnt = 0;
    if (min_r >= max_l) {
        cnt = min_r - max_l + 1;
    }
    cout << cnt << endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	//vector<string> w;
	int i;
	bool ok = true;
	map<string, int> wi;
	string s;
	cin >> s;
	wi[s]++;
	int len;
	len = s.length()-1;
	char last = s[len];
	for(i=1; i<n; i++){
		cin >> s;
		wi[s]++;
		//w.push_back(s);
		len = s.length()-1;
		if(last!=s[0]) ok = false;
		else last = s[len];
		//cout << ok << endl;
	}
	if(!ok){
		cout << "No\n";
	}
	else{
		for(auto it = wi.begin(); it!=wi.end(); ++it){
			//cout << it->second << endl;
			if(it->second > 1){
				ok = false;
				break;
			}
		}
		if(!ok) cout << "No\n";
		else cout << "Yes\n";
	}
	return 0;
}
	


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,d,b;
    cin>>n>>d;
    int a[n][d];
    for(int i=0; i<n; i++)
    for(int j=0; j<d; j++)
    cin>>a[i][j];
    int ans=0;
    for(int i=0; i<n; i++)
    for(int j=i+1; j<n; j++)
    {
        int sum=0;
        for(int k=0; k<d; k++)
        sum+=pow(a[i][k]-a[j][k],2);
        b=sqrt(sum);
        if(b*b==sum)
            ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
 
const int n_max=100000;
 
int main() {
 
    int n,m;
    scanf("%d %d",&n,&m);
 
    priority_queue<int> q;
    rep(i,n) {
        int a;
        cin>>a;
        q.push(a);
    }
    rep(i,m) {
        int a=q.top(); q.pop();
        q.push(a/2);
    }
    ll ans = 0;
    rep(i,n) {
        ans+= q.top(); q.pop();
    }
    cout<<ans<<endl;
  
 return 0;
}

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

int main()
{
    int D;
    cin >> D;
    if (D == 25)
        cout << "Christmas" << endl;
    else if (D == 24)
        cout << "Christmas Eve" << endl;
    else if (D == 23)
        cout << "Christmas Eve Eve" << endl;
    else
        cout << "Christmas Eve Eve Eve" << endl;
    return 0;
}

Measured memory_bytes: 256
#ifdef _WIN32
#define NOMINMAX
#define _CRT_SECURE_NO_WARNINGS
#include <Windows.h>
#define DEBUGBREAK() ::DebugBreak()
#else
#define DEBUGBREAK() static_cast<void>(0)
#endif

#include <iostream>
#include <sstream>
#include <iomanip>
#include <valarray>
#include <vector>
#include <string>
#include <fstream>
#include <cstdlib>
#include <queue>
#include <array>
#include <functional>
#include <stack>
#include <bitset>
#include <random>
#include <algorithm>
#include <unordered_map>

using namespace std;

const int64_t dx4[4] = { 0, -1, 1, 0 };
const int64_t dy4[4] = { -1, 0, 0, 1 };
const int64_t dx5[5] = { 0, -1, 0, 1, 0 };
const int64_t dy5[5] = { -1, 0, 0, 0, 1 };
const int64_t dx8[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int64_t dy8[8] = { -1, -1, -1, 0, 0, 1, 1, 1 };
const int64_t dx9[9] = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };
const int64_t dy9[9] = { -1, -1, -1, 0, 0, 0, 1, 1, 1 };

#define REP(i, K) for (int64_t i = 0; i < K; ++i)
#define REPYX() for (int64_t y = 0; y < H; ++y) for (int64_t x = 0; x < W; ++x)
#define REPX() REP(x, W)
#define REPY() REP(y, H)
#define INSIDE(x_, y_) (0 <= (x_) && 0 <= (y_) && (x_) < W && (y_) < H)
#define INSIDE_MARGIN(x_, y_, m_) ((m_) <= (x_) && (m_) <= (y_) && (x_) < W - (m_) && (y_) < H - (m_))

int get_assert_level() {
    const char* s = getenv("ASSERT_LEVEL");
    if (s) { return atoi(s); }
    return 0;
}
static int g_assert_level = get_assert_level();

#define LV_1() if (g_assert_level >= 1)
#define LV_2() if (g_assert_level >= 2)
#define LV_3() if (g_assert_level >= 3)
#define ASSERT_1(expr) do { const bool b = bool(expr); if (g_assert_level >= 1 && !b) { std::cerr << "[ASSERT 1] (" << #expr << ") failed." << std::endl; exit(-1); } } while (false)
#define ASSERT_2(expr) do { const bool b = bool(expr); if (g_assert_level >= 2 && !b) { std::cerr << "[ASSERT 2] (" << #expr << ") failed." << std::endl; exit(-1); } } while (false)
#define ASSERT_3(expr) do { const bool b = bool(expr); if (g_assert_level >= 3 && !b) { std::cerr << "[ASSERT 3] (" << #expr << ") failed." << std::endl; exit(-1); } } while (false)

vector<int64_t> divisor(int64_t n) {
    vector<int64_t> ret;
    for (int64_t i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return ret;
}

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

    int64_t N;
    cin >> N;

    const int64_t Amax = 1000000;
    vector<int64_t> nums(Amax + 1, 0);

    vector<int64_t> As(N);
    REP(i, N) {
        cin >> As[i];
        nums[As[i]] += 1;
    }

    int64_t count = 0;
    REP(i, N) {
        bool found = false;
        auto divs = divisor(As[i]);
        for (auto p : divs) {
            if (As[i] == p ? nums[p] > 1 : nums[p] > 0) {
                //cout << As[i] << " is divisible by " << p << endl;
                found = true;
                break;
            }
        }
        if (!found) ++count;
    }

    cout << count << endl;

    return 0;
}



Measured memory_bytes: 12700
program ABC044B
    implicit none
    integer(8)::i,flg
    character(100)::w
    integer(8),dimension(26)::C
    read(5,*)w
    flg=0
    C=0
    do i=1,len_trim(w)
        C(ichar(w(i:i))-96)=C(ichar(w(i:i))-96)+1
    end do

    do i=1,26
        if(mod(C(i),2)==1)then
            flg=1
            exit
        end if
    end do

    if(flg==0)print'(A)',"Yes"
    if(flg==1)print'(A)',"No"
end program ABC044B

Measured memory_bytes: 256
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    res = 1
    mode = "0"
    for i in range(n - 1):
        if a[i] > a[i + 1]:
            if mode == "+":
                res += 1
                mode = "0"
            else:
                mode = "-"
        elif a[i] < a[i + 1]:
            if mode == "-":
                res += 1
                mode = "0"
            else:
                mode = "+"
    print(res)


if __name__ == "__main__":
    resolve()


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int[]> table = new List<int[]>();

            string input;

            while (!string.IsNullOrEmpty(input = Console.ReadLine()))
            {
                int[] temp = Array.ConvertAll(input.Split(','), int.Parse);
                table.Add(temp);
            }

            int m = table.Count / 2;

            for (int i = 1; i <= m; i++)
            {
                table[i][0] += table[i - 1][0];
                table[i][i] += table[i - 1][i - 1];

                for (int j = 1; j < i; j++)
                {
                    table[i][j] += Math.Max(table[i - 1][j - 1], table[i - 1][j]);
                }
            }

            for (int i = m + 1; i < table.Count; i++)
            {
                for (int j = 0; j < table[i].Length; j++)
                {
                    table[i][j] += Math.Max(table[i - 1][j], table[i - 1][j + 1]);
                }
            }
            Console.WriteLine(table[table.Count - 1][0]);
        }
    }
}

Measured memory_bytes: 9336
using static System.Console;
class Program
{
    static void Main(string[] args)
    {
        var str = ReadLine();
        for(var i = 0; i <= int.MaxValue; i++)
        {
            str = str.Substring(0, str.Length - 2);
            var s = str.Substring(0, str.Length / 2);
            if (s + s == str) { WriteLine(str.Length);break; }
        }
    }
}


Measured memory_bytes: 13140
#include <vector>
#include <cstdint>
#include <cstddef>

template<std::uint_fast64_t B = 524287>
struct rolling_hash {
	using u32 = std::uint_fast32_t;
	using u64 = std::uint_fast64_t;
	using i128 = __int128_t;
	using size_type = std::size_t;

private :
	static constexpr u64 base = B;
	static constexpr u64 mod = (1UL << 61) - 1;

	std::vector<u64> hash, pow;

	u64 mul (const i128 &a, const i128 &b) const noexcept {
		i128 value = a * b;
		value = (value >> 61) + (value & mod);
		return (value < mod ? value : value - mod);
	}

	u32 xorshift (u32 value) const noexcept {
		value ^= value << 13;
		value ^= value >> 17;
		value ^= value << 5;
		return value;
	}

public :
	constexpr rolling_hash () = default;

	template<class InputIterator>
	constexpr rolling_hash (InputIterator first, InputIterator last) noexcept {
		build(first, last);
	}

	template<class InputIterator>
	void build (InputIterator first, InputIterator last) noexcept {
		const size_type n = (last - first);
		hash.assign(n + 1, 0);
		pow.assign(n + 1, 1);
		for (size_type i = 0; first != last; first++, i++) {
			hash[i + 1] = mul(hash[i], base) + xorshift((*first) + 1);
			pow[i + 1] = mul(pow[i], base);
		}
	}

	size_type size () const noexcept {
		return (hash.size() - 1);
	}

	u64 get () const noexcept {
		return (hash.back());
	}

	u64 get (size_type first, size_type last) const noexcept {
		if (first > last) std::swap(first, last);
		u64 value = hash[last] + mod - mul(hash[first], pow[last - first]);
		return (value < mod ? value : value - mod);
	}

};


#include <iostream>
#include <vector>
#include <string>
#include <cstddef>
#include <map>
#include <array>
#include <algorithm>

using usize = std::size_t;
using u64 = std::int_fast64_t;

int main() {
	usize _size;
	std::cin >> _size;
	std::vector<std::string> str(_size);
	for (auto &s : str) std::cin >> s;
	
	std::array<int, 26> one;
	std::fill(one.begin(), one.end(), 0);
	std::map<u64, std::array<int, 26>> map;
	
	for (const auto &s : str) {
		const usize n = s.length();
		int buff = 0;
		rolling_hash rh(s.begin(), s.end());
		
		for (usize i = 0; i < n; i++) {
			for (usize j = 0; j < 26; j++) {
				map[rh.get(i, n)][j] += (buff >> j & 1);
			}
			buff |= (1 << (s[i] - 'a'));
		}
		
		for (usize i = 0; i < 26; i++) {
			one[i] += (buff >> i & 1);
		}
	}
	
	u64 ans = 0;
	for (const auto &s : str) {
		if (s.length() == 1) {
			ans += (one[s[0] - 'a'] - 1);
		} else {
			rolling_hash rh(s.begin() + 1, s.end());
			ans += (map[rh.get()][s[0] - 'a'] - 1);
		}
	}
	
	std::cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 173656
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int n,x;cin>>n>>x;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    ll ans=0;
    REP(i,n-1){
        ll s=a[i]+a[i+1];
        if(s-x>0){
            ans+=s-x;
            if(a[i+1]>=s-x){
                a[i+1]-=s-x;
            }
            else{
                s-=a[i+1];
                a[i+1]=0;
                a[i]-=s-x;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
n,m = map(int,input().split())
f = [[] for i in range(n)]

for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    
    f[a].append(b)
    f[b].append(a)
    
import collections
q = collections.deque()

for i in range(n):
    for j in f[i]:
        q.append(j)
        
    while q:
        p = q.popleft()
        
        if p != i:
            f[i] += f[p]

            for k in f[p]:
                q.append(k)

            f[p] = []
        
    f[i] = sorted(set(f[i]))
            
ans = 1

for i in f:
    res = len(i)
    ans = max(ans,res)
    
print(ans)

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

#define ll long long
#define ar array
#define vi vector<int>
#define INF 1000000000

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int S, W;
	cin >> S >> W;
	string safety = W >= S ? "unsafe" : "safe";

	cout << safety << endl;	

	return 0;
}


Measured memory_bytes: 3620