akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    ll A[2];
    rep(i,2){
        cin >> A[i];
    }
    cout << A[0]*A[1]-A[0]-A[1]+1 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		if(n == 1) {
			System.out.println("Hello World");
		}else {
			int a = sc.nextInt();
			int b = sc.nextInt();
			System.out.println(a+b);
		}
	}
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define f first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define all(x) x.begin(), x.end()

const int N = 401, mod = 110119, inf = 1e9 + 7, LOG = 20;
ll n, a[N], dp[N][N], pr[N];

ll bp(int x, int y){
    if(y == 0)
        return 1;
    if(y % 2 == 0){
        ll z = bp(x, y / 2);
        return (z * z) % mod;
    }
    return (bp(x, y - 1) * x) % mod;
}

ll go(int l, int r){
    if(l == r)
        return 0;
    if(dp[l][r])
        return dp[l][r];
    ll ans = 1e18;
    for(int i = l; i < r; i++)
        ans = min(ans, go(l, i) + go(i + 1, r) + pr[r] - pr[l - 1]);
    dp[l][r] = ans;
    return ans;
}

int main(){
    boost;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        pr[i] = pr[i - 1] + a[i];
    }
    cout << go(1, n);
    return 0;
}



Measured memory_bytes: 1664
from collections import defaultdict

N = int(input())
A = [0] + list(map(int, input().split()))
d = defaultdict(int)

ans = 0
for i in range(1, N + 1):
    d[A[i] + i] += 1  # Ai + iを数える
    ans += d[i - A[i]]

print(ans)


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

#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
static vector<int> fin(1000000,0);
static int c=0;

struct UnionFind {
    //自身が親であれば、その集合に属する頂点数に-1を掛けたもの
    //そうでなければ親のid
    vector<int> r;
 
    UnionFind(int N) {
        r = vector<int>(N, -1);
    }
 
    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }
 
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }
 
    int size(int x) {
        return -r[root(x)];
    }

};

int main()
{
    int n,m;
    cin >> n >> m;
    UnionFind uf(n);

    rep(i,m){
        int a,b;
        cin >> a >> b;
        a-=1;b-=1;
        uf.unite(a,b);
    }

    int ans=0;
    rep(i,n){
        ans=max(ans,uf.size(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 8016
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
   int n,k;cin>>n>>k;
   int res = 1;
   while(n--){
       if(res>k)res += k;
       else res += res;
   }
   cout<<res;
}



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

using ll = long long;
const ll amari = 1e9+7;
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)

int main(){
	int n,k;
	string s;
	cin >> n >> k >> s;
	int l = 0,r = 1;
	int ok = 0;
	int sum = 0;
	int maxi = 0;
	int p[100000];
	if(n == 1){
		cout << 1 << endl;
		return 0;
	}
	for(int i = 1; i < n; i++){
		if(s[i] == '1' && s[i - 1] == '0'){
			p[ok] = i;
			ok++;
		}
	}
	int back = 0;
	while(true){
		if(s[r] == '0' && s[r + 1] == '1')sum++;

		if((sum == k && s[r] == '1' && s[r + 1] == '0') || (r == s.size() - 1)){
			maxi = max(maxi, r + 1 - l);
			if(r == n - 1)break;
			l = p[back];
			r = l + 1;
			back++;
			sum = 0;
		}
		else r++;
	}
	cout << maxi  << endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();

        final List<Integer> list = IntStream.range(0, n)
                .mapToObj(i -> scanner.nextInt())
                .collect(Collectors.toList());

        final int[] b = new int[n];
        for (int i = 0; i < list.size(); i++) {
            final int k = n % 2 == 0 ? i : -i;
            final int a = list.get(i);
            if (i % 2 == 0) {
                b[(n + k ) / 2] = a;
            } else {
                b[(n - k ) / 2] = a;
            }
        }

        for (final int i : b) {
            System.out.print(i + " ");
        }
    }
}


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

int main(void) {
	int n, m; cin >> n >> m;
	int a[n], b[n], c[m], d[m];
	int check = 1000000001 , ans[n];
	int i;
	for (i = 0; i < n; i++) {
		cin >> a[i];
		cin >> b[i];
	}

	for (i = 0; i < m; i++) {
		cin >> c[i];
		cin >> d[i];
	}

	for (i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (abs(a[i] - c[j]) + abs(b[i] - d[j]) < check) {
				check = abs(a[i] - c[j]) + abs(b[i] - d[j]);
				ans[i] = j + 1;
			}
		}
		check = 1000000001;
	}

	for (i = 0; i < n; i++) {
		cout << ans[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const int MAXN = 101024;

int a[MAXN];

int main() {
    int n; cin>>n;
    for(int i = 0; i < n; ++i) {
        cin>>a[i];
    }
    sort(a, a + n);
    int ai = a[n-1];
    int midl, midr;
    if(ai % 2 == 0) {
        midl = ai / 2;
        midr = midl;
    }
    else {
        midl = (ai - 1) / 2;
        midr = midl + 1;
    }
    int dist = INF;
    int ii;
    for(int i = 0; i < n-1; ++i) {
        int _dist = min(abs(a[i] - midl), abs(a[i] - midr));
        if(_dist < dist) {
            dist = _dist;
            ii = i;
        }
    }
    int aj = a[ii];
    cout << ai << " " << aj << endl;
    return 0;
}


Measured memory_bytes: 640
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    A = list(map(int, input().split()))
    BC = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: -x[1])
    C = []
    for b, c in BC:
        if len(C) >= n:
            break
        C += [c] * b
    A += C
    A.sort(reverse=True)
    res = sum(A[:n])
    print(res)


if __name__ == '__main__':
    resolve()


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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

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

int main(void){

    int s, w;
    cin >> s >> w;

    cout << (s <= w ? "unsafe": "safe");

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());
const int N = 1e5,M = 998244353;
int n,freq[N],ans = 1;
int power(int base,int to){
	int ret = 1;
	while(to){
		if(to&1)ret = ret*1LL*base%M;
		to>>=1;
		base = base*1LL*base%M;
	}
	return ret;
}
int main(){
	//freopen("input.txt","r",stdin);
	scanf("%d",&n);
	for(int i = 0,a;i < n;i++){
		scanf("%d",&a);
		freq[a]++;
		if(freq[0] != 1)ans = 0;
	}
	for(int i = 1;i < n;i++)ans = ans*1LL*power(freq[i - 1],freq[i])%M;
	printf("%d\n",ans);
}

Measured memory_bytes: 640
#include <iostream>
#include <queue>

using namespace std;

const int MAXN = 1e3 + 5;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

int m, n, ans = 0;
char ch[MAXN][MAXN];
bool vis[MAXN][MAXN];

struct Data{
	int x, y, val;
};

void Bfs() {
	queue<Data> q;
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			if (ch[i][j] == '#') {
				q.push((Data){i, j, 0});
				vis[i][j] = true;
			}
		}
	}
	while (!q.empty()) {
		Data now = q.front(); q.pop();
		ans = max(ans, now.val);
		for (int i = 0; i < 4; i++) {
			int nx = X[i] + now.x, ny = Y[i] + now.y;
			if (nx < 1 || nx > m || ny < 1 || ny > n) continue;
			if (ch[nx][ny] != '#') q.push((Data){nx, ny, now.val + 1}), ch[nx][ny] = '#';
		}
	}
}

int main() {
	cin >> m >> n;
	for (int i = 1; i <= m; i++) cin >> ch[i] + 1;
	Bfs();
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 14352
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cstdio>
using namespace std;

int getint(){
    int x = 0, c = getchar();
    while(c > 47 && c < 58){
        x = x * 10 + c - 48;
        c = getchar();
    }
    return x;
}

constexpr int MAX = 300001;
int res[MAX * 4];
//rows : 1 ~ MAX
//cols : 1 + MAX ~ 2 * MAX
//hs : 1 + 2 * MAX ~ 3 * MAX
//ws : 1 + 3 * MAX ~ 4 * MAX

int main(){
    int H = getint();
    int W = getint();
    int M = getint();
    int h, w, ans;
    int mxr = 0;
    int mxc = 0;
    int ctrow = 0;
    int ctcol = 0;
    for(int i = 0; i < M; ++i){
        h = getint(), w = getint();
        res[i + 2 * MAX] = h, res[i + 3 * MAX] = w;
        ++res[h], ++res[w + MAX];

        if(res[h] == mxr) ++ctrow;
        if(res[h] > mxr){
            mxr = res[h];
            ctrow = 1;
        }

        if(res[w + MAX] == mxc) ++ctcol;
        if(res[w + MAX] > mxc){
            mxc = res[w + MAX];
            ctcol = 1;
        }
    }

    long ct = ctrow;
    ct *= ctcol;
    ans = mxr + mxc;

    for(int i = 0; i < M; ++i) if(res[res[i + 2 * MAX]] == mxr && res[res[i + 3 * MAX] + MAX] == mxc) --ct;
    if(ct <= 0) --ans;
    printf("%d\n", ans);
}

Measured memory_bytes: 6288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll>PLL;
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll MOD = 1e4+7;
int main() {
    int n;
    int a, b;
    cin >> n >> a >> b;
    int ans = 0;
    for ( int i = 1; i <= n; ++i ) {
        int tmp_num = i;
        int tmp_sum = 0;
        while(tmp_num>0) {
            tmp_sum += tmp_num % 10;
            tmp_num /= 10;
        }
        if ( tmp_sum >= a && tmp_sum <= b ) ans += i;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll x,y,z;
  cin >> x >> y >> z;
  cout << z << " " << x << " " << y << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>

using namespace std;

double sq(double x){return x*x;}

int main(){
	int t;
	cin>>t;
	while(t--){
		double xa,ya,ra,xb,yb,rb;
		cin>>xa>>ya>>ra>>xb>>yb>>rb;
		double len = sqrt(sq(xa-xb)+sq(ya-yb));
		if(len + rb < ra)
			puts("2");
		else if(len + ra < rb)
			puts("-2");
		else if(len <= ra + rb)
			puts("1");
		else 
			puts("0");
	}

	return 0;
}

Measured memory_bytes: 0
//abc151_a.cpp
//Sun Jan 12 20:59:38 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	char s;
	cin >> s;

	char ans = s + 1;
	cout << ans<< endl;
//	printf("%.4f\n",ans);
}

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

int main(){
  int n, sn=0;
  cin >> n;

  int nc=n;

  while(n!=0){
    sn+=n%10;
    n/=10;
  }

  if(nc%sn==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;
int main() {
  int X;
  cin >> X;
  int i,j;
  bool f = true;
  for(i=-120;i<120&&f;i++) {
    for(j=-120;j<120&&f;j++) {
      if(pow(i,5)-pow(j,5)==X) {
        cout << i << " " << j << endl;
        f = false;
      }
    }
  }
}

Measured memory_bytes: 4060
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define inf 1e9
#define INF 1000000000000000000

int main() {
    ll N, K;
    cin >> N >> K;
    ll res = 0;
    if (K == 0)
        res += (1 + (N - K - 1)) * (N - K - 1) / 2;
    else
        res += (1 + (N - K)) * (N - K) / 2;

    for (int i = K + 1; i <= N; i++) {
        ll katamari = N / i - 1;
        ll amari = N % i;
        ll kosuu = i - K;
        res += katamari * kosuu;
        if (amari >= K)
            res += amari - K + 1;
    }

    cout << res << endl;
}

Measured memory_bytes: 256
import javax.print.DocFlavor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.BiConsumer;

public class Main {

    //グローバル変数を定義

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;

        while(true){
            if(n == 111){
                ans = 111;
                break;
            }
            if(n == 222){
                ans = 222;
                break;
            }
            if(n == 333){
                ans = 333;
                break;
            }
            if(n == 444){
                ans = 444;
                break;
            }
            if(n == 555){
                ans = 555;
                break;
            }
            if(n == 666){
                ans = 666;
                break;
            }
            if(n == 777){
                ans = 777;
                break;
            }
            if(n == 888){
                ans = 888;
                break;
            }
            if(n == 999){
                ans = 999;
                break;
            }
            n++;
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n,a,b;
  string s;
  cin >> n >> a >> b >> s;
  int cnt=0,cntb=0;
  rep(i,n){
    bool p=false;
    if(s[i]=='a'){
      if(cnt<a+b){
        p=true;
        cnt++;
      }
    }
    else if(s[i]=='b'){
      if(cnt<a+b && cntb<b){
        p=true;
        cnt++;cntb++;
      }
    }
    puts(p ? "Yes":"No");
  }
  return 0;
}


Measured memory_bytes: 896
#include<vector>
#include<iostream>
#include<list>
#include<algorithm>
#include<chrono>
#include<map>
#include<set>
#include<string>
#include<unordered_map>

using namespace std;


int main()
{
    char a;
    cin >> a;
    if(a >= 'A' && a <= 'Z') cout << 'A';
    if(a >= 'a' && a <= 'z') cout << 'a';
}

Measured memory_bytes: 3068
# 取得
nn = int(input());
n = nn;

a = []
while n % 2 == 0:
    a.append(2)
    n //= 2
f = 3
while f * f <= n:
    if n % f == 0:
        a.append(f)
        n //= f
    else:
        f += 2
if n != 1:
    a.append(n)

b = len(a);

#操作回数
if nn == 1:
    count = 0;
else:
    count = 1;
    x = 1;
    y = 1;

    for i in range(1,b):
        if a[i] == a[i-1]:
            x += 1;
            z = y * (y+1) // 2;
            if x - z > y:
                count += 1;
                y += 1;
            
        else:
            x = 1;
            y = 1;
            count += 1;
            
    
print(count);

Measured memory_bytes: 9068
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
S = [input() for _ in range(N)]

print(len(set(S)))


Measured memory_bytes: 107676
#include <bits/stdc++.h>
using namespace std;
//actual solution is at bottom//
////<pbds>////
/*OPTIONAL
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, 
    rb_tree_tag, tree_order_statistics_node_update>; 
// change null_type for map
#define ook order_of_key
#define fbo find_by_order
*/
///</pbds>///

#define int long long int
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()

///<constants>///
const int MOD = 1e9+7; // 998244353; // = (119<<23)+1
const int MX = 2e5+5; 
const ll INF = 1e18; 
const ld PI = 4*atan((ld)1); 
const int xd[4] = {0,1,0,-1}, yd[4] = {1,0,-1,0};
///</constants>///

///<IO>/// 
namespace io {
    void setIn(string s) { freopen(s.c_str(),"r",stdin); }
    void setOut(string s) { freopen(s.c_str(),"w",stdout); }
    void setIO(string s = "") {
        ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
        // cin.exceptions(cin.failbit); // ex. throws exception when you try to read letter into int
        if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
    }
}
 
using namespace io;
///</IO>///

///<execution-time>///
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
/*example for clock usage
    clock_t z = clock();
    debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
*/
///</execution-time>///

inline void google(int i){
    cout<<"Case #"<<i<<" :";
}
signed main(){
    setIO("");
    string s;cin>>s;
    if(s[s.size()-1]!='s')cout<<s<<"s";
    else cout<<s<<"es";
    return 0;
}
/* stuff you should look for
    * check whether you have read the problem correctly
    * int overflow, array bounds
    * special cases (n=1?), slow multiset operations
    * do smth instead of nothing and stay organized
*/

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

i64 N;
double dp[303][303][303];
bool flag[303][303][303];

double rec(i64 a, i64 b, i64 c) {
  if(a < 0 || b < 0 || c < 0) return 0;
  if(a <= 0 && b <= 0 && c <= 0) return 0;
  if(flag[a][b][c]) return dp[a][b][c];
  dp[a][b][c] = rec(a - 1, b, c) * a / N + rec(a + 1, b - 1, c) * b / N + rec(a, b + 1, c - 1) * c / N;
  dp[a][b][c] += 1;
  dp[a][b][c] /= (1 - (double)(N - a - b - c) / N);
  flag[a][b][c] = true;
  return dp[a][b][c];
}

int main() {
  cin >> N;
  i64 a = 0;
  i64 b = 0;
  i64 c = 0;
  for(int i = 0;i < N;i++) {
    i64 x;
    cin >> x;
    if(x == 1) a++;
    if(x == 2) b++;
    if(x == 3) c++;
  }
  cout << fixed << setprecision(10);
  cout << rec(a, b, c) << endl;
}


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

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

    int ma=-1e7;
    int i_max;
    int mi=1e7;
    int i_min;
    for(int i=0;i<N;i++){
        if(ma<=a[i]){
            ma=a[i];
            i_max=i;
        }
        if(mi>=a[i]){
            mi=a[i];
            i_min=i;
        }
    }
    vector<pair<int,int>> ans;
    //cout << ma << mi << endl;
    if(ma+mi>=0){
        for(int i=0;i<N;i++){
            if(a[i]<0){
                ans.push_back({i_max,i});
            }
        }
        for(int i=0;i<N-1;i++){
            ans.push_back({i,i+1});
        }
    }else{
        for(int i=0;i<N;i++){
            if(a[i]>0){
                ans.push_back({i_min,i});
            }
        }
        for(int i=N-1;i>0;i--){
            ans.push_back({i,i-1});
        }
    }
    cout << ans.size() << endl;
    for(int i=0;i<ans.size();i++){
        cout << ans[i].first+1 << " " << ans[i].second+1 << endl;
    }

}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
int a, b;
char op;


while(1)
{
scanf("%d %c %d", &a, &op, &b);

if(op == '+')
{
printf("%d\n", a + b);
}
if(op == '-')
{
printf("%d\n", a - b);
}
if(op == '*')
{
printf("%d\n", a * b);
}
if(op == '/')
{
printf("%d\n", a / b);
}
if(op == '?')
{
break;
}
}
return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define f1(n) for(int i=0;i<n;++i)
#define f2(n) for(int i=1;i<=n;++i)
#define lson(x) x<<1
#define rson(x) x<<1|1
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long double llf;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
const int maxn = 5e4 + 5;
const int mod = 0x3f3f3f3f;
const ll Mod = 998244353;
const int inf = 0x3f3f3f3f;
const ll Inf = (ll)1e15;
int n, m, u, v;
vector<int>e[maxn];
map<pii, int>p;
int in[maxn];
int main()
{
	llf l;
	cin >> l;
	printf("%llf\n", pow(l / 3, 3));




	return 0;
}

Measured memory_bytes: 1664
<?php
fscanf(STDIN, "%d %d %d", $a, $b,$c);

$checkList = array( 7, 5, 5 );

$numList = array( $a, $b, $c );
rsort($numList);

$result = "YES";
foreach( $checkList as $check )
{
  $tmp =array_shift($numList);
  if( $check != $tmp  )
  {
	$result = "NO";
    break;
  }
}

echo $result;


Measured memory_bytes: 4604
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repb(i, n) for (int i = (int)n; i >= 0; i--)
#define reps(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define repsb(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[])
{
    int a, b, c;
    cin >> a >> b >> c;
    if ((100 * a + 10*b + c )% 4 == 0)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

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

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

signed main(void)
{
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(n*a, b) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
int n;
LL a[301][301];
bool vis[301][301];
int main() {
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++) scanf("%d",&a[i][j]);
	memset(vis,1,sizeof(vis));
	for (int k=1;k<=n;k++)
		for (int i=1;i<=n;i++)
			for (int j=1;j<=n;j++) {
				if (k==i||k==j) continue;
				if (a[i][k]+a[k][j]<a[i][j]) {
					printf("-1\n");
					return 0;
				}
				if (a[i][k]+a[k][j]==a[i][j]) vis[i][j]=0;
			}
	LL ans=0;
	for (int i=1;i<=n;i++)
		for (int j=i+1;j<=n;j++)
			if (vis[i][j]) ans+=a[i][j];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){

	int n;

	cin >> n;
	for (int i = 0; i < n; i++){

		int a, b, c;
		cin >> a >> b >> c;

		if (a > c){
			int temp = a;
			a = c;
			c = temp;
		}
		if (b > c){
			int temp = b;
			b = c;
			c = temp;
		}

		if (a * a + b * b == c * c)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
}

Measured memory_bytes: 1152
k = int(input())

a = ["1","2","3","4","5","6","7","8","9"]
i = 0
while len(a)<=k:
  b = a[i]
  c = int(b[-1])
  i += 1
  for j in range(-1,2):
    if 0<=c+j<10:
      a.append(b+str(c+j))

print(a[k-1])

Measured memory_bytes: 10132
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node *NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer cur=nil->next;
  
  while(cur!=nil && cur->key!=key){
    cur=cur->next;
  }

  return cur;
}

void init(){
  nil=malloc(sizeof(struct node));
  nil->next=nil;
  nil->prev=nil;
}

void printList(){
  NodePointer cur=nil->next;
  int a=0;

  while(1){
    if(cur==nil) break;
    if(a++>0) printf(" ");
    printf("%d",cur->key);
    cur=cur->next;
  }

  printf("\n");
}

void dNode(NodePointer t){
  
  if(t==nil) return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void dFirst(){
  NodePointer t=nil->next;

  if(t==nil) return;

  dNode(t);
}

void dLast(){
  dNode(nil->prev);
}

void delete(int key){
  dNode(listSearch(key));
}

void insert(int key){
  NodePointer x=malloc(sizeof(struct node));
  
  x->key=key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}

int main(){
  int key,n,i,size=0,p=0,d=0;
  char com[20];

  scanf("%d",&n);

  init();

  for(i=0;i<n;i++){
    scanf("%s%d",com,&key);

    if(com[0]=='i'){
      insert(key);
      p++;
      size++;
    }
    else if(com[0]=='d') {
      if(strlen(com)>6){
	if(com[6]=='F') dFirst();
	else if(com[6]=='L') dLast();
      }
      else{
	delete(key);
	d++;
      }
      size--;
    }
  }

  printList();

  return 0;
}


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

bool prime(int n){
	for(int i = 2; i * i <= n; i++){
		if(n % i == 0) return false;
	}
	return n != 1;
}

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

Measured memory_bytes: 256
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

      string str;



     cin>>k>>n;

     ll ara[n+2];

     input(ara,n);

     sort(ara,ara+n);

     vector<ll>v;

     for(i=1; i<n; i++)
     {
        v.eb(abs(ara[i]-ara[i-1]))  ;
     }

    sort(vll(v));

    if(k>=n || n==1)
        cout<<0<<endl;

    else
    {
        for(i=0; i<n-k; i++)
        {
            sum+=v[i];
        }

        cout<<sum<<endl;
    }

}



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

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

  int A = 0, B = 0;

  if (X == 1) A = 300000;
  if (X == 2) A = 200000;
  if (X == 3) A = 100000;
  if (Y == 1) B = 300000;
  if (Y == 2) B = 200000;
  if (Y == 3) B = 100000;

  cout << ((X == 1 && Y == 1) ? 1000000 : A + B) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
vi w(222222),b(222222);
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  string s;cin>>s;
  for(int i=0;i<n;i++){
    if(s[i] == '#'){
      b[i+1] = b[i]+1;
      w[i+1] = w[i];
    }else{
      b[i+1] = b[i];
      w[i+1] = w[i]+1;
    }
  }
  ll ans = llINF;
  for(int i=0;i<=n;i++){
    ans = min(ans,b[i]+w[n]-w[i]);
  }
  cout<<ans<<endl;
  return 0;
}


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

struct RURM {
	using t1 = int;
	using t2 = int;
	static t1 id1() { return INT_MAX; }
	static t2 id2() { return -1; }
	static t1 op1(const t1& l, const t1& r) { return min(l, r); }
	static t1 op2(const t1& l, const t2& r) { return r != id2() ? r : l; }
	static t2 op3(const t2& l, const t2& r) { return r != id2() ? r : l; }
};

template <typename M>
class LazySegmentTree {
	using T1 = typename M::t1;
	using T2 = typename M::t2;
	const int h, n;
	vector<T1> data;
	vector<T2> lazy;
	void push(int node) {
		if (lazy[node] == M::id2()) return;
		if (node < n) {
			lazy[node * 2] = M::op3(lazy[node * 2], lazy[node]);
			lazy[node * 2 + 1] = M::op3(lazy[node * 2 + 1], lazy[node]);
		}
		data[node] = M::op2(data[node], lazy[node]);
		lazy[node] = M::id2();
	}
public:
	LazySegmentTree(int n_)
		: h(ceil(log2(n_))), n(1 << h), data(n * 2, M::id1()), lazy(n * 2, M::id2()) {}
	LazySegmentTree(int n_, T1 v1, T2 v2)
		: h(ceil(log2(n_))), n(1 << h), data(n * 2, v1), lazy(n * 2, v2) {}
	LazySegmentTree(const vector<T1>& data_)
		: h(ceil(log2(data_.size()))), n(1 << h), data(n * 2, M::id1()), lazy(n * 2, M::id2()) {
		init(data_);
	}
	void init() {
		for (int i = n - 1; i >= 1; i--) data[i] = M::op1(data[i * 2], data[i * 2 + 1]);
	}
	void init(const vector<T1>& data_) {
		for (int i = 0; i < (int)data_.size(); i++) data[i + n] = data_[i];
		init();
	}
	void update(int l, int r, T2 val) {
		l += n, r += n;
		for (int i = h; i > 0; i--) push(l >> i), push(r >> i);
		int tl = l, tr = r;
		r++;
		while (l < r) {
			if (l & 1) lazy[l] = M::op3(lazy[l], val), l++;
			if (r & 1) r--, lazy[r] = M::op3(lazy[r], val);
			l /= 2; r /= 2;
		}
		while (tl >>= 1, tr >>= 1, tl > 0) {
			if (lazy[tl] == M::id2()) data[tl] = M::op1(M::op2(data[tl * 2], lazy[tl * 2]), M::op2(data[tl * 2 + 1], lazy[tl * 2 + 1]));
			if (lazy[tr] == M::id2()) data[tr] = M::op1(M::op2(data[tr * 2], lazy[tr * 2]), M::op2(data[tr * 2 + 1], lazy[tr * 2 + 1]));
		}
	}
	T1 find(int l, int r) {
		l += n, r += n;
		for (int i = h; i > 0; i--) push(l >> i), push(r >> i);
		r++;
		T1 res = M::id1();
		while (l < r) {
			if (l & 1) res = M::op1(res, M::op2(data[l], lazy[l])), l++;
			if (r & 1) r--, res = M::op1(res, M::op2(data[r], lazy[r]));
			l /= 2; r /= 2;
		}
		return res;
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q, com, x, y, val;
	cin >> n >> q;
	LazySegmentTree<RURM> st(n);
	while (q--) {
		cin >> com >> x >> y;
		if (com) {
			printf("%d\n", st.find(x, y));
		}
		else {
			cin >> val;
			st.update(x, y, val);
		}
	}
	return 0;
}

Measured memory_bytes: 5104
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()
	a := make([]int, n)
	for i := range a {
		a[i] = scanInt()
	}
	b := make([]int, n)
	for i := range b {
		b[i] = scanInt()
	}

	d := 0
	cnt := 0
	for i := 0; i < n; i++ {
		d += b[i] - a[i]
		if a[i] < b[i] {
			cnt += (b[i] - a[i] + 1) / 2
		}
	}
	if d >= cnt {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;


void eating_symbols_easy()
{
  string s;
  cin >> s;

  int cnt = 0;
  for (int i = 0; i < 4; ++i)
  {
    if (s[i] == '+') ++cnt;
    else --cnt;
  }
  cout << cnt << "\n";
}


void multiple_of_2_and_n()
{
  int n;
  cin >> n;

  if (n % 2 == 0) cout << n << "\n";
  else cout << 2 * n << "\n";
}


void task_scheduling_problem()
{
  vector<int> a(3);
  for (int i = 0; i < 3; ++i) cin >> a[i];

  sort(a.begin(), a.end());

  cout << a[2] - a[0] << "\n";
}


void rated_for_me()
{
  int r;
  cin >> r;

  if (r < 1200) cout << "ABC\n";
  else if (r < 2800) cout << "ARC\n";
  else cout << "AGC\n";
}


int main()
{
  //eating_symbols_easy();
  //multiple_of_2_and_n();
  //task_scheduling_problem();
  rated_for_me();
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, j) for (long long i = 0; i < j; i++)
#define int long long
#define gcn(N) \
    int N;     \
    cin >> N;
#define debug(var)                  \
    do {                            \
        std::cout << #var << " : "; \
        view(var);                  \
    } while (0)
template <typename T>
void view(T e)
{
    std::cout << e << std::endl;
}
template <typename T>
void view(const std::vector<T>& v)
{
    for (const auto& e : v) {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>>& vv)
{
    for (const auto& v : vv) {
        view(v);
    }
}

using namespace std;
/*


*/

signed main()
{
    gcn(N);
    gcn(M);
    //A,B
    multimap<int, int> ab_m;
    int a, b;
    rep(i, N)
    {
        cin >> a >> b;
        ab_m.emplace(a, b);
    }
    priority_queue<int> ans_que;
    int ans = 0;
    auto m = ab_m.begin();
    for (int i = 0; i <= M; i++) {
        while (true) {
            if (m == ab_m.end()) {
                break;
            }
            a = m->first;
            b = m->second;
            if (a <= i) {
                ans_que.push(b);
                m++;
            } else {
                break;
            }
        }
        if (!ans_que.empty()) {
            ans += ans_que.top();
            ans_que.pop();
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 7676
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n, x;
  cin >> n >> x;
  vl l(n);
  rep(i, n) cin >> l[i];
  
  ll sum = 0;
  rep(i, n) {
    sum += l[i];
    if(sum > x) {
      cout << i+1 << newl;
      return 0;
    }
  }
  
  cout << n+1 << newl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define rep(I,N) for(int I = 0; I < (int)(N); I++)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);


int main(void){
	int N;
	cin >> N;
	rep(i, N){
		int K, P;
		cin >> K >> P;
		if(K%P == 0)cout << P << endl;
		else cout << (K%P) << endl;
	}

	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

Measured memory_bytes: 1168
N = int(input())
arrange = input().split()
split = True
count = 0

for i in range(N):
    arrange[i] = int(arrange[i])

while split:
    for i in range(N):
        if arrange[i] % 2 == 0:
            arrange[i] /= 2
        else:
            split = False
    count += 1

print(str(count - 1))

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

ll f(ll x){
    ll ret  = 1;
    for(ll i = x; i > 1; i--){
        ret *= i;
        ret = ret % ll(1e9+7);
    }
    return ret;
}

int main(){
    ll n, m; cin >> n >> m;
    if(n == m){
        put((f(n) * f(m)) * 2 % ll(1e9+7));
    }else if(abs(n - m) == 1){
        put((f(n) * f(m)) % ll(1e9+7));
    }else{
        put(0);
    }
}

Measured memory_bytes: 3592
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <cstring>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


int main(){
   int n, m;
   cin >> n >> m;
   int i = n*(n-1)/2, j = m*(m-1)/2, r = 0;
   if(i > 0) r += i;
   if(j > 0) r += j;
   printf("%d\n", r);
}


Measured memory_bytes: 3772
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

ll f(vector<int> &c, vector<int> &v, ll n){
  vector<ll> dp(n+1, 0);
  rep(i, dp.size()) dp.at(i) = i;
  rep(i, c.size()){
    int nc = c.at(i);
    int nv = v.at(i);
    rep2(j, nc, dp.size()){
      dp.at(j) = max(dp.at(j), dp.at(j-nc)+nv);
    }
  }
  return dp.at(n);
}

int main(){
  int n;
  cin >> n;
  vector<int> a(3);
  rep(i, 3) cin >> a.at(i);
  vector<int> b(3);
  rep(i, 3) cin >> b.at(i);
  ll ans = f(a, b, n);
  ans = f(b, a, ans);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 198472
#include <stdio.h>
#define N 100000

int main(void)
{
  int n, k, w[N];
  int i, c, sum;
  int right=0, left=0, mid;
  scanf("%d %d", &n, &k);
  for(i=0; i<n; i++){
    scanf("%d", &w[i]);
    right+=w[i];
    if(left<w[i]) left=w[i]-1;
  }
  while(right-left>1){
    c=1;
    sum=0;
    mid=(right+left)/2;
    for(i=0; i<n; i++){
      if(sum+w[i]<=mid) sum+=w[i];
      else{
        c++;
        sum=w[i];
      }
    }
    if(c>k) left=mid;
    else right=mid;
  }
  
  printf("%d\n", right);
  return 0;
}
  


Measured memory_bytes: 2184
import sys

input = sys.stdin.readline

N, K = map(int, input().split())
LR = [list(map(int, input().split())) for i in range(K)]
MOD = 998244353
 
dp = [0] * (N + 1)
dp[1] = 1
dp_sum = [0] * (N + 1)
dp_sum[1] = 1
 
 
def get(l, r, i):
    return dp_sum[max((i - l), 0)] - dp_sum[max((i - r-1), 0)]
 
 
for i in range(1, N+1):
    for l, r in LR:
        dp[i] += get(l, r, i) % MOD
    dp_sum[i] = (dp_sum[i - 1] + dp[i])%MOD

print(dp[N] % MOD)

Measured memory_bytes: 27324
#include <iostream>
#include <algorithm>

using namespace std;

int n, k;
int a[100], win[100001];

void dfs(int stones) { 
    bool first_win = false;
    for(int i=0;i<n&&a[i]<=stones;++i) {
        if(win[stones-a[i]] == 0) dfs(stones-a[i]);
        if(win[stones-a[i]] == 2) {
            first_win = true;
            break;
        }
    }
    win[stones] = (first_win ? 1 : 2);
}

int main() {
    cin >> n >> k;
    for(int i=0;i<n;++i) cin >> a[i];
    for(int i=0;i<a[0];++i) win[i] = 2;

    dfs(k);

    cout << (win[k] == 1 ? "First" : "Second") << "\n";
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	bool ok = false;
	FOR(a,1,10) FOR(b,1,10) if (a*b == n) ok = true;
	cout << (ok ? "Yes" : "No") << endl;
}



Measured memory_bytes: 256
package main

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

var (
	sc = bufio.NewScanner(os.Stdin)
)

func scanIntSplit(len int) []int {
	buf := make([]byte, 0) //ここのサイズは何でもよさそう
	sc.Buffer(buf, 1000000009)

	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " ") {
		tmp, err := strconv.Atoi(v)
		if err == nil {
			arr[i] = tmp
		}
	}
	return arr
}

func main() {
	var n int
	fmt.Scan(&n)
	as := scanIntSplit(3 * n)

	sort.Ints(as)
	len := len(as)

	var sum int
	for i := len - 1; i > n; i -= 2 {
		sum += as[i-1]
	}

	fmt.Println(sum)
}


Measured memory_bytes: 19584
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
//printf("%.12lf\n",mid);
//const long long sze = 2*(2^(long long)(ceil(log(100000)/log(2))));
/*
// get part of decimal
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/

const double eps = .0000000001;
inline void prep()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
};
vector<int> primeFactors(int n)
{
    // Print the number of 2s that divide n
    vector<int> res;
    
    // n must be odd at this point.  So we can skip 
    // one element (Note i = i +2)
    for (int i = 2; i <= sqrt(n); i++)
    {
      
        // While i divides n, print i and divide n
       
        while (n%i == 0)
        {
            n = n/i;
            res.push_back(i);
        }
        
    }

    // This condition is to handle the case when n 
    // is a prime number greater than 2
    if (n >= 2)
        res.push_back(n);
    return res;
}
int choose(int n, int k){
    if (k == 0) return 1;
    return (n * choose(n - 1, k - 1)) / k;
}
int main(){
    prep(); 
    int n;
    cin >> n;
    int arr[n+1] = {0};
    for (int i=2; i<=n; i++){
      vector<int> pf = primeFactors(i);
      for (int j=0; j<pf.size(); j++){
        arr[pf[j]]++;
  
      }
    }
    vector<int> ones;
    for (int i=0; i<=n; i++){
      if (arr[i] != 0){
        ones.push_back(arr[i]);
        //cout << arr[i] << " ";
      }
    }
    cout << endl;
    ones.push_back(0);
    sort(ones.begin(), ones.end());
    vector<int>::iterator seventyfour, two, four, fourteen, twentyfour; 
  
    // std :: lower_bound 
    seventyfour = lower_bound(ones.begin(), ones.end(), 74);
    two = lower_bound(ones.begin(), ones.end(), 2);
    four = lower_bound(ones.begin(), ones.end(), 4);
    fourteen = lower_bound(ones.begin(), ones.end(), 14);
    twentyfour = lower_bound(ones.begin(), ones.end(), 24);
    
    int num74 = seventyfour-ones.begin();
    int num2 = two-ones.begin();
    int num4 = four-ones.begin();
    int num14 = fourteen-ones.begin();
    int num24 = twentyfour-ones.begin();
    int numover74 = ones.size()-min(n, num74);
    int numover2 = ones.size()-min(n, num2);
    int numover4 = ones.size()-min(n, num4);
    int numover14 = ones.size()-min(n, num14);
    int numover24 = ones.size()-min(n, num24);
    
    cout << numover74+max(numover2-1, 0)*numover24+max(numover4-1, 0)*numover14+numover4*(numover4-1)*(numover2-2)/2;
    return 0;
}      

Measured memory_bytes: 256