akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

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

int main(){
    ll n;
    cin >> n;
    vector<ll> t(n), a(n);
    REP(i, n){
        cin >> t.at(i);
    }
    REP(i, n){
        cin >> a.at(i);
    }

    vector<pair<ll, ll>> h(n, make_pair(1, 1000000000));
    ll prev_t = 0;
    REP(i, n){
        if(t.at(i) > prev_t){
            h.at(i).first = max(h.at(i).first, t.at(i));
        }
        h.at(i).second = min(h.at(i).second, t.at(i));
        prev_t = t.at(i);
    }

    ll prev_a = 0;
    for(ll i = n - 1; i >= 0; --i){
        if(a.at(i) > prev_a){
            h.at(i).first = max(h.at(i).first, a.at(i));
        }
        h.at(i).second = min(h.at(i).second, a.at(i));
        prev_a = a.at(i);
    }

    ll ans = 1;
    for(auto p : h){
        if(p.first > p.second){
            ans = 0;
            break;
        }else{
            ans *= (p.second - p.first + 1);
            ans %= 1000000007;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  ll N;
  cin >> N;
  vector<char> W(26);
  W[0] = 'z';
  rep(i,25) W[i+1] = 'a' + i;
  
  vector<int> D;
  while (N > 0) {
    D.push_back(N%26);
    if (N%26==0)
      N = N/26 - 1;
    else
      N /= 26;
  }
  
  reverse(D.begin(),D.end());
  string ans;
  for (int J : D) {
    ans += W[J];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"

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

typedef long long LL;
typedef unsigned long UL;

using namespace std;


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

	int n;
	cin >> n;

	string s;
	vector<int> abc('z' - 'a' + 1, INT_MAX);

	REP(i, n)
	{
		cin >> s;
		
		for (char j = 'a'; j <= 'z'; ++j)
		{
			abc[j - 'a'] = min((int)count(s.begin(), s.end(), j), (int)abc[j - 'a']);
		}
	}

	for (char i = 'a'; i <= 'z'; ++i)
	{
		REP(j, abc[i - 'a'])
		{
			cout << i;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n; cin >> n;
	VVI a(10, VI(10, 0));
	ll ans = 0;
	REP(i, n) {
		string s = to_string(i + 1);
		a[s[0] - '0'][s[s.size() - 1] - '0']++;
	}
	REP(i, 9)REP(j, 9)ans += a[i + 1][j + 1] * a[j + 1][i + 1];
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
#define ll long long int
void readtxt()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}

int main() 
{ 
    //readtxt();
    string s, t;
    cin >> s >> t;
    int ss = s.size();
    string tt = t.substr(0,ss);
    //cout << tt << endl;
    if(tt==s)cout << "Yes" << endl;
    else cout << "No" << endl;
    
} 

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
const int sz=1e5+9;
int n,m;
int f[sz],t[sz];
vector<long long> v;
int p[sz],s[sz];
long long ans,cnt;
 
int findp(int a)
{
    return (a==p[a]?a:p[a]=findp(p[a]));
}
 
bool same(int a,int b)
{
    return findp(a)==findp(b);
}
 
long long unite(int a,int b)
{
    long long ret;
    a=findp(a);
    b=findp(b);
    ret=s[a];
    s[a]+=s[b];
    p[b]=a;
    ret*=s[b];
    return ret;
}
 
int main()
{
    
    cin >> n >> m;
    for(int i=0;i<m;i++) cin >> f[i] >> t[i];
    for(int i=1;i<=n;i++)
    {
        p[i]=i;
        s[i]=1;
    }
    ans=n;
    ans*=(n-1);
    ans>>=1;
    for(int i=m-1;i>=0;i--)
    {
        v.push_back(ans);
        if(!same(f[i],t[i]))
        {
            cnt=unite(f[i],t[i]);
            ans-=cnt;
        }
    }
    
    for(int i=v.size()-1;i>=0;i--) cout << v[i] << '\n';
    
    return 0;
}

Measured memory_bytes: 3828
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static StreamReader sr;

        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)998244353;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NMVP = Sarray();
            var N = NMVP[0];//問題数
            var M = NMVP[1];//ジャッジの人数
            var V = NMVP[2];//V問選ぶ
            var P = NMVP[3];//P位まで採用される
            // N-V問の点数を下げると考える
            var Ai = Sarray();
            Array.Sort(Ai);
            var rui = new long[N + 1];
            for (var i = 0; i < N; ++i)
                rui[i + 1] = rui[i] + Ai[i];
            var tp = N - P;// Ai[tp]以上にできればよい
            var ans = P;
            for (var i = tp - 1; 0 <= i; --i)
            {
                if (Ai[i] + M < Ai[tp])//無理
                    break;
                var df = tp - i;
                if ((N - V) * M < rui[tp + 1] - rui[i + 1] - df * Ai[i]) //無理
                    break;
                ++ans;
            }
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 23904
#include <iostream>
#include <string>
#include <stdio.h>
#include <set>
#include <map>
#include <vector>

using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
// #define req(j, n) for (ll j = 1; j < (n+1); j++)
// #define rer(k, n) for (ll k = 1; k < (n+1); k++)



int main()
{
    ll A, B, C;
    cin >> A >> B >> C;
    cout << C << endl;
    cout << A << endl;
    cout << B << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int A , B , mult , sum , sub  ;
    cin >> A >> B ;
    sum = A+B ;
    sub = A -B ;
     mult = A * B ;

    if ( mult > sub && mult > sum )
        cout << mult ;
    else if (sub > mult && sub >sum)
        cout << sub ;
    else cout << sum ;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second

#define MAX_N 6000

int cell[MAX_N + 1][MAX_N + 1];

void query(int xm,int xM,int ym,int yM,int d) {//[xm,xM),[ym,yM)+=d
	cell[ym][xm]+=d;
	cell[ym][xM]-=d;
	cell[yM][xm]-=d;
	cell[yM][xM]+=d;
}

void imosu(int x,int y) {
	REP(i,y) {
		FOR(j,1,x) {
			cell[i][j] += cell[i][j - 1];
		}
	}

	REP(i,x) {
		FOR(j,1,y) {
			cell[j][i] += cell[j - 1][i];
		}
	}
}
int n,k;


void query2(int x,int y) {
	query(x,x + k,y,y + k,1);
	if(x + k > 2 * k) {
		query(0,x + k - 2 * k,y,y + k,1);
	}
	if(y + k > 2 * k) {
		query(x,x + k,0,y + k - 2 * k,1);
	}
	if(x + k > 2 * k && y + k > 2 * k) {
		query(0,x + k - 2 * k,0 ,y + k - 2 * k,1);
	}
}

signed main(void) {
	cin >> n >> k;

	REP(l,n) {
		int x,y;
		char c;
		cin >> x >> y >> c;
		if(c == 'W')
			y += k;
		x %= (2 * k);
		y %= (2 * k);

		query2(x,y);

		x = (x + k) % (2 * k);
		y = (y + k) % (2 * k);
		query2(x,y);
	}
	imosu(2 * k,2 * k) ;
	int ans = 0;

	REP(i,2 * k) {
		REP(j , 2 * k) {
			ans = max(cell[i][j],ans);
		}
	}
	cout << ans << endl;
	return 0;
}


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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<double> v;

    REP(i,n){
        double t;
        cin >> t;
        v.pb((double)t);
    }

    sort(v.begin(),v.end(),greater<double>());

    FORB(i,(n-1),1){
        double a = v[i] + v[i-1];
        a /= 2.0;

        v.popb();
        v.popb();
        v.pb(a);
        sort(v.begin(),v.end(),greater<double>());
    }

    cout << v[0] << endl;
}

Measured memory_bytes: 256
/*
 * Coder: @SumitRaut
 */
#include <bits/stdc++.h>

using namespace std;
inline void solve() {
    double D,T,S;
    cin>>D>>T>>S;
    if(D/S>T) cout<<"No\n";
    else cout<<"Yes\n";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // int t; cin>>t; while(t--)
        solve();
    return 0;
}


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

long long INF = 1e18;

int main(){
    string s;
    cin>>s;
    if(s == "AAA" || s == "BBB"){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3


def main():
    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))

    ans = 0
    for i in range(N):
        if As[i] >= Bs[i]:
            ans += Bs[i]
        else:
            ans += As[i]
            ans += min(Bs[i] - As[i], As[i+1])
            As[i+1] -= Bs[i] - As[i]
            As[i+1] = max(0, As[i+1])

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18476
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) //[l, r)
#define rep(i,n) REP(i,0,n)           //[0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showslr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl //[l, r)

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}

void _DEBUG(){cerr<<endl;}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<",";_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<endl;out(b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int n;
int res=0;


signed main(){
    io();

    in(n);
    int a,b;
    rep(i,n){
        in(a, b);
        res+=b-a+1;
    }
    out(res);

    return 0;
}


Measured memory_bytes: 256
//Name: Packet Transportation
//Level: 2
//Category: グラフ,Graph,全点対間最短距離
//Note:

/**
 * 全点対間の最短距離を求めておけば良い。
 * オーダーは O(N^3)。
 */
#include <iostream>
#include <vector>

using namespace std;

template <typename T>
struct Maybe {/*{{{*/
    T val;
    bool valid;

    Maybe() : valid(false) {}
    Maybe(T &t) : val(t), valid(true) {}

    T& operator =(const T &rv) {
        val = rv;
        valid = true;
        return val;
    }

    operator T() const {
        return valid ? val : T();
    }

    template<typename Cond>
    bool update(const T &v, Cond cond) {
        if(!valid || cond(v, val)) {
            val = v;
            valid = true;
            return true;
        }
        return false;
    }

    bool update(const T &v) {
        return update(v, less<T>());
    }
};/*}}}*/

template<typename T>
struct WarshallFloyd {
    vector<vector<Maybe<T>>> graph;
    int N;

    WarshallFloyd(int size) : graph(size), N(size) {
        for(auto &v : graph) {
            v.resize(size);
        }
    }

    void add_edge(int from, int to, const T &dist) {
        graph[from][to] = dist;
    }

    void freeze() {
        for(int k = 0; k < N; ++k) {
            for(int i = 0; i < N; ++i) {
                for(int j = 0; j < N; ++j) {
                    if(graph[i][k].valid && graph[k][j].valid) {
                        graph[i][j].update(graph[i][k] + graph[k][j]);
                    }
                }
            }
        }
    }

    const Maybe<T>& query(int from, int to) {
        return graph[from][to];
    }
};

bool solve(bool first) {
    int N;
    if(!(cin >> N)) return false;
    if(!N) return false;

    WarshallFloyd<int> wf(N);
    for(int i = 0; i < N; ++i) {
        int from, k;
        cin >> from >> k;
        --from;
        while(k--) {
            int v;
            cin >> v;
            wf.add_edge(from, v-1, 1);
        }
    }
    wf.freeze();
    int P;
    cin >> P;
    while(P--) {
        int s, d, t;
        cin >> s >> d >> t;
        const auto &dist = wf.query(s-1, d-1);
        if(dist.valid && dist+1 <= t) {
            cout << dist+1 << endl;
        } else {
            cout << "NA" << endl;
        }
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(2);

    bool first = true;
    while(solve(first)) {
        first = false;
    }
    return 0;
}

Measured memory_bytes: 1284
import heapq
N = int(input())
X = []
Y = []
for n in range(N):
    x, y = map(int,input().split())
    X.append((x, n))
    Y.append((y, n))
X.sort()
Y.sort()
adj = [ [] for v in range(N)]
for n in range(N-1):
    cost = X[n+1][0] - X[n][0]
    adj[X[n+1][1]].append((cost, X[n][1]))
    adj[X[n][1]].append((cost, X[n+1][1]))
    cost = Y[n+1][0] - Y[n][0]
    adj[Y[n+1][1]].append((cost, Y[n][1]))
    adj[Y[n][1]].append((cost, Y[n+1][1]))

visited = [0] * N
pq = []
for w, t in adj[0]:
    heapq.heappush(pq, (w, t))
visited[0] = 1

ans = 0
while(pq):
    w, t = heapq.heappop(pq)
    if visited[t]:
        continue
    visited[t] = 1
    ans += w
    for w, s in adj[t]:
        if visited[s]==0:
            heapq.heappush(pq, (w, s))
print (ans)

Measured memory_bytes: 78904
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <math.h>
#include <cstdlib>
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;
using ll = long long;

int main()
{
    string s;
    cin>>s;
    if(s[1]=='B')
    {
        cout<<"ARC";
    }
    else
                cout<<"ABC";

    return 0;
}


Measured memory_bytes: 3624
a, b, c, d = map(int, input().split())
i = 0
r = ''
while True:
	if i % 2 == 0:
		c -= b
		if c <= 0:
			r = 'Yes'
			break
	else:
		a -= d
		if a <= 0:
			r = 'No'
			break
	i += 1
print(r)

Measured memory_bytes: 61824
X, K, D = map(int, input().split())
if X < 0:
    X = -X
steps, res = divmod(X, D)
if steps >= K:
    print(X - D * K)
else:
    K -= steps
    if K % 2 == 0:
        print(res)
    else:
        print(min(res + D, abs(res - D)))


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

	vector<string> S(N);
	
	
	rep(i,N){
		cin >> S[i];
	}
	
	sort(S.begin(),S.end());
	
	string ans="";
	
	rep(i,N){
		ans+=S[i];
	}
		
  
    cout << ans << 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);
			int N = sc.nextInt();
			String[] S = new String[N];

			for(int i = 0 ; i < N ; i++){
				S[i] = sc.next();
			}


		sc.close();

		int result = 0;
		int count = 0;
		int Acount = 0;
		int Bcount = 0;
		int ABcount = 0;

		for(int i = 0 ; i < N ; i++){

			if(S[i].substring(0, 1).equals("B") && !S[i].substring(S[i].length()-1, S[i].length()).equals("A")){
				Bcount++;
			}
			if(!S[i].substring(0, 1).equals("B") &&S[i].substring(S[i].length()-1, S[i].length()).equals("A")){
				Acount++;
			}
			if(S[i].substring(0, 1).equals("B") && S[i].substring(S[i].length()-1, S[i].length()).equals("A")){
				ABcount++;
			}



	        for (int j = 0; j < S[i].length(); j++) {
	            result = S[i].indexOf("AB", j);
	            if (result != -1) {
	                count++;
	                j = result;
	            }
	        }
		}

		if(ABcount == 0){
			System.out.println(Math.min(Acount, Bcount)+count);
		}
		else if(Acount + Bcount > 0){
			System.out.println(ABcount + Math.min(Acount, Bcount)+count);
		}
		else if(Acount + Bcount == 0){
			System.out.println(count+ABcount-1);
		}

	}
}

Measured memory_bytes: 32388
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	s := nextStr()

	idxA := -1
	idxZ := -1
	for i := 0; i < len(s); i++ {
		if idxA == -1 && s[i] == 'A' {
			idxA = i
		}
		if idxZ == -1 && s[len(s)-i-1] == 'Z' {
			idxZ = len(s) - i
		}
	}

	fmt.Println(idxZ - idxA)

}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 2172
w = input()
n = len(w)

chrs = [chr(i) for i in range(97, 97+26)]
lis = [0]*26

for i in range(26):
  tmp = w.count(chrs[i])
  lis[i] = tmp

for i in range(26):
  if lis[i]%2!=0:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 38480
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main() {
	int N,K;
	cin >> N >> K;
	bool ng[256]={};
	for(int i=0;i<K;i++){
		int a;
		cin >> a;
		ng[a+'0']=true;
	}
	while(1){
		ostringstream ostr;
		ostr<<N;
		string ret=ostr.str();
		bool ok=true;
		for(auto c:ret){
			if(ng[(int)c]){
				ok=false;
				break;
			}
		}
		if(ok){
			cout << N << endl;
			break;
		}
		N++;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define numa(x,a) for(auto x: a)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define pf push_front
#define sec second
#define sz(x) ((int)(x).size())
#define ALL( c ) (c).begin(), (c).end()
#define gcd(a,b) __gcd(a,b)
#define mem(x,n) memset(x,n,sizeof(x))
#define endl "\n"
using namespace std;
template <int POS, class TUPLE> void deploy(std::ostream &os, const TUPLE &tuple){}
template <int POS, class TUPLE, class H, class ...Ts> void deploy(std::ostream &os, const TUPLE &t){ os << (POS == 0 ? "" : ", ") << get<POS>(t); deploy<POS + 1, TUPLE, Ts...>(os, t); }
template <class T,class U> std::ostream& operator<<(std::ostream &os, std::pair<T,U> &p){ os << "(" << p.first <<", " << p.second <<")";return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::vector<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::set<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T, class K> std::ostream& operator<<(std::ostream &os, std::map<T, K> &mp){ int remain = mp.size(); os << "{"; for(auto e: mp) os << "(" << e.first << " -> " << e.second << ")" << (--remain == 0 ? "}" : ", "); return os; }
#define DEBUG1(var0) { std::cerr << (#var0) << "=" << (var0) << endl; }
#define DEBUG2(var0, var1) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG1(var1); }
#define DEBUG3(var0, var1, var2) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG2(var1,var2); }
#define DEBUG4(var0, var1, var2, var3) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG3(var1,var2,var3); }
using ll = long long;

ll memo[60][2600][60];

int main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int N,A;
  cin >> N >> A;
  vector <int> nums(N);
  for (int i = 0; i < N; i++) {
    cin >> nums[i];
  }
  memo[0][0][0] = 1;
  for (int i = 0; i < N; i++) {
    int x = nums[i];
    for (int j = 0; j <= A * N; j++) {
      for (int k = 0; k <= N; k++) {
        if (memo[i][j][k] > 0) {
          memo[i+1][j][k] += memo[i][j][k];
          if (j + x <= N * A) {
            memo[i+1][j+x][k+1] += memo[i][j][k];
          }
        }
      }
    }
  }
  ll ans = 0;
  for (int j = 1; j <= N * A; j++) {
    if (j % A == 0) {
      ans += memo[N][j][j / A];
    }
  }
  cout << ans << endl;


  return 0;
}



Measured memory_bytes: 15616
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }
template<class T>
ostream &operator<<(ostream &os,const vector<T> &v){
	for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i];
	os << "]";
	return os;
}

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n;
	cin >> n;
	cout << (n + 1) / 2 << endl;
}

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

#define int long long

signed main(){
  int n;
  cin >> n;
  
  double a[n+1];
  for(int i = 1;i<=n;i++)cin >> a[i];
  
  sort(a+1,a+n+1);
  double ans = a[1];
  
  for(int i = 2;i<=n;i++){
    ans = (ans+a[i])/2.0;
  }
  cout << fixed << setprecision(10) << ans << endl;
  
  return 0;
}

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

using namespace std;

    string ReplaceString(
        string String1,
        string String2,
        string String3
    ){
        std::string::size_type Pos(String1.find(String2));
        while (Pos != std::string::npos) {
            String1.replace(Pos, String2.length(), String3);
            Pos = String1.find(String2, Pos + String3.length());
        }

    return String1;
    }

int main() {
    string S;
    cin >> S;

    string str = ReplaceString(S,"?","D");

    cout << str << endl;

    return 0;
}

Measured memory_bytes: 3924
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
#define INF 1e9
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll N, M, Q;
ll A[100000];
ll ans;
string S;
ll K;
map<ll, ll> m;
int main() {
	cin >> N >> M;
	cin >> A[0];
	m[0]++;
	ans += m[A[0] % M];
	m[A[0] % M]++;
	rep(i, 1, N) {
		cin >> A[i];
		A[i] += A[i - 1];
		ans += m[A[i] % M];
		m[A[i] % M]++;
	}
	cout << ans << endl;
	cin >> ans;
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = (1 << 30) - 1;

int H, W, ans, cost[1111][1111], dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
char grid[1111][1111];

int main()
{
    cin >> H >> W;

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> grid[i][j];
            cost[i][j] = inf;
        }
    }

    queue<pair<int, pair<int, int>>> que;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (grid[i][j] == '#')
            {
                que.emplace(0, make_pair(i, j));
            }
        }
    }

    while (!que.empty())
    {
        auto p = que.front();
        que.pop();
        int y = p.second.first, x = p.second.second, cnt = p.first;
        if (cost[y][x] != inf)
            continue;
        cost[y][x] = cnt, grid[y][x] = '#', cnt++;
        for (int i = 0; i < 4; i++)
        {
            int ny = y + dy[i], nx = x + dx[i];
            if ((ny < 0 || ny >= H) || (nx < 0 || nx >= W) || (grid[ny][nx] == '#'))
                continue;
            que.emplace(cnt, make_pair(ny, nx));
        }
    }

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            ans = max(cost[i][j], ans);
        }
    }
    cout << ans << endl;
}


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

int main() {
	long long a, b; cin >> a >> b;
	if (a > b)swap(a, b);
	int dis = abs(a - b);

	if (dis % 2 == 0) {
		cout << a + dis / 2 << endl;
		return 0;
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

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

int main() {
  int n;
  cin>>n;
  string s,t;
  cin>>s>>t;
  int j;
  int a=n;
  for(int i=0;i<n;i++){
    for(j=0;j<n-i;j++)if(s[i+j]!=t[j])break;
    if(j==n-i){
      a=i;break;
    }
  }
  cout<<n+a<<endl;
}


Measured memory_bytes: 256
//K-OS WITH THE OCDE

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

using namespace std;

typedef long long int ll;
typedef long double db;


#define TEST ll t; cin>>t; while(t--)
#define vell vector<ll>
#define pl pair<ll,ll>
#define all(v) v.begin(),v.end()
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define dbg(x)  cerr << #x << ": "<< x <<endl
#define dbg2(x,y) cerr<< #x <<": "<< x <<" || "<< #y << ": " << y << endl

#define endl "\n"
#define MAX 1e18
#define MIN INT_MIN
// #define mod 1000000007

const int mxn = 2e5 + 2;
int gre[200005];
ll low[200005];
ll store[mxn];

ll mult(ll x , ll y , ll mod)
{
    return (((x % mod) * (y % mod)) % mod);
}
void pre()
{
    for (ll i = 0 ; i < mxn ; ++i) {

        ll x = i;
        ll count = 0;
        while (x) {

            ll y = __builtin_popcount(x);
            x %= y;
            count++;
        }

        store[i] = count;
    }

    // dbg2(store[1] , store[0]);
}

void prel(ll k , ll n)
{
    low[0] = 1 % k;

    for (ll i = 1 ; i < n ; ++i) {

        low[i] = mult(low[i - 1] , (2 % k) , k);
        low[i] %= k;
        //  cout << low[i] << " ";
    }
}

void preg(ll k , ll n)
{
    gre[0] = 1 % k;

    for (ll i = 1 ; i < n ; ++i) {

        gre[i] = mult(gre[i - 1] , (2 % k) , k);
        gre[i] %= k;
        // cout << gre[i] << " ";
    }
}

ll small = 0 , large = 0;

void sl(ll k , string s , ll n)
{
    ll i = 0 , j = n - 1;

    while (i < n) {

        if (s[j] == '1') {
            small += low[i];
            small %= k;
        }
        i++;
        j--;
    }



}

void sg(ll k , string s , ll n)
{
    ll i = 0 , j = n - 1;

    while (i < n) {

        if (s[j] == '1') {
            large += gre[i];
            large %= k;
        }
        i++;
        j--;
    }

}

void solve()
{
    ll n;
    cin >> n;
    string s;
    cin >> s;

    ll f = 0;
    for (ll i = 0; i < n ; ++i) {

        f += (s[i] == '1');
    }

    if (f - 1)
        prel(f - 1 , n);
    preg(f + 1 , n);
    if (f - 1)
        sl(f - 1, s , n);
    sg(f + 1, s, n);

    for (ll i = 0 ; i < n ; ++i) {
        ll x = 0;
        if (s[i] == '1' && f - 1 == 0) {
            cout << 0 << endl;
            continue;
        }

        if (s[i] == '1') {
            x = (small - low[n - i - 1] + (f - 1)) % (f - 1);
        }
        else if (s[i] == '0') {
            x = (large + gre[n - i - 1] + (f + 1));
            x %= (f + 1);

        }

        cout << 1 + store[x] << endl;
    }



}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0); cin.tie(0);
    //TEST
    pre();
    solve();
}



Measured memory_bytes: 7716
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAXN = 15;
char s[MAXN];
int main() {
    ios::sync_with_stdio(false);
    while(cin >> s){
        int len = strlen(s);
        long long ans = 0;
        for(int i = 0; i < (1 << (len - 1)); i++){
            long long t = s[0] - '0';
            for(int j = 0; j < len; j++){
                if(j == len - 1 || i & (1 << j)){
                    ans += t;
                    t = 0;
                    if(len - 1 == j) 
						break;
                }
                t *= 10;
                t += s[j + 1] - '0';
            }
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn = 2e5 + 10;
vector<long long>v;
vector<long long>u;
int C(int n)
{
	return n * (n - 1) / 2;
}
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		long long num;
		cin >> num;
		v.push_back(i * 1LL + num);
		u.push_back(i * 1LL - num);
	}
	sort(v.begin(), v.end());
	sort(u.begin(), u.end());
	long long ans = 0;
	int last = 0;
	for (int i = 0; i < n; i++)
	{
		long long now = 0;
		for (int j = last; j < n; j++)
		{
			if (u[i] > v[j])
				continue;
			else if (u[i] == v[j])
			{
				ans++;
				now++;
			}
			else if (u[i] < v[j])
			{
				while (i != n - 1 && u[i + 1] == u[i])
				{
					ans += now;
					i++;
				}
				last = j;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
    int n, m; cin >> n >> m;
    
    const int p = 100010;

    vector<int> acNum(p, 0), waNum(p, 0);
    for (int i = 0; i < m; i++) {
        int p;
        string s;
        cin >> p >> s;

        if (s == "AC") {
            acNum[p] = 1;
        }
        else {
            if (acNum[p] == 0) waNum[p]++;
        }
    }

    int ans_first = 0;
    int ans_second = 0;

    for (int i = 0; i < p; i++) {
        if (0 < acNum[i]) ans_first++;
        if (0 < waNum[i] && 0 < acNum[i]) ans_second += waNum[i];
    }

    cout << ans_first << " " << ans_second << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.io.*;

class Main
{
    public static void main (String args[]) throws IOException         //?????????
    {
        InputStreamReader is = new InputStreamReader(System.in);       //?????????
        BufferedReader br = new BufferedReader(is);                    //?????????

        String inStr = br.readLine();        // ??????????????\???
        int a = Integer.parseInt(inStr);    // ??´??°?????????
                
        int x = Power(a, 3);
        
        System.out.println(x);
    }

    static private int Power(int a, int n){
        int f = a;
    
        if(n == 0){
            return 1;
        }

        for(int i=n; i>1; i--){
            f *= a;
        }
        
        return f;
    }

}
    

Measured memory_bytes: 24176
N = int(input())
X = list(map(int, input().split()))
m = max(X)
res = float('Inf')
for m in range(1, m+1):
    total = 0
    for n in range(N):
        total += (X[n] - m)**2
    if res > total:
        res = total
print(res)

Measured memory_bytes: 3060
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


x = II()
a = II()
b = II()
print((x - a) % b)


Measured memory_bytes: 68444
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back
#define REP(i,a,b) for(int i=a; i<=b; i++)
#define MOD 1000000007

void solve(int test_case) {//209
	ll n,m;
	cin>>n>>m;
	if(abs(n-m)>1) {
		cout<<0;
		return;
	}
	ll ans = 1;
	if(n==m)ans=2;
	REP(i,2,n)ans = (ans*i)%MOD;
	REP(i,2,m)ans = (ans*i)%MOD;
	cout<<ans;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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

typedef long long ll;

#define PB push_back
#define MP make_pair

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
    string s; cin >> s;
    int nz = 0, no = 0;
    for (auto i : s) {
        if (i == '1') no++;
        else nz++;
    }
    cout << min(nz, no) * 2 << "\n";
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* print new lines
*/

Measured memory_bytes: 640
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
using namespace std;

int main()
{
    fast_io
    ll i;
    string s;
    cin>>s;
    for(i=1; s[i]; i++)
    {
    if(s[i-1]==s[i])
        return cout<<"Bad"<<endl,0;
    }
    cout<<"Good"<<endl;
   return 0;
}





Measured memory_bytes: 3656
readline()
A = map(x->parse(Int, x), split(readline()))

for i in 1:length(A)-1
  if A[i] < 0
    A[i] *= -1
    A[i+1] *= -1
  end
end
if A[end] >= 0
  println(sum(A))
else
  A[end] *= -1
  println(sum(A) - 2minimum(A))
end

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

const int INF = 1000000;
int c[10][10];
int d[10];
bool used[10];

void dijkstra()
{
    fill(d, d + 10, INF);
    fill(used, used + 10, false);
    d[1] = 0;
    while(1){
        int now = -1;
        int v = INF;
        for(int i = 0; i < 10; i++){
            if(!used[i] && d[i] < v){
                now = i;
                v = d[i];
            }
        }
        if(now == -1) break;
        used[now] = true;
        for(int i = 0; i < 10; i++){
            d[i] = min(d[i], d[now] + c[i][now]);
        }
    }
}

int main()
{
    int h, w;
    cin >> h >> w;
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            cin >> c[i][j];
        }
    }
    dijkstra();
    int ans = 0;
    int a[205][205];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> a[i][j];
            if(a[i][j] != -1) ans += d[a[i][j]];
        }
    }
    cout << ans << endl;
}

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

int N,A,B,C,D;
string S;

signed main(){
	cin>>N>>A>>B>>C>>D>>S;
	if(C<D||C<B){
		for(int i=A-1;i<C-1;i++){
			if(S[i]=='#'&&S[i+1]=='#'){
				cout<<"No"<<endl;
				return 0;
			}
		}
		for(int i=B-1;i<D-1;i++){
			if(S[i]=='#'&&S[i+1]=='#'){
				cout<<"No"<<endl;
				return 0;
			}
		}
		cout<<"Yes"<<endl;
	}
	else{
		for(int i=A-1;i<C-1;i++){
			if(S[i]=='#'&&S[i+1]=='#'){
				cout<<"No"<<endl;
				return 0;
			}
		}
		for(int i=B-1;i<D-1;i++){
			if(S[i]=='#'&&S[i+1]=='#'){
				cout<<"No"<<endl;
				return 0;
			}
		}
		for(int i=B-2;i<D-1;i++){
			if(S[i]=='.'&&S[i+1]=='.'&&S[i+2]=='.'){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define PR pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;

#define int ll
#define MAX 100005

// AOJ Country Road

signed main(){
  int t;
  cin>>t;
  for(int i=0; i<t; i++){
    int houses[MAX];
    vector<int> vec;
    int fir=0,last=0;
    int n,k;
    cin>>n>>k;
    for(int j=1; j<=n; j++) {
      cin>>houses[j];
      if(j==1) fir=houses[j];
      if(j==n) last=houses[j];
    }
    
    if(n<=k){
      cout<<0<<en
      continue;
    }
    int dis=last-fir;
    for(int j=1; j<=n; j++){
      vec.push_back(houses[j+1]-houses[j]);
    }
    
    sort(vec.begin(), vec.end(),greater<int>());
    for(int j=0; j<k-1; j++){
      dis-=vec[j];
    }
    
    cout<<dis<<en
  }
}



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

int main() {
  double n;
  cin >> n;
  vector<int>a(n);
  int sum =0;
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    sum +=a.at(i);
  }
  double ave= (sum/n);
  double dx =1<<30;
  int ans;
  for(int i=0;i<n;i++){
    if( dx > abs(a.at(i) - ave)){
      dx = abs(a.at(i)-ave);
      ans = i;
    }
  }
  cout <<ans;
       
       
}


Measured memory_bytes: 256
K,A,B = map(int,input().split())

bisket = 1

if B <= A + 1 :
    bisket = K + 1
elif K <= A :
    bisket = K + 1
else :
    exCount =  (K + 1 - A) // 2
    hit = (K + 1 - A) % 2
    bisket = exCount * (B-A) + A + hit

print(bisket)
    

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 1e17;
const char ENDL = '\n';

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    ll d = 1;
    int ans = 10;
    while(d*d<=n){
        if (n%d==0){
            ll x = n / d;
            int cnt = 0;
            while (x>0){
                cnt++;
                x /= 10;
            }
            ans = min(ans, cnt);
        }
        d++;
    }
    cout << ans << ENDL;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long K = sc.nextLong();
        long Q = sc.nextLong();

        long[] list = new long[N];
        for (int i=0; i < N ; i++) {
        	list[i] = K - Q ;
        }

        for (int i = 0; i < Q ; i ++) {
        	list[sc.nextInt()-1] += 1;
        }
        sc.close();
        for (int i=0; i < N ; i++) {
        	if (list[i] > 0) {
        		System.out.println("Yes");
        	}
        	else {
        		System.out.println("No");
        	}
        }
    }
}

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

int n;
char s[100005];
ll dp[100005][13];

const int MOD=1000000000+7;

int main(){
  int i,j,k;
  string s;
  cin >> s;
  ll res=0;
  n=s.size();

  dp[0][0]=1;
  for(i=0;i<n;++i){
    int c;
    if(s[i]=='?') c=-1;
    else c=s[i]-'0';

    for(j=0;j<10;++j){
      if(c!=-1 && c!=j) continue;
      for(k=0;k<13;k++){
        dp[i+1][(k*10+j)%13]+=dp[i][k];
      }
    }
    for(j=0;j<13;++j) dp[i+1][j]%=MOD;
  }
  res=dp[n][5];
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 10752
#include <bits/stdc++.h>
#define em3 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define X real()
#define Y imag()
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define EPS 1e-6
#define endl '\n'
long long mod = 1e9 + 7;
const int N = 1e5 + 5;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double pi = acos(-1);
typedef complex <double> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
ll n , arr[N], brr[N] , ans , pre;
int main()
{
    em3
    cin >> n;
    for(int i = 0 ; i < n + 1 ; i++)
        cin >> arr[i];
    for(int i = 0 ; i < n ; i++)
        cin >> brr[i];
    pre = arr[n];
    for(int i = n - 1 ; i >= 0 ; i--)
    {
        ///cout << pre << endl;
        ans += min(pre , brr[i]) , brr[i] -= min(pre , brr[i]);
        if(brr[i] >= arr[i])
            pre = 0 , brr[i] -= arr[i] , ans += arr[i];
        else
            pre = arr[i] - brr[i] , ans += brr[i] , brr[i] = 0;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]

mp = {}
for c in s:
    if c in mp:
        mp[c] += 1
    else:
        mp[c] = 1

ans = 0
for key in mp.keys():
    ans += mp[key]*(mp[key]-1)/2
print(int(ans))


Measured memory_bytes: 19404
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<cstdio>
#include<cstring>

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

int di[4] = {1, 0, -1, 0};
int dj[4] = {0, 1, 0, -1};
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int table[86400];

int convert2sec(int hh, int mm, int ss){
    return 3600*hh + 60*mm + ss;
}

int main(){
    int n;
    while(cin >> n && n != 0){
        memset(table,0,sizeof(table));
        REP(i,n){
            int hd, md, sd, ha, ma, sa;
            scanf("%d:%d:%d %d:%d:%d", &hd, &md, &sd, &ha, &ma, &sa);
            int dep_sec = convert2sec(hd,md,sd);
            int arr_sec = convert2sec(ha,ma,sa);
            table[dep_sec]++;
            table[arr_sec]--;
        }
        REP(i,86400) if(i>0) table[i] += table[i-1];

        int m = 0;
        REP(i,86400) if(table[i] > m) m = table[i];
        cout << m << endl;
    }
    return 0;
}

Measured memory_bytes: 1584
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

constexpr int64_t DIV1097 = 1000000007LL;

using namespace std;

int main()
{
    int64_t N, M;
    std::cin >> N >> M;

    std::cout << ((N-M)*100 + 1900*M)*std::pow(2,M) << std::endl;

    return 0;
}


Measured memory_bytes: 384
import sys
def こたえ():
    H,W = [int(_) for _ in input().split()]
    aM = [_.rstrip() for _ in sys.stdin.readlines()]
    aH = [True]*H
    aW = [True]*W
    for i in range(H):
        bH = True
        for j in range(W):
            bW = True if aM[i][j] == "." else False
            if bH and not bW:
                bH = False
            if aW[j] and  not bW :
                aW[j]=False
        aH[i] = bH
    for i in range(H):
        if not aH[i]:
            for j in range(W):
                if not aW[j]:
                    sys.stdout.write(aM[i][j])
            sys.stdout.write("\n")
こたえ()


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,s[100],sum = 0;
    cin>>n;
    for(int i = 0;i < n;i ++)
    {
        cin>>s[i];
    }
    sort(s,s + n);
    for(int i = n - 1;i >= 0;i -= 2)
    {
        sum += s[i];
        if(i - 1 >= 0)sum -= s[i - 1];
    }
    cout<<sum;
}


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

#define cp_io ios_base::sync_with_stdio(0);cin.tie(0)
#define ll long long int
#define oo 1000000010
#define MAX 1000000
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define nl "\n"

int main()
{
    cp_io;
    #ifndef ONLINE_JUDGE
    freopen("z_input.txt","rt",stdin);
    freopen("z_output.txt","wt",stdout);
    #endif
    int h,w,m;
    cin >> h >> w >> m;

    vector <ll> row(h);
    vector <ll> col(w);
    set <pair<ll,ll>> mat;
    
    ll a,b;
    for(int i=0; i<m; i++)
    {
        cin >> a >> b;
        a--; b--;
        row[a]++;
        col[b]++;
        mat.insert({a,b}); 
    }

    ll rmx = INT_MIN;
    ll cmx = INT_MIN;

    for(int i=0; i<h; i++) rmx = max(rmx, row[i]);
    for(int i=0; i<w; i++) cmx = max(cmx, col[i]);

    ll ans = 0;
    ll c1 = 0, c2 = 0;

    for(int i=0; i<h; i++) if(rmx == row[i]) c1++;
    for(int i=0; i<w; i++) if(cmx == col[i]) c2++;
    
    ll k = c1*c2;

    for(auto it : mat) if(rmx == row[it.ff] && cmx == col[it.ss]) k--;
    
    ans = rmx + cmx;
    if(k==0) ans--;
    cout << ans << nl;
    return 0;
}

Measured memory_bytes: 26684