akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <limits.h>
#include <float.h>
#include <numeric>
#include <queue>
#include <typeinfo>
#include <memory>


using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define fs first
#define sc second


ll gcd(ll x, ll y){
    ll r = x % y;
    while(r != 0){
        x = y;
        y = r;
        r = x % y;
    }
    return y;
}



int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;

    ll cd = c * d / gcd(c, d);
    // cout << b / cd << endl;
    // cout << (b - (b / c + b / d - b / cd)) << endl;
    cout << (b - (b / c + b / d - b / cd)) - (a - (a / c + a / d - a / cd)) << endl;


    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
    char S[200001],T[200001];
    int i,d=0;
  
    scanf("%s",S);
    scanf("%s",T);
  
    for(i=0;i<strlen(S);i++)
      if(S[i]!=T[i]) d++;
  
    printf("%d\n",d);
  
    return 0;
}
      

Measured memory_bytes: 2084
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  int64_t X;
  cin >> X;

  int64_t Y = 100;
  int result = 0;
  while (Y < X) {
    Y += Y / 100;
    result++;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3636
import sys
input = sys.stdin.readline

def main():
  n, m, p = map(int, input().split())
  edge = []
  for _ in range(m):
    a, b, c = map(int, input().split())
    edge.append((a, b, c-p))
  dist = [-float("inf")]*(n+1)
  dist[1] = 0
  for i in range(n):
    for a, b, c in edge:
      if dist[b] < dist[a] + c:
        dist[b] = dist[a] + c
  ans = max(dist[n], 0)
  for i in range(n):
    for a, b, c in edge:
      if dist[b] != float("inf") and dist[b] < dist[a] + c:
        dist[b] = float("inf")
  if dist[n] == float("inf"):
    ans = -1
  print(ans)
if __name__ == "__main__":
  main()

Measured memory_bytes: 75168
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll MOD2=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI = 2.0*acos(0);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

void solve(int ca){
    int N,M;
    cin>>N>>M;
    vector<int> a(M);

    int total=0;
    for(int i = 0; i < M; ++i) {
      cin>>a[i];
      total+=a[i];
    }

    if(total<=N) cout<<N-total<<endl;
    else cout<<-1<<endl;




}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(1);
#endif
    return 0;
}


Measured memory_bytes: 3648
N, M, C = map(int,input().split())
B = list(map(int,input().split()))

A=[]


for i in range(N):
    A.append(list(map(int,input().split())))

count = 0
for i in range(N):
    tmp = 0
    for j in range(M):
        tmp += A[i][j]*B[j]
    if(tmp + C > 0):
        count += 1

print(count)

Measured memory_bytes: 3064
#include<stdio.h>

//按顺序输数出组元素
void trace(int A[], int N) {
	int i;
	for ( i = 0; i < N; i++) {
		if( i > 0) printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
}

void insertionSort(int A[], int N) {
	int j, i, v;
	for ( i = 1; i < N; i++ ) {
		v = A[i];
		j = i - 1;
		while ( j >= 0 && A[j] > v) {
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = v;
		trace(A, N);
	}
} 

int main() {
	int N, i, j;
	int A[100];
	
	scanf("%d", &N);
	for ( i = 0; i < N; i++) scanf("%d", &A[i]);
	
	trace(A, N);
	insertionSort(A, N);
	
	return 0; 
}


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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  vector<ll> X(N);
  for (ll i = 0; i < N; i++) cin >> X[i];
  ll ans = 1e9;
  for (ll p = 1; p <= 100; p++) {
    ll sum = 0;
    for (ll i = 0; i < N; i++) {
      ll d = X[i] - p;
      sum += d * d;
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3604
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

LL S;

void MAIN() {
    scanf("%lld", &S);
    LL x1 = 1e9;
    LL y2 = (S + x1 - 1) / x1;
    LL y1 = x1 * y2 - S;
    LL x2 = 1;
    printf("0 0 %lld %lld %lld %lld", x1, y1, x2, y2);
    eprintf("%lld %lld\n", x1 * y2 - x2 * y1, S);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}


int main(){

  string s,t;
  cin >> s >> t;
  for(int i = s.size() - t.size(); i >= 0;  i--){
    bool flag = true;
    for(int j = 0; j < t.size(); j++){
      if(s[i+j] == t[j] || s[i+j] == '?')continue;
      else flag = false;
    }

    if(flag){
      for(int j = 0; j < t.size(); j++){
        s[i+j] = t[j];
      }
      for(int j = 0; j < s.size(); j++){
        if(s[j] == '?') s[j] = 'a';
      }
      cout << s << endl;
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;
  return 0;
}


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

using namespace std;

#define MAX 114
#define INF (1<<29)
typedef pair<int, int> pii;

vector<pii> G[MAX];

void init()
{
    for (int i = 0; i < MAX; i++) {
        G[i].clear();
    }
}

int prim()
{
    int res = 0;
    priority_queue<pii, vector<pii>, greater<pii>> Q;
    Q.push(pii(0, 0));

    bool close[MAX] = {};
    
    while (!Q.empty()) {
        pii p = Q.top(); Q.pop();
        int v = p.second;
        
        if (close[v]) continue;
        close[v] = 1;
        
        res += p.first;
        
        for (int i = 0; i < (int)G[v].size(); i++) {
            pii e = G[v][i];
            Q.push(pii(e.second, e.first));
        }        
    }    
    return res;
}

int main()
{
    int N, M, a, b, c;
    while (cin >> N >> M, N) {
        init();
        for (int i = 0; i < M; i++) {
            cin >> a >> b >> c;
            G[a].push_back(pii(b, c));
            G[b].push_back(pii(a, c));
        }
        cout << prim() << endl;
    }
    return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int a,b,c=0,d=0;
    cin>>a>>b;
    c=max(a,b);
    d=min(a,b);
    if(a!=3&&b!=3) cout<<"3"<<endl;
    else cout<<c-d<<endl;
    return 0;
    }


Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    A.resize(unique(A.begin(), A.end()) - A.begin());
    if (A.size() == n) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 505;
const ll LINF = 1e18 + 5;
int n, k;
int a[N], t[N]; 
bool check(int x)
{
	ll tmp = 0;
	for(int i=1; i<=n; i++) 
		t[i] = a[i]%x;
	sort(t+1, t+n+1);
	int l = 1, r = n;
	while(l<r)
	{
		if(t[l]<x-t[r])
		{
			t[r] += t[l];
			tmp += t[l];
			l++;
		}
		else
		{
			tmp += x - t[r];
			t[l] -= x - t[r];
			r--;
			if(!t[l]) l++;
		}
	}
	return tmp <= k;
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n >> k;
 	int sum = 0;
 	for(int i=1; i<=n; i++) 
	{
		cin >> a[i]; 
		sum += a[i];
	}
	int ans = 0;
	for(int i=1; i*i<=sum; i++)
	{
		if(sum%i) continue; 
		if(check(i) && i>ans) ans = i;
		if(i*i!=sum && check(sum/i) && sum/i>ans) ans = sum/i;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
A,B,C,X,Y=map(int,input().split())

ans=10**10
Z=max(X,Y)

for i in range(2*Z+1):
    temp=i*C
    x=max(X-i//2,0)
    y=max(Y-i//2,0)
    temp+=A*x+B*y
    ans=min(ans,temp)
    
print(ans)

Measured memory_bytes: 41692
#include <stdio.h>
#include <math.h>
int main(void) {
	int N;
	int sum1 = 0;
	int sum2 = 0;
	int min = 10000;
	scanf("%d", &N);
	int W[100];
	for (int i = 0; i < N; i++){
		scanf("%d", &W[i]);
		sum1 += W[i];
}
	for (int i = 0; i < N; i++) {
		sum1 -= W[i];
		sum2 += W[i];
		if (sum1 >= sum2&&sum1-sum2<min) {
			min = sum1 - sum2;
		}
		else if (sum2 >= sum1 && sum2 - sum1 < min) {
			min = sum2 - sum1;
		}

	}
	printf("%d", min);


	return 0;

}

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


int main(void) {
    int a,b,c,x;
    cin >> a >> b >> c >> x;

    int count = 0;
    for (int i=0;i <= a;i++) {
        for(int j=0;j <= b;j++) {
            for(int k=0;k <= c;k++) {
                if(x == 500*i + 100*j + 50*k)count ++;
            }
        }
    }
    cout << count << endl;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;


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

    ll n;cin>>n;
    ll ans=0;
    vll p(n); REP(i,n) cin>>p[i];
    FOR(i,1,n-2){
        if (p[i-1]>p[i] && p[i]>p[i+1]) ans++;
        else if (p[i-1]<p[i] && p[i]<p[i+1]) ans++;
    }
    cout <<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace aoj_ALDS1_2_B
{
    class MainClass
    {
        public static void Main(string[] args)
        {
			int numberCount = int.Parse(Console.ReadLine());
			int[] numberArray = Console.ReadLine().Split(' ').Select(number => int.Parse(number)).ToArray();
			int tradeCount = 0;
			for (int i = 0; i < numberCount; i++)
			{
				int minIndex = i;
				for (int j = i; j < numberCount; j++)
				{
                    if (numberArray[j] < numberArray[minIndex])
					{
						minIndex = j;
					}
				}

                if (minIndex != i)
				{
					int temp = numberArray[i];
					numberArray[i] = numberArray[minIndex];
					numberArray[minIndex] = temp;

					tradeCount++;
				}
			}

			Console.WriteLine(String.Join(" ", numberArray));
			Console.WriteLine(tradeCount);
        }
    }
}



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

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

    ll x;
    cin >> x;

    const int MOD = 11;

    int t = x % MOD;
    ll v = x / MOD;

    int cnt = 0;
    if(t == 0) {
        cnt = 0;
    }
    else if(t <= 6) {
        cnt = 1;
    }
    else {
        cnt = 2;
    }

    ll ans = (v*2) + cnt;

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

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {
  
  int n;
  cin >> n;
  vec2 s(n);
  for(int i = 0; i < n; i++) cin >> s.at(i);
  int m;
  cin >> m;
  vec2 t(m);
  for(int i = 0; i < m; i++) cin >> t.at(i);
  
  int ans = 0;
  int c = 0;
  for(int i = 0; i < n; i++) {
    c = 0;
    for(int j = 0; j < n; j++) {
      if(s.at(i) == s.at(j)) {
        c++;
      }
    }
    for(int j = 0; j < m; j++) {
      if(s.at(i) == t.at(j)) {
        c--;
      }
    }
    ans = max(ans,c);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
/**So..a**/
#include<bits/stdc++.h>
//#include <chrono>
// Success after trying 5 hour 11 minute :(


using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define PB(x, v) x.push_back(v);
#define M_P(a, b) make_pair(a, b)
#define pll pair<ll, ll>
#define ll long long
#define mll map<ll, ll>
#define vl vector<ll>
#define fa(x, v) for(auto x: v)
#define fr(i, a, b) for(ll i= a;i <=b; i++)
#define TEST  int test; cin >> test; while(test--)
#define FTEST int TesT; cin >> TesT; for(int test = 1; test<=TesT; test++)

#define B_ begin()
#define E_ end()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define NL_ "\n"
#define F first
#define S second
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second

#define MOD 1000000000+7
#define  ull unsigned long long

 int cnt[1000000+10];

int main()
{

      int n;
      scanf("%d", &n);
      for(int i=1; i<n; i++)
      {
          for(int j  = i; j<n; j+=i) cnt[j]++;
      }
      int ans = 0;
      for(int i= 1; i<n; i++) ans += cnt[i];
      printf("%d", ans);
    return 0;
}


Measured memory_bytes: 7632
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: u32,
        b: u32
    }
    if a < b {
        for _ in 0..b {
            print!("{}", a);
        }
    } else {
        for _ in 0..a {
            print!("{}", b);
        }
    }
    println!("");
}


Measured memory_bytes: 4352
#include <iostream>
#include <stdlib.h>
using namespace std;
#define limit 104750

int main(void){
  int* table=(int*)malloc(sizeof(int)*limit);
  for(int i=0;i<limit;i++){
    table[i]=1;
  }
  table[0]=0;
  table[1]=0;
  int k;
  for(int i=0;i<limit;i++){
    if(table[i]==0)continue;
      k=2;
      while(k*i<=limit){
        table[k*i]=0;
        k++;
      }
  }
  int n;
  int i,retval,counter;
  while(1){
    cin>>n;
    if(n==0){
      break;
    }
    i=0;
    retval=0;
    counter=0;
    while(counter<n){
      if(table[i]==1){
        retval+=i;
        counter++;
      }
      i++;
    }
    cout<<retval<<endl;
  }
  return 0;
}



Measured memory_bytes: 3412
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int a[] = new int[n];
        for (int i=0;i<n;i++)
            a[i] = sc.nextInt();
        Arrays.sort(a);
        int count=0;
        long sum=0;
        for (int i=0;i<n;i++) {
            sum+=a[i];
            if (sum==x || (i!=n-1 && sum<x)) count++;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 21844
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
struct edge {
	int to, sum;
};
int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<edge> > G(N);
	vector<int> a(M), b(M), c(M);
	for (int i = 0; i < M; ++i) {
		cin >> a[i] >> b[i] >> c[i]; --a[i], --b[i];
		G[a[i]].push_back(edge{ b[i], c[i] });
		G[b[i]].push_back(edge{ a[i], c[i] });
	}
	vector<int> parity(N, -1); vector<long long> pot(N);
	parity[0] = 0;
	queue<int> que;
	que.push(0);
	while (!que.empty()) {
		int u = que.front(); que.pop();
		for (edge e : G[u]) {
			if (parity[e.to] == -1) {
				parity[e.to] = parity[u] ^ 1;
				pot[e.to] = e.sum - pot[u];
				que.push(e.to);
			}
		}
	}
	bool ok = true;
	vector<long long> candy;
	for (int i = 0; i < M; ++i) {
		if (parity[a[i]] == parity[b[i]]) {
			if (((pot[a[i]] + pot[b[i]]) & 1) != (c[i] & 1)) {
				ok = false;
				break;
			}
			long long delta = c[i] - (pot[a[i]] + pot[b[i]]);
			if (parity[a[i]] == 1) delta *= -1;
			delta >>= 1;
			candy.push_back(delta);
		}
		else if (pot[a[i]] + pot[b[i]] != c[i]) {
			ok = false;
			break;
		}
	}
	if (!ok) {
		cout << 0 << endl;
	}
	else {
		sort(candy.begin(), candy.end());
		candy.erase(unique(candy.begin(), candy.end()), candy.end());
		if (candy.size() >= 2) {
			cout << 0 << endl;
		}
		else if (candy.size() == 1) {
			bool valid = true;
			for (int i = 0; i < N; ++i) {
				if (parity[i] == 0) pot[i] += candy[0];
				else pot[i] -= candy[0];
				if (pot[i] <= 0) valid = false;
			}
			cout << (valid ? 1 : 0) << endl;
		}
		else {
			long long L = 0, R = 1LL << 60;
			for (int i = 0; i < N; ++i) {
				if (parity[i] == 0) {
					L = max(L, -pot[i]);
				}
				else {
					R = min(R, pot[i]);
				}
			}
			cout << max(R - L - 1, (long long)(0)) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 9464
#include <bits/stdc++.h>
using namespace std;
long long dp[100005], n, a[20][20];
long long solve(int bitmask){
	if (dp[bitmask]!=-1) return dp[bitmask];
	dp[bitmask]=0;
	for (int i=0; i<n; i++){
		for (int j=i+1; j<n; j++){
			if (bitmask&(1<<i) and bitmask&(1<<j))
				dp[bitmask]+=a[i][j];
		}
	}
	int ekstramask=bitmask;
	while (true){
		ekstramask--; ekstramask&=bitmask;
		if (!ekstramask) break;
		dp[bitmask] = max(dp[bitmask], solve(ekstramask)+solve(bitmask^ekstramask));
	}
	return dp[bitmask];
}
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i=0; i<n; i++){
	for (int j=0; j<n; j++){
		cin >> a[i][j];
	}
} 
for (int i=1; i<(1<<n); i++) dp[i]=-1;
cout << solve((1<<n)-1);
return 0;
}


Measured memory_bytes: 4172
// by gantheory™
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;

int n, a[ N ];

int main() {
  ios_base::sync_with_stdio( 0 ); cin.tie( 0 );
  cin >> n;
  for ( int i = 0; i < n; ++i ) cin >> a[ i ];

  map< int, int > mp;
  for ( int i = 0; i < n; ++i )
    ++mp[ a[ i ] ];

  int ans = 0;
  for ( auto it : mp ) {
    if ( it.second >= it.first )
      ans += it.second - it.first;
    else
      ans += it.second;
  }
  cout << ans << '\n';
}


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

#define int long long
#define pii pair<int, int>
#define pb push_back

signed main(){

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int n;
    cin >> n;
    int x;
    set<int> s;
    for(int i = 0; i < n ; i++){
        cin >> x;
        s.insert(x);
    }
    if(s.size() == n){
        cout << "YES";
    }
    else{
        cout << "NO";
    }

    return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;
const int maxn = 1000005;

void solve() {
	int n;
	cin >> n;
	ll num = 0;
	ll cnt[30][30] = {};
	ll ans = 0;
	f(n) {
		string s;
		cin >> s;
		int f = 0;
		int ptr = -1;
		for (int j = 0 ; j < s.size() ; j++) {
			if (s[j] == '.') {
				f = 1;
				ptr = j;
				break;
			}
		}
		if (ptr == -1) {
			s += ".000000000";
		}
		while(s.size() - ptr <= 9) {
			s += '0';
		}
		ll real = 0;
		for (auto &j : s) {
			if (j == '.')continue;
			real *= 10;
			real += j - '0';
		}
		int c2 = 0, c5 = 0;
		//cout << real << '\n';

		if (real == 0) {
			cnt[20][20]++;
		}
		else {
			while (real % 2 == 0) {
				real /= 2;
				c2++;
			}
			while (real % 5 == 0) {
				real /= 5;
				c5++;
			}
			//cout << c2 << ' '<<c5<<endl;
			c2 = min(c2, 20);
			c5 = min(c5, 20);
			cnt[c2][c5]++;
		}
	}
	for (int i = 0 ; i < 30 ; i++) {
		for (int j = 0 ; j < 30 ; j++) {
			for (int k = i ; k < 30 ; k++) {
				for (int l = (i == k ? j : 0) ; l < 30 ; l++) {
					if (((i + k) < 18) || ((j + l) < 18))continue;
					if (i == k && l == j) {
						ans += cnt[i][j] * (cnt[i][j] - 1) / 2;
					}
					else {
						ans += cnt[i][j] * cnt[k][l];
					}
				}
			}
		}
	}
	cout << ans << '\n';
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        solve();
    }
}


Measured memory_bytes: 3644
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
using namespace std;

int main() {
	int a, b, c, d,x,y;
	cin >> a >> b >> c >> d;
	if (a < b)
	{
		x = a;
	}
	else
	{
		x = b;
	}
	if (c < d)
	{
		y = c;
	}
	else
	{
		y = d;
	}
	cout << x + y << endl;
}

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

int main(){

  int a,b;

  cin>>a>>b;

  if(a>b || ( a-1) > b ) cout<<a + (a-1)<<endl;

  else if(a>b || (a-1) == b) cout<<a+b<<endl;

  else if( a==b ) cout<<a+b<<endl;

  else if(b>a || (b-1) > a ) cout<< b + (b-1) <<endl;

  else if(b>a || (b-1)== b ) cout<<a+b<<endl;

  return 0;
}


Measured memory_bytes: 256
{
  const main = (input: string) => {
    const r = reader(input)
    const N = r.n()
    const l = r.ns()
    let res = 0

    l.sort((a, b) => b - a)
    for (let i = 0; i < N - 2; i++) {
      const l1 = l[i]

      // console.log(' ', l1)

      for (let j = i + 1; j < N - 1; j++) {
        const l2 = l[j]

        // console.log('  ', l2)
        const k = j + 1

        // console.log('   need v >=', l1 - l2 + 1)

        const p = _bound(k, N, l, v => v > l1 - l2)

        // console.log('   ', l.slice(k, N).join(', '))
        // console.log('   ', p)

        // console.log(p)
        // console.log('    ', p - j - 1)
        res += p - j - 1
      }
    }

    console.log(res)
  }

  const reader = (str: string) => {
    const lines = str.trim().split('\n')
    const s = () => lines.shift() || ''
    const n = () => Number(s())

    const ss = () => s().split(' ')
    const ns = () => ss().map(Number)
    const nls = () => lines.map(Number)

    return { lines, s, n, ss, ns, nls }
  }

  const _bound = (
    lo: number,
    hi: number,
    arr: number[],
    compare: (v: number) => boolean
  ) => {
    while (lo < hi) {
      const mid = lo + Math.floor((hi - lo) / 2)

      if (compare(arr[mid])) {
        lo = mid + 1
      } else {
        hi = mid
      }
    }
    return hi
  }

  const _binarySearch = <T>(
    lo: number,
    hi: number,
    iFunc: ((i: number) => T) | T[],
    compare: (v: T) => boolean
  ): number => {
    const valFunc = typeof iFunc === 'function' ? iFunc : v => iFunc[v]

    while (lo < hi) {
      const mid = lo + Math.floor((hi - lo) / 2)

      if (compare(valFunc(mid))) {
        lo = mid + 1
      } else {
        hi = mid
      }
    }
    return hi
  }
  const getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')

  main(getInput())
}


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

class UnionFind {  
public:
  vector<long long> par;
  vector<long long> rank;

  UnionFind(long long N) : par(N + 1), rank(N + 1){
    for(int i = 0; i <= N; i++){  
      par[i] = i;
      rank[i] = 1;
    }
  }

  long long root(long long x){  
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  long long size(long long x){  
    return rank[root(x)]; 
  }

  void unite(long long x, long long y){  
    long long rx = root(x); 
    long long ry = root(y);
    if (rx == ry) return;

    if(rank[rx] < rank[ry]){  
      par[rx] = ry; 
    } else{  
      par[ry] = rx;
      if(rank[rx] == rank[ry]) rank[rx]++; 
    }
  }

  bool same(long long x, long long y){  
    return root(x) == root(y); 
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int N, K, L;
  cin >> N >> K >> L;
  UnionFind car(N), train(N);
  for(int i = 0; i < K; i++){  
    int p, q;
    cin >> p >> q;
    car.unite(p, q);
  }
  for(int i = 0; i < L; i++){  
    int p, q;
    cin >> p >> q;
    train.unite(p, q);
  }
  map<pair<long long, long long>, long long> m;
  for(int i = 1; i <= N; i++){  
    m[make_pair(car.root(i), train.root(i))]++; 
  }
  for(int i = 1; i <= N; i++){  
    cout << m[make_pair(car.root(i), train.root(i))] << " ";
  }
}


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

int main(){
	char S[4];
	cin >> S;
	int t0, t1;
	t0 = (S[0] - '0') * 10 + S[1] - '0';
	t1 = (S[2] - '0') * 10 + S[3] - '0';
	if(1 <= t0 && t0 <= 12){
		if(t1 > 12) cout << "MMYY" << endl;
		else if(1 <= t1 && t1 <= 12) cout << "AMBIGUOUS" << endl;
		else if(t1 == 0) cout << "MMYY" << endl;
		else cout << "NA";
	}
	else if(t0 > 12){
		if(1 <= t1 && t1 <= 12) cout << "YYMM" << endl;
		else cout << "NA" << endl;
	}
	else{
		if(1 <= t1 && t1 <= 12) cout << "YYMM" << endl;
		else cout << "NA" << endl;
	}
}


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

int main()
{
    ll a[]= {1,3,5,7,8,10,12},b[]= {4,6,9,11},c=2,x[3],i;
    ll f1[3]= {0};
    ll f2[3]= {0},f3=0,j;
    cin>>x[0]>>x[1];
ll g1=0,g2=0;
    for(j=0; j<2; j++)
    {
        for(i=0; i<7; i++)
        {
            if(x[j]==a[i])
            {
                f1[j]=1;
                break;
            }
        }

    }
    if(f1[0]==1&&f1[1]==1)
    {
        g1=1;
    }
    for(j=0; j<2; j++)
    {
        for(i=0; i<4; i++)
        {
            if(x[j]==b[i])
            {
                f2[j]=1;
                break;
            }
        }

    }
       if(f2[0]==1&&f2[1]==1)
    {
        g2=1;
    }

    if((x[0]==c&&x[1]==c)||g1==1||g2==1)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define ll long long
#define M 1000000007
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  ll n;
  cin >> n;
  ll power = 1;
  while(n)
  {
    power = (power*n)%M;
    n--;
  }
  cout << power << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    int N;
    cin >> N;
    vector<int>X(N);
    vector<int>Y(N);
    for(int i = 0; i < N; i++) {
        cin >> X[i];
        Y[i] = X[i];
    }
    sort(X.begin(),X.end());
    for(int i = 0; i < N; i++) {
        if(Y[i] < X[N/2]) {
            cout << X[N/2] << endl;
        }
        else {
            cout << X[N/2-1] << endl;
        }
    }
}


Measured memory_bytes: 5376
// 解き直し.
// ABC 136解
// https://img.atcoder.jp/abc136/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int N;
LL K, S, A[505], G;

// 与えられた正の整数のすべての約数を抽出.
// @param X: 約数を抽出したい正の整数.
// @return ret: すべての約数.
vector<LL> div(LL X){
    vector<LL> ret;
    ret.push_back(1);
    for(LL d = 2; d * d <= X; d++){
        if(X % d == 0){
            ret.push_back(d);
            if(d * d != X) ret.push_back(X / d);
        }
    }
    ret.push_back(X);
    sort(ret.begin(), ret.end());
    return ret;
}

int main(){

    // 1. 入力情報取得.
    scanf("%d %llu", &N, &K);
    for(int i = 0; i < N; i++){
        scanf("%llu", &A[i]);
        S += A[i];
        if(i == 0) G = A[i];
        else       G = __gcd(G, A[i]);
    }
    
    // 2. 解説通り.
    // S の 約数 を 計算.
    vector<LL> divisors = div(S);
    
    // 3. 各約数について, 操作の回数を計算.
    LL ans = G;
    for(auto &d : divisors){
        // 3-1. 各 A[i] を d で 割った余り を 確認.
        priority_queue<LL> r;
        for(int i = 0; i < N; i++) if(A[i] % d != 0) r.push(A[i] % d);
        
        // 3-2. d を 正にするもの, 負にするもの を 集計.
        int l = r.size();
        LL dPlus[l], dMinus[l];
        int index = 0;
        while(!r.empty()){
            // 余りを取得.
            LL v = r.top();
            r.pop();
            
            // d を 正 にする.
            dPlus[l - index - 1]  = d - v;
            // d を 負 にする.
            dMinus[l - index - 1] = -v;
            
            // index を increment.
            index++;
        }
        
        // 3-3. 前項で集計した結果の累積和を計算.
        // d を 正 にする.
        LL pCum[l];
        pCum[l - 1] = dPlus[l - 1];
        for(int i = l - 2; i >= 0; i--) pCum[i] = pCum[i + 1] + dPlus[i];
        
        // d を 負 にする.
        LL mCum[l];
        mCum[0] = dMinus[0];
        for(int i = 1; i < l; i++) mCum[i] = mCum[i - 1] + dMinus[i];
        
        // 3-4. 前項の累積和から, 操作回数が, K回以内で実現できるかをチェック.
        for(int i = 0; i < l - 1; i++){
            if(pCum[i + 1] + mCum[i] == 0 && pCum[i + 1] <= K){
                // 操作後の A の 全要素を割り切る正の整数について, 最大値を更新.
                ans = max(ans, d);
                break;
            }
        }
    }
    
    // 4. 出力 ～ 後処理.
    printf("%llu", ans);
    return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void){
  int n,cnt = 0;
  scanf("%d", &n);
  for(int i = 1; i <= n; i++){
    if((int)log10(i) % 2 == 0){
    cnt++;
   }
  }
  printf("%d\n", cnt);
  return 0;
}

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

int main() {
  int n,k,sum;
  cin >> n >> k;
  sum = 1;
  for(int i=0; i<n; i++){
    if(sum*2 < sum+k){
      sum *= 2;
    }else{
      sum += k;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define vi vector <int>
#define si set <int>
#define mii map <int,int>
#define pii pair <int,int>
#define endl "\n"
#define ZERO 0ll
#define FOR(P,Q) for(int P=0;P<(Q);P++)
#define FORR(P,Q) for(int P=1;P<=(Q);P++)
#define rep(P,R,Q) for(int P=(R);P<=(Q);P++)
#define repb(P,R,Q) for(int P=(R);P>=(Q);P--)
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef long double ld;
using namespace std;


    
int32_t main()
{
	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
	#ifndef ONLINE_JUDGE
	freopen("error.txt","w",stderr);
	#endif
	//change ll to int before using string builtin operations
	int tces=1;
	//cin>>tces;
	while(tces--){
		double n;
		cin>>n;
		double a=n/3;
		a=a*a;
		a=a*(n/3);
		printf("%0.9f", a);  

	}
	
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cstdio>
using namespace std;

int main(void){
  string s;
  cin >> s;
  sort(s.begin(), s.end());

  if(s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef struct{
    long weight;
    long no;
} wn;

bool wncw(const wn& a, const wn& b){
    if(a.weight != b.weight){
        return a.weight < b.weight;
    }else{
        return a.no < b.no;
    }
}
bool wncn(const wn& a, const wn& b){
    if(a.no != b.no){
        return a.no < b.no;
    }else{
        return a.weight < b.weight;
    }
}

using node = vector<long>;
/*
   void connect_check(long from, const vector<node>& graph, vector<wn>& a){
   long s=graph[from].size();
   for(long j=0; j<s; j++){
   long to = graph[from][j];
   if(a[from].no!=a[to].no){
   a[to].no=a[from].no;
   connect_check(to, graph, a);
   }
   }
   }
   */
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long n, m;
    cin >> n >> m;
    //最初から木
    if(m==n-1){
        cout << "0" << endl;
        return 0;
    }
    if(2*(n-m-1)>n){
        cout << "Impossible" << endl;
        return 0;
    }
    vector<wn> a(n);
    for(long i=0; i<n; i++){
        cin >> a[i].weight;
        a[i].no = -1;
    }
    vector<node> graph(n);
    for(long i=0; i<m; i++){
        long x, y;
        cin >> x >> y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    long no=0;
    function<void(long)> connect_check = [&connect_check, &graph, &a](long from){
        long s=graph[from].size();
        for(long j=0; j<s; j++){
            long to = graph[from][j];
            if(a[from].no!=a[to].no){
                a[to].no=a[from].no;
                connect_check(to);
            }
        }
    };

    for(long i=0; i<n; i++){
        if(a[i].no==-1){
            a[i].no=no;
            connect_check(i);
            no++;
        }
    }
    long cost_sum=0;
    sort(a.begin(), a.end(), wncn);
    for(long k=0, i=0; k<n-m; k++){
        while(a[i].no!=k) i++;
        cost_sum += a[i].weight;
        a[i].weight = 1e10;
    }
    sort(a.begin(), a.end(), wncw);
    for(long k=0; k<n-m-2; k++){
        cost_sum += a[k].weight;
    }
    cout << cost_sum << endl;
    /*
       for(long i=0; i<n; i++){
       long s=graph[i].size();
       cout << i << " : ";
       cout << a[i].weight << " : ";
       cout << a[i].no << " : ";
       for(long j=0; j<s; j++){
       cout << graph[i][j] << " ";
       }
       cout << endl;
       }
       */
    return 0;
}


Measured memory_bytes: 7808
import std.conv, std.functional, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }




void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const K = readInt();
      const ans = (N >= 1 + 2 * (K - 1));
      writeln(ans ? "YES" : "NO");
    }
  } catch (EOFException e) {
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF=2e18;
string S;
ll N,H;
ll b[100010];
int main(){
    cin>>N>>H;
    ll maxA=0;
    for(int i=0;i<N;i++){
        ll a;
        cin>>a>>b[i];
        maxA=max(a,maxA);
    }
    sort(b,b+N);
    ll ans=0;
    for(int i=N-1;i>=0;i--){
        if(b[i]<maxA || H<=0){
            break;
        }
        H-=b[i];
        ans++;
    }
    cout<<ans+( H>0 ? ((H-1)/maxA+1):0 );
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
    vector<int> a(3);
    int ans=0;
    for(int i=0;i<3;i++){
        cin>>a.at(i);
    }
    
    sort(a.begin(),a.end());
    ans=a.at(1)+a.at(0);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>

using namespace std;

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

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n-1;i >= 0;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second

const long double pi = 3.141592653589793;
const int mod = 1e9 + 7;

int A[1<<20], N, a;
int gcd(int x, int y) {
    if(y == 0)
        return x;
    else
        return gcd(y, x % y);
}

vector<bool> sieve;
bool scen1 = false;

void fill_sieve(int n) {
    sieve = vector<bool>(n+1, true);
    sieve[0] = sieve[1] = false;

    for(int i = 2;i <= n;i++) {
        if(sieve[i]) {
            int ans = A[i];
            int j = 2*i;
            while(j <= n) {
                sieve[j] = false;
                ans += A[j];
                j += i;
            }

            scen1 |= (ans > 1);
        }
    }
}

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);

 ios_base::sync_with_stdio(false);
 cin.tie(nullptr);
cin>>N;
int ans = 0;
rep(i, N) {cin>>a;A[a]++;ans = gcd(ans, a);}

string a1 = "pairwise coprime";
string a2 = "setwise coprime";
string a3 = "not coprime";

fill_sieve(1e6);
if(!scen1) cout << a1;
else if(ans == 1) cout << a2;
else cout<<a3;

 return 0;
}


Measured memory_bytes: 7664
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i): is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res
## libs ##
from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
import string
#======================================================#

def check(t, sidx):
    for idx in sidx.values():
        if idx:
            tmp = set()
            for i in idx:
                tmp.add(t[i])
            if len(tmp) > 1:
                return False
    return True

def main():
    s = IS()
    t = IS()

    sidx = {a: [] for a in string.ascii_lowercase}
    tidx = {a: [] for a in string.ascii_lowercase}
    for i, si in enumerate(s): sidx[si].append(i)
    for i, ti in enumerate(t): tidx[ti].append(i)

    if check(s,tidx) and check(t,sidx):
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 21424
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

int main(){
  int x,sum = 0;
  cin >> x;
  for(int i = 1; i <= x; i++ ){
    sum += i;
    if(sum >= x){
      cout << i << endl;
      return  0;;
    }
  }
  return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
const double PI = acos(-1);

signed main() {
	vector<int> v;
	int n;
	cin >> n;
	int a;
	for (int i = 0; i < n; i++) {
		cin >> a;
		v.emplace_back(a);
	}
	sort(v.begin(), v.end());
	int ans = 0;
	int num = v[0];
	int count = 1;
	for (int i = 1; i < n; i++) {
		if (v[i] == num)count++;
		else {
			if (count % 2 == 1)ans++;
			num = v[i];
			count = 1;
		}
	}
	if (count % 2 == 1)ans++;

	cout << ans << endl;
}

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

using namespace std;

typedef long double ld;
typedef long long ll;

#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

template<typename T, typename U> bool ckmin(T &a, U b){ return b < a ? a = b, true : false; }
template<typename T, typename U> bool ckmax(T &a, U b){ return b > a ? a = b, true : false; }

int cur = 0, mod;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> mod;
    for(int i = 1; i <= 5e7; ++i){
        cur = (cur * 10 + 7)%mod;
        if(!cur){
            cout << i;
            return 0;
        }
    }
    cout << -1;
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ui long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vii vector<vi>
#define lb lower_bound
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
#define rep0(i,a,b) for(int i=(a);i<(b);++i)
#define fore(i,a) for(int i=0;i<a.size();++i)
#define gc() getchar()
#define ls x<<1,l,m
#define rs x<<1|1,m+1,r
inline ll rd()
{
	ll x=0,w=1;char c=gc();while(!isdigit(c)&&c!='-')c=gc();
	if(c=='-')c=gc(),w=-1;while(isdigit(c))x=x*10+c-48,c=gc();return x*w;
}
const int N=5005,P=1e9+7;
int n,a,b,f[N],g[N],F[N],G[N],sf[N],sg[N],sF[N],sG[N];
int main()
{
	n=rd();a=rd();b=rd();if(a>b)swap(a,b);
	f[1]=1;g[1]=0;sf[1]=1;sg[1]=0;
	rep(i,2,b)
	{
		f[i]=sg[i-1]+1;g[i]=i>=a?sf[i-a]:0;
		sf[i]=(sf[i-1]+f[i])%P;sg[i]=(sg[i-1]+g[i])%P;
	}
	F[0]=1;sF[0]=1;G[0]=1;sG[0]=1;
	rep(i,1,n)
	{
		F[i]=(sG[i-1]+P-(i>=a?sG[i-a]:0))%P;
		rep(j,1,b-1)if(i-j>=0)G[i]=(G[i]+1ll*F[i-j]*f[j])%P;
		if(i<b)rep(j,a,i-1)G[i]=(G[i]+f[i-j])%P;
		sF[i]=(sF[i-1]+F[i])%P;sG[i]=(sG[i-1]+G[i])%P;
	}
//	rep(i,1,b-1)cout<<f[i]<<" ";cout<<endl;
//	rep(i,1,b-1)cout<<g[i]<<" ";cout<<endl;
//	rep(i,0,n)cout<<F[i]<<" ";cout<<endl;
//	rep(i,0,n)cout<<G[i]<<" ";cout<<endl;
	int ans=(F[n]+G[n])%P;//cout<<ans<<endl;
	rep(i,1,b-1)rep(j,a,i-1)ans=(ans+1ll*F[n-i]*f[i-j])%P;
	int t=1;rep(i,1,n)t=2ll*t%P;
	printf("%d\n",(t+P-ans)%P);return 0;
}


Measured memory_bytes: 3872
n,m=map(int,input().split())
A=[]
B=[]
for i in range(n):
    a,b=map(int,input().split())
    A.append([a,i])
    B.append(b)
A.sort()
i=0
ans=0
l=0
while True:
    l+=B[A[i][1]]
    if m>l :
        ans+=A[i][0]*B[A[i][1]]
    elif l==m:
        ans+=A[i][0]*B[A[i][1]]
        break
    else:
        ans+=A[i][0]*B[A[i][1]]-(l-m)*A[i][0]
        break
    i+=1
print(ans)


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

namespace AtCoder.XXX.A
{ 
    public class Program
    {
        public static void Main(string[] args)
        {
            var datas = cr();
            var a = datas[0];
            var b = datas[1];
            var d = datas[2];
            var cnt = 0;
            for(var i  = a; i <= b;i++)
			{
                if(i%d==0)
				{
                    cnt++;
				}
			}
            P(cnt);
        }

        private static StreamReader sr;
        public static int[] Ecr()
        {
            if (sr == null)
            {
                sr = new StreamReader("input.txt", Encoding.GetEncoding("UTF-8"));
            }
            return sr.ReadLine().Split().Select(int.Parse).ToArray();
        }
        public static string Er()
        {
            if (sr == null)
            {
                sr = new StreamReader("input.txt", Encoding.GetEncoding("UTF-8"));
            }
            return sr.ReadLine();
        }
        public static string r()
        {
            return Console.ReadLine();
        }
        public static  int[] cr()
        {
            return Console.ReadLine().Split().Select(int.Parse).ToArray();
        }
        public static int cri()
        {
            return int.Parse(Console.ReadLine());
        }
        public static void P(string str)
        {
            Console.WriteLine(str);
        }
        public static void P(int num)
        {
            P(num.ToString());
        }
    }
}


Measured memory_bytes: 27936
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int a, b, c; cin >> a >> b >> c;

    if(a == b + c ||b == c + a ||c == a + b) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256