akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
template< typename flow>
struct max_flow {
    struct edge {
        int to;
        flow cap;
        int rev; };
    int V;
    vector<vector<edge>> G;
    vector<int> itr, level;

    max_flow(int V) : V(V) { G.assign(V,vector<edge>()); }

    void add_edge(int from, int to, flow cap) {
        G[from].push_back((edge) {to, cap, (int) G[to].size()});
        G[to].push_back((edge) {from, 0, (int) G[from].size()-1});
    }

    void bfs(int s) {
        level.assign(V,-1);
        queue<int> q;
        level[s] = 0; q.push(s);
        while (!q.empty()) {
            int v = q.front(); q.pop();
            for(auto &e: G[v]){
                if (e.cap > 0 and level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
    }

    flow dfs(int v, int t, flow f) {
        if (v == t) return f;
        for (int& i = itr[v]; i < (int) G[v].size(); ++i) {
            edge& e = G[v][i];
            if (e.cap > 0 and level[v] < level[e.to]) {
                flow d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    flow run(int s, int t) {
        flow ret = 0, f;
        while (bfs(s), level[t] >= 0) {
            itr.assign(V,0);
            while ((f = dfs(s, t, INF)) > 0) ret += f;
        }
        return ret;
    }
};

int gcd(int a, int b) {
    if(a < b) swap(a, b);
    if(a % b == 0) return b;
    return gcd(b, a % b);
}


int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        int n, m;
        cin >> m >> n;
        if(n == 0) break;
        max_flow<int> graph(2001);
        int a[505], b[505];
        for(int i = 1; i <= m; i++) {
            cin >> a[i];
            graph.add_edge(0, i, 1);
        }
        for(int i = 1; i <= n; i++) {
            cin >> b[i];
            graph.add_edge(i + 1000, 2000, 1);
        }
        for(int i = 1; i <= m; i++) {
            for(int j = 1; j <= n; j++) {
                if(gcd(b[j], a[i]) != 1) graph.add_edge(i, j + 1000, 1);
            }
        }
        cout << graph.run(0, 2000) << endl;
    }
    return 0;
}


Measured memory_bytes: 7444
/*********************************************************************************\
*  _________  _      _  ________  _       _       __       ________               *
* |___   ___|| |    | ||  ______|| |     | |     /  \     |  ____  |              *
*     | |    | |    | || |______ | |_____| |    / /\ \    | |____| |              *
*     | |    | |    | ||______  ||  _____  |   / /__\ \   |  __  __|              *
*     | |    | |____| | ______| || |     | |  / ______ \  | |  \ \                *
*     |_|    |________||________||_|     |_| /_/      \_\ |_|   \_\               *
*  ________       __      ________  _    __       __       ________               *
* |  ______|     /  \    |  ____  || |  / /      /  \     |  ____  |              *
* | |______     / /\ \   | |____| || |_/ /      / /\ \    | |____| |              *
* |______  |   / /__\ \  |  __  __||  __ \     / /__\ \   |  __  __|              *
*  ______| |  / ______ \ | |  \ \  | |  \ \   / ______ \  | |  \ \                *
* |________| /_/      \_\|_|   \_\ |_|   \_\ /_/      \_\ |_|   \_\               *
*                                                                                 *
*                                                                                 *
*   Department of Computer Science & Engineering                                  *
*   Student ID : 18CSE035                                                         *
*   Bangabnadhu Sheikh Mujibur Rahman Science & Technology University,Gopalgonj.  *
*                                                                                 *
\*********************************************************************************/

//Now Write to Code ___________________________


#include<bits/stdc++.h>
using namespace std;

const int N = (int) 1e5 + 5;



int main() {
	string s;
	int i,a=0,b=0;

	cin >> s;
	for(i = 0; i < 3; i++)
	{
		if(s[i] == 'A')
		{
			a++;
		}
		else
		{
			b++;
		}
	}
	if(a > 0 && b > 0)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}


	return 0;
}

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

typedef long long ll;

int main(){
    int n,i,j,tmp;
    cin >> n;
    int d[n];
    for(i=0;i<n;i++) cin >> d[i];
    
    
    sort(d,d+n);
    
    int a=(n+1)/2-1;
    int ans = d[a+1]-d[a];
    cout<<ans;
}


Measured memory_bytes: 640
n,m = map(int, input().split())

uoo = []

for _ in range(m):
    x = list(map(int, input().split()))
    x.pop(0)
    uoo.append(x)

p = list(map(int, input().split()))


pattern = []

for i in range(2 ** (n)):
    tmp = [0] * (n)
    for j in range(n):
        if i >> j & 1:
            tmp[j] = 1
    pattern.append(tmp)


ans = 0

for pat in pattern:
    is_light_up = True
    cnt = 0
    for uo in uoo:
        is_even = True
        for u in uo:
            if pat[u-1] == 1:
                is_even = not is_even
        if is_even:
            if p[cnt] == 1:
                is_light_up = False
        else:
            if p[cnt] == 0:
                is_light_up = False
        cnt += 1
    if is_light_up:
        ans += 1

print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <map>

using namespace std;

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

    map<string, int> m;

    for (int i = 0; i < N; ++i) {
        string s;
        cin >> s;

        m[s]++;
    }

    int M;
    cin >> M;

    for (int i = 0; i < M; ++i) {
        string t;
        cin >> t;

        m[t]--;
    }

    int ans = 0;
    for (auto x:m) {
        ans = max(ans, x.second);
    }

    cout << ans << endl;
}

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

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;


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

    if(s[2]==s[3]&&s[4]==s[5])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	k := make([]int, 81)

	h := 0
	for i := 1; i <= 9; i++ {
		for j := 1; j <= 9; j++ {
			k[h] = i * j
			h++
		}
	}

	for _, v := range k {
		if n == v {
			fmt.Println("Yes")
			return
		}
	}

	fmt.Println("No")
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pi;
const int MAXN=500005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define fst first
#define snd second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())
#define LSOne(S) ((S) & -(S))
typedef vector<int> vi;
class FenwickTree {
	private: vi ft; int n;
	public: FenwickTree(int _n) : n(_n) { ft.assign(n+1, 0); }
    FenwickTree(const vi& f) : n(f.size()-1) { ft.assign(n+1, 0);
        for (int i = 1; i <= n; i++) {
            ft[i] += f[i];
            if (i+LSOne(i) <= n)
            ft[i+LSOne(i)] += ft[i];
        }
    }
    int rsq(int j) {
        int sum = 0; for (; j; j -= LSOne(j)) sum += ft[j];
        return sum;
    }
    int rsq(int i, int j) {
        return rsq(j) - rsq(i-1);
    }
    void update(int i, int v) {
        for (; i <= n; i += LSOne(i)) ft[i] += v;
    }
};

vector<int> tmp(MAXN);
vector<FenwickTree> arr(26,FenwickTree(tmp));

int N,Q;
string S;

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>S>>Q;
	FOR(i,1,N){
		int c=(int)S[i-1]-'a';
		arr[c].update(i,1);
	}
	FOR(i,1,Q){
		int a;cin>>a;
		if(a==1){
			int b;
			char c; cin>>b>>c;
			int org=(int)S[b-1]-'a';
			int neu=(int)c-'a';
			arr[org].update(b,-1);
			arr[neu].update(b,1);
			S[b-1]=c;
		}
		else{
			int l,r;cin>>l>>r;
			int ans=0;
			FOR(i,0,25){
				if (arr[i].rsq(l,r)>0)ans++;
			}
			cout<<ans<<"\n";
		}
	}
}


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

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

const int INF = 1001001001;

using namespace std;

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

    int n, k; cin >> n >> k;
    vector<int> h(n); rep(i,n) cin >> h[i];

    vector<int> dp(n+k,INF);

    dp[0] = 0;
    dp[1] = abs(h[0]-h[1]);

    for(int i=0; i<n; i++) {
        for(int j=1; j<=k; j++) {

            dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]));

        }
    }

    cout << dp[n-1] << "\n";

    return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
#include <stack>
using namespace std; 

// #define int long long // debug
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef map<int, int> Mii;
typedef vector<int> Vi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;



int main()
{
	int n;
	cin >> n;
	rep(i,0,n) {
		int t;
		cin >> t;
		int cnt = 0;
		bool f = true;
		while (f && t>=10) {
			Vi q;
			f = false;
			for (int i=1; t/i; i*=10) {
				int a = t/i;
				int b = t%i;
				q.pb(a*b);
			}
			sort(all(q));
			//debug(q[len(q)-1]);
			if (len(q) && q[len(q)-1] >= 10) f = true;
			cnt++;
			t = q[len(q)-1];
		}
		cout << cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

int main()
{
  unsigned long long a,b,k;
  cin>>a>>b>>k;

  if(k <= a){
    cout << a - k << ' ' << b <<endl;
  }else if(k <= a+b){
    cout << 0 << ' ' << b - (k-a) <<endl;
  }else{
    cout << 0 << ' ' << 0 <<endl;
  }
  return 0;
}

Measured memory_bytes: 384
N = int(input())
s = set()
pr = None
ok = 1
for i in range(N):
    w = input()
    if pr and pr != w[0]:
        ok = 0
    if w in s:
        ok = 0
    pr = w[-1]
    s.add(w)
print('Yes'*ok or'No')

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

using namespace std;

void solve() {
  vector<int> n(3);
  cin >> n[0] >> n[1] >> n[2];

  unordered_set<int> s;

  s.emplace(n[0]);
  s.emplace(n[1]);
  s.emplace(n[2]);

  cout << (s.size() == 2 ? "Yes" : "No") << endl;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<math.h>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
using namespace std;
int fact(int x)
{
    if(x==0)
        return 1;
    else
        return x*fact(x-1);
}
int main()
{
    int n,m; cin>>n>>m;
    int ans;
    if(n<=1)
    {
        ans = m*(m-1)/2;
    }
    else if(m<=1)
        ans = n*(n-1)/2;
    else if(n<=1 && m<=1)
        ans = 0;
    else
        ans = n*(n-1)/2 + m*(m-1)/2;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstring>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <unordered_map>

#define DEBUG false
#define OJ_DEBUG

#define $(x) {if (DEBUG) {cout << __LINE__ << ": "; {x} cout << endl;}}
#define _(x) {cout << #x << " = " << x << " "; }
const double E = 1e-8;
const double PI = acos(-1);

using namespace std;

typedef long long ll;
typedef std::pair<int, int> pii;
typedef unsigned long ul;

int main() {
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s;
    int q;
    cin >> s >> q;
    bool st = 0;
    vector<char> v[2];
    while (q--) {
        int fl;
        cin >> fl;
        if (fl == 1) st = !st;
        else {
            int ft;
            char c;
            cin >> ft >> c, --ft;
            //cout << ft << "^" << st << " : " << (ft^st) << '\n';
            v[ft^st].push_back(c);
        }
    }
    string t;
    for (int i = (int)v[0].size() - 1; ~i; --i) {
        t += v[0][i];
    }
    t += s;
    for (char c : v[1])
        t += c;

    if (st)
        reverse(t.begin(), t.end());
    cout << t << '\n';
}

Measured memory_bytes: 1448
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define bg begin
#define en end 
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll gcd(ll a,ll b){
    if(a==0)
    return b;
    else
    return gcd(b%a,a);
}
using namespace std;
int main()
{
    ll a,b,c,r=0;
    cin>>a>>b>>c;
    ll k,i;
    cin>>k;
    while(b<=a){
        b*=2;
        r++;
    }
    while(c<=b){
        c*=2;
        r++;
    }
    if(r<=k)
    cout<<"Yes";
    else
    cout<<"No";
}

Measured memory_bytes: 3648
import scala.io.StdIn.{readInt,readLine}
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args:Array[String]) = {
    var n = 0
    val b = new ArrayBuffer[String]
    while({n=readInt;n} != 0) {
      val l = readLine.split(" ").map(_.toInt)
      if(l.filter(_>=2).length==0) b+="NA"
      else b+=(l.filter(_>=1).length+1).toString
    }
    println(b.mkString("\n"))
  }
}

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

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; }
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
using Graph = vector<vector<int>>;
queue<int> quex,quey;

int main(){
    int a,b;    cin >> a >> b;
    if(500*a>=b)    cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

main {
  forever {
    vi v(6);
    cin >> v;
    if (accumulate(all(v), 0LL) == 0LL) break;
    vi w(3);
    rep(i, 3) w[i] = v[i] + v[i + 3];
    int m = *min_element(all(w));
    int maxi = 0;
    loop(i, max(0LL, m - 2), m + 1) {
      int s = i;
      rep(j, 3) s += (w[j] - i) / 3;
      cmax(maxi, s);
    }
    cout << maxi << endl;
  }
}

Measured memory_bytes: 3092
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    n = int(input())
    ab = [list(map(int, input().split())) for i in range(n)]
    a = [ab[i][0] for i in range(n)]
    b = [ab[i][1] for i in range(n)]
    a.sort()
    b.sort()
    if n % 2 == 0:
        print(b[n // 2 - 1] + b[n // 2] - a[n // 2 - 1] - a[n // 2]+1)
    else:
        print(b[n//2]-a[n//2]+1)

if __name__ == "__main__":
    main() #endline===============================================

Measured memory_bytes: 67104
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
    ios
    int n;
    cin>>n;
    ll x,sum=0;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        sum+=(x-1);
    }
    cout<<sum;
}

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

int main() {
  ll n;
  cin>>n;
  vector<ll> s(n);
  rep(i,n){
    cin>>s[i];
  }
  ll ans=0;
  ll l,r,t;
  //直接飛ぶとき０
  for(ll c=1;c<n;c++){
    l=0;r=n-1;t=0;
    if(r%c==0){
      while(l<r){
        t+=s[l]+s[r];
        ans=max(ans,t);
        l+=c;r-=c;
      }
    }
    else{
      while(r>c){
        t+=s[l]+s[r];
        ans=max(ans,t);
        l+=c;r-=c;
      }
    }
  }
    cout<<ans;

}


Measured memory_bytes: 1152
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

cnt = 1
ans = 0

for a in A:
    if a != cnt:
        ans += 1
        continue
    else:
        cnt += 1

if cnt == 1:
    if ans == 0:
        print(ans)
    else:
        print(-1)
else:
    print(ans)


Measured memory_bytes: 100960
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

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

    ll h,w;cin>>h>>w;
    if(h==1){
        cout<<1<<endl;
        return 0;
    }
    if(w==1){
        cout<<1<<endl;
        return 0;
    }

    ll ans=(h*w+1)/2;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
typedef double D;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
//typedef pair<int, int> P;

/** Problem0554 : Total Time **/
int main()
{
	int s=0;
	rep(i, 4) {
		int a; cin>>a; s+=a;
	}
	cout << s/60 << endl;
	cout << s%60 << endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>

using namespace std;
const long long mod=1e9+7;
const long long INF=1LL<<60;

int main(){
   string s;
   cin>>s;
   vector<int> a(26);
   for(int i=0;i<4;i++){
       a[s[i]-'A']++;
   }
   int cnt=0;
   for(int i=0;i<26;i++){
       if(a[i]==2)cnt++;
   }
   if(cnt==2)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
}
 
   

Measured memory_bytes: 888
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

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

    double bottom = 0.0;
    for (int i = 0; i < N; i++)
        bottom += (double)1.0/A[i];

    double ans = 1.0/bottom;
    printf("%.5lf\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)


int main() {
	ll n,ans=0;
	in(n);

	if (n >= 10)	ans += 9;
	else ans += n;
	if (n >= 1000)	ans += 900;
	else if (n >= 100) ans += n - 99;
	if (n >= 100000)	ans += 90000;
	else if (n >= 10000)	ans += n - 9999;

	outn(ans);
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void doIt() {
		int d = sc.nextInt();
		System.out.print("Christmas ");
		for(int i = 0; i < 25 - d; i++) {
			System.out.print("Eve ");
		}
		System.out.println();
	}
	Main(){doIt();}
	public static void main(String[] args) {
		new Main();
	}

}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=998244353;
const ll mod=998244353;
//Combination
long long extGCD(long long a,long long mod,long long &x,long long &y){
    if(mod==0){
        x=1;
        y=0;
        return a;
    }
    long long d=extGCD(mod,a%mod,y,x);
    y-=(a/mod)*x;
    return d;
}
long long invmod(long long a,long long mod){
    long long x,y;
    extGCD(a,mod,x,y);
    x%=mod;
    if(x<0)x+=mod;
    return x;
}
ll fac[2000010],finv[2000010],inv[2000010];
void combinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    REP(i,2,2000010){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=invmod(i,mod);
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
ll rui(ll a,ll b){
    ll res=1;
    ll x=a;
    while(b){
        if(b&1){
            res=res*x%mod;
        }
        x=x*x%mod;
        b/=2;
    }
    return res;
}
signed main(){
    ll n,m,k;cin>>n>>m>>k;
    /* if(m==1){
        if(k==n-1){
            cout<<1<<endl;
        }else{
            cout<<0<<endl;
        }
        return 0;
    }*/
    ll ans=0;
    combinit();
    rep(i,k+1){
        ll now=m;
        ans=(ans+now*rui(m-1,n-i-1)%mod*comb(n-1,i)%mod)%mod;
        //cout<<ans<<endl;
    }
    if(ans<0)ans+=mod;
    cout<<ans<<endl;
}

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

typedef long long ll;
#define fore(i,ii,iii) for(ll i=ii;i<iii;i++)
#define mset(a,b) memset(a,b,sizeof(a))
#define pb push_back

const ll N=2e5+15;
ll n,h[N],a[N],c[N],ft[N];
map<ll,ll>mp;

void upd(int i0, ll v){ // add v to i0th element (0-based)
	for(int i=i0+1;i<=N;i+=i&-i)ft[i]=max(ft[i],v);
}
ll get(int i0){ // get sum of range [0,i0)
	ll r=0;
	for(int i=i0;i;i-=i&-i)r=max(r,ft[i]);
	return r;
}


int main() {
  ios::sync_with_stdio(false);
  cin>>n;
  fore(i,0,n)cin>>h[i],c[i]=h[i];
  fore(i,0,n)cin>>a[i];
  sort(c,c+n);
  fore(i,0,n)mp[c[i]]=i+1;
  fore(i,0,n)h[i]=mp[h[i]];
  fore(i,0,n)upd(h[i],a[i]+get(h[i]));
  cout<<get(n+1)<<endl;
}

Measured memory_bytes: 19072
n, w = [int(i) for i in input().split()]
wv = [[int(i) for i in input().split()] for _ in range(n)]

dp = [[0]*(w+1) for _ in range(n+1)]

for i in range(1, n+1):
    wi, vi = wv[i-1]
    for j in range(1, w+1):
        if j < wi:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-wi] + vi)
print(dp[-1][-1])


Measured memory_bytes: 119916
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int n = 0; n < N; ++n) {
        cin >> A[n];
    }
    
    map<ll, int> Map;
    ll Res = 0;
    for (int n = 1; n <= N; ++n) {
        Res += Map[n-A[n-1]];
        ++Map[n+A[n-1]];
    }
    cout << Res << endl;

    return 0;
}


Measured memory_bytes: 27392
#include <iostream>
#include <algorithm>
#include <utility>

using namespace std;

typedef pair<int, int> pii;

const int Z = 998244353;
const int LGN = 18;

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

    int n;
    cin >> n;
    pii xd[n];
    for (int i = 0; i < n; i++) {
        cin >> xd[i].first >> xd[i].second;
    }
    sort(xd, xd+n);

    int lg2[n+1];
    for (int i = 1; i <= n; i++) {
        lg2[i] = i == 1 ? 0 : lg2[i/2] + 1;
    }

    int st[n+1][LGN];
    st[n][0] = 1;
    int dp[n+1];
    dp[n] = 1;

    for (int i = n - 1; i >= 0; i--) {
        int j = upper_bound(xd, xd+n, pii(xd[i].first + xd[i].second, -1)) - xd;

        if (j == i + 1) {
            st[i][0] = i + 1;
        } else {
            int lg = lg2[j-i-1];
            st[i][0] = max(st[i+1][lg], st[j-(1<<lg)][lg]);
        }

        dp[i] = (dp[i+1] + dp[st[i][0]]) % Z;

        for (int k = 1; i + (1 << k - 1) <= n; k++) {
            st[i][k] = max(st[i][k-1], st[i+(1<<k-1)][k-1]);
        }
    }

    cout << dp[0] << endl;

    return 0;
}


Measured memory_bytes: 17408
#include<stdio.h>

int A[1000000], n;

int binarySearch(int key){
  int left = 0;
  int right = n;
  int mid;

  while(left < right){
    mid = (left + right) / 2;
    if(key == A[mid]) return 1; /* key を発見*/
    if(key > A[mid]) left = mid + 1;
    else if(key < A[mid]) right = mid;
  }
  return 0;
}

int main(){
  int i, q, k, sum = 0;

  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d", &A[i]);
  }

  scanf("%d", &q);
  for(i=0; i<q; i++){
    scanf("%d", &k);
    if(binarySearch(k)) sum++;
  }
  printf("%d\n", sum);

  return 0;
}


Measured memory_bytes: 2116
'''
Created on 2020/08/20

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N=int(pin())
  ans=0
  pre=0
  for _ in [0]*N:
    A,B=map(int,pin().split())
    if ans<A:
      ans=A 
      pre=B 
  print(ans+pre)
  return 

main()

Measured memory_bytes: 9592
# -*- coding: utf-8 -*-
n = int(input())

cnt = 0
max_cnt = 0
for _ in range(n):
    a, b = map(int, input().split())
    if a == b:
        cnt += 1
        max_cnt = max(max_cnt, cnt)
    else:
        cnt = 0

print("Yes" if max_cnt >= 3 else "No")


Measured memory_bytes: 9164
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int a, b;
	std::cin >> a >> b;
	std::cout << ((a+b+1)/2) << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)
            r=(r*a)%m;
        b>>1;
        a=(a*a)%m;
    }
    return r%m;
}

int main(){
    ll n;cin>>n;
    cout<<n*n*n<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=998244353;
const int INF=1e9;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int h,w;
  cin >> h >> w;
  int f[h][w];
  rep(i,h){
    rep(j,w){
      cin >> f[i][j];
    }
  }
  vector<P>mae;
  vector<P>ato;
  rep(i,h){
    if(i%2==0){
      rep(j,w){
        if(f[i][j]%2==0)continue;
        if(j!=w-1){
          f[i][j]--;
          f[i][j+1]++;
          mae.push_back(P(i,j));
          ato.push_back(P(i,j+1));
        }
        else{
          if(i==h-1)continue;
          f[i][j]--;
          f[i+1][j]++;
          mae.push_back(P(i,j));
          ato.push_back(P(i+1,j));
        }
      }
    }
    else{
      for(int j=w-1;j>=0;j--){
        if(f[i][j]%2==0)continue;
        if(j!=0){
          f[i][j]--;
          f[i][j-1]++;
          mae.push_back(P(i,j));
          ato.push_back(P(i,j-1));
        }
        else{
          if(i==h-1)continue;
          f[i][j]--;
          f[i+1][j]++;
          mae.push_back(P(i,j));
          ato.push_back(P(i+1,j));
        }
      }
    }
  }
  cout << mae.size() << endl;
  rep(i,mae.size()){
    cout << mae[i].first+1 << " " << mae[i].second+1 << " " << ato[i].first+1 << " "<< ato[i].second+1 << endl;
  }
      
  return 0;     
}


Measured memory_bytes: 7268
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int a,b,c; cin >> a >> b >> c;
  cout << c/a*b << endl;
}


Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"


def main():
    num = [10 ** 4, 10 ** 8, 10 ** 12, 10 ** 16, 10 ** 20, 10 ** 24, 10 ** 28, 10 ** 32, 10 ** 36, 10 ** 40, 10 ** 44, 10 ** 48, 10 ** 52, 10 ** 56, 10 ** 60, 10 ** 64, 10 ** 68]
    uni = ["Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan", "Sei", "Sai", "Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts"]
    while True:
        m, n = map(int, input().split())
        if m == 0 and n == 0:
            break

        a = m ** n
        ans = ""
        for i in range(len(num) - 1, -1, -1):
            if a >= num[i]:
                ans += str(a // num[i]) + uni[i]
                a %= num[i]

        print(ans + str(a if a != 0 else ""))


if __name__ == '__main__':
    main()



Measured memory_bytes: 6800
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

int ts[105];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    scanf("%d", &ts[i]);
  }
  int m;
  scanf("%d", &m);
  REP(i, m) {
    int p, x;
    scanf("%d%d", &p, &x);
    --p;
    int sum = 0;
    REP(j, n) {
      sum += j == p ? x : ts[j];
    }
    printf("%d\n", sum);
  }
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (b % a == 0) {
			System.out.println(a + b);
		} else {
			System.out.println(b - a);
		}
	}
}

Measured memory_bytes: 23252
h,w=map(int,input().split())
l=[]
for i in range(1,h):
  s1=w*i
  s2=(h-i)*(w//2)
  s3=h*w-s1-s2
  l.append(max(s1,s2,s3)-min(s1,s2,s3))
for i in range(1,w):
  s1=h*i
  s2=(w-i)*(h//2)
  s3=h*w-s1-s2
  l.append(max(s1,s2,s3)-min(s1,s2,s3))
for i in range(1,h-1):
  s1=w*i
  s2=w*((h-i)//2)
  s3=w*h-s1-s2
  l.append(max(s1,s2,s3)-min(s1,s2,s3))
for i in range(1,w-1):
  s1=h*i
  s2=h*((w-i)//2)
  s3=w*h-s1-s2
  l.append(max(s1,s2,s3)-min(s1,s2,s3))
print(min(l))

  

Measured memory_bytes: 18904
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int ans[N];

int main(){
//   freopen("input.txt", "r", stdin);
   int n, a, b;
   string s;
   cin >> n >> a >> b;
   cin >> s;
   int currentRank = 0, currentRankB = 0;
   for(int i = 0; i < s.size(); ++i){
      if(s[i] == 'c') continue;
      if(s[i] == 'a'){
         if(currentRank < a + b)
            ans[i] = true, ++currentRank;
      }else{
         ++currentRankB;
         if(currentRankB <= b && currentRank < a + b)
            ans[i] = true, ++currentRank;
      }
   }
   for(int i = 0; i < s.size(); ++i)
      puts(ans[i] ? "Yes" : "No");
}


Measured memory_bytes: 1280
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

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

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    LL n;
    cin >> n;
    cout << n * (n-1) / 2 << endl;
}

int main() {
    solve();
    
    return 0;
}

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

using namespace std;

struct state {
    int a_len;  // A の長さ
    int a_num;  // A の竹の本数

    int b_len;  // B の長さ
    int b_num;  // B の竹の本数

    int c_len;  // C の長さ
    int c_num;  // C の竹の本数

    int depth;
};

int calc_mp(state &st, int A, int B, int C) {
    int sum_mp = 0;
    if (st.a_num > 0
     && st.b_num > 0
     && st.c_num > 0
    ) {
        sum_mp += (st.a_num - 1) * 10;
        sum_mp += abs(st.a_len - A);

        sum_mp += (st.b_num - 1) * 10;
        sum_mp += abs(st.b_len - B);

        sum_mp += (st.c_num - 1) * 10;
        sum_mp += abs(st.c_len - C);
       
        return sum_mp;
    } else {
        return -1;  //  無から竹を作ることはできない
    }
}

int main(int argc, char *argv[]) {
    //
    //  それぞれの竹の選択を、以下のように言い換える
    //
    //  1. A の合成材料にする
    //  2. B の合成材料にする
    //  3. C の合成材料にする
    //  4. 使わない
    //
    //  N本それぞれについて、上記の組み合わせをすべて試し、
    //  それぞれについて、適切に[延長|短縮] 魔法を使い、合計MPを出す。
    //
    //  最後に、合計MPが最小の組み合わせを選び出す
    //
    int N, A, B, C;
    cin >> N >> A >> B >> C;

    int cur;
    vector<int> arr;
    for (int i = 0; i < N; i++) {
        cin >> cur;
        arr.push_back(cur);
    }

    stack<state> st;
    state root = {0};
    st.push(root);  //  樹形図のroot

    int ans = INT_MAX;
    int loop = 0;
    while (!st.empty()) {
        state cur = st.top();
        st.pop();
        
        if (cur.depth == N) {
            int mp = calc_mp(cur, A, B, C);
            if (mp != -1) {
                ans = min(mp, ans);
            }
        }

        if (cur.depth != N) {
            int cur_len = arr[cur.depth];
    
            state a_new_state(cur);
            state b_new_state(cur);
            state c_new_state(cur);
            state d_new_state(cur);

            //  a の材料にする 
            a_new_state.a_len += cur_len;
            a_new_state.a_num += 1;
            a_new_state.depth += 1;
            st.push(a_new_state);

            //  b の材料にする
            b_new_state.b_len += cur_len;
            b_new_state.b_num += 1;
            b_new_state.depth += 1;
            st.push(b_new_state);

            //  c の材料にする 
            c_new_state.c_len += cur_len;
            c_new_state.c_num += 1;
            c_new_state.depth += 1;
            st.push(c_new_state);

            //  採用しない
            //  合成しないので、状態は変わらない
            d_new_state.depth += 1;
            st.push(d_new_state);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
using namespace std;
using ll = long long;
const ll mod = 998244353;

int N, S;
vector<int> A;

int main (void)
{
	cin >> N >> S;
	A.resize (N);
	for (auto& e: A)
		cin >> e;

	vector<vector<vector<ll>>> DynamicP (N+1);
	for (auto& e: DynamicP)
	{
		e.resize (S+1);
		for (auto& e2: e)
			e2.resize (3);

	}
	DynamicP[0][0][0] = 1;
	for (int i = 0; i < N; i++)
		for (int s = 0; s <= S; s++)
		{
			(DynamicP[i+1][s][0] += DynamicP[i][s][0]) %= mod;
			(DynamicP[i+1][s][1] += DynamicP[i][s][0] + DynamicP[i][s][1]) %= mod;
			(DynamicP[i+1][s][2] += DynamicP[i][s][0] + DynamicP[i][s][1] + DynamicP[i][s][2]) %= mod;
			if (s + A[i] <= S)
			{
				(DynamicP[i+1][s+A[i]][1] += DynamicP[i][s][0] + DynamicP[i][s][1]) %= mod;
				(DynamicP[i+1][s+A[i]][2] += DynamicP[i][s][0] + DynamicP[i][s][1]) %= mod;
			}
		}
	cout << DynamicP [N][S][2] << endl;
	return 0;
}

Measured memory_bytes: 492928
package main

import "fmt"

func main() {
	// Code for D - Derangement
	var N int
	fmt.Scan(&N)

	p := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&p[i])
	}

	var count int
	var temp int
	for i := 0; i < N-1; i++ {
		if p[i] == i+1 {
			count++
			temp = p[i]
			p[i] = p[i+1]
			p[i+1] = temp
		}
	}
	if p[N-1] == N {
		count++
	}
	fmt.Println(count)
}


Measured memory_bytes: 6312
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <set>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()

string getsumstr(string a, string b) {
    int carry = 0;
    string sum = "";
    int alen = a.length();
    int blen = b.length();
    while(alen && blen) {
        int an = a[alen-1] - '0';
        int bn = b[blen-1] - '0';
        if (an + bn + carry < 10) {
            sum += to_string(an + bn + carry);
            carry = 0;
        }else {
            sum += to_string(an + bn + carry - 10);
            carry = 1;
        }
        alen--;
        blen--;
    }
    if (alen > 0) {
        while(alen) {
            int an = a[alen-1] - '0';
            if(an + carry < 10) {
                sum += to_string(an + carry);
                carry = 0;
            }else {
                sum += to_string(an + carry - 10);
                carry = 1;
            }
            alen--;
        }
    }else {
        while(blen) {
            int bn = b[blen-1] - '0';
            if(bn + carry < 10) {
                sum += to_string(bn + carry);
                carry = 0;
            }else {
                sum += to_string(bn + carry - 10);
                carry = 1;
            }
            blen--;
        }
    }
    if (carry) sum += "1";
    reverse(sum.begin(), sum.end());
    return sum;
}

int main() {
    string a, b;
    int n;
    cin >> n;
    REP(i,n) {
        cin >> a >> b;
        if (a.size() > 80 || b.size() > 80) cout << "overflow" << endl;
        else {
            string sum = getsumstr(a,b);
            if (sum.size() > 80) cout << "overflow" << endl;
            else cout << sum << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3216
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int d = sc.nextInt();
    // n=6, d=2
    // 6,5,4,3,2,1
    // 1,1,2,2,1,1 8
    // max(n-d,0)*2
    // n=3,d=2
    // 3,2,1
    // 1,0,1
    float ans = d == 0
      ? (float)(m-1)/n
      : (float)((long)(m-1)*(n-d)*2)/((long)n*n);
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
    ll int n;
    cin>>n;
    ll int arr[n];
    set<int>s;
    for(ll int i=0;i<n;i++)
    {
        cin>>arr[i];
        s.insert(arr[i]);
    }
    if(s.size()==n)
    cout<<"YES";
    else
    cout<<"NO";
    
    
    
    return 0;
}


    
    
    
    
    
    
    
    

Measured memory_bytes: 11136
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>

using namespace std;

long long comb(const long long a, const long long b){
  long long mod = 1000000007;

  long long fact[a + 1];
  long long inv[a + 1];
  fact[0] = 1;
  inv[0] = 1;

  for(long long i = 1; i <= a; i++){
    fact[i] = (fact[i-1] * i) % mod;

    long long ans = 1;
    long long n = mod-2;
    long long x = fact[i];
    while(n){
      if(n & 1){
        ans = (ans * x) % mod;
      }
      x = (x * x) % mod;
      n>>=1;
    }
    inv[i] = ans % mod;
    // cout << fact[i] << " " << inv[i] << endl;
  }
  return ( fact[a] * (inv[b] * inv[a-b] % mod)) % mod;
}

// long long mo=1000000007;
// long long comb(long long N_, long long C_) {
// 	const int NUM_=400001;
// 	static long long fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
// 	if (fact[0]==0) {
// 		inv[1]=fact[0]=factr[0]=1;
// 		for (int i=2;i<=NUM_;++i){
//       inv[i] = inv[mo % i] * (mo - mo / i) % mo;
//     }
// 		for (int i=1;i<=NUM_;++i){
//       fact[i]=fact[i-1]*i%mo;
//       factr[i]=factr[i-1]*inv[i]%mo;
//     }
// 	}
// 	if(C_<0 || C_>N_) return 0;
// 	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
// }


int main(){
  long long mo = 1000000007;
  long long n, m, k;
  cin >> n >> m >> k;
  long long x = 0;
  long long y = 0;

  for(long long i = 1 ; i < n ; i++){
    long long d = (i * (n-i))%mo;
    x += d;
    x = x%mo;
  }
  for(long long i = 1 ; i < m ; i++){
    long long d = (i * (m-i))%mo;
    y += d;
    y = y%mo;
  }
  cout << ((x*m*m+y*n*n)%mo * comb(n*m-2, k-2)) %mo << endl;
  // cout << comb(18, 2) << endl;
}


Measured memory_bytes: 3328