akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>

using namespace std;

const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
template <typename T>
void printV(const std::vector<T>& v, const char * const separator = " ")
{
    if(!v.empty())
    {
        std::copy(v.begin(),
                  --v.end(),
                  std::ostream_iterator<T>(std::cout, separator));
        std::cout << v.back() << "\n";
    }
}


Int gcd(Int a, Int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

Int lcm(Int a, Int b) {
    return a / gcd(a, b) * b;
    //a*bは64bit integer overflow
}

int Max(int a, int b, int c) {
    int temp = max(a, b);
    return max(temp, c);
}

int Min(int a, int b, int c) {
    int temp = min(a, b);
    return min(temp, c);
}

bool integer(double num) {
    return floor(num) == num;
}

Int fact(int num) {
    if (num == 0)
        return 1;
    else
        return num * fact(num - 1);
}

void y() {
    cout << "Yes" << endl;
    exit(0);
}

void n() {
    cout << "No" << endl;
    exit(0);
}

void Y() {
    cout << "YES" << endl;
    exit(0);
}

void N() {
    cout << "NO" << endl;
    exit(0);
}

Int yakusu(int n) {
    int cnt = 0;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            cnt++;
            if (i * i != n) cnt++;
        }
    }
    return cnt;
}

/*   kokomade  */

int cnt = 0;
bool is_prime[ 50000 + 1 ];
vector<int> P;
void Eratosthenes( const int N )
{
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;//初期化
    }
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
}

int main() {
    IOS;
    //int n,x,t;cin>>n>>x>>t;
    int a,b,c;cin>>a>>b;
    // string str;cin>>str;
    //vector<int> l(n);
    // vector<string> s(n);
    int cnt;
    if(b==1){
        cout<<0;
        return 0;
    }

    for (int i = 1; i < 100; ++i) {
        cnt=i;
        //cout<<a*i-cnt+1<<endl;
        if(a*i-cnt+1>=b){
            cout<<cnt;
            break;
        }
    }


    cout<<endl;
    return 0;
}

/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

char c[200010];
int cntW[200010], cntR[200010];

int main() {
    ios_base::sync_with_stdio(0);
    int n; cin >> n;
    for (int i=1;i<=n;i++) cin >> c[i];
    for (int i=1;i<=n;i++) cntW[i] = cntW[i-1] + (c[i]=='W');
    for (int i=n;i>=1;i--) cntR[i] = cntR[i+1] + (c[i]=='R');

    int ans = 1e9;
    for (int i=0;i<=n;i++) ans = min(ans, max(cntW[i], cntR[i+1]));
    cout << ans << endl;
}


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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

int D, E;
void solve() {
    double ans = 1e8;
    rep(y, 101) rep(x, 101) {
        if (x + y != D) continue;

        ans = min(ans, abs(sqrt(x * x + y * y) - E));
    }
    printf("%.20f\n", ans);
}
int main() {
    while (cin >> D >> E, E) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3132
#include <stdio.h>
int main(){
    int n,r,t;
    scanf("%d",&n);
    while(n--){
        scanf("%d%d",&r,&t);
        if(r%100==0){
            if(t%30==0)printf("%d\n",(t/30)*5+r/100);
            else printf("%d %d\n",(t/30)*5 +r/100,(t/30+1)*5 +r/100);
        }
        else{
            if(t%30==0)printf("%d %d\n",(t/30)*5+ r/100,(t/30)*5+ r/100 +1);
            else printf("%d %d %d %d\n",(t/30)*5+ r/100,(t/30)*5+ r/100 +1,(t/30)*5+ r/100 +5,(t/30)*5+ r/100 +6);
            
        }
    }
}


Measured memory_bytes: 2676
package main

import "fmt"

func main() {
	var (
		l   int
		r   int
		min = 10000000000
	)
	fmt.Scan(&l, &r)

	for i := l; i < l+2019; i++ {
		for j := l; j < l+2019; j++ {
			if i < j && j <= r && i >= l {
				if min > (i*j)%2019 {
					min = (i * j) % 2019
				} else {
					continue
				}
			}
		}
	}
	fmt.Println(min)
}

Measured memory_bytes: 1768
N,Q = map(int,input().split())
S = input()
t = [0]*(N)
for i in range(N-1):
    t[i+1] = t[i]+1 if S[i:i+2] == 'AC' else t[i]
for i in range(Q):
    l,r = map(int,input().split())
    print(t[r-1]-t[l-1])

Measured memory_bytes: 6060
#include<stdio.h>

int main(){
  long long int T1,T2,A1,A2,B1,B2;
  scanf("%lld %lld",&T1,&T2);
  scanf("%lld %lld",&A1,&A2);
  scanf("%lld %lld",&B1,&B2);
  long long int diff = T1*(A1-B1)+T2*(A2-B2);
  if(diff == 0){printf("infinity\n");}
  else{
    long long diff2 = T1*(A1-B1);
    if((diff > 0&&diff2 > 0)||(diff<0&&diff2<0)){printf("0\n");}
    else{
      long long int ct = -diff2 / diff;
      ct *= 2;ct++;
      if(diff2 % diff==0){ct--;}printf("%lld\n",ct);
    }
  }
  return 0;
}

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

namespace CSharpSample01
{

	class Program
	{

		static void Main(string[] args)
		{
			var N = int.Parse(Console.ReadLine());

			var inputNum = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			var answerDic = new Dictionary<int, int>();

			// 初期化
			for(int i = 1; i <= N; i++)
			{
				answerDic[i] = 0;
			}

			for(int i = 0; i < N - 1; i++)
			{
				var key = inputNum[i];

				if (answerDic.ContainsKey(key))
				{
					answerDic[key]++;
				}
				else
				{
					answerDic[key] = 1;
				}
			}

			// 回答出力
			for (int i = 1; i <= N; i++)
			{
				Console.WriteLine(answerDic[i]);
			}


		}
	}
}

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

int main () {
  int n, a, b;
  cin >> n >> a >> b;
  int grand_sum = 0;
  for (int i = 0; i <= n; i++) {
    int v, w, x, y, z;
    v = i / 10000;
    w = i / 1000 % 10;
    x = i / 100 % 10;
    y = i / 10 % 10;
    z = i / 1 % 10;
    int sum = v + w + x + y + z;
    if (sum >= a && sum <= b) {
      grand_sum += i;
    }
  }
  cout << grand_sum << endl;
}


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


#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define scan(x) scanf("%lld",&x);
#define inf 5555555555555555555
#define mod 1000000007
#define pi 3.14159265358979323846
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool flag, ok;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111


ll sm1[MAX], sm2[MAX], a[MAX];
int main(void) {
  cin >> n;
  FOR(i, 0, n) cin >> a[i];

  mi = 0;
  if (a[0] <= 0) {
	mi += llabs(a[0]) + 1;
	sm1[0] = 1;
  }
  else {
	sm1[0] = a[0];
  }

  FOR(i, 0, n - 1) {
	sm1[i + 1] = sm1[i] + a[i + 1];
	if (sm1[i + 1] == 0) {
	  if (sm1[i] > 0) {
		sm1[i + 1] = -1;
		mi++;
	  }
	  else {
		sm1[i + 1] = 1;
		mi++;
	  }
	}
	if (sm1[i + 1] > 0) {
	  if (sm1[i] > 0) {
		mi += llabs(sm1[i + 1]) + 1;
		sm1[i + 1] = -1;
	  }
	}
	else {
	  if (sm1[i] < 0) {
		mi += llabs(sm1[i + 1]) + 1;
		sm1[i + 1] = 1;
	  }
	}
  }
  ans = inf;
  ans = min(ans, mi);

  mi = 0;
  if (a[0] >= 0) {
	mi += llabs(a[0]) + 1;
	sm2[0] = -1;
  }
  else {
	sm2[0] = a[0];
  }
  FOR(i, 0, n - 1) {
	sm2[i + 1] = sm2[i] + a[i + 1];
	if (sm2[i + 1] == 0) {
	  if (sm2[i] > 0) {
		sm2[i + 1] = -1;
		mi++;
	  }
	  else {
		sm2[i + 1] = 1;
		mi++;
	  }
	}
	if (sm2[i + 1] > 0) {
	  if (sm2[i] > 0) {
		mi += llabs(sm2[i + 1]) + 1;
		sm2[i + 1] = -1;
	  }
	}
	else {
	  if (sm2[i] < 0) {
		mi += llabs(sm2[i + 1]) + 1;
		sm2[i + 1] = 1;
	  }
	}
  }
  ans = min(ans, mi);

  cout << ans << endl;

  return 0;
}

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

int main(){
  string s;
  cin >> s;
  std::vector<int> A(26, 0);
  for (int i = 0; i < s.size(); i++) {
    A.at(s.at(i)-'a')++;
  }
  for (int i = 0; i < 26; i++) {
    if(A.at(i)>1){
      cout << "no" << endl;
      return 0;
    }
  }
  cout << "yes" << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush

def main():
    a = int(input())
    b = int(input())

    if b < a:
        print('GREATER')
    elif a == b:
        print('EQUAL')
    else:
        print('LESS')


if __name__ == '__main__':
    main()


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

int main() {
	int N;
  	cin >> N;
  	
  	vector<int> V(N),C(N),D(N);
  
  	for(int i = 0; i < N; i++) {
    	cin >> V.at(i);
    }
  
  	for(int i = 0; i < N; i++) {
    	cin >> C.at(i);
    }
  	
  	for(int i = 0; i < N; i++) {
    	D.at(i) = V.at(i) - C.at(i);
    }
  
  	int ans = 0;
  
  	for(int i = 0; i < N; i++) {
    	if(D.at(i) >= 0) {
        ans += D.at(i);
        }
    }
  
  		cout << ans << endl;
  	
}

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

using namespace std;

typedef long long ll;

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;
}

const ll MOD = ll(1e9 + 7);

// A: 1, C: 2, G: 3, T: 4
vector<vector<ll>> dp;

ll str_to_id(const string str) {
    ll id = 0;
    for (auto &c : str) {
        int x;
        if (c == 'A') x = 0;
        else if (c == 'C') x = 1;
        else if (c == 'G') x = 2;
        else x = 3;
        id = id * 4 + x;
    }
    return id;
}

string id_to_str(ll id) {
    string S;
    while (id != 0) {
        int x = id % 4;
        char c;
        if (x == 0) c = 'A';
        else if (x == 1) c = 'C';
        else if (x == 2) c = 'G';
        else c = 'T';
        S += c;
        id /= 4;
    }
    reverse(S.begin(), S.end());
    return S;
}

bool check(const string last4) {
    if (last4.substr(1) == "AGC" ||
            last4.substr(1) == "GAC" ||
            last4.substr(1) == "ACG" ||
            (last4[0] == 'A' && last4[1] == 'G' && last4[3] == 'C') ||
            (last4[0] == 'A' && last4[2] == 'G' && last4[3] == 'C')) {
        return false;
    }
    return true;
}

ll solve(const int pos, const string last3, const int N) {
    const ll id = str_to_id(last3);

    if (pos == N) return 1LL;

    if (dp[pos][id] >= 0) {
        return dp[pos][id];
    }

    ll acc = 0;
    vector<char> cs = {'A', 'C', 'G', 'T'};
    for (auto &c : cs) {
        string str = last3 + c;
        if (!check(str)) {
            continue;
        }
        acc = (acc + solve(pos + 1, str.substr(1), N)) % MOD;
    }

    dp[pos][id] = acc;
    // printf("pos: %d, last3: %s, acc: %lld\n", pos, last3.c_str(), acc);
    return acc;
}

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

    dp.resize(N, vector<ll>(1000, -1));
    cout << solve(0, "ZZZ", N) << endl;

    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<double,double> dd;
typedef pair<ll,ll> pll;
typedef pair<string,int> psi;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvll;
typedef vector<vector<ii> > vvip;
typedef vector<ii> vii;
typedef map<int,int> mpi;
#define pb push_back
#define F first
#define S second
#define MOD 1000000007
#define NA -1
#define ALL(v) v.begin(),v.end()
#define mp make_pair
#define rep(i, n) for (int (i) = 0; (i) < (n); (i) ++)
#define rep1(i, n) for (int (i) = 1; (i) <= (n); (i) ++)
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define db(x) {cout << #x << " = " << (x) << endl;}
#define dba(a, x, y) {cout<<#a<<" :";FOR(i123,x,y)cout<<setw(4)<<(a)[i123];cout<<endl;}
#define foreach(e, x) for (__typeof(x.begin()) e = x.begin(); e != x.end(); e++) 
#define clr(x) memset(x,0,sizeof(x));
#define sz(x) int((x).size())
#define endl '\n'
const int INF = INT_MAX;
const ll INFL = LLONG_MAX;
const ld pi = acos(-1);
#define sc(t) scanf("%d",&t)
// vector<string> split(const string &s, char delim) {
//     stringstream ss(s);
//     string item;
//     vector<string> tokens;
//     while (getline(ss, item, delim)) {
//         tokens.push_back(item);
//     }
//     return tokens;
// }
typedef pair<pll,ll> ppll;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
#define re return

int main()
{
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt","r",stdin);
	//     freopen("output.txt","w",stdout);;
	// #endif
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	//ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
	
	int n,m;
	cin>>n>>m;
	vii v;
	rep(i,n)
	{
		int x,y;
		cin>>x>>y;
		v.pb({x,y});
	}
	vii w;
	rep(i,m)
	{
		int x,y;
		cin>>x>>y;
		w.pb({x,y});
	}
	vi ans;
	foreach(e,v)
	{
		int x=e->F;
		int y = e->S;
		int mn=INF;
			int mni=-1;
		rep(i,m)
		{
			
			int xx= w[i].F;
			int yy=w[i].S;
			int d = (int)abs(xx-x )+(int)abs(yy-y);
			if( d<mn)
			{
				mni = i;
				mn  = d;
			}
			
		}
		ans.pb(mni);
	}
	rep(i,sz(ans))
		cout<< ans[i]+1<<"\n";
	cout<<endl;
	
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define V vector<pair<pair<int,int>,int> >
using namespace std;
int main(){
  int n;
  while(cin >>n,n){
    V code;
    code.push_back(make_pair(make_pair(0,1000000000),-1));
    for(int i=0; i<n; i++){
      string s;
      int a,b;
      cin >>s;
      if(s == "W"){
	cin >>a>>b;
	for(int i=0; i<code.size(); i++){
	  if(code[i].second == -1){
	    int start = code[i].first.first;
	    int goal = code[i].first.second;
	    int size = goal-start+1;
	    if(size>b){
	      code[i].first.first = start+b;
	      code.push_back(make_pair(make_pair(start,start+b-1),a));
	      sort(code.begin(),code.end());
	      break;
	    }
	    else{
	      code[i].second = a;
	      b-=size;
	      if(b == 0) break;
	    }
	  }
	}
      }
      if(s == "D"){
	cin >>a;
	for(int i=0; i<code.size(); i++){
	  if(code[i].second == a) code[i].second = -1;
	}
      }
      if(s == "R"){
	cin >>a;
	for(int i=0; i<code.size(); i++) if(code[i].first.first<=a && code[i].first.second>=a){cout <<code[i].second<<endl;}
      }
    }
    cout <<endl;
  }
  return 0;
}

Measured memory_bytes: 1340
def factorization(n):
    if n == 1:
        return []
    else:
        arr = []
        temp = n
        for i in range(2, int(-(-n**0.5//1))+1):
            if temp % i == 0:
                cnt = 0
                while temp % i == 0:
                    cnt += 1
                    temp //= i
                arr.append(i)
        if temp != 1:
            arr.append(temp)
        if not arr:
            arr.append(n)
        return arr


input_values = list(map(int, input().split()))
print(len(list(set(factorization(input_values[0])) & set(factorization(input_values[1])))) + 1)


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

void main_()
{
    ll N;
    cin >> N;
    vector<ll> As;
    As.reserve(N);
    copy_n(istream_iterator<ll>(cin), N, back_inserter(As));

    sort(begin(As), end(As));
    if (N % 2 == 1) {
        if (As[0] != 0) {
            cout << 0 << endl;
            return;
        }

        // 先頭の0を取り除き、他をすべて-1する
        As.erase(begin(As));
        transform(begin(As), end(As), begin(As), [](int a) { return a - 1; });
        N--;
    }

    // 1,1,3,3,5,5,7,7…となっているかチェック
    for (ll i = 1; i <= N; ++i) {
        if (As[i - 1] != (i + 1) / 2 * 2 - 1) {
            cout << 0 << endl;
            return;
        }
    }

    ll ans = 1;
    for (ll i = 0; i < N / 2; ++i) {
        ans *= 2;
        ans %= (ll)1e9 + 7;
    }
    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k,l;
	string s;
	cin>>k>>s;
	l=s.length();
	if(l>k){
		for(int i=0;i<k;i++){
			cout<<s[i];
		}
		cout<<"...";
	}
	else
	cout<<s;
	return 0;
}

Measured memory_bytes: 3624
function main() {
  var
  i,
  l, h,
  line,
  n = parseInt(input[0], 10),
  lines = input.slice(1);
  for(i = 0; i < n; i++) {
    line = lines[i].split('').map(parseFloat);
    line.sort(function(a, b){return a - b;});
    min = parseInt(line.join(''), 10);
    line.sort(function(a, b){return b - a;});
    max = parseInt(line.join(''), 10);
    console.log(max - min);
  }
}

var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

Measured memory_bytes: 7652
#include <bits/stdc++.h>
using namespace std;
#define md 1000000007
int main() {
   long long int n,k;
   cin>>n>>k;
   long long int sum=0;
   for(long long int i=k;i<=n+1;i++)
    {
    	//from n+1 elements select i
    	long long int y=(n*(n+1)/2)-((n-i)*(n-i+1)/2);
    	long long int x=y-((i-1)*i)/2+1;
    	sum=(sum+x)%md;
    }
    cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

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

    int N; cin >> N;
    ll K; cin >> K;
    vector<ll> A(N);
    ll maxA = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        maxA = max(maxA, A[i]);
    }

    auto digit = [](ll n) {
        int res = 0;
        while (n) {
            res++;
            n >>= 1;
        }
        return res;
    };

    int d = max(digit(maxA), digit(K));
    vector<int> count(d);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < d; j++) {
            count[j] += A[i] & 1;
            A[i] >>= 1;
        }
    }

    vector<ll> dp(2);
    bool flag = false;
    for (int i = d-1; i >= 0; i--) {
        ll bit = K & 1LL << i;
        ll x = 1LL << i;
        if (!flag) {
            dp[0] += x * count[i];
            if (bit) {
                dp[1] += x * (N-count[i]);
                flag = true;
            }
            else
                dp[1] += x * count[i];
        }
        else {
            int c = max(count[i], N-count[i]);
            dp[0] += x * c;
            if (bit) {
                dp[0] = max(dp[0], dp[1] + x * count[i]);
                dp[1] += x * (N-count[i]);
            }
            else
                dp[1] += x * count[i];
        }
    }
    cout << max(dp[0], dp[1]) << "\n";
}

Measured memory_bytes: 1024
// In the name of God

#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
const long long mod = (int)1e9+7;
long long a[N], n, k;
long long fastpow(long long x, long long y) {long long ret=1;for(;y;y>>=1){if(y&1)ret=ret*x%mod;x=x*x%mod;}return ret;}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> k;
	k%=mod;
	for(int i=0;i<n;i++) cin >> a[i];
	long long ans = 0;
	for(int i=0;i<n;i++) {
		long long x = 0;
		for(int j=i+1;j<n;j++) {
			if(a[j] < a[i]) x++;
		}
		long long add = k*(k+1)%mod;
		add = add*fastpow(2,mod-2)%mod;
		add = x*add%mod;
		ans += add;
		ans %= mod;
		x=0;
		for(int j=i-1;j>=0;j--) {
			if(a[j] < a[i]) x++;
		}
		add = (k-1)*k%mod;
		add = add*fastpow(2,mod-2)%mod;
		ans += x*add;
		ans %= mod;
	}
	cout << ans%mod;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count());
//int rnd(int x) { return mrand()%x;}
typedef long long ll;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
char s[500];
ll dp[500][500][500];
ll k;
vector<ll> v;
ll suf[400];
int len;
const ll md=998244353;
ll dfs(ll pos,ll lim,ll res){
	if(pos==len){
		if(lim==0) return 1;
		else return 0;
	}
	if(dp[pos][lim][res]!=-1) return dp[pos][lim][res];
	ll ret=0;
	for(int i=max(v[pos]-lim,0ll);i-v[pos]+lim<=suf[pos] && i-v[pos]<=res;i++){
		ret=(ret+dfs(pos+1,lim+i-v[pos],res-max(0ll,i-v[pos])))%md;
	}
	dp[pos][lim][res]=ret;
	return ret;
}
int main(){
	memset(dp,-1,sizeof(dp));
	scanf("%s%lld",s+1,&k);
	k=min(k,300ll);
	ll cnt=0;
	for(int i=1;s[i];i++){
		if(s[i]=='0'){
			v.push_back(cnt);
			cnt=0;	
		}
		else{
			cnt++;
		}
	}
	v.push_back(cnt);
	len=(int)v.size();
	suf[len]=0;
	for(int i=len-1;i>=0;i--){
		suf[i]=suf[i+1]+v[i];
	}
	ll ans=dfs(0,0,min(k,300ll));
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 980348
#include<bits/stdc++.h>
#define N 16
using namespace std;
int n,x,y,z,ans,val[1<<(N+1)],cnt[N*2],dp[1<<N];
vector<int>G[N*2];
inline int read(){
	char ch=getchar();int f=1,w=0;
	for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar()) w=w*10+ch-'0';
	return w*f;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<n;i++){
		x=read()+1;y=read()+1;z=read();
		val[x]^=z;val[y]^=z;
	}
	for (int i=1;i<=n;i++) cnt[val[i]]++;
	for (int i=1;i<=15;i++) ans+=cnt[i]/2,val[i]=cnt[i]%2;
	int now=0,tot=0;
	for (int i=1;i<=15;i++) if (val[i]) now|=(1<<i),tot++;
	memset(dp,127,sizeof(dp));int inf=dp[now];dp[now]=0;
	for (int i=0;i<(1<<16);i++) G[__builtin_popcount(i)].push_back(i);
	/*for (int i=tot;i;i--){
		for (int j=0;j<(int)G[i].size();j++){
			int S=G[i][j];
			if (dp[S]==inf) continue;
			for (int x=1;x<=15;x++){
				for (int y=1;y<=15;y++){
					if (x==y||(!(S>>x&1))||(!(S>>y&1))) continue;
					int tmp=x^y;
					int S1=S^(1<<x)^(1<<y);
					if (S1&(1<<tmp)) dp[S1^(1<<tmp)]=min(dp[S1^(1<<tmp)],dp[S]+2);
					else dp[S1|(1<<tmp)]=min(dp[S1|(1<<tmp)],dp[S]+1);
				}
			}
		}
	}*/
	for (int i=tot;i;i--){
		for (int j=0;j<(int)G[i].size();j++){
			int S=G[i][j];
			if (dp[S]==inf) continue;
			x=__builtin_ctz(S);
				for (int y=1;y<=15;y++){
					if (x==y||(!(S>>x&1))||(!(S>>y&1))) continue;
					int tmp=x^y;
					int S1=S^(1<<x)^(1<<y);
					if (S1&(1<<tmp)) dp[S1^(1<<tmp)]=min(dp[S1^(1<<tmp)],dp[S]+2);
					else dp[S1|(1<<tmp)]=min(dp[S1|(1<<tmp)],dp[S]+1);
				}
		}
	}
	//cerr<<inf<<endl;
	printf("%d\n",min(dp[1],dp[0])+ans);
	return 0;
}

Measured memory_bytes: 1280
import java.io.*;
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int a[][][];
    a=new int[4][3][10];
    for(int i=0;i<n;i++){
      int b=sc.nextInt();
      int f=sc.nextInt();
      int r=sc.nextInt();
      int v=sc.nextInt();
      a[b-1][f-1][r-1]+=v;
    }
    for(int i=0;i<4;i++){
      for(int j=0;j<3;j++){
        for(int k=0;k<10;k++){
          System.out.print(" "+a[i][j][k]);
        }
        System.out.println();
      }
      if(i<3){
        for(int c=0;c<20;c++){
          System.out.print("#");
        }
        System.out.println();
      }
    }
  }
}



Measured memory_bytes: 29836
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb(a) push_back(a)
#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
const lint LINF = 1e18;



using namespace std;
int n;
map <int,int> mp;
int ans;

int main(){
  cin >> n;
  REP(i,n){
    int k;
    cin >> k;
    mp[k] ++;
  }
  for(map<int,int>:: iterator it=mp.begin(),end=mp.end();it!=end;++it){
    if(it->first > it->second) ans += it->second;
    else ans += it->second- it->first;
  }
  cout << ans <<endl;
  return 0;
}


Measured memory_bytes: 4736
use std::io::stdin;

fn main () {
    let mut l = String::new();
    stdin().read_line(&mut l).unwrap();
    let l: Vec<isize> = l.trim().split_whitespace().take(2).flat_map(str::parse).collect();
    println!("{}", l[0] * l[1] / 2);
}


Measured memory_bytes: 4352
P = 998244353
S, K = input().split()
A = [len(a) for a in S.split("0")][::-1]
K = int(K)
M = 301
X = [[0] * M for _ in range(M)]
X[0][0] = 1
for a in A:
    nX = [[0] * M for _ in range(M)]
    Y = [x[:] for x in X]
    for i in range(M-1)[::-1]:
        for j in range(M):
            Y[i][j] += Y[i+1][j]
            if Y[i][j] >= P: Y[i][j] -= P
    Z = [[0] * (M + 1)] + [[0] + x[:] for x in X]
    for i in range(M):
        for j in range(M):
            Z[i+1][j+1] = Z[i][j] + X[i][j]
            if Z[i+1][j+1] >= P: Z[i+1][j+1] -= P
    
    for i in range(M):
        for j in range(M):
            nX[i][j] += Y[i][j]
            t = min(a, i, j)
            nX[i][j] += Z[i][j] - Z[i-t][j-t]
            nX[i][j] %= P
    X = nX
print(sum(X[0][:K+1]) % P)

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

int main(){
    string s,t; cin >> s >> t;
    vector<string> ans;
    int l = s.size() - t.size() + 1;
    for(int i = 0; i < max(0,l); i++){
        string tmp = s;
        for(int j = 0; j < t.length(); j++){
            if(i+j>s.size()-1) break;
            if(tmp[i+j]=='?' || tmp[i+j]==t[j]) tmp[i+j] = t[j];
            else break;
            if(j == t.length() - 1){
                for(int k = 0; k < tmp.length(); k++){
                    if(tmp[k]=='?')tmp[k] = 'a';
                }
                ans.push_back(tmp);
            }
        }
    }
    sort(ans.begin(), ans.end());
    cout << (ans.size() > 0 ? ans[0] : "UNRESTORABLE") << endl;
    return 0;
    
}

Measured memory_bytes: 3632
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)

    val a, p = sc.nextInt()

    val apples = a * 3 + p

    println(apples / 2)

  }
  def debug(args: Any*): Unit = {
    Console.err.println(args.mkString(" "))
  }

  def printExecTime(process: => Unit): Unit = {
    val start = System.currentTimeMillis
    process
    debug("処理時間： " + (System.currentTimeMillis - start) + " ミリ秒")
  }

}


Measured memory_bytes: 25648
N = int(input())
C = input()

l = 0
while l < N and C[l] == "R":
    l += 1
r = N-1
while r > 0 and C[r] == "W":
    r -= 1

ans = 0
while l < r:
    if C[l] == "W" and C[r] == "R":
        ans += 1
        l += 1
        r -= 1
    elif C[l] == "W":
        r -= 1
    elif C[r] == "R":
        l += 1
    else:
        l += 1
        r -= 1

print(ans)

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

using namespace std;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ( a + b - c - d > 0 ) {
    cout << "Left" << endl;
  }
  else if ( a + b - c - d == 0 ) {
    cout << "Balanced" << endl;
  }
  else
    cout << "Right" << endl;
  return 0;
}

Measured memory_bytes: 256
<?php
$y_lines = intval(trim(fgets(STDIN)));
for ($i=1; $i <= $y_lines; $i++) {
    $order[$i] = $i;
}
$x_lines = intval(trim(fgets(STDIN)));
for ($i=0; $i < $x_lines; $i++) {
    $shuffle_nums = explode(',', trim(fgets(STDIN)));
    $shuffle_num_a = intval($shuffle_nums[0]);
    $shuffle_num_b = intval($shuffle_nums[1]);

    $tmp_1 = $order[$shuffle_num_a];
    $tmp_2 = $order[$shuffle_num_b];
    $order[$shuffle_num_a] = $tmp_2;
    $order[$shuffle_num_b] = $tmp_1;
}
foreach ($order as $num) {
    echo $num . "\n";
}

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

int main(){
int N, ans=0, c=0; cin >> N;
int H[N]; cin >> H[0];
for(int i=1; i<N; i++){
  cin >> H[i];
  if(H[i-1]>=H[i]){c++;}
  else{ if(ans<c){ans=c;} c=0; }
}
if(ans<c){ans=c;}  
cout << ans << "\n";
}

Measured memory_bytes: 640
# a1が決まればb1,b2,b3が決まり、b1が決まればa,a3が決まる
table = [list(map(int, input().split())) for _ in range(3)]
for a1 in range(101):
    b1 = table[0][0] - a1
    b2 = table[1][0] - a1
    b3 = table[2][0] - a1
    a2 = table[0][1] - b1
    a3 = table[0][2] - b1
    if (
        a2 + b2 == table[1][1]
        and a3 + b2 == table[1][2]
        and a2 + b3 == table[2][1]
        and a3 + b3 == table[2][2]
    ):
        print("Yes")
        exit()
print("No")


Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
  int n,seki;
  int sekisuu=0;
  scanf("%d",&n);
  int suuji,suuji2;
  for(int k=1;k<=n;k++){
        scanf("%d",&suuji);
        scanf("%d",&suuji2);
        seki=suuji2-suuji+1;
        sekisuu += seki;
    }

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

  return 0;
}

Measured memory_bytes: 128
from sys import stdin, setrecursionlimit
from itertools import accumulate

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


def prime_numbers(n):
    if n < 2:
        return []

    m = (n + 1) // 2
    p = [True] * m
    for i in range(1, int((n ** 0.5 - 1) / 2) + 1):
        if p[i]:
            for j in range(2 * i * (i + 1), m, 2 * i + 1):
                p[j] = False

    return {2} | {2 * i + 1 for i in range(1, m) if p[i]}


N = 10 ** 5
primes = prime_numbers(N)
a = [n in primes and (n + 1) // 2 in primes for n in range(N + 1)]
a = list(accumulate(a))

Q, *LR = map(int, open(0).read().split())
for l, r in zip(*[iter(LR)] * 2):
    print(a[r] - a[l - 1])


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

typedef long long int ll;
typedef pair <int, int> pii;
const int mod = 1e9+7;

ll g[205][205];

void pre(){
    for(int i=1;i<=200;i++){
        for(int j=1;j<=200;j++){
            g[i][j] = __gcd(i,j);
        }
    }
}

ll v(int n){
    pre();
    ll ans = 0;
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=n;j++){
            for(ll k=1;k<=n;k++){
                ll temp = g[i][j];
                temp = g[temp][k];
                ans+=temp;
            }
        }
    }
    return ans;
}

int main(){
    int n;
    scanf("%d",&n);
    ll ans = v(n);
    printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4144
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {

    string str;
    cin >> str;

  if(*(str.begin() + 2) == *(str.begin() + 3)){
      if(*(str.begin() + 4) == *(str.begin() + 5)){
            cout << "Yes";
      }else{
          cout << "No";
      }
  } else{
      cout << "No";
  }







    return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> table(H, vector<char>(W));
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> table.at(i).at(j);
    }
  }
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(table.at(i).at(j) == '#'){
        break;
      }
      else if(j == W - 1){
        for(int k = 0; k < W; k++){
        table.at(i).at(k) = '~';
        }
      }
    }
  }
  for(int i = 0; i < W; i++){
    for(int j = 0; j < H; j++){
      if(table.at(j).at(i) == '#'){
        break;
      }
      else if(j == H - 1){
        for(int k = 0; k < H; k++){
        table.at(k).at(i) = '~';
        }
      }
    }
  }
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(table.at(i).at(j) == '~' && j == W - 1){
        cout << endl;
      }
      else if(table.at(i).at(j) == '~'){
        continue;
      }
      else if(j == W - 1){
        cout << table.at(i).at(j) << endl;
      }
      else{
        cout << table.at(i).at(j);
      }
    }
  }
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int L[] = new int[N];
		
		for(int i=0;i<N;i++) {
			L[i]=sc.nextInt();
		}
		
		Arrays.sort(L);
		//小さい順に並んでいる。
		
		
		//三角形ができない組み合わせを数える。
		long count=0;
		long count_memo=0;
		
		int sh =0;
		int mi =0;
		int sum=0;
		for(int i=0;i<N-2;i++) {
			sh=L[i];
			for(int j=i+1;j<N-1;j++) {
				mi=L[j];
				sum = sh + mi;
				int k=L.length;
				count_memo=count;
				while(sum<=L[k-1]) {
					count++;
					k--;
				}
				if(count_memo==count) {
					break;
				}
			}
		}
		
		//組み合わせの総数　
		long total = (N*(N-1)*(long)(N-2))/(3*2); 
		
		long ans = total-count;
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 28628
#include<stdio.h>
#include<math.h>

int main()
{
	int x[100], y[100],n;
	double p;
/*?°???\??¨???*/
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &x[i]);
	}
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &y[i]);
	}
/*??????????????????????????¢*/
	for (p = 1; p < 4; p++)
	{
		double minkohu = 0;
		for (int a=0; a < n; a++)
		{
			minkohu = minkohu + pow(fabs(x[a] - y[a]), p);
		}
		minkohu = pow(minkohu, 1 / p);
		printf("%lf\n", minkohu);
		minkohu = 0;
	}
/*?????§????????§????????¢*/
	double distance,num;
	distance = fabs(x[0] - y[0]);
	for (int j = 1; j < n; j++)
	{
		num = fabs(x[j] - y[j]);
		if (num > distance)
		{
			distance = num;
		}
	}
	printf("%lf\n", distance);
	return 0;
}

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

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

int main() {
    map<string, int> MAP;
    int num_query;
    scanf("%d", &num_query);
    int command, x;
    for (int loop = 0; loop < num_query; loop++) {
        string tmp;
        scanf("%d", &command);
        if (command == 0) {
            cin >> tmp >> x;
            MAP[tmp] = x;
        } else {
            cin >> tmp;
            printf("%d\n", MAP[tmp]);
        }
    }
    return 0;
}


Measured memory_bytes: 27972
#include<bits/stdc++.h>
	using namespace std;
	#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
	#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
	#define RI(i,n) FOR(i,1,(n))
	#define REP(i,n) FOR(i,0,(n)-1) 
	#define mp make_pair
	#define pb push_back
	#define st first
	#define nd second
	#define sz(w) (int) w.size()
	#define MOD 1e9+7
	#define inf 1e9+9
	#define int long long
	#define ld long double
	#define fast  ios_base::sync_with_stdio(false);  cin.tie(NULL);
	typedef vector<int> vi;
	typedef pair<int,int> pii; 
	int max(int a, int b){
		if(a>b) return a;
		return b;
	}
	void solve(){
		int n,k; cin>>n>>k;
		int arr[n];
		for(int i=0;i<n;i++) 
			cin>>arr[i];
		int dp[n+1];
		dp[0]=0;
		dp[1]=0;
		dp[2]=abs(arr[1]-arr[0]);
		FOR(i,3,n)	{
			dp[i] = inf; 
			for(int j=i-1;j>=max(1,i-k);j--){ 
				dp[i]=min(dp[i], dp[j]+abs(arr[i-1]-arr[j-1]) );
			}
		}
		 
		cout << dp[n] << endl;
	}


	int32_t main(){
		fast
		int t;
		// cin>>t;
		t=1;
		while(t--){
			solve();
		}
	}

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

vector < vector < pair < pair < int, int > , int > > > memo(3005, vector < pair < pair < int, int > , int > > (3005 , {{-1, -1}, 0}) );
string s, t, finans = "";
int n1, n2;



signed main(){

    
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> s >> t;

    n1 = s.length();
    n2 = t.length(); 

    for(int i = n1 - 1;i >= 0;--i){
        for(int j = n2 - 1;j >= 0;--j){
            if(s[i] == t[j]) memo[i][j] = {{i + 1, j + 1}, 1 + memo[i + 1][j + 1].second};
            else if(memo[i + 1][j].second < memo[i][j + 1].second){
                memo[i][j] = {{i, j + 1}, memo[i][j + 1].second};
            }
            else{
                memo[i][j] = {{i + 1, j}, memo[i + 1][j].second};
            }
        }
    }

    int x = 0, y = 0, temp;
    while(x< n1 and y < n2 and x != -1 and y != -1){
        if(s[x] == t[y]) finans += s[x];
        temp = y;
        y = memo[x][y].first.second;
        x = memo[x][temp].first.first;
    }

    cout << finans;

}

Measured memory_bytes: 109628
function Main(input) {
  line = input.split(" ");
  X = parseInt(line[0], 10);
  A = parseInt(line[1], 10);
  
  if(X < A){
  	console.log(0);
  }
  else{
	console.log(10);
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 7372
import sys
from collections import deque,Counter
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n = I()
    l = list(IL())
    m = max(l)
    s = sum(l)-m
    if m<s:
        print('Yes')
    else:
        print('No')
    return

if __name__=='__main__':
    Main()

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;
//1125~
void solve()
{
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(int i = 0; i < n; ++i)
  {
    cin >> a[i];
  }

  ll ans = n;
  int num = 0;
  int si = 0;
  for(int i = 0; i < n; ++i)
  {
    while((num & a[i]) > 0) 
    {
      num ^= a[si];
      si++;
    }

    num ^= a[i];

    ans += (i - si);
    // cout << setw(5) << num << setw(3) << si << setw(3) << i;
    // cout << " add " << i - si << endl;
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 4756
#include<stdio.h>
int main()
{

int n,k,count=0;
scanf("%d %d",&n,&k);
 //int rem,num=0,i=0;
 while(n>0)
 {
     /*rem=n%k;
     num=num + rem * pow(10,i);
     i++;*/
     n=n/k;
     count++;
 }
 printf("%d",count);
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
#define MAX 45

int F[MAX];

void Fibonacci(){
  F[0] = 1; F[1] = 1;
  for( int i = 2 ; i < MAX ; i++ ) F[i] = F[i-2] + F[i-1];
}

int main(void){
  Fibonacci();
  int i;

  cin >> i;
  cout << F[i] << endl;

  return 0;
}

Measured memory_bytes: 1160
import sys
from collections import defaultdict

n, m, *xxx = map(int, sys.stdin.buffer.read().split())
d = defaultdict(lambda: defaultdict(int))

for x in xxx:
    d[x % m][x] += 1

ans = sum(d[0].values()) // 2
if m % 2 == 0:
    ans += sum(d[m // 2].values()) // 2

for a in range(1, (m + 1) // 2):
    b = m - a
    a_pair = 0
    a_alone = 0
    for c in d[a].values():
        k, l = divmod(c, 2)
        a_pair += k
        a_alone += l
    b_pair = 0
    b_alone = 0
    for c in d[b].values():
        k, l = divmod(c, 2)
        b_pair += k
        b_alone += l
    if a_alone > b_alone:
        a_pair, b_pair = b_pair, a_pair
        a_alone, b_alone = b_alone, a_alone
    remaining_alone = b_alone - a_alone
    if a_pair * 2 >= remaining_alone:
        ans += a_pair + b_pair + a_alone + remaining_alone // 2
    else:
        ans += a_pair * 2 + b_pair + a_alone

print(ans)


Measured memory_bytes: 48192
/*
	考虑到交换操作的传递性
	可以交换的球连边, 那么同一个联通块内的点都可以相互交换
	而且, 每种颜色只需要考虑其最小的重量, 它可以代表全部的交换
	不同种颜色也只需要考虑最小和次小就行了...
	有一些神奇的性质 :
	对答案有贡献的交换集合有且只有 1 个
	所以答案是一个多项式系数
*/
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
#define N 200005

using namespace std;

const int mod = 1e9 + 7;

int n, x, y;
int fac[N], cnt[N];

struct node { int c, w; } ball[N], mBall[N], m1Ball, m2Ball;

inline void read(int &x) {
	x = 0; char ch = getchar();
	while(!isdigit(ch)) ch = getchar();
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
}
inline int fpm(int bs, int mi) {
	int res = 1;
	while(mi) {
		if(mi & 1) res = 1LL * res * bs % mod;
		bs = 1LL * bs * bs % mod, mi >>= 1;
	}
	return res;
}

inline bool judge(node A, node B) { return A.c == B.c ? A.w + B.w <= x : A.w + B.w <= y; }

int main() {
	read(n), read(x), read(y);
	
	fac[0] = 1;
	for(int i = 1; i <= n; ++i) {
		fac[i] = 1LL * i * fac[i - 1] % mod;
		mBall[i].c = i, mBall[i].w = 1e9;
	}
	for(int i = 1, c, w; i <= n; ++i) {
		read(c), read(w);
		ball[i].c = c, ball[i].w = w;
		mBall[c].w = min(mBall[c].w, w);
	}
	
	m1Ball.w = m2Ball.w = 1e9;
	for(int i = 1; i <= n; ++i) {
		if(mBall[i].w < m2Ball.w) {
			m2Ball = mBall[i];
			if(m2Ball.w < m1Ball.w)
				swap(m1Ball, m2Ball);
		}
	}
	
	if(m1Ball.w + m2Ball.w > y) return puts("1"), 0;
	
	for(int i = 1; i <= n; ++i) {
		int c = ball[i].c;
		if(judge(m1Ball, ball[i])) {
			++cnt[c];
		} else if(judge(m2Ball, ball[i])) {
			++cnt[c];
		} else if(judge(m1Ball, mBall[c]) && judge(mBall[c], ball[i])) {
			++cnt[c];
		}
	}
	
	int ans = 1, sum = 0;
	for(int i = 1; i <= n; ++i) {
		if(!cnt[i]) continue;
		sum += cnt[i];
		ans = 1LL * ans * fpm(fac[cnt[i]], mod - 2) % mod;
	}
	ans = 1LL * fac[sum] * ans % mod;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 4992
#include<stdio.h>
 
main(void){
   
  int s[10000],n,t[500],q,i,count=0,j,temp;
  int l,m,r,value;
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
     
  }
 
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&t[i]);
  }
   
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(s[j]<s[j-1]){
    temp=s[j];
    s[j]=s[j-1];
    s[j-1]=temp;
      }
    }
  }
     
   
  for(i=0;i<q;i++){
    r=n;
    l=0;
    value=t[i];
    
    while(l<=r){
      m=(l+r)/2;
 
      if(s[m]==value){
    count=count+1;
    break;
      }
 
      else if(s[m]<value)l=m+1;
 
      else r=m -1;
 
    }
  }
   
  printf("%d\n",count);
  return 0;
}

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

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

#ifdef DEBUG
    #define cek(x) cout<<x
#else
    #define cek(x) if(false){}
#endif // DEBUG

#define fi first
#define se second
#define INF 1000000000
#define INFLL 1000000000000000000LL
#define EPS 1e-9
#define PI acos(-1.0)
#define pb push_back
#define TC() while(tc--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORN(i,n) for(int i=0;i<=n;i++)
#define REP(i,a,b,c) for(int i=a;i<b;i+=c)
#define REPN(i,a,b,c) for(int i=a;i<=b;i+=c)
#define reset(a,b) memset(a,b,sizeof(a))
#define sc(x) scanf("%d",&x)

int main(void){
    int n;
    sc(n);
    int cur = 30000;
    int ret[2][20010];
    int x[20010];
    for(int i = 0;i<n;i++){
        sc(x[i]);
        ret[0][i] = cur;
        cur += 30000;
    }
    for(int i = 0;i<n;i++){
        ret[0][x[i]-1] += i+1;
    }
    for(int i = 0;i<n;i++){
        cur -= 30000;
        ret[1][i] = cur;

    }

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

    printf("\n");
    for(int i = 0;i<n;i++){
        printf("%d ", ret[1][i]);
    }

    return 0;
}



Measured memory_bytes: 896
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    static Scanner scan = new Scanner(System.in);
    public static void main(String[] args) {
        int n, a, b, c, x;
        while((n = scan.nextInt()) != 0){
            a = scan.nextInt();
            b = scan.nextInt();
            c = scan.nextInt();
            x = scan.nextInt();
            int match_count = 0, create_count = 0;
            boolean same_number = false;
            ArrayList<Integer> y = new ArrayList<Integer>();

            for(int i=0; i<n; i++){
                y.add(scan.nextInt());
            }

            while(match_count < y.size() && create_count <= 10000){
                if(y.get(match_count)==x && same_number == false){
                    match_count += 1;
                    same_number = true;
                    continue;
                }
                if(same_number == true){
                    same_number = false;
                }
                x = create(a, b, c, x);
                create_count += 1;
            }

            if(match_count == y.size()){
                System.out.println(create_count);
            } else{
                System.out.println(-1);
            }
        }
    }

    public static int create(int a, int b, int c,int x){
        int result = (a * x + b)%c;
        return result;
    }
}

Measured memory_bytes: 32056
#include<bits/stdc++.h>
using namespace std;
const int N=4005,INF=1e9;
struct S {
	int x,y;
}s[N];
int one[N],b[N],a[N],l[N],r[N];
int t,p,D,L,R,X,Y,ans,min1,max1,tmp;
bool cmp(S x,S y) {
	return x.x>y.x;
}
int sssum(int i) {
	if(i<0) return 0;
	else return one[i];
}
int yi(int l,int r) {
	if(r<l) return sssum(r)+sssum(t-1)-sssum(l-1);
	else return sssum(r)-sssum(l-1);
} 
int main() {
//	freopen("data.in","r",stdin);
	char c=getchar();
	while(c!='0'&&c!='1') c=getchar();
	while(c=='0'||c=='1') a[t++]=c-'0',c=getchar();
	t=0;
	while(c!='0'&&c!='1') c=getchar();
	while(c=='0'||c=='1') b[t++]=c-'0',c=getchar();
	one[0]=b[0];
	for(int i=1;i<t;i++)
		one[i]=one[i-1]+b[i];
	if(!one[t-1]) {
		for(int i=0;i<t;i++) 
			if(a[i]==1) {cout<<"-1";return 0;}
		cout<<"0";return 0;
	}
	for(int i=0;i<t;i++) {
		int cnt=0,now=i;
		while(!b[now]) 
			cnt++,now=(now-1+t)%t;
		l[i]=cnt;
		cnt=0,now=i;
		while(!b[now])
			cnt++,now=(now+1)%t;
		r[i]=cnt;
	}
	ans=INF;
	for(int i=0;i<=t;i++) {
		p=0;
//		if(i==2)
//			system("pause");
		for(int j=0;j<t;j++) {
			if(a[j]!=b[(j+i)%t]&&!yi(j,(j+i)%t)) 
				s[p++].x=l[j],s[p-1].y=r[(j+i)%t];
		}
		sort(s,s+p,cmp);
		min1=INF,max1=0,X=0,Y=0;
		for(int j=0;j<p;j++) {
			if(s[j].x+max1<min1) X=s[j].x,Y=max1,min1=X+Y;
			max1=max(max1,s[j].y);
		}
		if(max1<min1) X=0,Y=max1;
		D=i,L=-X,R=Y+D,tmp=0;
		for(int j=0;j<t;j++)
			if(a[j]!=b[(j+i)%t]) tmp++;
		ans=min(ans,2*(R-L)-D+tmp);
	}
	for(int i=-1;i>=-t;i--) {
		p=0;
		for(int j=0;j<t;j++) {
			if(a[j]!=b[(j+i+t)%t]&&!yi((j+i+t)%t,j)) 
				s[p++].x=l[(j+i+2*t)%t],s[p-1].y=r[j%t];
		}
		sort(s,s+p,cmp);
		min1=INF,max1=0,X=0,Y=0;
		for(int j=0;j<p;j++) {
			if(s[j].x+max1<min1) X=s[j].x,Y=max1,min1=X+Y;
			max1=max(max1,s[j].y);
		}
		if(max1<min1) X=0,Y=max1;
		D=i,L=-X+D,R=Y,tmp=0;
		for(int j=0;j<t;j++)
			if(a[j]!=b[(j+i+t)%t]) tmp++;
		ans=min(ans,2*(R-L)+D+tmp);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N=2e5+5;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string s;cin>>s;
    ll n = s.size();
    s="0" + s;
    if(s[n]=='1' || s[1]=='0')return cout<<"-1" , 0;
    for(ll i=1;i<=n-1;i++)if(s[i]!=s[n-i])return cout<<"-1" , 0;
    for(ll i=1,u=1,prv=0;i<=n-1;i++){
        if(s[i]=='0')continue;
        ll v=u+i-prv;
        for(ll j=u+1;j<=v;j++)cout<<u<<" "<<j<<"\n";
        u=v,prv=i;
    }
}

Measured memory_bytes: 1664