akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>

using namespace std;

#define gettime printf("\nTime : %0.3lf\n",clock()*1.0/CLOCKS_PER_SEC);
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repp(i,a,b) for(int i=a;i>=b;i--)
#define Set(x,a) memset(x,a,sizeof(x));

#define vs vector<string>
#define vi vector<int>
#define ll long long
#define ff first
#define ss second

struct comp {
       bool operator() (int a,int b) {
            return a>b;
       }
};

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //std::ios::sync_with_stdio(false);
    int a, b;
    scanf("%d %d", &a, &b);
    int c;
    if (b < 10) c = a * 10 + b;
    else if (b < 100) c = a * 100 + b;
    else c = a * 1000 + b;
    int d = sqrt(c);
    if (d * d == c) printf("Yes\n");
    else printf("No\n");
    return 0;
}


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

using namespace std;

void solve(int N, string S) {
  vector<int> ans(N);
  for (int ri = 0; ri < 2; ri++) {
    {
      int cnt = 0;
      for (int i = 0; i < N; i++) {
        if (S[i] == 'R') {
          cnt += 1;
        } else {
          ans[i] += cnt / 2;
          ans[i - 1] += (cnt + 1) / 2;
          cnt = 0;
        }
      }
    }
    reverse(ans.begin(), ans.end());
    reverse(S.begin(), S.end());
    for (int i = 0; i < N; i++) {
      if (S[i] == 'L') {
        S[i] = 'R';
      } else {
        S[i] = 'L';
      }
    }
  }
  for (int i = 0; i < N; i++) {
    printf("%d%c", ans[i], i == N - 1 ? '\n' : ' ');
  }
}

int main() {
  int N;
  string S;
  cin >> S;
  N = S.size();
  solve(N, S);
  return 0;
}

Measured memory_bytes: 1088
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<fstream>
#include<algorithm>
using namespace std;
using ll = long long;


int main(){
    map<string, int> mp;
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        string str;
        cin >> str;
        mp[str]++;
    }
    vector<string> vc;
    int M = 0;
    for(auto iter=mp.begin();iter!=mp.end();iter++){
        if(iter->second > M){
            M = iter->second;
            vc.clear();
            vc.push_back(iter->first);
        }
        else if(iter->second == M){
            vc.push_back(iter->first);
        }
    }
    sort(vc.begin(),vc.end());
    for(int i=0;i<vc.size();i++){
        cout << vc[i] << endl;
    }
}

Measured memory_bytes: 26868
#include <cstdio>
#include <map>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long int64;
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz(a) ((int) (a).size())

const int N = 333;
int n, ans;
char a[N][N], c[N][N];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			scanf(" %c", &a[i][j]);
		}
	}
	for (int b = 0; b < n; ++b) {
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				c[i][j] = a[i][(j + b) % n];
			}
		}
		bool ok = true;
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				if (c[i][j] != c[j][i]) {
					ok = false;
					break;
				}
			}
		}
		if (ok) {
			ans += n;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ve vector
#define chmin(x,y) x = min(x,y)

struct Sieve{
    int n;
    vector<int> f,primes;
    Sieve(int n = 1):n(n), f(n+1) {
        f[0] = f[1] = -1;
        for(ll i = 2;i <= n; i++){
            if(f[i])continue;
            primes.push_back(i);
            f[i] = i;
            for(ll j = i * 2; j <= n; j += i){
                if(!f[j])f[j] = i;
            }
        }
    }
    bool isPrime(int x){return f[x] == x;}
    vector<int> factorList(int x){
        vector<int> res;
        while(x != 1){
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    vector<P> factor(int x){
        vector<int> fl = factorList(x);
        if(fl.size() == 0) return {};
        vector<P> res(1,P(fl[0],0));
        for(int p: fl){
            if(res.back().first == p){
                res.back().second++;
            }else{
                res.emplace_back(p,1);
            }
        }
        return res;
    }
};

int main(){
    int n;
    cin >> n;
    Sieve sv(55560);
    
    ve<int> ans;
    rep(i,55555){
        if(sv.isPrime((int)i+1)){
            if((i+1)%5==1) ans.push_back((int)i+1);
        }
        if(ans.size() == n)break;
    }
    rep(i,n-1)cout<<ans[i]<<" ";
    cout<<ans[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 3684
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;

ll A[100005];

int main() {

	priority_queue<ll> que;

	int N, M;

	scanf("%d %d",&N,&M);

	int i;

	for (i = 0; i < N; i++) {
		scanf(" %lld",&A[i]);
		que.push(A[i]);
	}

	while (1) {
		if (M == 0) { break; }
		ll X = que.top(); que.pop();
		que.push(X / 2ll);
		M--;
	}
	ll ans = 0ll;
	while (que.size() != 0) {
		ll X = que.top(); que.pop();
		ans += X;
	}
	printf("%lld\n",ans);

	return 0;
}

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

using namespace std;
typedef long long ll;

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

int main()
{
    int n;
    cin >> n;
    vector<int> l(n), r(n);
    rep(i, n) cin >> l[i] >> r[i];

    int ans = 0;
    rep(i, n)
    {
        ans += r[i] - l[i] + 1;
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

int main() {
    string X,Y;
    cin >> X >> Y;

    if(X>Y)cout << ">" << endl;
    else if(X==Y)cout << "=" << endl;
    else if (X < Y)cout << "<" << endl;

    return 0;

}

Measured memory_bytes: 256
<?php

ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_WARNING);
ini_set('display_errors', 'Off');

// define('DEBUG', true);
define('DEBUG', false);

fscanf(STDIN, "%d %d", $N, $M);

$ans = 0;
$v = array();
$sum = array();

for ($i = 0; $i < $M; $i++) {
    fscanf(STDIN, "%d %d", $a, $b);
    $v[$a][$b] = 1;
    $v[$b][$a] = 1;
}
if (DEBUG) var_dump($v);

$flag = true;
while($flag) {
    $flag = false;
    foreach ($v as $key => $val) {
        if (DEBUG) echo "no.{$key} " . count($val) . PHP_EOL;
        if (count($v[$key]) == 1) {
            $ans++;
            $flag = true;
            foreach ($v[$key] as $no => $one) {
                if (DEBUG) echo "X: no:{$no} one:{$one}\n";
                unset($v[$key][$no]);
                unset($v[$no][$key]);
            }
        } 
    }
    // sleep(1);
}
echo $ans . PHP_EOL;


Measured memory_bytes: 4856
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll N,K,ad=0;
  cin>>N>>K;
  for(ll i=0;i<K;i++){
    ll a;
    cin>>a;
    ad+=a;
  }
  if(ad>=N){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
}

Measured memory_bytes: 256
#define rep(i,n) for (int i=0;i<n;i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
double pi=acos(-1);


int main(){
 double A,B,H,M;
  cin >> A>>B>>H>>M;
  
  double a,b;
  
  a=pi*2/12*H+pi*2/12/60*M;
  b=pi*2/60*M;
  
  double c=(a>b)?a-b:b-a;
  
  c=(c>2*pi-c)?2*pi-c:c;
  
  
  cout << fixed << setprecision(10) << sqrt(A*A+B*B-2*A*B*cos(c))<<endl;
 // cout <<  fixed << setprecision(10) <<cos(c) << endl;
  
 // cout << fixed << setprecision(10) << A/cos(c) << endl;
 
  
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define ll             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
//mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void sb()
{	
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int main()
{
	sb();
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='?')
			cout<<'D';
		else cout<<s[i];
	}
}

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

int main() {
  int D;
  cin >> D;
  const int T = 26;
  vector<int> c(T+1);
  vector<vector<long>> s(D+1, vector<long>(T+1));
  map<int, int> last;
  for (int i = 1; i <= D; i++) {
    last[i] = 0;
  }
  vector<long> t(D+1);
  long satis = 0;
  
  // 入力
  for (int i = 1; i <= T; i++) {
    cin >> c.at(i);
  }
  for (int i = 1; i <= D; i++) {
    for (int j = 1; j <= T; j++) {
      cin >> s.at(i).at(j);
    }
  }
  for (int i = 1; i <= D; i++) {
    cin >> t.at(i);
  }
  
  // 処理
  for (int i = 1; i <= D; i++) {
    // last更新
    last[t.at(i)] = i;
    // 増加分
    satis += s.at(i).at(t.at(i));
    // 減少分
    for (int j = 1; j <= T; j++) {
      if (j != t.at(i)) {
        satis -= c.at(j) * (i - last[j]);
      }
    }
    cout << satis << endl;
  }
  return 0;
}

Measured memory_bytes: 3740
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  while(n--){
    int m;
    int sx, sy, h, w;
    cin >> sx >> sy >> w >> h;
    cin >> m;
    int x, y;
    int cnt = 0;
    while(m--){
      cin >> x >> y;
      if(sx <= x && x <= sx+w && sy <= y && y <= sy+h) cnt++;
    }
    cout << cnt << endl;
  }
}

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

int main() {
	ll n, m, k;
	cin >> n >> m >> k;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			if (k - i * m - j * n + i * j + i * j==0) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
x = int(input())

#def prime number discriminator

def prime_or_not(a):
  b = 0
  i = 2

  if a == 2:
    ans = True
    
  else:
    while i <= a - 1 and b < 1:
      if a % (i)== 0:
        b += 1
        i += 1
      else:
        i += 1
      
      if b >= 1:
        ans = False
      else:
        ans = True

    return ans

ans = 0

if x == 2:
  print(2)
else:
  while ans <1:
    ans += prime_or_not(x)
    x += 1
  print(x - 1)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>

// MARK: - header
namespace {
using namespace std;
using ll = long long;
using ull = unsigned long long;
template<ull MOD>
struct Mod {
    ull v = 0;
    Mod() {};
    Mod(ull val) : v(val) {}
    operator ull() const {return v;}
    ull operator=(ll x) {return v = x % MOD;}
    ull operator+=(ll x) {return operator=(v + x);}
    ull operator*=(ll x) {return operator=(v * x);}
};
}

// MARK: - answer

vector<ll> ants;
ll K;

void input() {
    ants.resize(5);
    for (auto& a : ants)
        cin >> a;
    cin >> K;
}

bool solve() {
   return ants[4]-ants[0] <= K;
}

int main() {
    input();
    cout << (solve() ? "Yay!" : ":(") << endl;
//    solve();
    
    return 0;
}



Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(ll i=(x);i<(y);i++)
#define RREP(i,x,y) for(ll i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class FSumDifference {
public:
    void solve(std::istream& in, std::ostream& out) {
        ll N, X, D;
        in >> N >> X >> D;
        if (D == 0) {
            if (X == 0) {
                out << 1 << "\n";
            } else {
                out << N + 1 << "\n";
            }
            return;
        }
        if (D < 0) {
            X = -X;
            D = -D;
        }

        // k * X ~ k * X + (N-1) * D
        // range: k * X + (k-1)k/2 ~ k * X + ...
        // <=> Ck ~ Ck + D * Lk (Ck = k * X + (k-1)k/2 * D, Lk = (N-k)*k)
        // <=> C'k ~ C'k + Lk (C'k = (Ck - Ck % D) / D)

        unordered_map<ll, vector<pair<ll, ll>>> segments;
        REP(k, 0, N+1) {
            ll Ck = k * X + (k-1) * k / 2 * D;
            ll Lk = k * (2 * N - k - 1) / 2 - (k-1) * k / 2;
            ll s1 = (((k * abs(X)) / D + 1) * D + k * X) % D;
            ll s2 = ((abs(Ck) / D + 1) * D + Ck) % D;
            ll Cdk = (Ck - s2) / D;
            assert(abs(Ck - s2) % D == 0);
            segments[s1].emplace_back(Cdk, Cdk + Lk);
        }

        ll answer = 0;
        for (auto &seg : segments) {
            auto &pairs = seg.second;
            sort(all(pairs));
            int i = 0;
            while (i < pairs.size()) {
                ll left = pairs[i].first, right = pairs[i].second;
                while (true) {
                    i++;
                    if (i < pairs.size() && right >= pairs[i].first) {
                        right = max(right, pairs[i].second);
                    } else {
                        break;
                    }
                }
                answer += right - left + 1;
            }
        }
        out << answer << "\n";
    }
};


signed main() {
    FSumDifference solver;
    std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 17864
A,B,C,D=map(int,input().split())

takahashi=C//B
aoki=A//D
if C%B!=0:
    takahashi=takahashi+1
if A%D!=0:
    aoki=aoki+1
if takahashi <= aoki:
    print('Yes')
else:    
    print('No')



Measured memory_bytes: 9164
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define sz() size()
#define fr first
#define sc second
#define int long long
#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
using namespace std;

int n;

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    srand(chrono::steady_clock::now().time_since_epoch().count());
    cin >> n;
    vector<vector<int>> cost(n, vector<int>(n));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin >> cost[i][j];
        }
    }
    // O(2^n * n * n ~ 2 * 10^7)
    vector<int> precalc(1 << n);
    for(int i=0;i<(1 << n);i++){
        for(int j=0;j<n;j++){
            for(int t=j+1;t<n;t++){
                if(i & (1 << j) && i & (1 << t)) precalc[i] += cost[j][t];
            }
        }
    }
    // O(3^n) ~ 4 * 10^7
    vector<int> dp((1 << n));
    for(int i=1;i<(1 << n);i++){
        for(int j=i;j!=0;j=(j-1)&i){
            dp[i] = max(dp[i], dp[i ^ j] + precalc[j]);
        }
    }
    cout << dp[(1 << n) - 1] << '\n';
}


Measured memory_bytes: 4284
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main(){
    int n, ans = 0;
    cin >> n;
    vector<int> h(n), c(n, 1000000000);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    c[0] = 0;
    c[1] = abs(h[0] - h[1]);
    for(int i = 2; i < n; i++){
        c[i] = min(c[i - 2] + abs(h[i] - h[i - 2]), c[i - 1] + abs(h[i] - h[i - 1]));
    }
    cout << c[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 1024
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def main():
    N, A = map(int, input().split())
    X = list(map(int, input().split()))

    # dp[i][k][s] := i個までみて，それまでにk選んでて，そのときの総和がsとなる物の総数
    dp = [[[0] * (N * A + 1) for _ in range(N + 1)] for _ in range(N + 1)]

    dp[0][0][0] = 1
    for i in range(N):
        for k in range(N):
            for s in range(N * A + 1):
                # 使わない
                dp[i + 1][k][s] += dp[i][k][s]

                # 使う
                if s + X[i] <= N * A:
                    dp[i + 1][k + 1][s + X[i]] += dp[i][k][s]

    ans = 0
    for i in range(1, N + 1):
        ans += dp[-1][i][i * A]

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 91612
N, W = map(int, input().split())
w = [0] * N
v = [0] * N

for i in range(N):
    w[i], v[i] = map(int, input().split())

dp = [[0] * (W+1) for _ in range(N+1)]

for i in range(N):
    for sum_w in range(W+1):
        if w[i] <= sum_w:
            dp[i+1][sum_w] = max(dp[i][sum_w], dp[i][sum_w - w[i]] + v[i])
        else:
            dp[i+1][sum_w] = dp[i][sum_w]

print(dp[N][W])

Measured memory_bytes: 120172
#include<iostream>
using namespace std;
int main()
{
	string a;
	int i,k,j,q,w,s;
	while(cin>>a){
		s=0;w=0;q=0;
		for(i=0;a[i]!=NULL;i++){
			if(a[i]=='0')q++;
			else w++;
		}
		if(q>=w)cout<<w*2<<endl;
		else cout<<q*2<<endl;
		a.clear();
	}
	return 0;
} 

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

signed main() {
    string s;
    cin >> s;
    vector<int> b;
    vector<int> w;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'B') b.push_back(i);
        else w.push_back(i);
    }
    reverse(b.begin(), b.end());
    int cnt_b = 0;
    int cnt_w = 0;
    for (int i = 0; i < b.size(); i++) {
        cnt_b += s.size() - 1 - i - b[i];
    }
    for (int i = 0; i < w.size(); i++) {
        cnt_w += w[i] - i;
    }
    cout << max(cnt_b, cnt_w) << "\n";
}

Measured memory_bytes: 2808
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
 
public class Main {
	static Scanner in;
	static char s[];
	static long k;
	public static void main(String[] args) throws FileNotFoundException {
//		in = new Scanner(new File("input.txt"));
		in = new Scanner(System.in);
		s = in.next().toCharArray();
		k = in.nextLong();
		for(int i = 0;i < s.length;i++){
			if(s[i] == 'a') continue;
			int diff = 'z' + 1 - s[i];
			if(k < diff) continue;
			s[i] = 'a';
			k -= diff;
		}
		if(k > 0){
			int diff = 'z' - s[s.length - 1];
			k = k%26;
			if(k > diff) s[s.length - 1] = (char) ('a' + k - diff - 1);
			else s[s.length - 1] = (char) (s[s.length - 1] + k);
		}
		for(int i = 0;i < s.length;i++) System.out.print(s[i]);
	}
}

Measured memory_bytes: 23532
#include<iostream>

using namespace std;

int main(){
	char b;
	cin >> b;
	if (b == 'A') {
		cout << 'T' << endl;
	}
	else if (b == 'T') {
		cout << 'A' << endl;
	}
	else if (b == 'C') {
		cout << 'G' << endl;
	}
	else {
		cout << 'C' << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 110
#define ll long long
#define For(i,x,y) for(int i=(x);i<=(y);++i)
#define Rof(i,x,y) for(int i=(x);i>=(y);--i)
#define Edge(x) for(int i=head[x],to=e[i].v;i;i=e[i].nxt,to=e[i].v)
#define Cur(x) for(int &i=cur[x],to=e[i].v;i;i=e[i].nxt,to=e[i].v)
#define mset(x,y) memset(x,y,sizeof(x))
using namespace std;
const int S=0,T=102;
int dep[N],n,head[N],cur[N],cnt=1,a[N];
queue<int> q;
struct ed{ int v,nxt;ll f; }e[N*32];
void add(int u,int v,ll f){
	e[++cnt]=(ed){v,head[u],f},head[u]=cnt;
	e[++cnt]=(ed){u,head[v],0},head[v]=cnt;
}
bool bfs(){
	while(!q.empty()) q.pop();
	For(i,0,T) cur[i]=head[i],dep[i]=0;
	dep[S]=1,q.push(S);
	while(!q.empty()){
		int x=q.front();q.pop();
		Edge(x) if(!dep[to] && e[i].f) dep[to]=dep[x]+1,q.push(to);
	}
	return dep[T];
}
ll dfs(int x,ll f){
	if(x==T) return f;
	ll use=0;
	Cur(x){
		if(dep[to]==dep[x]+1 && e[i].f){
			ll o=min(f-use,e[i].f);
			ll w=dfs(to,o);
			use+=w,e[i].f-=w,e[i^1].f+=w;
			if(f==use) return f;
		}
	} return use;
}
int main(){
	ll ans=0,sum=0;
	scanf("%d",&n);
	For(i,1,n) scanf("%d",&a[i]),a[i]=-a[i];
	For(i,1,n) for(int j=2*i;j<=n;j+=i) add(i,j,(ll)1e18);
	For(i,1,n){
		if(a[i]>0) add(S,i,a[i]);
		else add(i,T,-a[i]),sum+=-a[i];
	}
	while(bfs()) ans+=dfs(S,(ll)1e18);
	printf("%lld\n",sum-ans);
}

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

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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef long double ld;

int vector_finder(std::vector<int> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  } else { // 発見できなかったとき
    return 0;
  }
}

struct edge_t {
  int dest;
  int weight;
};

struct vertex_t {
  vector<edge_t> edges;
  vector<int> weight;

  // for dijkstra
  bool done; // confirm or not
  int cost;  // now cost
  int from;

  bool operator<(const vertex_t &another) const { // priority --> min
    return another.cost < cost;                   // order(cost)
  }

  bool operator>(const vertex_t &another) const { // priority --> min
    return another.cost > cost;                   // order(cost)
  }

  bool operator==(const vertex_t &another) const {
    return another.cost == cost; // order(cost)
  }

  vertex_t() {
    cost = INF;
    done = false;
  }
};

int bellman_ford(vector<vertex_t> &graph, int size, int start) {
  int i, j, k, count = 0;
  bool flag = false;
  graph[start].cost = 0;
  REP(i, size) {
    REP(j, size) {
      vertex_t cur = graph[j];
      for (edge_t edge : cur.edges) {
        if (cur.cost + edge.weight < graph[edge.dest].cost) {
          if (i == size - 1)
            flag = true;
          graph[edge.dest].cost = cur.cost + edge.weight;
        }
      }
    }
  }
  if (flag) {
    return 1;
  } else {
    return 0;
  }
}

class tree_t {
  public:
  bool is_leaf;
  tree_t *right;
  tree_t *left;

  tree_t() {
    is_leaf = false;
    right = NULL;
    left = NULL;
  }
};

vector<string> splitstr(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch : s) {
    if (ch == delim) {
      if (!item.empty())
        elems.push_back(item);
      item.clear();
    } else {
      item += ch;
    }
  }
  if (!item.empty())
    elems.push_back(item);
  return elems;
}

////////////////////////// let's code! /////////////////////////////

int i, j, k;

///// variables frequent to use /////

unsigned GetDigit(unsigned num) {
  unsigned digit = 0;
  while (num != 0) {
    num /= 10;
    digit++;
  }
  return digit;
}

int main() {

  int N;

  cin >> N;

  int n = GetDigit(N);

  int sum = 0;

  if (n % 2 == 0) {
    //偶数
    //n-1, n-3, ..., 1
    for (i = n - 1; i > 0; i = i - 2) {
      sum += pow(10, i) - pow(10, i - 1);
    }
  } else {
    //odd
    //n-2, n-4, ..., 1
    for (i = n - 2; i > 0; i = i - 2) {
      sum += pow(10, i) - pow(10, i - 1);
    }
    sum += N - pow(10, n - 1) + 1;
  }

  cout << sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1000000007;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) cout << (x) << endl;
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
 
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;

int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll n;
    cin >> n;
    ll a,b;
    cin >> a >> b;
    vector<ll> p(n);
    rep(i,n) cin >> p[i];
    ll min1 = 0;
    ll min2 = 0;
    ll min3 = 0;
    rep(i,n){
      if(p[i] <= a) min1++;
      if(a+1 <= p[i] && p[i] <= b) min2++;
      if(p[i] >= b+1) min3++;
    }
    print(min({min1,min2,min3}));
}

Measured memory_bytes: 256
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;

int main()
{
    int k;
    string s;
    cin >> k >> s;
    if(s.size() <= k) cout << s << endl;
    else{
        rep(i, k){
            cout << s[i];
        }
        cout << "..." << endl;
    }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (int) 2e5 + 17;

int n, m;

bool read()
{
	if (scanf("%d %d", &n, &m) != 2)
		return false;

	return true;
}

llong f(llong i) { return i == 0 ? 1 : f(i - 1) * i % inf; }

void solve()
{
	llong ans = 0;

	if (n == m)
		ans = 2ll * f(n) * f(m) % inf;
	else if (max(n, m) == min(n, m) + 1)
		ans = f(n) * f(m) % inf;

	printf("%lld\n", ans);
}

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif
 
	while (read())
		solve();
 
	return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

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

        String str = sc.next();

        sc.close();

        int date = Integer.parseInt(str.replace("/", ""));

        //        Date in = DateFormat.getDateInstance().parse(str);
        //        Date date = DateFormat.getDateInstance().parse("2019/04/30");

        if (date <= 20190430) {
            System.out.println("Heisei");
        } else {
            System.out.println("TBD");
        }
    }
}


Measured memory_bytes: 21844
def nC2(n):
    if n < 2:
        return 0
    return n * (n-1) // 2

def main():
    N = int(input())
    S = [''.join(sorted(input())) for _ in range(N)]
    counter = {}
    for s in S:
        if s in counter:
            counter[s] += 1
        else:
            counter[s] = 1
    ans = sum([nC2(v) for v in counter.values()])
    print(ans)

main()

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

int main() {
  ll l,r;
  cin >> l >> r;
  
  r = min(r,l+2019);
  
  int ans = 2018;
  
  for (ll i=l; i<r; i++){
    for(ll j=i+1; j<=r; j++){
      int amari = i*j%2019;
      ans = min(ans, amari);
    }
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

int main() {
    int n;  ll m;   cin >> n >> m;
    vector<ll> a(n), s(n+1, 0);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        s[i+1] = (s[i] + a[i]) % m;
    }

    map<ll, ll> mp;
    for (int i = 0; i <= n; i++) {
        mp[s[i]]++;
    }

    ll ans = 0;
    for (auto ite: mp) {
        ll c = ite.second;
        ans += c * (c-1) / 2;
    }

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

Measured memory_bytes: 8688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
#define int long long
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

signed main() {
    int n;
    cin >> n;
    int d[n];
    rep (i, 0, n) cin >> d[i];
    int m;
    cin >> m;
    int t[m];
    map<int, int> mp;
    rep (i, 0, m) {
        cin >> t[i];
        mp[t[i]]++;
    }
    sort (d, d + n);
    for (auto p : mp) {
        int cnt =
            upper_bound (d, d + n, p.first) - lower_bound (d, d + n, p.first);
        if (cnt < p.second) {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
}

Measured memory_bytes: 19224
#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
ll n,x,a[3000],b[3000];
int main(){
	cin >> n >> x;
	REP(i,n) {
		cin >> a[i];
		b[i] = a[i];
	}

	ll ans = 1000000000000000;
	REP(i,n) {
		ll sum = 0;
		REP(j,n) {
			b[j] = min(b[j],a[(j - i + n) % n]);
		}
		REP(j,n)
			sum += b[j];
		ans = min(ans,sum + x * i);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<pair<int, int>> ba(n);
    // vector<int> a(n), b(n);
    rep(i,n){
        long long int bufa, bufb;
        // cin >> a[i] >> b[i];
        cin >> bufa >> bufb;
        pair<int, int> buf = make_pair(bufb,bufa);
    //   ba.insert(buf);
        ba[i] = buf;
    //   show(buf.first)
    }
    sort(all(ba));
    vector<long long int> dp(n+10);
    dp[0] = 0;
    // auto itr =  ba.begin();
    rep(i,n){
                    // show(i)
                    // show()
        // pair<int, int> che = *itr;
        // shows(ba[i].first) show(ba[i].second)
        dp[i+1] = dp[i] + ba[i].second;
        // shows(dp[i+1]) shows(che.first) show(che.second)
        if (dp[i+1] > ba[i].first){
            cout << "No";
            return 0;
        }
            // itr++;
    }
    cout << "Yes";
}

Measured memory_bytes: 3328
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static long mod =1000000007;
	public static void main(String[] args) {
		long N=sc.nextLong();
		
		List<Long> cc = new ArrayList<>((int)N);
		for(int i=0;i<3*N;i++) {
			cc.add(sc.nextLong());
		}
		Collections.sort(cc);
		int a=(int) (3*N-2);
		long ans=0;
		for(int i=0;i<N;i++) {
			ans+=cc.get(a);
			a-=2;
			
		}p(ans);
		//System.out.println(cc);
	}
	//N==S
	//E==W
//83 S 
	//69E
	//78N
	//87W
	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 103100
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,tuple<int,int,int>> pti;
#define rep(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

int S;
int main(){
  cin >> S;
  int xx = S%100;
  int yy = S/100;
  bool YYMM,MMYY;
  YYMM = (xx>=1&&xx<=12);
  MMYY = (yy>=1&&yy<=12);
  if(YYMM&&MMYY) cout << "AMBIGUOUS" << endl;
  if(YYMM&&!MMYY) cout << "YYMM" << endl;
  if(!YYMM&&MMYY) cout << "MMYY" << endl;
  if(!YYMM&&!MMYY) cout << "NA" << endl;
}

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a>=b)
        	System.out.println("delicious");
        else if((b-a) <= x)
        	System.out.println("safe");
        else
        	System.out.println("dangerous");

	}

}


Measured memory_bytes: 23764
#include <stdio.h>
#include <stdlib.h>
 
#define WHITE 0  
#define GRAY 1    
#define BLACK 2   
 
char Adj[100][100]; 
int n, d[100],f[100],color[100],time;         
 


void visit( int u ) {
short v;
 
color[u] = GRAY;    
d[u] = ++time;  
   
for( v = 0 ; v < n ; v++ ) {
if( Adj[u][v] == 1 && color[v] == WHITE ) {
visit( v );                             
}
}
 
color[u] = BLACK;
f[u] = ++time;
 
return;
 
}

void dfs() {
short i;
   
for( i = 0 ; i < n ; i++ ) {
if( color[i] == WHITE ) {
visit( i );
}
}
return;
}
 
 
 
main() {
 
int i, j,u, k, v;
 
scanf( "%d",&n );
   
for( i = 0 ; i < n ; i++ ) {
for( j = 0 ; j < n ; j++ ) {
Adj[i][j] = 0;
}
}
 
   
for( i = 0 ; i < n ; i++ ) {
scanf( "%d%d", &u,&k );
     
for( j = 0  ; j < k; j++ ) {
scanf( "%d",&v );
Adj[u-1][v-1] = 1;
}
     
}
 
dfs();
   
for( i=0; i<n; i++ ) {
printf("%d %d %d\n", i+1, d[i], f[i] );
}

return 0;
 
}
  

Measured memory_bytes: 604
import java.io.*;
import java.util.*;

/**
 * Created by tela on 2017/06/18.
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; ++i) a[i] = in.nextInt();

            int max = a[0];
            int min = a[0];
            for (int i = 0; i< n; i++){
                if(max < a[i])max = a[i];
                if(min > a[i])min = a[i];
            }

            int n0 = 0;
            int n1 = 0;
            for (int x : a){
                if (x == max) n0+=1;
                if (x == min) n1+=1;
            }

            if(max-min >= 2){
                out.println("No");
                return;
            }
            else if((max-min)==0){
                if(max == n - 1){
                    out.println("Yes");
                    return;
                }
                else if(2*max <= n){
                    out.println("Yes");
                    return;
                }else{
                    out.println("No");
                    return;
                }
            }else if(((max-min)==1)){
                if(max > n1 &&2*(max - n1) <= n0){
                    out.println("Yes");
                    return;
                }else{
                    out.println("No");
                    return;
                }
            }
        }
    }

    //input
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


Measured memory_bytes: 34184
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>
#include <cstdint>

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

using namespace std;
typedef long long ll;

const int INF = 1 << 30;
const int MOD = 1e9 + 7;

vector<int> memo1;
vector<int> memo2;
vector<vector<int>> g;

void dfs(int v, vector<int>& memo, int d=0,int p=-1){
    memo[v] = d;
    for (int nv: g[v]) {
        if (nv == p) continue;
        dfs(nv, memo, d+1, v);
    }
}

int main() {
    int k; cin >> k;
    vector<int> a(k); rep(i, k) cin >> a[i];
    ll child = 2;
    ll mn = 2;
    ll mx = 2;
    for (int i = k-1; i >= 0; i--) {
        if ((mn + a[i]) % a[i] > 0) mn = (mn / a[i] + 1) * a[i];
        mx = mx / a[i] * a[i] + a[i] - 1;
        if (mn > mx) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << mn << " " << mx << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll p(ll a, ll n)
{
    if(n == 0) return 1;
    ll x = p(a, n/2);
    ll ans = x * x % mod;
    if(n % 2 == 1) ans = ans *a % mod;
    return ans%mod;
}
ll C(ll n,ll m) {
    if(n < m) return 0;
    ll res = 1;
    for(ll i=1; i<=m; i++) {
        ll a = (n+i-m)%mod;
        ll b = i%mod;
        res = res*(a*p(b,mod-2)%mod)%mod;
    }
    return res;
}
ll Lucas(ll n,ll m) {
    if(m == 0) return 1;
    return C(n%mod, m%mod) * Lucas(n/mod,m/mod)%mod;
}
int main(){
  ll n,a,b;
    cin>>n>>a>>b;
    ll ans=p(2,n)-Lucas(n,a)-Lucas(n,b)-1;
   while(ans<0) {
        ans+=mod;
    }
    cout<<ans%mod;
    return 0;
}

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

int n;
long long int dis[20][20];
long long int dp[1 << 16];
long long int inf = 100000 * 16 + 1;

int main() {

    while(true) {

        scanf(" %d",&n);

        if(n == 0){
            break;
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n + 1; j++) {
                scanf(" %lld",&dis[i][j]);
            }
        }

        for (int i = 0; i < (1 << n); i++) {
            dp[i] = inf;
        }

        dp[0] = 0;

        for (int i = 0; i < (1 << n); i++) {
            for (int j = 0; j < n; j++) {
                if (dp[i] == inf) continue;

                //次の状態について探索
                for (int k = 0; k < n; k++) {
                    if ((i >> k) % 2 == 1) {
                        continue;
                    }
                    int next_i = i | (1 << k);
                    long long int min_dis = dis[k][0];

                    for (int r = 0; r < n; r++) {
                        if (i & (1 << r)) {
                            min_dis = min(min_dis, dis[k][r + 1]);
                        }
                    }

                    long long int next_d = dp[i] + min_dis;
                    dp[next_i] = min(dp[next_i], next_d);
                }
            }
        }

        int all = 0;

        for (int i = 0; i < n; i++) {
            int add = 1 << i;
            all += add;
        }

        printf("%lld\n",dp[all]);

    }

    return 0;
}


Measured memory_bytes: 3720
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

int n;
char s[100002];

int f (int i, char a, char b, char* ans) {
  if (i == n) {
    if (b == 'S') {
      if (s[n-1] == 'o' && ans[0] != a) return 1;
      else if (s[n-1] == 'x' && ans[0] != (a == 'S'?'W':'S')) return 1;
    } else {
      if (s[n-1] == 'x' && ans[0] != a) return 1;
      else if (s[n-1] == 'o' && ans[0] != (a == 'S'?'W':'S')) return 1;
    }
    if (ans[0] == 'S') {
      if ( s[0] == 'o' && ans[1] != b) {return 1;}
      else if (s[0] == 'x' && ans[1] != (b == 'S'?'W':'S')) {return 1;}
    } else {
      if (s[0] == 'x' && ans[1] != b) return 1;
      else if (s[0] == 'o' && ans[1] != (b == 'S'?'W':'S')) return 1;
    }
    return 0;
  }
  if (b == 'S') {
    if (s[i-1] == 'o') ans[i] = a;
    else ans[i] = a == 'S'? 'W' : 'S';
  } else {
    if (s[i-1] == 'x') ans[i] = a;
    else ans[i] = a == 'S'? 'W' : 'S';
  }
  return f(i+1, b, ans[i], ans);
}

int main () {
  int ret;
  string str = "";
  char ans[1000002];
  cin >> n >> s;
  for (int i = 0; i < n + 1; i++) ans[i]=0;

  if ( f(2, ans[0] = 'S', ans[1] = 'S', ans)
       && f(2, ans[0] = 'W', ans[1] = 'S', ans)
       && f(2, ans[0] = 'S', ans[1] = 'W', ans)
       && f(2, ans[0] = 'W', ans[1] = 'W', ans) ) {
    cout << -1 << endl;
  } else cout << ans << endl;
  return 0;
}

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

typedef long long ll;

const int N = 51;
int n;
int d[N];
int psum[N];

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

    cin >> n;
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> d[i];
        sum += d[i];
        psum[i] = sum;
    }
    int res = 0;
    for (int i = 0; i < n; ++i) {
        res += d[i] * (sum - psum[i]);
    }
    cout << res << endl;


    return 0;
}



Measured memory_bytes: 256
import bisect
 
n = int(input())
as_ = list(map(int, input().split()))
bs_ = list(map(int, input().split()))
cs_ = list(map(int, input().split()))
 
as_.sort()
bs_.sort()
cs_.sort()
 
ans = 0
for b in bs_:
  ans += bisect.bisect_left(as_, b) * (n-bisect.bisect_right(cs_, b))
print(ans)

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int a, b, tmp, ans;
  while (cin >> a >> b) {
    tmp = a + b;
    ans = 0;
    while (true) {
      ans++;
      if (tmp / 10 <= 0) {
        cout << ans << '\n';
        break;
      }
      tmp /= 10;
    }
  }
  return 0;
}



Measured memory_bytes: 3112