akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define rep(x, n) for (int x = 1; x <= n; ++x)
#define FOR(x, l, r) for (int x = l; x <= r; ++x)
const int maxN = 505;
struct T
{
	double l, r, bg;
	int a;
	double ed()
	{
		return bg + a * (r - l);
	}
	double dis()
	{
		return (bg + ed()) * (r - l) * 0.5;
	}
	void print()
	{
		cout << l << " " << r << " " << bg << " " << a << endl;
	}
}st[maxN];
int v[maxN], t[maxN], n, top;

void add(double l, double r, double bg, int a)
{
	++top;
	st[top].l = l; st[top].r = r;
	st[top].bg = bg; st[top].a = a;
}

void make(double v)
{
	if (st[top].ed() <= v) return;
	double l = st[top].l, r = st[top].r;
	double bg = st[top].bg;
	if (bg > v + (r - l))
	{
		top--;
		make(v + (r - l));
		add(l, r, v + (r - l), -1);
	}
	else
	{
		double a = st[top].a;
		double x = (v + r + l * a - bg) / (1 + a);
		st[top].r = x;
		add(x, r, v + r - x, -1);
	}
}

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

	add(-1, 0, 0, 0);

	double ti = 0;
	rep(i, n)
	{
		make(v[i]);
		double last = st[top].ed();
		if (t[i] > (v[i] - last))
		{
			add(ti, ti + v[i] - last, last, 1);
			add(ti + v[i] - last, ti + t[i], v[i], 0);
		}
		else
		{
			add(ti, ti + t[i], last, 1);
		}
		ti += t[i];
	}
	make(0.0);

	double ans = 0;
	rep(i, top) ans += st[i].dis();

	printf("%.10lf\n", ans);
	return 0;
}


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

using namespace std;


int main(){
    
    long int A, B;
    cin >> A >> B;
    long int K = (A+B)/2;
    
    if ((A-K) == -(B-K)) {
        cout << K << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
    
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
int main(){
  ll N,W,i,j,k,b;scanf("%lld%lld",&N,&W);
  pair<ll,ll> T[N];
  for(i=0;i<N;i++) scanf("%lld%lld",&T[i].first,&T[i].second);
  b = T[0].first;
  for(i=0;i<N;i++) T[i].first -= b;
  ll dp[N+1][N+1][N*3+1];memset(dp,0,sizeof(dp));
  for(i=0;i<N;i++){
    for(j=0;j<=N;j++){
      for(k=0;k<=N*3;k++) dp[i+1][j][k] = dp[i][j][k];
    }
    for(j=1;j<=N;j++){
      for(k=T[i].first;k<=N*3;k++) dp[i+1][j][k] = max(dp[i+1][j][k],dp[i][j-1][k-T[i].first]+T[i].second);
    }
  }
  ll ans = 0;
  for(j=1;j<=N;j++){
    W -= b;
    for(k=0;k<=min(N*3,W);k++) ans = max(ans,dp[N][j][k]);
  }
  printf("%lld\n",ans);
}

Measured memory_bytes: 27740
var
n,i,j,cnt,t:Longint;
a,b:array[1..10000]of Longint;
begin
read(n);
t:=n+1-n mod 2;
for i:=1 to n do begin
for j:=i+1 to t-i-1 do begin
inc(cnt);
a[cnt]:=i;
b[cnt]:=j;
end;
if(j=t-i-1)or(j=t-i)then j:=t-i+1;
for j:=j to n do begin
inc(cnt);
a[cnt]:=i;
b[cnt]:=j;
end;
end;
writeln(cnt);
for i:=1 to cnt do writeln(a[i],' ',b[i]);
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long 
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define LOL cout<<'\n';

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  ll x,s=0; cin>>x;
  s+=x/500*1000;
  x%=500;
  s+=x/5*5;
  cout<<s;
  LOL
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat May 30 21:00:31 JST 2020
 **/

signed main() {
    Int h1, m1, h2, m2, K;
    std::cin >> h1 >> m1 >> h2 >> m2 >> K;
    Int t1 = h1 * 60 + m1;
    Int t2 = h2 * 60 + m2;
    std::cout << t2 - t1 - K << std::endl;
}


Measured memory_bytes: 3652
program kadai
	implicit none

	integer  ::  in(2)
    integer  ::  N,K,i,num,j
    real(8)  ::  n_n,ans
    read(*,*) in
    ans=0
    N=in(1)
    K=in(2)
    
    n_n=real(N,8)
    do i=1,N
    num=i
    	do while(num<K)
        	num=num*2
            j=j+1
        end do
    ans=ans+(1.0_8/2.0_8)**j
    j=0
    end do
    
    ans=ans/n_n
    
    write(*,*) ans
    
    
end program kadai

Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
const ll LLINF = 1LL << 50;
using namespace std;



int main() {
    string s;
    int x, y, sx = 0, num = 0, ans = 0;
    vector<int> xm, ym;
    bool dp[3000][16010] = {};
    cin >> s >> x >> y;
    char d = 'x';
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'F') {
            if (i == 0) {
                while (s[i] == 'F') {
                    sx++;
                    i++;
                }
                i--;
                num++;
            }
            else {
                int count = 0;
                while (s[i] == 'F') {
                    count++;
                    i++;
                }
                i--;
                if (d == 'x')xm.push_back(count);
                else ym.push_back(count);
                num++;
            }
        }
        else {
            if (d == 'x') d = 'y';
            else d = 'x';
        }
    }

    dp[0][sx+8000] = true;
    for (int i = 1; i <= xm.size(); i++) {
        for (int j = 0; j <= 16000; j++) {
            if (dp[i - 1][j] == true) {
                dp[i][j + xm[i - 1]] = true;
                dp[i][j - xm[i - 1]] = true;
            }
        }
    }
    if (dp[xm.size()][x+8000] == true) ans++;

    fill(dp[0], dp[2000], 0);
    dp[0][8000] = true;
    for (int i = 1; i <= ym.size(); i++) {
        for (int j = 0; j <= 16000; j++) {
            if (dp[i - 1][j] == true) {
                dp[i][j + ym[i - 1]] = true;
                dp[i][j - ym[i - 1]] = true;
            }
        }
    }
    if (dp[ym.size()][y+8000] == true) ans++;

    if (ans == 2) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 47232
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    map<int, int> m;
    for(int i = 0; i < n; i++)
    {
        m[a[i]] = i % 2;
    }
    sort(a.begin(), a.end());
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        if(m[a[i]] != i % 2) ans++;
    }
    cout << ans / 2 << endl;
}


Measured memory_bytes: 8316
/**
 * JJOOII
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			List<Character> cs = new ArrayList<Character>();
			List<Integer> ls = new ArrayList<Integer>();
			int last = 0;

			//parse
			cs.add('X');
			ls.add(1);
			for (int i = 0; i < line.length(); i++) {
				if (cs.get(last) == line.charAt(i)) {
					ls.set(last, ls.get(last) + 1);
				} else {
					cs.add(line.charAt(i));
					ls.add(1);
					last++;
				}
			}
			cs.add('X');
			ls.add(1);

			//solve
			int k = 0;
			for (int i = 0; i < cs.size(); i++) {
				if (cs.get(i) == 'O') {
					int l = ls.get(i);
					if (l <= k) continue;
					
					if (cs.get(i - 1) == 'J' && cs.get(i + 1) == 'I'
							&& ls.get(i - 1) >= l && ls.get(i + 1) >= l) {
						k = Math.max(k, l);
					}
				}
			}
			System.out.println(k);
		}
	}
}

Measured memory_bytes: 52044
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef pair<double,double> P;
typedef complex<double> CP;
typedef long long ll;


ll a[110][110]={0};

int main(){
	int n;
	cin>>n;
	rep(i,n){
		rep(j,n){
			cin>>a[i+1][j+1];
		}
	}
	ll res=-10000;
	
	rep(i,n){
		rep(j,n){
			a[i+1][j+1]+=a[i+1][j]+a[i][j+1]-a[i][j];
		}
	}
	rep(i,n){
		rep(j,n){
			for(int s=i;s<n;s++){
				for(int t=j;t<n;t++){
					res=max(res,a[s+1][t+1]-a[i][t+1]-a[s+1][j]+a[i][j]);
				}
			}
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 1252
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define rep(i, j) FOR(i, 0, j, 1)
#define rrep(i, j) RFOR(i, j, 0, 1)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define endl "\n"
#define MOD 1000000007
#define DEB(x) cout<<"##"<<x<<"##"<<endl;
void solve()
{ 
	int a,b;
	cin>>a>>b;
	cout<<a*b;
} 
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int tt=1;
	//cin>>tt;
	while(tt--)
	solve(); 	
	return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<map>
#include<string>
#include<vector>
using namespace std;
int main (){
  int N;
  cin >> N;
  map<string,int> mp;
  vector<string>t(N);
  for (int i=0;i<N;i++){
    cin >> t[i];
    mp[t[i]]++;
  }
  int M;
  cin >> M;
  vector<string>s(M);
  int a=0;
  for(int i=0;i<M;i++){
    cin >> s[i];
    mp[s[i]]--;
  }
  for(int i; i<N;i++){
    if(a<=mp[t[i]]){
      a=mp[t[i]];
    }
  }
  cout << a << endl;
}





Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace abc172
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
            solve_abc172B();
            Console.Out.Flush();
        }

        public static void solve_abc172B()
        {
            string s = Console.ReadLine();
            string t = Console.ReadLine();
            int cnt = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] != t[i])
                {
                    cnt++;
                }
            }
            Console.WriteLine(cnt);
        }

        public static void solve_abc172A()
        {
            int a = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine(a + Math.Pow(a, 2) + Math.Pow(a, 3));
        }
    }
}

Measured memory_bytes: 28260
class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0] * n

    def sum(self, i):
        res = 0
        while i >= 0:
            res += self.data[i]
            i = (i & (i + 1)) - 1
        return res

    def add(self, i, val):
        while i < self.n:
            self.data[i] += val
            i |= i + 1


N = int(input())
bit = BIT(N + 1)
for i, c in enumerate(input()):
    ind = ord(c) - ord("a")
    bit.add(i + 1, 1 << (ind * 20))
Q = int(input())
for _ in range(Q):
    parts = input().split()
    if parts[0] == "1":
        ind = int(parts[1])
        nval = 1 << ((ord(parts[2]) - ord("a")) * 20)
        val = bit.sum(ind) - bit.sum(ind - 1)
        bit.add(ind, nval - val)
    else:
        l, r = map(int, parts[1:])
        val = bit.sum(r) - bit.sum(l - 1)
        mask = (1 << 20) - 1
        ans = 0
        while val:
            if val & mask:
                ans += 1
            val >>= 20
        print(ans)


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

bool check_loop(int i) {
    vector<int> vec;
    while (i > 0) {
        vec.push_back(i % 10);
        i /= 10;
    }
    
    for (int j = 0; j < vec.size() / 2; j++) {
        if (vec.at(j) != vec.at(vec.size()-1-j)) {
            return false;
        }
    }
    return true;
}

int main() {
    int a, b;
    cin >> a >> b;
    int count = 0;
    for (int i = a; i <= b; i++) {
        if (check_loop(i)) {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		sc.close();
		String s = Long.toString(N);
		int l = s.length();
//		int[][] dp = new int[l + 1][2];
//		dp[1][0] = s.charAt(0) - '0';
//		dp[1][1] = s.charAt(0) - '0' - 1;
//		for(int i = 0; i < l; i++) {
//			if(s.charAt(i) == '1') {
//
//			}
//		}
		int cnt = 0;
		int max = 0;
		for(int i = 0; i < l; i++) {
			char c = s.charAt(i);
			if(c == '9') {
				cnt++;
			}
			max += c - '0';
		}
		if(cnt == l) {
			System.out.println(l * 9);
			System.exit(0);
		}
		int k = (l - 1) * 9 + s.charAt(0) - '0' - 1;
		max = Math.max(max, k);
		System.out.println(max);

	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        2000005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}

signed main()
{
    showoff;
    string s;
    int k,ans = 0;
    cin >> s >> k;
    if(sz(s) == 1){
        cout << k/2;
        return 0;
    }
    if(s[0] != s[sz(s)-1] || k == 1){
        FOR(i,0,sz(s)-1)if(s[i] == s[i+1])++ans,++i;
        cout << ans*k;
        return 0;
    }
    else{
        int ans1 = 0,fo = 0,fi = 0;
        FOR(i,0,sz(s)){
            if(i == sz(s)-1){fo = 1;break;}
            if(s[i] == s[i+1])++ans1,++i;
        }
        if(fo == 0){cout << ans1*k;return 0;}
        FOR(i,1,sz(s)){
            if(i == sz(s)-1){fi = 1;break;}
            if(s[i] == s[i+1])++ans,++i;
        }
        if(fi == 0)cout << (1+ans)*(k/2)+ans1*(k-k/2);
        else cout << ans1+ans*(k-1)+k-1;
        return 0;
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ... 

Measured memory_bytes: 256
import sys

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))

    ans = [False for i in range(n)]

    for i in range(n-1, -1, -1):
        num = i + 1
        j = 2
        accum = 0
        while num * j <= n:
            accum = (accum + ans[num * j - 1]) % 2
            j += 1
        ans[i] = (not accum == a[i])

    out = list()
    for i in range(n):
        if ans[i]:
            out.append(i + 1)
    print(len(out))
    print(*out)


        

Measured memory_bytes: 70620
import scala.io.StdIn._
import scala.collection.mutable.ArrayBuffer
object Main extends App {
  val sr = new StdinReader
  val n, q = sr.nextInt

  val edges: Array[ArrayBuffer[Int]] = Array.tabulate(n + 1)(_ => new ArrayBuffer[Int]())
  (1 to n - 1).foreach {i =>
    val a, b = sr.nextInt
    edges(a) += b
    edges(b) += a
  }

  val vs = new Array[Long](n + 1)
  (1 to q).foreach {i =>
    val p, x = sr.nextInt
    vs(p) += x
  }

  def check(checks: List[Int]): Unit = {
    if (checks.nonEmpty) {
      check(checks.flatMap { i =>
        edges(i).foreach {v =>
          vs(v) += vs(i)
          edges(v) -= i
        }
        edges(i)
      })
    }
  }
  check(List(1))

  println(vs.tail.mkString(" "))
}

class StdinReader {
  val is = System.in
  val buffer = new Array[Byte](1024 * 1024)
  var size = 0
  var pos = 0

  private def readByte: Byte = {
    if (pos >= size) {
      pos = 0;
      size = is.read(buffer);
    }
    if (size < 0) -1
    else {
      val ret = buffer(pos)
      pos += 1
      ret
    }
  }

  // support single byte char only
  def next: String = {
    @scala.annotation.tailrec
    def r(sb: StringBuilder, reading: Boolean): String = {
      readByte match {
        case b if ('!' <= b && b <= '~') => r(sb.append(b.asInstanceOf[Char]), true)
        case _ => if (reading) sb.toString else r(sb, false)
      }
    }
    r(new StringBuilder, false)
  }

  def nextInt: Int = {
    @scala.annotation.tailrec
    def r(i: Int, reading: Boolean): Int = {
      readByte match {
        case '-' => r(i * -1, true)
        case b if '0' <= b && b <= '9' => r(i * 10 + (b - '0'), true)
        case _ => if (reading) i else r(i, false)
      }
    }
    r(0, false)
  }
}

Measured memory_bytes: 105068
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string str;
    string terg = "keyence";
    int diff;
    int f = 0;

    cin >> str;

    diff = str.size() - terg.size();

    for (int i = 0; i < str.size() - diff; i++) {

        int j = -1;
        int k = -1;

        do {
            k++;

            if (j + 1 == i && diff != 0) {
                j = j + diff + 1;
            } else {
                j++;
            }
            
        } while (str[j] == terg[k] && k < terg.size());

        
        if (k == terg.size()) {
            f = 1;
        }
        
    }

    cout << (f ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int n, k[5][105], sum, ans = 0;
	cin >> n;
	for (int i = 0; i < 2; ++i) {
		for (int j = 0; j < n; ++j) {
			cin >> k[i][j];
		}
	}
	for (int i = 0; i < n; ++i) {
		sum = 0;
		for (int j = 0; j <= i; ++j) {
			sum += k[0][j];
		}
		for (int l = i; l < n; ++l) {
			sum += k[1][l];
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
}

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

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

  vector<vector<int>> X(N, vector<int>(D));

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      int x;
      cin >> x;

      X[i][j] = x;
    }
  }

  int count = 0;

  for (int i1 = 0; i1 < N - 1; i1++) {
    for (int i2 = i1 + 1; i2 < N; i2++) {
      vector<int> p1 = X[i1];
      vector<int> p2 = X[i2];

      int squared_distance = 0;
      for (int j = 0; j < D; j++) {
        squared_distance += pow(p1[j] - p2[j], 2);
      }
      float distance = sqrt(squared_distance);

      if (distance == floor(distance)) {
        count++;
      }
    }
  }

  cout << count << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int c[4];

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


    for (int i = 0; i < 3; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        c[a]++;
        c[b]++;
    }

    for (int i = 0; i < 4; i++) {
        if (c[i] > 2) {
            cout << "NO\n";
            return 0;
        }
    }

    cout << "YES\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int a,b;
	char c;
	while(scanf("%d %c%d",&a,&c,&b)){
		if(c=='+') printf("%d\n",a+b);
		if(c=='-') printf("%d\n",a-b);
		if(c=='*') printf("%d\n",a*b);
		if(c=='/') printf("%d\n",a/b);
		if(c=='?') break;
	}
	
	return 0;
}


Measured memory_bytes: 3208
#!/usr/bin/env python3
import sys


def Base_10_to_n(X, n):
    if int(X / n):
        return Base_10_to_n(int(X / n), n) + str(X % n)
    return str(X % n)


def solve(N: int, K: int):
    print(len(str(Base_10_to_n(N, K))))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#define INF 10000
using namespace std;

struct edge {
    int from, to, cost;
};

edge es[100];
int d[11];
int n,maxV=0;

int shortest_path(int s){
    int sum=0;
    for(int i=0;i<maxV+1;i++){
        d[i] = INF;
    }
    d[s] = 0;
    while(1){
        bool update = false;
        for(int i=0;i<2*n;i++){
            edge e = es[i];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                update = true;
            }
        }
        if(!update){
            break;
        }
    }
    for(int i=0;i<maxV+1;i++){
        if(d[i] != INF){
        	// cout << i << " " << d[i] << endl;
            sum += d[i];
        }
    }
    return sum;
}

int main(void){
    
    while(cin >> n && n){
    	maxV = 0;
        int a, b, c, tmp, min,sum2=100000;
        for(int i=0;i<n;i++){
            cin >> a >> b >> c;
            es[i].from = a;
            es[i].to = b;
            es[i].cost = c;

            es[i+n].from = b;
            es[i+n].to = a;
            es[i+n].cost = c;
            
            if(maxV < b){
           		maxV = b;
           	}
           	
        }
        //??????????????°?????????
        for(int i=0;i<maxV+1;i++){
            int tmp = shortest_path(i);
            // cout << tmp << endl;
            if(sum2 > tmp){
                sum2 = tmp;
                min = i;
            }
        }
        cout << min << " " << sum2 << endl;
    }
    return 0;
}

Measured memory_bytes: 2988
import fractions
A,B,C,D = map(int,input().split())
all = B-A+1
X = fractions.gcd(C,D)
gC = B//C - ((A-1)//C)
gD = B//D - ((A-1)//D)
gcdcd = C*D//X
gCD = B//gcdcd - ((A-1)//gcdcd)
ans = all - (gC+gD -gCD)
print(ans)

Measured memory_bytes: 5048
w = input()
lst=[]
while True:
    t_r = input()
    if t_r == 'END_OF_TEXT':
        break
    else:
        t_r = t_r.strip(',.\"\'')
        t_r = t_r.lower()
        lst.append(list(map(str, t_r.split())))
count = 0
for i in range(len(lst)):
    for v in lst[i]:
        if v == w:
            count += 1
print(count)


Measured memory_bytes: 5572
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h,w,k;
    cin >> h >> w >> k;
    vector<string> grid(h);
    rep(i,h) cin >> grid[i];
    ll ans = 0;
    rep(i,(1<<h)){
        rep(j,(1<<w)){
            auto g = grid;
            rep(a,h){
                if (i&(1<<a)){
                    rep(b,w) g[a][b] = '.';
                }
            }
            rep(b,w){
                if (j&(1<<b)){
                    rep(a,h) g[a][b] = '.';
                }
            }
            ll c = 0;
            rep(a,h){
                rep(b,w){
                    if (g[a][b] == '#') c++;
                }
            }
            if (c == k) ans++;
        }
    }
    PRINT(ans);
}


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

namespace ConsoleApplication14
{
   class Program
    {
        static void Main()
        {
            int a = int.Parse(Console.ReadLine()), b=0, c=0;
            for(int u = 0; u < a; u++)
            {
                string[] w = Console.ReadLine().Split().ToArray(); if (w[0] == w[1]) { b++;c++;continue; } string p = w[0];
                Array.Sort(w);if (p == w[0]) c += 3; else b += 3;
            }
            Console.WriteLine("{0} {1}",b,c);
        }
    }
}

Measured memory_bytes: 10288
#include<bits/stdc++.h>
using namespace std;
int x[4];
int change(int num,int f)
{
	if(f==0)
		return -num;
	else
		return num;
}
void print(int num,int f)
{
	if(f==0)
		printf("-%d",num);
	else
		printf("+%d",num);
} 
int main()
{
	for(int i=0;i<4;i++)x[i]=getchar()-'0';
	for(int a=0;a<2;a++)
	{
		for(int b=0;b<2;b++)
		{
			for(int c=0;c<2;c++)
			{
				if(x[0]+change(x[1],a)+change(x[2],b)+change(x[3],c)==7)
				{
					cout<<x[0];
					print(x[1],a);
					print(x[2],b);
					print(x[3],c);
					puts("=7");
					return 0;
				}
			}
		}
	}
	return 0;
} 


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

void ABC084D()
{
	int Q;
	cin >> Q;
	vector<int> primes(100001);
	primes[0] = 1;
	primes[1] = 1;
	for (int i = 2; i < 317; ++i)
	{
		if (primes[i] == 1)
			continue;
		for (int j = 2; j * i < 100001; ++j)
		{
			primes[j*i] = 1;
		}
	}
	vector<int> primeOnly; primeOnly.reserve(1000);
	for (int i = 0; i < 100001; ++i)
		if (primes[i] == 0)
			primeOnly.push_back(i);

	vector<int> prime2Only; prime2Only.reserve(1000);
	for (int i = 0; i < static_cast<int>(primeOnly.size()); ++i)
	{
		int p2 = (primeOnly[i] + 1) / 2;
		auto p = lower_bound(primeOnly.cbegin(), primeOnly.cend(), p2);
		if (p != primeOnly.cend() && *p == p2)
			prime2Only.push_back(primeOnly[i]);
	}

	vector<int> ct(100001);
	for (int i = 0; i < prime2Only.size(); ++i)
		ct[prime2Only[i]] = 1;
	for (int i = 0; i < 100000; ++i)
		ct[i + 1] += ct[i];


	//for (int i = 1; i < 100000; i += 2)
	//{
	//	for (int j = i; j < 100000; j += 2)
	//	{
	//		int l = i; int r = j;
	//		int y = ct[r] - ct[l - 1];
	//		//cout << ct[r] - ct[l - 1] << endl;
	//		//continue;

	//		auto pl = lower_bound(prime2Only.begin(), prime2Only.end(), l);
	//		auto pr = upper_bound(prime2Only.begin(), prime2Only.end(), r);

	//		int x = pl == prime2Only.cend() ? 0 : pr - pl;
	//		if (x != y)
	//			throw "Bad";
	//	}
	//}
	//return;

	for (int i = 0; i < Q; ++i)
	{
		int l, r;
		cin >> l >> r;
		int y = ct[r] - ct[l - 1];
		cout << ct[r] - ct[l - 1] << endl;


		auto pl = lower_bound(prime2Only.cbegin(), prime2Only.cend(), l);
		auto pr = upper_bound(prime2Only.cbegin(), prime2Only.cend(), r);
		int x = pl == prime2Only.cend() ? 0 : pr - pl;
		if (x != y)
			throw "Bad";
//		cout << x << endl;
	}
}
int main()
{
	ABC084D();
	return 0;
}


Measured memory_bytes: 1536
#include <stdio.h>
#include <algorithm>
using namespace std;
bool cmp(int a,int b){
	return a>b;
}
int main(){
	int a[5],b[20];
	while(scanf("%d,%d,%d,%d,%d",&a[0],&a[1],&a[2],&a[3],&a[4])!=EOF){
		sort(a,a+5);
		for(int i=0;i<14;i++)b[i]=0;
		for(int i=0;i<5;i++)b[a[i]]++;
		sort(b,b+14,cmp);
		if(b[0]==4)printf("four card\n");
		else if(b[0]==3){
			if(b[1]==2)printf("full house\n");
			else printf("three card\n");
		}
		else if(b[0]==2){
			if(b[1]==2)printf("two pair\n");
			else printf("one pair\n");
		}
		else if(a[1]==a[2]-1&&a[3]==a[2]+1&&a[3]==a[4]-1){
			if(a[0]==a[1]-1)printf("straight\n");
			else if(a[0]==1&&a[4]==13)printf("straight\n");
			else printf("null\n");
		}
		else printf("null\n");
	}
}

Measured memory_bytes: 2656
#include <stdio.h>
         
        int main(){
          	int i=0;
          	char cc[4];
          	scanf("%s",&cc[0]);
          	if(cc[0]==cc[1]&&cc[1]==cc[2]){
            	printf("No");
            }else{
            	printf("Yes");    
            }
        	
        	return 0;
        }

Measured memory_bytes: 128
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;
const int INF = 1e9;
 
long long gcd(long long x, long long y){
			if (x==0)return y;
      if(y==0)return x;
      if(x<y){
				long long temp = x;
			x = y;
				y = temp;
			}
			long long r = x % y;
				while(r!=0){
					x = y;
					y = r;
				r = x % y;
	    		}
			return y;
	    }

int main(){
	int N,M;
	cin >> N >> M;
	vector<long long> A(N);
	for(int i=0;i<N;i++){
		cin >> A[i];
	}
	vector<int> B(M);
	vector<long long> C(M);
	for(int i=0;i<M;i++){
		cin >> B[i] >> C[i];
	}
	priority_queue<pair<long long,int>> q;
	for(int i=0;i<N;i++){
		q.push(make_pair(A[i],1));
	}
	for(int i=0;i<M;i++){
		q.push(make_pair(C[i],B[i]));
	}
	long long ans=0;
	for(int i=0;i<N;i++){
		auto p = q.top();
		q.pop();
		ans+=p.first;
		if(p.second>1)q.push(make_pair(p.first,p.second-1));
		}
	cout << ans << endl;
	}


Measured memory_bytes: 8432
#include <iostream>
#include <string>
#include <map>
#include <stdio.h>
#include <cmath>

using namespace std;

int N;
int A[210];

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

    int res = 0;

    // 操作が行える限り操作を繰り返す
    while (true) {
        bool exist_odd = false;  // A[i] がすべて偶数かどうかを判定するフラグ
        for (int i = 0; i < N; ++i) {
            if (A[i] % 2 != 0) exist_odd = true;  // 奇数があったらフラグを立てる
        }

        if (exist_odd) break;  // 奇数があったら break

        // 操作を行えるなら操作を実際に行う
        for (int i = 0; i < N; ++i) {
            A[i] /= 2;
        }
        ++res;  // 操作回数をインクリメント
    }

    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
	int n,c=0;
	cin>>n;
	int p[100000];
	for(int i=0;i<n;i++)cin>>p[i];
	for(int i=0;i<n;i++){
		if(p[i]==i+1){
			swap(p[i],p[i+1]);
			c++;
		}
	}
	cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
const ll INF = 1000000000000007;

using namespace std;

int main(){
    ll A,B,C,X,Y,res;
    cin >> A >> B >> C >> X >> Y;

    ll iMin = INF;

    //plan1 A,BをそれぞれX,Y枚買う
    iMin = min(iMin, A*X + B*Y);

    //plan2 AB をmin(A,B) * 2枚 買い、 残り * 1枚を買う
    ll zan = max(X,Y) - min(X,Y);
    if(X > Y)
    {
      //Aを多く買う
      iMin = min(iMin, min(X,Y) * 2* C + zan * A);
    }
    else
    {
      //Bを多く買う
      iMin = min(iMin, min(X,Y) * 2* C + zan * B);
    }
    
    //plan3 AB をmax(A,B) * 2枚買う
    iMin = min(iMin, max(X,Y) * 2 * C);

    cout << iMin << endl;

    return 0;

}

Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    graph = [[] for _ in range(N)]
    for _ in range(M):
        A, B = map(int, input().split())
        graph[A-1].append(B-1)
        graph[B-1].append(A-1)

    distances = [-1] * N
    instructions = [-1] * N
    distances[0] = 0
    d = deque([0])
    while d:
        current_room = d.popleft()
        for next_room in graph[current_room]:
            if distances[next_room] == -1 or distances[current_room] + 1 < distances[next_room]:
                distances[next_room] = distances[current_room] + 1
                instructions[next_room] = current_room
                d.append(next_room)
    print('Yes')
    for v in instructions[1:]:
        print(v+1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 93196
#include<iostream>
using namespace std;
int n;
bool f[1<<15];
main()
{
	cin>>n;
	if(n<6)
	{
		cout<<(n==3?"2 5 63":n==4?"2 5 20 63":"2 5 20 30 63")<<endl;
	}
	else
	{
		int sum=0,i=2;
		for(;i<=3e4;i++)
		{
			if(i%2==0||i%3==0)
			{
				f[i]=1;
				sum+=i;
				n--;
				if(n==0)break;
			}
		}
		i++;
		if(sum%6==2)
		{
			f[8]=0;
			while(i%6)i++;
			f[i]=1;
		}
		else if(sum%6==3)
		{
			f[9]=0;
			while(i%6)i++;
			f[i]=1;
		}
		else if(sum%6==5)
		{
			f[9]=0;
			while(i%6!=4)i++;
			f[i]=1;
		}
		int s=0;
		for(int i=0;i<=3e4;i++)
		{
			if(f[i])
			{
				if(s++)cout<<" ";
				cout<<i;
			}
		}
		cout<<endl;
	}
}


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

signed main(void)
{
	int n, k, cnt;
	cin >> n >> k;
	vector<int> a(n);
	
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	cnt = 0;
	for (int i = 1; i < n; i++)
	{
		if (a[0] == a[i]) cnt++;
	}
	n -= cnt + 1;
	if (n < k)
		cnt = 1;
	else
	{
		cnt = n / (k - 1);
		if (n % (k - 1) != 0)
			cnt++;
	}
	cout << cnt << endl;
	return 0;
}


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

using namespace std;

int INF = 1e9 + 5;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int> (3));
    for (int i = 0; i < n; i++) {
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    
    vector<vector<int>> dp(n, vector<int> (3, -1));
    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];
    for (int i = 0; i < n-1; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (k != j) {
                    dp[i+1][k] = max(dp[i+1][k], a[i+1][k] + dp[i][j]);
                }
            }
        }
    }
    
    cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;
    return 0;
}

Measured memory_bytes: 11264
import sys
from collections import deque
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, x, y = map(int, input().split())
    tree = [[] for _ in range(n)]
    for i in range(1, n):
        tree[i - 1].append(i)
        tree[i].append(i - 1)

    tree[x - 1].append(y - 1)
    tree[y - 1].append(x - 1)

    def bfs(v):
        dist = [f_inf for _ in range(n)]
        dist[v] = 0
        q = deque()
        q.append(v)
        while q:
            u = q.popleft()
            for nv in tree[u]:
                if dist[nv] == f_inf:
                    dist[nv] = dist[u] + 1
                    q.append(nv)

        for d in dist:
            res[d] += 1

    res = [0 for _ in range(n)]
    for i in range(n):
        bfs(i)

    for j in range(1, n):
        print(res[j] // 2)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 4200
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <cmath>
#include <iomanip>

#define INF (int)1e8
#define EPS 1e-10
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define RFOR(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)
#define debug(x) cerr << #x << ": " << x << endl
#define all(a) (a).begin(), (a).end()
const long double PI=3.14159265358979323846264338327950288419716939937510L;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int, int> PII;

// vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len - 1) s << "\t";
    }
    return s;
}

// 2 dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
    int len = vv.size();
    for (int i = 0; i < len; ++i) {
        s << vv[i] << endl;
    }
    return s;
}

long double a, b, x;


long double mass(long double theta) {
    long double m;
    if (theta > PI / 2.0 - EPS)  {
        return 0.0;
    }
    if (a * tan(theta) <= b) {
        m = (2 * b - a * tanl(theta)) * a / 2.0L * a;
    } else {
        m = b * b * tanl(PI / 2.0L - theta) / 2.0 * a;
    }
    //debug(m);
    return m; 
}

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

    cin >> a >> b >> x;

    long double l = 0.0L;
    long double r = 90.0L;
    long double mid;

    REP (i, 2000) {
        mid = (l + r) / 2.0L;
        debug(mid);
        if (mass(mid / 180.0L * PI) >= x) {
            l = mid;
        } else {
            r = mid;
        }
    }

    cout << fixed << setprecision(10) << mid << endl;

    return 0;
}


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

using ll = long long;

bool f(ll x, vector<ll> &a) {
  ll v = a.at(x);
  for(int i = 0; i < a.size(); i++){
    if(i == x) continue;
    if(a.at(i) <= 2 * v) v += a.at(i);
    else return false;
  }
  return true;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<ll> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  
  sort(a.begin(), a.end());
  
  int left = -1, right = n - 1, mid;
  while(left + 1 < right){
    mid = (left + right) / 2;
    if(f(mid, a)) right = mid;
    else left = mid;
  }
  
  cout << n - right << '\n';
}

Measured memory_bytes: 1024
n = int(input())
a = list(map(int,input().split()))
b= list(map(int,input().split()))
c = list(map(int,input().split()))
 
m=0
 
for i in range (0,n):
  m += b[a[i]-1]
  if i !=0 and a[i]==a[i-1]+1:
    m += c[a[i-1]-1]
print(m)

Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<string>
#include<assert.h>
#include<sstream>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define setIO(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
typedef long long ll;
typedef pair<int, int> pii;
const ll LINF = 1e18 + 7;
const int N = 55;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
//-------------head-------------
int n, ave, x[N];
ll f[N][N * N];
int main() {
	scanf("%d%d", &n, &ave);
	rep(i, 1, n + 1)
		scanf("%d", &x[i]);
	memset(f, -1, sizeof(f));
	f[0][0] = 1;
	int sum = 0;
	rep(i, 1, n + 1)
	{
		sum += x[i];
		for (int j = i; j > 0; --j) {
			for (int k = sum; k >= x[i]; --k)
				if (~f[j - 1][k - x[i]]) {
					if (f[j][k] == -1) {
						f[j][k] = f[j - 1][k - x[i]];
					} else {
						f[j][k] += f[j - 1][k - x[i]];
					}
				}
		}
	}
	ll ans = 0;
	rep(i, 1, n + 1)
		if (~f[i][i * ave])
			ans += f[i][i * ave];
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1536
#include <iostream>

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <iomanip>
#include <numeric>

using namespace std;

typedef long long LL;
typedef unsigned int UI;

#define DescSort(a) sort(a.begin(),a.end(),std::greater<LL>())
#define Sort(a) sort(a.begin(),a.end())

int main(int argc, const char * argv[]) {

	cin.tie(0);
	ios::sync_with_stdio(false);

	LL N, M;
	LL ans = 0;

	cin >> N >> M;

	vector<LL>X((UI)M);

	for (int i = 0; i < M; i++) {
		cin >> X.at(i);
	}

	Sort(X);

	vector<LL>L((UI)M, 0);

	for (int i = 1; i < M; i++) {
		L[i] = X[i] - X[i - 1];
	}

	Sort(L);

	for (int i = 0; i < M - N + 1; i++) {
		ans += L[i];
	}

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <tuple>
#include <cstdio>
#include <numeric>

using namespace std;
int main() {
    int A, B, C;
    cin >> A >> B >> C;

    A -= B;
    C -= A;

    if (C < 0) {
        cout << 0 << endl;
    } else {
        cout << C << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>

using namespace std;

int cards[200];
int temp[200];

int main(){
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < 2 * n; i++){ cards[i] = i + 1; }
	while(m--){
		int k;
		cin >> k;
		memcpy(temp, cards, sizeof(int) * n * 2);
		if(k == 0){
			for(int i = 0; i < 2 * n; i++){
				cards[i] = temp[(i % 2) * n + (i / 2)];
			}
		}else{
			for(int i = k; i < 2 * n; i++){ cards[i - k] = temp[i]; }
			for(int i = 0; i < k; i++){ cards[2 * n + i - k] = temp[i]; }
		}
	}
	for(int i = 0; i < 2 * n; i++){
		cout << cards[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int n,a[105],i,maxx,minn=999999999;
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        if(maxx<abs(a[i])) maxx=abs(a[i]);
        if(minn>abs(a[i])) minn=abs(a[i]);
    }
    cout<<maxx-minn;
    return 0;
}

Measured memory_bytes: 256
fn getline() -> String{
  let mut __ret=String::new();
  std::io::stdin().read_line(&mut __ret).ok();
  return __ret;
}

fn main() {
  let line = getline();
  
  for i in 0..26 {
    let c = std::char::from_u32(0x61 + i).unwrap();
    if line.find(c) == None {
      println!("{}", c);
      break;
    }
    if i == 25 {
      println!("None");
    }
  }
}

Measured memory_bytes: 4352
import java.util.Scanner;

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

        while (n > 0) {
            sum = sum + n % 10;
            n = n / 10;
        }
        if (originalN % sum > 0) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }

    }
}

Measured memory_bytes: 21588
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

int h, w;
int n;
vector<int> graph[400];

int ceil(int x, int y) { return (x % y == 0) ? x / y : x / y + 1; }

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

int lcm(int x, int y) { return x / gcd(x, y) * y; }

void bfs(int s, int dist[]) {
  fill(dist, dist + n, INF_INT);
  dist[s] = 0;
  queue<int> que;
  que.push(s);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (int t : graph[v]) {
      if (dist[t] > dist[v] + 1) {
        dist[t] = dist[v] + 1;
        que.push(t);
      }
    }
  }
}

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

  cin >> h >> w;
  n = h * w;
  string s[20];
  for (int i = 0; i < h; i++) cin >> s[i];

  int dw[] = {1, 0, -1, 0};
  int dh[] = {0, 1, 0, -1};
  int v = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '.') {
        for (int k = 0; k < 4; k++) {
          int i2 = i + dh[k];
          int j2 = j + dw[k];
          if (i2 < 0 || i2 >= h) continue;
          if (j2 < 0 || j2 >= w) continue;
          int t = i2 * w + j2;
          if (s[i2][j2] == '.') {
            graph[v].push_back(t);
          }
        }
      }
      ++v;
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int dist[n];
    bfs(i, dist);
    for (int j = 0; j < n; j++) {
      if (dist[j] != INF_INT) ans = max(ans, dist[j]);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1144
#include<iostream>
#include<cstdio>
using namespace std;
int f[100010],w[101],v[101];
int main ()
{
	int n,z,i,j;
	scanf("%d%d",&n,&z);
	for(i=1;i<=n;++i) scanf("%d%d",&w[i],&v[i]);
	for(i=1;i<=100000;++i) f[i]=z+1;
	for(i=1;i<=n;++i)
	  for(j=100000;j>=v[i];--j) f[j]=min(f[j],f[j-v[i]]+w[i]);
	for(i=100000;i>=0;--i) 
	  if(f[i]<=z)
	  {
	  	printf("%d",i);
	  	break;
	  }
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

/*
    even 2:1,...,n-1
    odd 1:0,2:n-1,n-3,...,2
    1 2 3 4 5
    4 2 0 2 4

    1 2 3 4
    3 1 1 3
    1 2 3 4 5 6 7 8
    7 5 3 1 1 3 5 7
*/

void solve(){
    int n;
    cin >> n;
    vector<int> count(100010);
    rep(i,0,n){
        int a;
        cin >> a;
        ++count[a];
    }
    int64_t ans=1,mod=1e9+7;
    if(n%2==0){
        for(int i=1; i<=n-1; i+=2){
            if(count[i]!=2) ans*=0;
            else ans=ans*2%mod;
        }
    }else{
        if(count[0]!=1) ans=0;
        for(int i=2; i<=n-1; i+=2){
            if(count[i]!=2) ans*=0;
            else ans=ans*2%mod;
        }
    }
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 640