akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  long long k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int si = 1;
  while ((1ll << si) <= k * n) si++;
  vector<vector<long long>> par(si, vector<long long>(n, 1e18));
  map<int, int> ma;
  for (int i = n - 1; i >= 0; i--) {
    if (ma.count(a[i])) {
      par[0][i] = ma[a[i]] - i;
    }
    ma[a[i]] = i + 1;
  }
  for (int i = n - 1; i >= 0; i--) {
    if (par[0][i] == 1e18) {
      par[0][i] = ma[a[i]] + n - i;
    }
  }
  for (int i = 0; i < si - 1; i++) {
    for (int j = 0; j < n; j++) {
      if (par[i][j] == 1e18) continue;
      int p = (par[i][j] + j) % n;
      if (par[i][j] + par[i][p] <= k * n) {
        par[i + 1][j] = par[i][j] + par[i][p];
      }
    }
  }
  long long sum = 0;
  for (int i = si - 1; i >= 0; i--) {
    if (sum + par[i][sum % n] <= k * n) {
      sum += par[i][sum % n];
    }
  }
  vector<int> ans;
  while (sum < k * n) {
    if (sum + par[0][sum % n] <= k * n) {
      sum += par[0][sum % n];
    } else {
      ans.push_back(a[sum % n]);
      sum++;
    }
  }
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i];
    cout << (i == ans.size() - 1 ? '\n' : ' ');
  }
  return 0;
}


Measured memory_bytes: 103652
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  while (cin >> n, n) {
    vi v(n);
    rep(i, n) {
      string s;
      cin >> s;
      v[i] = s.size();
    }
    int t[] = {0, 5, 7, 5, 7, 7};
    rep(i, n) {
      stack<int> s;
      loop(j, i, n) {
        if (!s.size()) {
          s.push(v[j]);
          continue;
        }
        if (s.top() == t[s.size()]) {
          if (s.size() == 5) {
            cout << i + 1 << endl;
            goto next;
          }
          s.push(v[j]);
          continue;
        }
        if (s.top() > t[s.size()]) {
          break;
        }
        s.top() += v[j];
      }
      if (s.size() == 5 && s.top() == t[s.size()]) {
        cout << i + 1 << endl;
        goto next;
      }
    }
  next:;
  }
}

Measured memory_bytes: 3140
/**
*     ________   ________   ___        ________          ________   ___        ________       ___    ___  _______    ________
*    |\   ____\ |\   __  \ |\  \      |\   __  \        |\   __  \ |\  \      |\   __  \     |\  \  /  /||\  ___ \  |\   __  \
*    \ \  \___|_\ \  \|\  \\ \  \     \ \  \|\  \       \ \  \|\  \\ \  \     \ \  \|\  \    \ \  \/  / /\ \   __/| \ \  \|\  \
*     \ \_____  \\ \  \\\  \\ \  \     \ \  \\\  \       \ \   ____\\ \  \     \ \   __  \    \ \    / /  \ \  \_|/__\ \   _  _\
*      \|____|\  \\ \  \\\  \\ \  \____ \ \  \\\  \       \ \  \___| \ \  \____ \ \  \ \  \    \/  /  /    \ \  \_|\ \\ \  \\  \|
*        ____\_\  \\ \_______\\ \_______\\ \_______\       \ \__\     \ \_______\\ \__\ \__\ __/  / /       \ \_______\\ \__\\ _\
*       |\_________\\|_______| \|_______| \|_______|        \|__|      \|_______| \|__|\|__||\___/ /         \|_______| \|__|\|__|
*       \|_________|                                                                        \|___|/
*/

#include <ext/rope>
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long
typedef vector<vector<ll>> mat;

const int N = 2e5 +5;
int n , x , cnt[N] , a[N] , mx1 , mx2;

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

    cin >> n;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> a[i];
        cnt[a[i]]++;
        if(a[i] > mx1) mx2 = mx1 , mx1 = a[i];
        else mx2 = max(mx2 , a[i]);
    }

    for(int i = 0 ; i < n ; i++)
    {
        cnt[a[i]]--;
        if(cnt[mx1] == 0) cout << mx2;
        else cout << mx1;
        cnt[a[i]]++;
        cout << '\n';
    }

    return 0;
}


Measured memory_bytes: 3072
fun main(args: Array<String>) {
    val n = readLine()!!.map { it.toLong() }.first()
    val ds = readLine()!!.split(" ").take(n.toInt()).map { it.toLong() }.toList()

    val sum = ds.mapIndexed { i, dx ->
        ds.drop(i+1).map { dy ->
            dx * dy
        }.sum()
    }.sum()

    print(sum);
}

Measured memory_bytes: 38336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

    int H,W; cin >> H >> W;
    ve_ves s(H,ves(W));
    rep(i,H) rep(j,W) cin >> s[i][j];

    rep(i,H) rep(j,W) {
        if(s[i][j] == "snuke") {cout << (char) (j + 'A') << i+1 << endl; return 0;}
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>

bool isprime[1000000];

void eratos(){
	for(int i=0;i<1000000;i++){
		isprime[i] = true;
	}
	isprime[0] = isprime[1] = false;
	for(int i=2;i<=1000;i++){
		if(isprime[i] == true){
			int j = i + i;
			while(j < 1000000){
				isprime[j] = false;
				j = j + i;
			}
		}
	}
}

int main(void){
	int n;
	eratos();
	while(scanf("%d",&n) != EOF){
		int cnt = 0;
		for(int i=0;i<=n;i++){
			if(isprime[i] == true){
				cnt++;
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 3592
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <math.h>
#include <climits>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <map> 
#include <set>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
const ll MD = 1000000007;

/* sample input

*/

int main()
{
	string str,str2;
	cin >> str;
	str2 = "YAKI";


	if (str.length() < 4) {
		cout << "No"<<endl;
		return 0;
	}

	bool flug = true;
	for (int i = 0; i < 4; i++) {
		if (str[i] != str2[i]) {
			flug = false;
			break;
		}

	}

	if (flug) {
		cout << "Yes" << endl;
	}
	else {
		cout <<"No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;
int main(int argc, char const *argv[]) {
  ll n, k;std::cin >> n >> k;
  vll t(n);
  re(i, n) std::cin >> t[i];
  sort(all(t));
  reverse(all(t));
  ll ans = 0;
  for(int i=0;i<k;i++) ans += t[i];
  std::cout << ans << '\n';
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
struct BIT {
  int n;
  vector<int> xs;
  BIT(int n) : n(n), xs(n+1, 0) {}
  void add(int i, int v) {
    for (int x=i+1; x<=n; x+=x&-x) xs[x] += v;
  }
  int sum(int i) {
    int s = 0;
    for (int x=i+1; x>0; x-=x&-x) s += xs[x];
    return s;
  }
};
inline int nC2(int x) { return (1LL*x*(x-1)/2) % MOD; }
inline int mul(int x, int y) { return (1LL*x*y) % MOD; }

int N;
int A[500000];
bool used[500000];
int fact[500001];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  fact[0] = 1;
  for (int i=1; i<=500000; i++) fact[i] = (1LL*i*fact[i-1]) % MOD;
  cin >> N;
  BIT bit(N);
  int X = 0, Y = 0;
  rep(i, N) {
    cin >> A[i], A[i]--;
    if (A[i] == -1) X++;
    else used[A[i]] = true;
  }
  vector<int> unused;
  rep(i, N) if (!used[i]) unused.pb(i);
  int s = fact[X], r = 0;
  for (int i=N-1; i>=0; i--) {
    int w = 0;
    if (A[i] == -1) {
      // ? -> ?
      if (X >= 2) w = (w+mul(mul(Y, nC2(X)), fact[X-2])) % MOD;
      // ? -> C
      w = (w + mul(r, fact[X-1])) % MOD;
      Y++;
    }
    else {
      int a = bit.sum(A[i]);
      // C -> C
      w = (w + mul(a, fact[X])) % MOD;
      // C -> ?
      if (X > 0) {
        int c = upper_bound(all(unused), A[i]) - unused.begin();
        r = (r+X-c) % MOD;
        w = (w + mul(mul(c, Y), fact[X-1])) % MOD;
      }
      bit.add(A[i], 1);
    }
    s = (s + 1LL*w*fact[N-1-i]) % MOD;
  }
  cout << s << "\n";
  return 0;
}


Measured memory_bytes: 8820
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <string>
#include <cmath>
#define SIZE 6005

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

string dp[SIZE];
char str[SIZE];
int pa[SIZE],pb[SIZE];
int pos[SIZE];
bool use[SIZE];

int main()
{
	int n;
    int q;
    string s;
    scanf("%d", &n);
    if (n == 0){
        puts("0");
        return 0;
    }
    for (int i = 0; abs(n) > 0 && i < 100; i++){
        q = abs(n % 2);
        if (q == 1){
            s = "1" + s;
        }
        else
        {
            s = "0" + s;
        }
        if (n < 0) {
            n = (n - 1)/(-2);
        } else {
            n /= -2;
        }
    }
    printf("%s\n", s.c_str());
    return 0;
}

Measured memory_bytes: 256
n=int(raw_input())
a=map(int,raw_input().split())
ans1=0
ans2=0
su1=a[0]
su2=a[0]
if a[0]==0:
    su1+=1
    su2-=1
    ans1=1
    ans2=1
if a[0]!=0:
    if a[0]>0:
        su2=-1
        ans2+=a[0]+1
    else:
        su2=1
        ans2+=-a[0]+1
for i in xrange(1,n):
    tmp=su1
    su1+=a[i]
    if su1*tmp<0:
        continue
    else:
        if su1==0 and tmp<0:
            ans1+=1
            su1+=1
        elif su1==0 and tmp>0:
            ans1+=1
            su1-=1
        elif tmp<0 and su1<0:
            ans1+=-su1+1
            su1=1
        elif tmp>0 and su1>0:
            ans1+=su1+1
            su1=-1
for i in xrange(1,n):
    tmp=su2
    su2+=a[i]
    if su2*tmp<0:
        continue
    else:
        if su2==0 and tmp<0:
            ans2+=1
            su2+=1
        elif su2==0 and tmp>0:
            ans2+=1
            su2-=1
        elif tmp<0 and su2<0:
            ans2+=-su2+1
            su2=1
        elif tmp>0 and su2>0:
            ans2+=su2+1
            su2=-1
print min(ans1,ans2)


Measured memory_bytes: 11244
n = int(raw_input())
A = [0]
NY = range(1, n)
a = [[0 for i in xrange(n)] for j in xrange(n)]
for i in xrange(n):
    a[i] = map(int,raw_input().split())
long = 0
while NY != []:
    amin = 2001
    for i in A:
        for j in NY:
            if 0 <= a[i][j] < amin:
                amin = a[i][j]
                addA = j
    A.append(addA)
    NY.remove(addA)
    long += amin
print long

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

typedef unsigned long long ulli;

const ulli B = 1000000007ULL;


ulli getHash(const string &s) {
  int n = s.size();
  ulli res = 0;
  for(int i = 0; i < n; ++i) {
    res = res * B + s[i];
  }
  return res;
}

int main() {
  for(int n, d; cin >> n && n; ) {
    cin >> d;
    vector<string> ss(n);
    for(int i = 0; i < n; ++i) {
      cin >> ss[i];
    }

    sort(ss.begin(), ss.end());

    vector<set<ulli> > nextHash(n);
    for(int k = 0; k < n; ++k) {
      string s = ss[k];
      // Deleting
      for(int i = 0; i < s.size(); ++i) {
        char tmp = s[i];
        s.erase(i, 1);
        nextHash[k].insert(getHash(s));
        s.insert(i, string(1, tmp));
      }
      // Inserting
      for(int i = 0; i <= s.size(); ++i) {
        for(char c = 'a'; c <= 'z'; ++c) {
          s.insert(i, string(1, c));
          nextHash[k].insert(getHash(s));
          s.erase(i, 1);
        }
      }
      // Replacing
      for(int i = 0; i < s.size(); ++i) {
        char tmp = s[i];
        for(char c = 'a'; c <= 'z'; ++c) {
          s[i] = c;
          nextHash[k].insert(getHash(s));
        }
        s[i] = tmp;
      }
      // Swapping
      for(int i = 0; i + 1 < s.size(); ++i) {
        int j = i + 1;
        swap(s[i], s[j]);
        nextHash[k].insert(getHash(s));
        swap(s[i], s[j]);
      }
    }

    map<ulli, int> A;
    map<ulli, set<int> > B;
    for(int i = 0; i < n; ++i) {
      A[getHash(ss[i])] = i;
      if(d <= 1) continue;
      for(set<ulli>::iterator it = nextHash[i].begin();
          it != nextHash[i].end(); ++it) {
        B[*it].insert(i);
      }
    }

    set<pair<int, int> > ans;
    for(int i = 0; i < n; ++i) {
      for(set<ulli>::iterator it = nextHash[i].begin();
          it != nextHash[i].end(); ++it) {
        if(A.count(*it)) {
          pair<int, int> p(i, A[*it]);
          if(p.first > p.second) swap(p.first, p.second);
          ans.insert(p);
        }
      }
      for(set<ulli>::iterator it = nextHash[i].begin();
          it != nextHash[i].end(); ++it) {
        if(B.count(*it)) {
          for(set<int>::iterator it2 = B[*it].begin();
              it2 != B[*it].end(); ++it2) {
            pair<int, int> p(i, *it2);
            if(p.first > p.second) swap(p.first, p.second);
            ans.insert(p);
          }
        }
      }
    }

    int res = 0;
    for(set<pair<int, int> >::iterator it = ans.begin();
        it != ans.end(); ++it) {
      if(it->first == it->second) continue;
      ++res;
      cout << ss[it->first] << "," << ss[it->second] << endl;
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 28700
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int result = 0;
int i, j;
int n, m, k;
int s[100005] = {};
int memo=0;
char word[105][15];

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

	for (i = 1; i < n; i++) {
		if (word[i][0] != word[i-1][s[i-1]-1])memo = 1;
		for (j = i + 1; j < n; j++) {
			if (strcmp(word[i], word[j]) == 0) { memo = 1; 
			}
		}
	}

	for (j = 1; j < n; j++) {
		if (strcmp(word[0], word[j]) == 0) {
			memo = 1;
		}
	}

	if (memo == 1)printf("No");
	if (memo == 0)printf("Yes");
}

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


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] str = Console.ReadLine().Split(' ');
            int n = int.Parse(s);

            int[] Array = new int[n];
            for (int i = 0; i < n; ++i)
            {
                Array[i] = int.Parse(str[i]);
            }

            for (int j = (n - 1); j >= 0; --j)
            {
                if (j == 0)
                {
                    Console.Write(Array[j]);
                }
                else
                {
                    Console.Write("{0} ", Array[j]);

                }
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 5652
#include <algorithm>
#include <iostream>
#include <string>
 
using namespace std;
 
int main() {
  int n,i,j,tmp=0,lb=0,rb=0;
  string s;
  cin >> n >> s;
  n = s.length();
  int a[10007];
  for (i = 0; i < n; i++) {
    if (s[i] == '(') {
      a[i] = 1;
    } else if (s[i] == ')') {
      a[i] = -1;
    }
  }
  for (int i = 0; i < n; i++) {
    tmp += a[i];
    if (tmp < 0) {
      tmp = 0;
      lb++;
    }
  }
  rb = tmp;
 
  for (i = 0; i < lb; i++) {
    cout << "(";
  }
  cout << s;
  for (i = 0; i < rb; i++) {
    cout << ")";
  }
  cout << endl;
 
  return 0;
}

Measured memory_bytes: 256
object Main{
  def main(args: Array[String]){
    val input=io.Source.stdin.getLines().mkString("\n")
    println(solve(input).trim())
  }

  def solve(input:String):String={
    val Array(ns,ks,xss)=input.split("\n")
    val k=ks.toInt
    val xs=xss.split(" ").map(_.toInt);
    (xs.map(v=>if (k-v<v) k-v else v).sum*2).toString
  }
}


Measured memory_bytes: 27188
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;


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

    long sum = 0;
    for(int i = 1; i < N ; i++){
        sum += i;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define ff first 
#define ss second  
typedef pair<ll,ll> pp;
bool com(pp x,pp y){
    return x.ff<y.ff;
} 

void solve(){
    int n,x;
    cin>>x>>n;
    map<int,int> a;
    int mx=1e6,ans=0;
    for(int i=0,y;i<n;i++){
        cin>>y;
        a[y]=1;
    }
    for(int i=-100;i<=120;i++){
        if(!a[i]){
            if(mx>abs(i-x)){
                mx=abs(i-x);
                ans=i;
            }
        }
    }
    cout<<ans;
    
}
int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	solve();
	return 0; 
	
}


Measured memory_bytes: 3672
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
int MOD=1000000007;
int main(){
    int A,B;
    cin >> A >> B;
    if(A>=13) cout << B << endl;
    else if(A<=5) cout << 0 << endl;
    else cout << B/2 << endl;

}


Measured memory_bytes: 256
def func(z,c):
    if c == 0:
        z = 0
    else:
        z = z%c
    a = bin(z)
    b = 0
    for i in range(len(a)):
        if a[i] == "1":
            b += 1
    return z,b

n = int(input())
x = input()
c = 0
for i in range(n):
    if x[i] == "1":
        c += 1
s0 = int(x,2)%(c+1)
if c <= 1:
    s1 = 0
else:
    s1 = int(x,2)%(c-1)
for i in range(n):
    sw = 0
    if x[i] == "0":
        d = c + 1
        z = (s0 + pow(2,n-i-1,d))%d
    else:
        d = c - 1
        if d == 0:
            z = 0
            sw = 1
        else:
            z = (s1 - pow(2,n-i-1,d))%d
    ans = 1
    p = bin(z)
    e = 0
    for A in str(p):
        if A == "1":
            e += 1
    d = e
    if sw == 1:
        ans = 0
    else:
        while z:
            z,d = func(z,d)
            ans += 1
    print(ans)

Measured memory_bytes: 9436
#include<cstdio>
#include<cstdlib>
#include<utility>
using namespace std;

struct Stack {
  int numbers[100];
  int current_index = 0;

  void push(int n) {
    numbers[current_index] = n;
    current_index++;
  }

  int pop() {
    int last = move(numbers[current_index - 1]);
    current_index--;
    return last;
  }

  void print() {
    printf("[ ");

    for (int i = 0; i < current_index; i++) {
      printf("%d ", numbers[i]);
    }

    printf("]\n");
  }
};

int main() {
  char input[7];
  int n, p, q;
  Stack s;

  while (scanf("%s", input) != EOF) {
    if (input[0] == '+') {
      q = s.pop();
      p = s.pop();
      s.push(p + q);
    } else if (input[0] == '-') {
      q = s.pop();
      p = s.pop();
      s.push(p - q);
    } else if (input[0] == '*') {
      q = s.pop();
      p = s.pop();
      s.push(p * q);
    } else if (input[0] == '/') {
      q = s.pop();
      p = s.pop();
      s.push(p / q);
    } else {
      n = atoi(input);
      s.push(n);
    }
  }

  printf("%d\n", s.pop());

  return 0;
}



Measured memory_bytes: 2760
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(v) ((v).begin()), ((v).end())
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int M = 1000000007;

int binMod(int a, int b, int mod)
{
    int an = 1;
    while (b != 0)
    {
        if ((b % 2) == 1)
            an = (an * a) % mod;
        a = (a * a) % mod;
        b /= 2;
    }
    return an;
}

signed main()
{
    int n;
    cin >> n;
    int x = binMod(10LL, n, M);
    int y = binMod(9LL, n, M);
    int z = binMod(8LL, n, M);
    cout << (M + M + x - 2*y + z) % M;
    return 0;
}

Measured memory_bytes: 3608
v = list(input().split())

stack = [0] * len(v)
top = 0

for i in range(len(v)):
  if v[i] == '+':
    a = stack[top-1]
    b = stack[top]
    stack[top-1] = a + b
    top -= 1
  elif v[i] == '-':
    a = stack[top-1]
    b = stack[top]
    stack[top-1] = a - b
    top -= 1
  elif v[i] == '*':
    a = stack[top-1]
    b = stack[top]
    stack[top-1] = a * b
    top -= 1
  else:
    top += 1
    stack[top] = int(v[i])

print(stack[top])



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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = int(1e9) + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 100 * 1000 + 13;

int n;
pt a[N];

bool read () {
	if (scanf("%d", &n) != 1)
		return false;
	forn(i, n)
		scanf("%d%d", &a[i].x, &a[i].y);
	return true;
}

int dp[N];
int sum[N];

void solve() {
	sort(a, a + n, [](const pt &a, const pt &b){
		if (a.x + a.y != b.x + b.y)
			return a.x + a.y < b.x + b.y;
		return a.x < b.x;
	});
	forn(i, n) sum[i] = a[i].x + a[i].y;
	
	forn(i, n + 1) dp[i] = INF;
	dp[0] = 0;
	forn(i, n){
		int it = upper_bound(sum, sum + n, a[i].x - a[i].y) - sum;
		dp[i + 1] = min(dp[i] + 1, dp[it] + (i - it));
	}
	printf("%d\n", n - dp[n]);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int tt = clock();
#endif
	
	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

#ifdef _DEBUG
	while(read()) {	
#else
	if(read()) {
#endif
		solve();
		
#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

Measured memory_bytes: 1792
s = input()
k = int(input())
lst = sorted(list(set(s)))
tank = []
for tg in lst:
    for i in range(len(s)):
        if s[i]==tg:
            for j in range(k):
                if i+j<=len(s) and (s[i:i+j+1] not in tank):
                    tank.append(s[i:i+j+1])
    if len(tank) >= k:
        break
tank.sort()
print(tank[k-1])

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

int main(){
	string s;
	cin >> s;
	string rev = s;
	int n =s.length();
	reverse(rev.begin(),rev.end());
	if(s!=rev){
		cout << "No" << endl;return 0;
	}

	string s1 = s.substr(0,(n-1)/2);
	string s1rev =s1;
	reverse(s1rev.begin(),s1rev.end());
	if(s1!=s1rev){
		cout << "No" << endl;return 0;
	}

	string s2 = s.substr((n+3)/2-1,n/2);
	string s2rev = s2;
	reverse(s2rev.begin(),s2rev.end());
	if(s2!=s2rev){
		cout << "No" << endl;return 0;

	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#if 0
  30 ????¨???????
  ???????????????????????????????????£????????§ http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=1874216#1 ???????????????????????????
  r ??????????????? 1<<30 ?????????????????¨ 2 ????????????????????±????????? 6 ??§?????? 5 ????????£????????????????????????
#endif
#include <cstdio>
#define rep(i,a) for(int i=0;i<(a);++i)

const int MAX_N = 100001;

int n, k, w[MAX_N];

bool C( int P )
{
  int tr = 0, cnt = 1;

  rep( i, n )
  {
    if( tr+w[i] <= P && cnt <= k )
      tr += w[i];
    else if( w[i] <= P && cnt <= k-1 )
    {
      tr = w[i];
      ++cnt;
    }
    else
      return false;
  }

  return true;
}

int main()
{
  scanf( "%d%d", &n, &k );
  rep( i, n )
    scanf( "%d", w+i );

  // [l, r]
  int l = 0, r = 1e9;
  while( l < r )
  {
    int mid = (l+r)/2;

    if( C( mid ) )
      r = mid;
    else
      l = mid+1;
  }

  printf( "%d\n", l );

  return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int dp[200005];
int main()
{
    int n,a[200005],i,j,k;
    cin>>n>>k;
    for(i=0;i<n;i++){
        cin>>a[i];
        dp[i]=1e9;
    
    }
    dp[0]=0;
    for(i=0;i<n;i++){
        for(j=1;j<=k;j++){
            dp[i+j]=min(dp[i]+abs(a[i]-a[i+j]),dp[i+j]);
            //cout<<dp[i+j]<<' ';
            
        }
    }
    cout<<dp[n-1];
}


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

#define MOD 1000000007

int main(){

    int n; cin >> n;
    vector<long long> t(n);
    vector<long long> a(n);

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

    vector<long long> table(n, 0);
    for(int i = 0; i < n; i++){
        if(i == 0 || t[i] != t[i - 1]){
            table[i] = t[i];
        }else{
            table[i] = -t[i];
        }
    }


    for(int i = n - 1; i >= 0; i--){
        if(table[i] > 0){
            if(a[i] < table[i]){
                cout << 0 << endl;
                return 0;
            }
            continue;
        }
        else if(i == n - 1 || a[i] != a[i + 1]){
            table[i] = a[i];
        }
        else{
            table[i] = max(table[i], -a[i]);
        }
    }


    long long ans = 1;
    for(int i = 0; i < n; i++){
        if(table[i] < 0){
            ans = (ans * (-table[i])) % MOD;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
// template version 1.6
// {{{ define basic macro
using namespace std;
#include <iostream>
#include <bits/stdc++.h>
// varibable settings
#define int long long
#define INF 1000000000000000000LL
// #define INF 2147483647
#define MOD 1000000007LL
// #define MOD 998244353LL
#define infile "../test/sample-1.in"

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)
template<class T, size_t N> size_t sza(const T (&array)[N]) { return N; }
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
template<class T=int> T in() {T x; cin>>x; return (x);}
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

int solve(){
  int a,b;cin>>a>>b;
  
  if (a*b<=0){
    cout << "Zero" << endl;
  }
  else if(a>0 and b>0){
    cout << "Positive" << endl;
  }
  else{
    if ((b-a)%2==0) cout << "Negative" << endl;
    else cout << "Positive" << endl;
  }

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256
#include<stdio.h>
#include<cstring>

int main(){
    char  t[1001];
    while(1){
       scanf("%s", t);
       if(t[0]=='0')break;
       int j = 0 ;
       for(int i = 0; i < strlen(t); i++){
             j = j + (t[i]-'0');
       }
        printf("%d\n",j);
    }
    
    return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

string s;

int main(){
	cin.sync_with_stdio(false);
	cin>>s;
	int ag=0,ap=0;
	rep(i,s.length()){
		if(s[i]=='g')ag++;
		else ap++;
	}
	cout<<(ag-ap)/2<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N; cin >> N;
	VI A(N);
	REP(i, N)cin >> A[i];
	rSORT(A);
	int a = 0, b = 0;
	REP(i, N) {
		if (i % 2)b += A[i];
		else a += A[i];
	}
	cout << a - b << endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int X = sc.nextInt();
        int Y = sc.nextInt();
        String ans = "No";
        for(int i=0;i<=X;i++){
            if(2 * i + 4 *(X -i) == Y){
                ans = "Yes";
            }
        }
        System.out.println(ans);


    }

}


Measured memory_bytes: 35840
#include<bits/stdc++.h>
using namespace std;
int x(int arr[],int dp[],int n)
{
    dp[0]=0;
    dp[1]=abs(arr[0]-arr[1]);
    for(int i=2;i<n;i++)
    {
        //cout<<arr[i];
        dp[i]+=min(dp[i-1]+abs(arr[i-1]-arr[i]),dp[i-2]+abs(arr[i]-arr[i-2]));
        //cout<<dp[i]<<" ";
    }
    return dp[n-1];

}
int main()
{

    int t;
    cin>>t;
    int arr[t];
    for(int i=0;i<t;i++)
    {
        cin>>arr[i];
    }
    int dp[t]={0};
    cout<<x(arr,dp,t);
}


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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int n, a, b; cin >> n >> a >> b;
    int ans = 0;
    REP(i, 1, n+1){
        string s = to_string(i);
        int k = 0;
        REP(l, 0, s.size()){
            k += (s[l] - '0');
        }
        if(k >= a && k <= b){
            ans += i;
        }
    }
    cout << ans << endl;
}

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

int main()
{
  int N; cin >> N;
  vector<long long> A(N);

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

  int k = 0;
  vector<long long> sumA(N * 2 + 1);
  for (int i = 0; i < N * 2; i++)
  {
    sumA[i + 1] = sumA[i] + A[k];
    k = (k + 2) % N;
  }

  for (int i = 0; i < N; i++)
  {
    int start;
    if (i % 2 == 0) start = i / 2;
    else start = (N + i) / 2;
    cout << (sumA[start + (N + 1) / 2] - sumA[start] - all) * 2 << endl;
  }
}

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

int main(){

  int N,K,ans;

  cin>>N;
  cin>>K;

  if(N%K==0 || N%K==K){
    ans=0;
  }
  else{
    ans=1;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N,M;
  int c,d;
  int e,f;
  cin >> N >> M;
  vector<int> a(N);
  vector<int> b(N);
  for (int i= 0 ; i<N;i++ )
  {
    cin >> a.at(i);
      b.at(i) = 1;
  }
  for (int j = 0 ; j<M; j++)
  {
    cin >> c >> d;
    e= min(a.at(c-1),a.at(d-1));
    if ((a.at(c-1) == e) &&  (a.at(d-1) == e))
    {
      b.at(c-1)=0;
      b.at(d-1)=0;
    }
    else
    {
      if (a.at(c-1) == e)
      {
        b.at(c-1)= 0;
      }
      else
      {
        b.at(d-1)=0;
      }
    }
  }
  for (int k = 0 ; k < N ; k++)
  {
    if(b.at(k)==1)
    {  
      f++;
    }      
  } 
  cout << f <<endl;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n, m, x;
  cin >> n >> m >> x;
  
  vector<vector<int>> b(n, vector<int>(m));
  vector<int> c(n);
  for (int i=0; i<n; i++){
    cin >> c.at(i);
    for (int j=0; j<m; j++){ 
    cin >> b.at(i).at(j);
    }}
  
  int min_cost= 100000*12+1;
  for (int tmp = 0; tmp < (1 << n); tmp++) {
    bitset<12> s(tmp);
    vector<int> abi(m);
    int cost=0;
    for(int i=0; i<n; i++){    
      if(s.test(i)==1){
         cost += c.at(i);
      	for(int j=0; j<m; j++){
          abi.at(j) += b.at(i).at(j);
        }
      }
    }
    sort(abi.begin(), abi.end());
    if(abi.at(0)>= x){min_cost = min(cost, min_cost );}
 }
   if(min_cost == 100000*12+1){min_cost = -1;}
    cout << min_cost << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  string a, b, c;
  cin >> a >> b >> c;
  cout << a[0] << b[0] << c[0];
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int r,g,b;
	scanf("%d %d %d",&r,&g,&b);
int i,num=b;
for(i=1;i<=g;i++){
	num+=10;

}

	if(num%4==0){
		printf("YES");
	}else printf("NO");
}

Measured memory_bytes: 128
import java.util.*;
import java.math.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		List<String> list = new ArrayList<String>();
		while(scan.hasNext()){
			int N = scan.nextInt();
			for(int i = 0; i < N; i++){
				BigInteger a = scan.nextBigInteger();
				BigInteger b = scan.nextBigInteger();
				String bigNum = String.valueOf(a.add(b));
				if(bigNum.length() > 80){
					list.add("overflow");
				} else{
					list.add(bigNum);
				}
			}
		}

		for(String s : list){
			System.out.printf("%s\n", s);
		}
	}
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int x;
  cin >> x;
  int ans = 1;
  for (int i = 2; i <= x; i++) {
    for (int j = i * i; j <= x; j *= i) {
      ans = max(ans, j);
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
 
//int in() { int x; scanf("%d", &x); return x; }
//ll lin() { ll x; scanf("%lld", &x); return x; }
//void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }


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

    int n, k;
    cin >> n >> k;

    VI vi(n);
    FOR(i, n){
    	cin >> vi[i];
    }

    sort(ALL(vi));
    int ans = 0;
    FOR(i, k){
    	ans += vi[i];
    }

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


Measured memory_bytes: 3660
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

ll now = 0;
ll kotae;
int K, k;
ll keta[13];
void keisan(int d, int mae) {
	if (kotae) return;
	if (d == 0) {
		k++;
		if (k == K) kotae = now;
		return;
	}
	if (mae) {
		now += keta[d] * (mae - 1);
		keisan(d - 1, mae - 1);
		now -= keta[d] * (mae - 1);
	}
	now += keta[d] * (mae);
	keisan(d - 1, mae);
	now -= keta[d] * (mae);
	if (mae != 9) {
		now += keta[d] * (mae + 1);
		keisan(d - 1, mae + 1);
		now -= keta[d] * (mae + 1);
	}
}


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


	cin >> K;


	keta[1] = 1;
	rep1(i, 11) {
		keta[i + 1] = keta[i] * 10;
	}
	rep(k, 13) {
		rep1(mae, 9) {
			now += keta[k + 1] * mae;
			keisan(k, mae);
			now -= keta[k + 1] * mae;
		}
	}

	co(kotae);

	Would you please return 0;
}

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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

char str[5];

int main(){
	cin.getline(str, 5);
	for(int i = 0; i < 3; i++){
		if(str[i] == '7'){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 3600
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def isOK(A):
    A.sort()
    for i in range(len(A) - 1):
        if A[i] + 1 != A[i + 1]:
            return False
    return True


def solve():
    N, M = Scanner.map_int()
    A = Scanner.map_int()
    S = sum(A)
    r = 1 / (4 * M) * S
    cnt = 0
    for a in A:
        if a >= r:
            cnt += 1
    print('YNeos'[not cnt >= M::2])


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 62444
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N;

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

  if (N % 2 == 0) {
    cout << (N - 1) / 2 << endl;
  } else {
    cout << N / 2 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>

#define _min(_a_,_b_) ((_a_)<(_b_)?(_a_):(_b_))
#define _max(_a_,_b_) ((_a_)>(_b_)?(_a_):(_b_))

	char __B[1<<20],*__S=__B,*__T=__B;
	#define getchar() (__S==__T&&(__T=(__S=__B)+fread(__B,1,1<<20,stdin),__S==__T)?EOF:*__S++)

inline int getnum()
{
	register char c=0;
	while(!(c>='0' && c<='9'))
		c=getchar();
	register int a=0;
	while(c>='0' && c<='9')
	{
		a*=10;a+=c-'0';
		c=getchar();
	}
	return a;
}

int N,M;
int _b[2050505],*b[105050];
long long a[105050];

int _log[105050],__fb[20505050],*_fb[2050505],**fb[105050];
#define segmax(_j, _l, _r) \
	_max(fb[_j][_log[_r-_l+1]][_l],fb[_j][_log[_r-_l+1]][_r-(1<<_log[_r-_l+1])+1])

long long ans;
void Divide(register int l,register int r,register int kl,register int kr)
{
	if(l>r)
		return;
	register int mid=(l+r)>>1,kb=kl,kll=_max(mid,kl);
	long long tgans=LLONG_MIN;
	for(register int i=kll;i<=kr;i++)
	{
		long long tans=a[mid-1]-a[i-1];
		for(register int j=1;j<=M;j++)
			tans+=segmax(j,mid,i);
		if(tans>tgans)
			tgans=tans,kb=i;
	}
	ans=_max(ans,tgans);
	
	Divide(l,mid-1,kl,kb);
	Divide(mid+1,r,kb,kr);
}

int main()
{
	register int N=getnum(),M=getnum();
	::N=N,::M=M;
	for(register int i=1;i<=N-1;i++)
		a[i]=a[i-1]+getnum();
	for(register int i=0,lst=0;i<=M;i++)
		b[i]=&_b[lst],lst+=N+2;
	for(register int i=1;i<=N;i++)
		for(register int j=1;j<=M;j++)
			b[j][i]=getnum();
	
	for(register int i=2;i<=N;i++)
		_log[i]=_log[i>>1]+1;
	
	for(register int k=0,lst=0;k<=(_log[N]+2)*(M+2)+1;k++)
		_fb[k]=&__fb[lst],lst+=N+2;
	for(register int j=0,lst=0;j<=M+1;j++)
		fb[j]=&_fb[lst],lst+=_log[N]+2;
	for(register int j=1;j<=M;j++)
	{
		for(register int i=1;i<=N;i++)
			fb[j][0][i]=b[j][i];
		for(register int k=1;k<=_log[N];k++)
			for(register int i=1;i<=N;i++)
				fb[j][k][i]=_max(fb[j][k-1][i],fb[j][k-1][i+(1<<(k-1))]);
	}
	
	ans=LLONG_MIN;
	Divide(1,N,1,N);
	printf("%lld\n",ans);
	
	return 0;
}

Measured memory_bytes: 66816
#include <iostream>
#include <vector>

signed main() {
    intmax_t N, X, M;
    scanf("%jd%jd%jd", &N, &X, &M);

    const intmax_t L = 35;
    std::vector<std::vector<intmax_t>> nxt_num(L + 1, std::vector<intmax_t>(M, 0));
    std::vector<std::vector<intmax_t>> nxt_sum(L + 1, std::vector<intmax_t>(M, 0));
    for (intmax_t n = 0; n < M; ++n) {
        nxt_num[0][n] = (n * n) % M;
        nxt_sum[0][n] = n;
    }
    for (size_t i = 0; i < L; ++i) {
        for (intmax_t n = 0; n < M; ++n) {
            nxt_num[i + 1][n] = nxt_num[i][nxt_num[i][n]];
            nxt_sum[i + 1][n] = nxt_sum[i][n] + nxt_sum[i][nxt_num[i][n]];
        }
    }

    size_t i = 0;
    intmax_t cur = X;
    intmax_t res = 0;
    while (N > 0) {
        if (N & 1) {
            res += nxt_sum[i][cur];
            cur = nxt_num[i][cur];
        }
        N >>= 1;
        ++i;
    }

    printf("%jd\n", res);
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	string S; cin >> S;
	string T, ans = "YES";
	for(int i = S.size() - 1; i >= 0; i += 0) {
		if(S[i] != 'm' && S[i] != 'r' && S[i] != 'e') {
			ans = "NO"; break;
		}
		string s;
		if(S[i] == 'm') {
			if(i - 4 < 0) {
				ans = "NO"; break;
			}
			s = S.substr(i - 4, 5);
			if(s == "dream") i -= 5;
			else {
				ans = "NO"; break;
			}
		}
		else if(S[i] == 'e') {
			if(i - 4 < 0) {
				ans = "NO"; break;
			}
			s = S.substr(i - 4, 5);
			if(s == "erase") i -= 5;
			else {
				ans = "NO";
				break;
			}
		}
		else if(S[i] == 'r') {
			if(i - 5 < 0) {
				ans = "NO"; break;
			}
			else {
				s = S.substr(i - 5, 6);
				if(s == "eraser") i -= 6;
				else {
					if(i - 6 < 0) {
						ans = "NO"; break;
					}
					else {
						s = S.substr(i - 6, 7);
						if(s == "dreamer") i -= 7;
						else {
							ans = "NO"; break;
						}
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3764