akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(),v.rend())
#define mkp(a,b) make_pair(a,b)
#define scf2(a,b) scanf("%lld%lld",&a,&b)
#define scf(a) scanf("%lld",&a)
#define pf(a) printf("%lld\n",a)
#define mx 100005
#define show(x) cout << #x << " : " << x << endl

using namespace std;

ll A[mx][4];
ll b[mx];
ll c[mx],sum=0,ans=0,n;

ll dp[mx][4];

ll rec(ll i , ll bol)
{
    if (dp[i][bol] != -1)return dp[i][bol];
    if (i==n-1)return dp[i][bol] = A[i][bol];

    ll a = (bol+1)%3 , b = (bol+2)%3;
    return dp[i][bol] = max(rec(i+1,a),rec(i+1,b))+A[i][bol];

}

int main()
{
    cin >> n;
    for(ll i=0;i<n;i++)cin >> A[i][0]  >> A[i][1] >> A[i][2];

    memset(dp,-1,sizeof(dp));
    cout << max(rec(0LL,0LL) , max(rec(0LL,1LL) , rec(0LL , 2LL))) << endl;
}

Measured memory_bytes: 12800
//om nama sivaya
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define INF 9223372036854777ll
#define pb push_back
using namespace std;

void solve(){
    ll n;
    cin>>n;
    int base=1;
    while(base<=n)base*=2;
    vector<ll> tree(2*base);
    vector<ll> hei(n),bea(n);
    for(int i=0;i<n;i++)
    cin>>hei[i];
    for(int i=0;i<n;i++)
    cin>>bea[i];
    vector<ll> dp(n+1);
    for(int flo=0;flo<n;flo++){
        //max in interval 0 to h[flo]
        int x=hei[flo]+base;
        ll bes=0;
        while(x>1){
            if(x&1)
            bes=max(bes,tree[x-1]);
            x/=2;
        }
        dp[hei[flo]]=bes+bea[flo];
        for(int i=base+hei[flo];i>=1;i/=2)
        tree[i]=max(tree[i],dp[hei[flo]]);
        
    }
    ll res=0;
    for(int i=0;i<=n;i++)
    res=max(res,dp[i]);
    cout<<res;
    
    
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tt=1;
    //cin>>tt;
    while(tt--){
        solve();
    }
}


Measured memory_bytes: 11912
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <climits>
using namespace std;
#define Rep(i,n) for(int i = 0; i < n; ++i)
#define For(i, s, e) for(int i = s; i <= e; ++i)
int N, M;
int P[100001];
int X[100001];
int Y[100001];
int C[100001];

int main()
{
	scanf("%d %d", &N, &M);
	For(i, 1, N) {
		scanf("%d", &P[i]);
		C[i] = i;
	}
	For(i, 1, M)
		scanf("%d %d", &X[i], &Y[i]);

	For(i, 1, M) {
		int a = X[i];
		int b = Y[i];
		while (a != C[a]) a = C[a];
		while (b != C[b]) b = C[b];
		if (a < b) C[b] = a;
		if (a > b) C[a] = b;
	}
	int k = 0;
	for (int i = N; i > 0; --i) {
		int a = i;
		int b = P[i];
		while (a != C[a]) a = C[a];
		while (b != C[b]) b = C[b];
		if (a == b)
			++k;
	}
	printf("%d", k);
	return 0;
}

Measured memory_bytes: 1792
N = int(input())
N3 = N // 3
N3 = 0.5 * N3 * (2 * 3 + (N3 - 1) * 3)
N5 = N // 5
N5 = 0.5 * N5 * (2 * 5 + (N5 - 1) * 5)
N15 = N // 15
N15 = 0.5 * N15 * (2 * 15 + (N15 - 1) * 15)

print(int(N*(N+1) // 2 - (N3 + N5 - N15)))

Measured memory_bytes: 9188
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  int a = sc.nextInt();
  int b = sc.nextInt();
  System.out.print(a >= b ? b:a);
  System.out.print(" ");
  int min = (a + b) - n;
  System.out.println(0 <= min ? min:"0");
}}


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

int main(){
  int X, Y;
  cin >> X >> Y;
  int a = 0;
  while(2*a + 4*(X-a) != Y){
    a++;
    if(a > X){
      cout << "No";
      break;
    }
  }
  if(a <= X){
    cout << "Yes";
  }
  return 0;
}

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

int main() {
  int n,k;
  cin >>n>>k;
  long long count=0;
  for(int i=1;i<=n;i++){
    int shou=n/i;
    int amari=n%i;
    count+=max(i-k,0)*shou+max(amari-k+1,0);
    if(k==0)count--;
    //cout<<i<<" "<<shou<<" "<<amari<<" "<<count<<endl;
  }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
string s;
int n;
long mod=1e9+7,cnt[26];
main()
{
	cin>>n>>s;
	for(int i=0;i<s.size();i++)cnt[s[i]-'a']++;
	long ans=1;
	for(int i=0;i<26;i++)ans=ans*(cnt[i]+1)%mod;
	cout<<(ans+mod-1)%mod<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define li long long int
using namespace std;
int main(){
    li a,b,c;
    cin>>a>>b>>c;
    li k;
    cin>>k;
    while(k!=0&&b<=a)
    {
        b=b*2;
        k--;
    }
    if(b<=a){
        cout<<"No"<<endl;
        return 0;
    }
    while(k!=0&&c<=b){
        c=c*2;
        k--;
    }
    if(c<=b){
        cout<<"No"<<endl;
        return 0;
    }
    if(c>b&&b>a)
    cout<<"Yes"<<endl;
    
}

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


int main(void) {
    string s;
    cin >> s;
    rep(i,s.size()){
        if((i+1) % 2 > 0)cout << s.at(i);
    }
    cout << endl;
}


Measured memory_bytes: 512
N=int(input())
A=input()
B=input()
C=input()
ans=0
for i in range(N):
  X=[0]*26
  X[ord(A[i])-ord('a')]+=1
  X[ord(B[i])-ord('a')]+=1
  X[ord(C[i])-ord('a')]+=1
  X.sort()
  ans+=3-X[25]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <string>

using namespace std;
typedef long long ll;
const ll INF = 1LL << 50;

int solve();

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

int solve() {

	int n;
	cin >> n;

	if (!n) { return 0; }

	int ansNum = 0, winner = 0;
	vector<int> pts(26, 0);
	vector<char> ch(n);

	for (int i = 0; i < n; i++)
		cin >> ch[i];

	//	開票作業
	for (int i = 0; i < n; i++) {

		if (ansNum > 0) { break; }

		pts[ch[i] - 'A'] ++;

		//	二着が残りの票をすべて集めても一着に勝てないか？
		int M = *max_element(pts.begin(), pts.end());

		int topNum = 0;
		for (int p : pts) { if (p == M) topNum++; }

		//	同着がいる
		if (topNum > 1) {
			if (i == n - 1) {
				ansNum = -1; break;
			}
			else {
				continue;
			}
		}
		//	同着がいない
		else if(topNum == 1) {

			int cnt = 0;	//	のこりを集めて一着に勝てる人数
			
			for (int p : pts) {
				if (p == M) { continue; }
				const int rest = (n - 1) - i;	//	のこり票数
				if (p + rest >= M) { cnt++; }
			}
			
			//	勝てる候補者がいなければ
			if (cnt == 0) {
				ansNum = i + 1;
				for (int j = 0; j < 26; j++) {
					if (pts[j] == M) {
						winner = j;
						break;
					}
				}
			}


		}
	}

	if (ansNum < 1) {
		cout << "TIE" << endl;
	}
	else {
		char ansname = winner + 'A';
		cout << ansname << " " << ansNum << endl;
	}


	return 1;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 2e5 + 7;

int a[N], vis[N];


signed main()
{
	IO_OP;
	
	int n, k;
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> a[i];
	memset(vis, -1, sizeof vis);
	vis[1] = 0;
	int cur = 1;
	for(int i = 1; i <= k; i++) {
		cur = a[cur];
		if(vis[cur] == -1) {
			vis[cur] = i;
		} else {
			int left = k - i;
			int len = i - vis[cur];
			left %= len;
			for(int j = 0; j < left; j++) cur = a[cur];
			break;
		}
	}
	cout << cur << endl;
}





Measured memory_bytes: 6728
from itertools import product
S = input()
if len(S)==1:
    print(int(S))
else:
    Sum = 0
    for TR in product([0,1],repeat=(len(S)-1)):
        Op = ['+' if TO==1 else '' for TO in TR]+['']
        Sum += eval(''.join([TS+TO for TS,TO in zip(S,Op)]))
    print(Sum)

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

int main() {
  int N, a, b, c, d;
  cin >> N;
  a = N / 1000;
  b = N / 100 % 10;
  c = N / 10 % 10;
  d = N % 10;
  if ((a == b && b == c) || (b == c && c == d)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> a(n);    
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    sort(a.begin(), a.end());
    
    for (int i = 0; i < n - 1; i++) {
        if (a[i] == a[i+1]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define Rep(i,n) for(int i = 0; i < (n); i++)
#define For(i,start,end) for(i64 i = start; i < end; i++)
inline void nl(){std::cout<<std::endl;}
using namespace std;
typedef long long ll;
typedef unsigned long ul;

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ui = uint64_t;

//----------------library in this time--------------------------------
template <class T>
T gcd(const T a,const T b) {
    return (b == 0) ? a : gcd (b, a % b);
}
template <class T>
T lcm(const T a, const T b) {
    return a * b / gcd(a,b);
}
template <class T>
inline T ave(const T a, const T b) {
    return (a + b) / 2.0f;
}

long long squareTwo(const long long a,const long long b) {
    return (b == 1) ? a : squareTwo(a * 2, b - 1);
}

template<class T> inline bool UpdateMin(T& a, T b) {
    if (a > b) { a = b; return 1; } return 0;
}

template<class T> inline bool UpdateMax(T& a, T b) {
    if (a < b) { a = b; return 1; } return 0;
}

//------------------------main function-------------------------------
void Main(){
    ll n; cin >> n;
    vector<char> v(n);
    ll ans = 1;
    cin >> v[0];
    for(ll i = 1; i<n ; i++){
        cin >> v[i];
        if(v[i] != v[i-1]){
            ans++;
        }
    }
    cout << ans << endl;
}
//--------------------------------------------------------------------
int main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    
    Main();
    return 0;
}

Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int n;
        int k;
        Scanner s = new Scanner(System.in);
        n = s.nextInt();
        k = s.nextInt();
        int arr[] = new int[n];
        for (int i = 0; i <n ; i++) {
            arr[i] = s.nextInt();
        }
        Arrays.sort(arr);
        int sum=0;
        for (int i = 0; i <k ; i++) {
            sum+=arr[i];
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 30240
import itertools

def factorize(n):
    """素因数分解を行う

    Args:
        n (int): 素因数分解したい数

    Returns:
        fct (list[int]): 素因数分解した結果

    Examples:
        >>> factorize(1000)
        [2, 2, 2, 5, 5, 5]
    """
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct


def resolve():
    N = int(input())

    ans = 0
    factorize_N = factorize(N)

    if len(factorize_N) == 0:
        print(0)
        return

    for key, value in itertools.groupby(factorize_N):
        tmp = len(list(value))
        for i in range(1, tmp + 1):
            tmp -= i
            if (tmp < 0):
                break
            ans += 1

    print(ans)

resolve()

Measured memory_bytes: 9220
#include <iostream>
#include <map>
#include <algorithm>
#define rep(i, n) for(int i=0; i<n; i++)

using namespace std;
typedef tuple<int, string, int> psi;
// typedef pair<string, int> psi;

int main (void) {
    int n, m;
    cin >> n >> m;
    int k[m];
    int s[m][n];
    rep(i, m) {
        cin >> k[i];
        rep(j, k[i]) {
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    int p[m];
    rep(i, m) cin >> p[i];

    int c = 0;
    rep(pattern, 1 << n) {
        bool allok = true;
        rep(i, m) {
            int ci = 0;
            rep(j, k[i]) {
                ci += (pattern >> s[i][j] & 1);
            }
            allok &= ci % 2 == p[i];
        }
        c += allok;
    }
    cout << c << endl;
    return 0;
}



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

#define int long long

int mod = 998244353;

//#include "debug.cpp"

int32_t main(){
	int n, k, i, j, x, y;
	cin >> n >> k;

	vector<pair<int, int>> vp;
	for(i=0; i<k; i++){
		cin >> x >> y;
		vp.push_back({x, y});
	}

	int pref[n] = {0};
	pref[0] = 1;

	int ans[n]={0};
	ans[0] = 1;

	for(i=1; i<n; i++){
		// debug(i);
		pref[i] = pref[i-1];
		for(auto x: vp){
			if(x.first > i)
				continue;
			int left = max(0ll, i-x.second);
			int right = i-x.first;
			// debug(left, right);

			if(left == 0){
				pref[i] += pref[right];
				ans[i] += pref[right];
			}
			else{
				pref[i] += (pref[right]-pref[left-1] + mod) % mod;
				ans[i] += (pref[right]-pref[left-1] + mod) % mod;
			}

			pref[i] %= mod;
			ans[i] %= mod;
		}
	}

	// print(pref, n);
	// print(ans, n);

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

}

Measured memory_bytes: 6756
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define dd double
#define ld long double
#define ff float
#define pb push_back
#define ist insert
#define vec vector <int>
#define vecc vector <char>
#define vecs vector <string>
#define vecl vector <ll int>
#define vecp vector <pair<int,int>>
#define vecpl vector <pair<ll int,ll int>>
#define ub upper_bound
#define lb lower_bound
#define bg begin()
#define en end()
#define el endl
#define fr(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define wl while
#define sz size()
#define ss set <int>
#define ssl set <ll int>
#define mapi map<int,int>
#define mapl map<ll int,ll int>
#define mapc map<char,ll int>
#define maps map<string,ll int>
#define mapss map<string,string>
#define scni(x) scanf("%d",&x)
#define scns(x) scanf("%s",x)
#define scnc(x) scanf("%c",&x)
#define pti(x) printf("%d",x)
#define pts(x) printf("%s",x)
#define ptc(x) printf("%c",x)
#define test int t;cin>>t;while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
const int mod=1e9+7;
const int mex=1e6+1;
ll power(ll a,ll b)
{
    ll ans=1,temp=a;
    while(b!=0)
    {
        if(b&1)
        ans=ans*temp;
        ans=ans%mod;
        temp=temp*temp;
        temp=temp%mod;
        b/=2;
    }
    return ans;
}
int spf[mex];
void seive()
{
    int p[mex];
    for(int i=0;i<mex;i++) p[i]=1;
    p[0]=0;
    p[1]=0;
    for(int i=2;i*i<mex;i++)
    {
        if(p[i])
        for(int j=i*i;j<mex;j+=i)
        p[j]=0;
    }
    
}
ll int x1,x2,d1;
void exeu(ll int a1,ll int b1)
{
    if(b1==0)
    {
        x1=1;
        x2=0;
        d1=a1;
    }
    else
    {
        exeu(b1,a1%b1);
        ll int temp=x1;
        x1=x2;
        x2=temp-(a1/b1)*x2;
    }
}
ll int modinv(ll int A,ll int M)
{
    exeu(A,M);
    return (x1%M+M)%M;
}
vec adj[100005];
int vis[100005],dp[100005];
void dfs(int s)
{
    vis[s]=1;
    fr(i,adj[s].sz)
    {
        if(!vis[adj[s][i]]) dfs(adj[s][i]);
        dp[s] = max(dp[s], 1 + dp[adj[s][i]]);
    }
}
int main()
{
    fast
    int n,m;
    cin>>n>>m;
    while(m--)
    {
        int u,v;
        cin>>u>>v;
        u--;
        v--;
        adj[u].pb(v);
    }
    int ans=-1;
    fr(i,n)
    {
        if(!vis[i])
        {
            dfs(i);
        }
    }
    fr(i,n)
    {
        ans=max(ans,dp[i]);
       // cout<<i<<" "<<dp[i]<<el;
    }
    cout<<ans<<el;
    return 0;
}

Measured memory_bytes: 9472
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		
		int c1 = x/500;
		x -= c1*500;
		int c2 = x/5;
		
		System.out.println(c1*1000 + c2*5);
	}

}


Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

//#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << -1; return;}

const int N = 1007;

queue <int> q[N];

void solve() {
    int n; cin >> n;
    loop1(i, n) {
        loop(j, n - 1) {
            int x; cin >> x;
            q[i].push(x);
        }
    }
    bool ok = 1;
    int ans = 0;
    while (ok) {
        ok = 0; ++ans;
        vector <int> del;
        loop1(i, n)
            if (!q[i].empty()) {
                ok = 1;
                if (i == q[q[i].front()].front())
                    del.pb(i);
            }
        if (ok && del.empty())
            no;
        for (int x : del)
            q[x].pop();
    }
    cout << ans - 1;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 8044
import copy

from typing import List, Tuple


def main():
    d, g = map(int, input().split())
    v = []
    for _ in range(d):
        p, c = map(int, input().split())
        v.append((p, c))

    print(ag(v, g))


def ag(v: List[Tuple[int, int]], g: int) -> int:
    # ex. [(3, 500), (5, 800)] -> [(1, 3, 500), (2, 5, 800)]
    v = [(i, p, c) for i, (p, c) in enumerate(v, 1)]

    result = 100 ** 10
    for j in range(2 ** len(v)):
        cb = []
        for k in range(len(v)):
            if ((j >> k) & 1):
                cb.append(v[k])

        sc = 0
        cnt = 0
        # calc bonus score
        for (i, p, c) in cb:
            sc += i * 100 * p + c
            cnt += p

        for idx in reversed(range(len(v))):
            if sc >= g:
                break
            if v[idx] in cb:
                continue
            i, p, _ = v[idx]
            for _ in range(p - 1):
                if sc >= g:
                    break
                sc += i * 100
                cnt += 1

        if sc >= g:
            result = min(result, cnt)
    return result


if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{
  int ncards, ngates;
  std::cin >> ncards >> ngates;
  int first = 1;
  int last = ncards;
  for (int i = 0; i < ngates; i++) {
    int current_first, current_last;
    std::cin >> current_first >> current_last;
    first = max(first, current_first);
    last = min(last, current_last);
  }
  std::cout << max(0, last - first + 1) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
static auto x = []() {
    std::ios::sync_with_stdio(false); // turn off sync
    cin.tie(nullptr);                 // untie in/out streams
    return 0;
}();
bool check(int x)
{
    for (int i = 2; i * i <= x; i++) if (x % i == 0) return true;
    return false;
}

int ans = 0;
void work(char t, int r, int s, int p)
{
    if (t == 's') ans += r;
    else if (t == 'p') ans += s;
    else ans += p;
}
int main()
{
    int n, k, r, s, p;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;
    for (int i = 0; i < k; i++)
    {
        int ii = i;
        char now = 'q';
        while (ii < t.length())
        {
            if (t[ii] != now)
            {
                now = t[ii];
                work(t[ii], r, s, p);
            }
            else now = 'q';
            ii += k;
        }
    }
    cout << ans;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll  long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
#define ld long double
using namespace std;

int main()
{ 


fast;
ll n,m,x;
cin>>n>>m>>x;

ll c[n];
ll a[n][m];

for(ll i=0;i<n;i++)
{
  cin>>c[i];
  for(ll j=0;j<m;j++)
    cin>>a[i][j];
}

ll ans=inf;
ll chk=(1<<n);
//cout<<chk<<endl;

for(ll i=0;i<chk;i++)
{
  vector<ll> temp(m,0);
  ll ct=0;

  for(ll j=0;j<n;j++)
    if((i & (1<<j)))
    {
      ct+=c[j];
      //cout<<i<<" "<<j<<endl;
      for(ll k=0;k<m;k++)
        temp[k]+=a[j][k];
    }

    bool f=1;
    for(ll i=0;i<m;i++)
    {
      if(temp[i]<x)
      {
        f=0;
        break;
      }
    }

    if(f)
      ans=min(ans,ct);
}



if(ans==inf)
  cout<<-1<<endl;
else cout<<ans<<endl;

}

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

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  int N;
  cin >> N;
  const int INF = 1000000000000;
  
  vector<int> H(N);
  for( int i = 0; i < N; i++ ) cin >> H.at(i);
  
  vector<int> dp(N+10, INF);
  dp.at(0) = 0;
  
  for( int i = 1; i < N; i++ ){
    chmin( dp.at(i), dp.at(i-1) + abs(H.at(i)-H.at(i-1)) );
    if( i > 1 ){
      chmin( dp.at(i), dp.at(i-2) + abs(H.at(i)-H.at(i-2)) );
    }
  }
  cout << dp.at(N-1) << endl;
}




Measured memory_bytes: 1792
//region trash
#ifndef LOCAL
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#define DB(x){if(cond)cerr<<__LINE__<<" "<<#x<<" " <<x<<endl;}
#else
#define DB(x){}
#endif
#define REP(i,b)for(auto i=0;i<(b);++i)
#define FOR(i,a,b)for(auto i=(a);i<=(b);++i)
#define FORD(i,a,b)for(auto i=(a);i>=(b);--i)
#define FORDE(rit,x)for(auto rit=(x).rbegin();rit!=(x).rend();rit++)
#define VV vector
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
template<typename X, typename Y>bool MA(X&a,Y b){if(a<b){a=b;return true;} return false;}
template<typename X, typename Y>bool MI(X&a,Y b){if(a>b){a=b;return true;} return false;}
typedef long long LL,ll;typedef long double LD,ld;
typedef array<int,2>I2,i2;typedef VV<int>VI,vi;
using namespace std;
int cond=0;
//endregion

int mode=0;

struct Solver {
  void solve() {
    int N;cin>>N;
    VV<string>A(N);
    REP(n,N)cin>>A[n];

    int res = 0;
    int ba = 0, a=0, b=0;
    REP(n,N) {
      REP(as,(int)A[n].size() - 1) {
        if (A[n][as] == 'A' && A[n][as+1] == 'B') {
          res += 1;
        }
      }
      if (A[n][0] == 'B') {
        if (A[n].back() == 'A') {
          ba += 1;
        }
        else b+=1;
      }
      else if (A[n].back() == 'A') {
        a+=1;
      }
    }
    DB(a<<" "<<b<<" "<<ba);
    if (ba >= 1) {
      res += ba - 1;
      DB(res<<" "<<a<<" "<<b);
      if (a>=1) {
        a--;
        res+=1;
      }
      if (b >= 1) {
        b--;
        res+=1;
      }
      DB(res<<" "<<a<<" "<<b);
    }
    res += min(a,b);
    cout<<res<<endl;
  }
};


int main(int argc,char** argv){
  struct Solver2 {
    void gen() {}
    void brute() {}
  };
  random_device rd{};
  uint64_t seed = (uint64_t)rd()
      ^ (uint64_t)std::chrono::steady_clock::now().time_since_epoch().count()
      ^ (uint64_t)__builtin_ia32_rdtsc()
      ^ (uint64_t)make_unique<char>().get();
  srand(seed); mt19937 rng(seed);

  ios::sync_with_stdio(false),cin.tie(nullptr);
  FOR(a,1,argc-1){if(argv[a][0]=='g') { Solver2 solver; solver.gen(); return 0; }}
  FOR(a,1,argc-1){if(argv[a][0]=='q') cond=1U<<30U;}
  cout.setf(ios::fixed),cout.precision(10);
  int t{};if(mode >= 1)cin>>t;else t=1;
  bool isBrute=false;FOR(a,1,argc-1)if(argv[a][0]=='b')isBrute=true;
  FOR(i,1,t){if(cond)cerr<<__LINE__<<" "<<i<<endl;if(mode == 2)cout<<"Case #"<<i<<": ";
    auto solver = make_unique<Solver>();
    auto solver2 = make_unique<Solver2>();
    if (isBrute)
      solver2->brute();
    else
      solver->solve();
  }
  return 0;
}


Measured memory_bytes: 768
import sys
for number in sys.stdin:
   	ans = []
	n = int(number)
	for b in [512,256,128,64,32,16,8,4,2,1]:
		if n >= b:
			n -= b
			ans.append(b)
	ans.reverse()
	ans = map(str,ans)
	ans = ' '.join(ans)
	print ans

Measured memory_bytes: 4220
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello{
    public Hello(){}
    public static void Main(){
        new Hello().Calc();
    }
    void Calc(){
        var inputs = InputValue;
        foreach(var i in inputs){
            Console.WriteLine(i);
        }
    }
    string MakeRectangle(int h,int w){
        var temp = "";
        for(var y = 0;y < h;y++){
            for(var x = 0;x < w;x++){
                temp += "#";
            }
            temp += "\n";
        }
        return temp;
    }
    List<string> InputValue{
        get{
            var inputs = new List<string>();
            
            while(true){
                var line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                if(line[0] == 0 && line[1] == 0){
                    break;
                }else{
                    inputs.Add(MakeRectangle(line[0],line[1]));
                }
                
            }
            return inputs;
        }
    }
}



Measured memory_bytes: 32188
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int X;
    int five = 0, seven = 0;
    REP(i, 3) {
        cin >> X;
        if (X == 5) {
            five++;
        } else if (X == 7) {
            seven++;
        }
    }
    if (five == 2 && seven == 1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#ここまでテンプレ
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

n,m = map(int,stdin.readline().rstrip().split())

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

f = UnionFind(n)

for _ in range(m):
    a,b = map(int,stdin.readline().rstrip().split())
    a -= 1
    b -= 1
    f.union(a,b)

ma = 0

for i in range(n):
    ma = max(ma,f.size(i))

print(ma)

Measured memory_bytes: 14572
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
 
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
  
  int n,m;
  cin >> n >> m;

  int lc = max(m - n * 2, 0ll);

  cout << min(n, m / 2) + lc / 4 << endl;

  return 0;
}


Measured memory_bytes: 256
from math import sqrt
n = int(input())
ans = 0
for i in range(2, 1 + int(sqrt(n))):
    c = 0
    while n % i == 0:
        n //= i
        c += 1
    ans += int((-1 + sqrt(1 + 8 * c)) / 2)
if n != 1:
    ans += 1
print(ans)


Measured memory_bytes: 9212
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
//const ll MOD=998244353LL;
//const ll MAX_V=114514LL;
const ll MAX = 510000LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};
ll q;
ll sumb,sumL,sumR;
priority_queue<ll>L;
priority_queue<ll,vl,greater<ll> >R;
int main(){
  cin>>q;
  for(;q--;){
    ll id;cin>>id;
    if(id==1){
        ll a,b;cin>>a>>b;
        sumb+=b;
        if(!R.empty()&&R.top()<=a)R.push(a),sumR+=a;
        else L.push(a),sumL+=a;
        ll dim=(L.size()+R.size())%2;
        while(R.size()+dim<L.size()){
          ll now=L.top();
          sumL-=now;
          sumR+=now;
          R.push(now);
          L.pop();
        }
        while(R.size()+dim>L.size()){
          ll now=R.top();
          sumR-=now;
          sumL+=now;
          L.push(now);
          R.pop();
        }
    }
    else {
      ll now=L.top();
      cout<<now<<" "<<sumb+(sumR-now*(ll)R.size())+(now*(ll)L.size()-sumL)<<endl;
    }
    
  }
}

Measured memory_bytes: 3828
N = int(input())
arr = [int(n) for n in input().split()]

swap_cnt = 0
for i in range(0, N):
    minj = i
    for j in range(i + 1, N):
        if arr[j] < arr[minj]:
            minj = j
    if (i != minj):
        arr[i], arr[minj] = arr[minj], arr[i]
        swap_cnt += 1

print(' '.join(map(str, arr)))
print(swap_cnt)



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


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

class AFrog1 {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;
        vector<ll> h(n);
	    rep(i,n){
	        in >> h[i];
	    }
	    vector<ll> dp(n,0);
        dp[1]=abs(h[1]-h[0]);
        for(int i=2;i<n;i++){
            dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
        }
        out << dp.back() << endl;
    }
};


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


Measured memory_bytes: 1792
N=int(input())
a=[int(input()) for i in range(N)]
j=[0]*N
ans=0
b=1
while(1):
    ans+=1
    b=a[b-1]
    j[b-1]+=1
    if j[b-1]==2:
        ans=-1
        break
    if b==2:break
print(ans)

Measured memory_bytes: 7852
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

struct edge{
  int s,t,c;
};

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

  //L=2からスタート
  //必要な操作を求める 0:1足す　1:2倍
  vector<int> ope;
  while(L > 2){
    if(L%2==1){
      ope.push_back(0);
      L--;
    } else {
      ope.push_back(1);
      L /= 2;
    }
  }
  reverse(ope.begin(),ope.end());

  /*for(int i=0;i<ope.size();i++){
    cout << ope[i] << endl;
  }*/

  int N = 2;
  int M = 2;
  vector<edge> e;
  edge e1,e2;
  e1.s = 1; e1.t = 2; e1.c = 0;
  e2.s = 1; e2.t = 2; e2.c = 1;
  e.push_back(e1);
  e.push_back(e2);

  for(int i=0;i<(int)ope.size();i++){
    if(ope[i] == 0){
      edge tmp;
      tmp.s = 1; tmp.t = N; tmp.c = L;
      e.push_back(tmp);
      M++;
      L++;
    }

    if(ope[i] == 1){
      for(int j=0;j<(int)e.size();j++) e[j].c *= 2;
      edge tmp1,tmp2;
      tmp1.s = N; tmp1.t = N+1; tmp1.c = 0;
      tmp2.s = N; tmp2.t = N+1; tmp2.c = 1;
      e.push_back(tmp1);
      e.push_back(tmp2);
      N++;
      M += 2;
      L *= 2;
    }
  }

  cout << N << " " << M << endl;
  for(int i=0;i<(int)e.size();i++){
    cout << e[i].s << " " << e[i].t << " " << e[i].c << endl;
  }
  return 0;
}

Measured memory_bytes: 256
K = int(input())
from collections import deque
p = deque()
for i in range(1,10):
    p.append(i)
for i in range(K):
    if p[0] % 10 != 0:
        p.append(10*p[0]+p[0]%10-1)
    p.append(10*p[0]+p[0]%10)
    if p[0] % 10 != 9:
        p.append(10*p[0]+p[0]%10+1)
    q = p[0]
    p.popleft()
print(q)

Measured memory_bytes: 11900
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<int,int> point;
#define rep(i,n) for(i,0,n)
 
int main() {
	// 入力
	int N;
	cin >> N;
 
	// 解法
	int ans = 0;
	
	for (int i = 1; i <= N; ++i) {
		if (i%2==0) continue;
		int yakusuu = 0;
		for (int k = 1; k <= i; ++k) {
			if (i%k==0) yakusuu++;
		}
		if (yakusuu==8){ 
			ans++;
			// cout << i << endl;
		}
	}
	
	// cout << yakusuu << endl;
	//出力
	printf("%lld\n", ans);
}
 


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    A, B, N = Scanner.map_int()

    x = min(B - 1, N)
    print((A * x) // B - A * (x // B))


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 10732
#include<iostream>
using namespace std;
int main()
{
	int r,c,a[100][100],sum=0,haji=0;
	cin >> r >> c;
	for(int i=0;i<r;++i){
		for(int j=0;j<c;++j){
			cin >> a[i][j];
		}
	}
	for(int	i=0;i<r;++i){
		sum=0;
		for(int j=0;j<c;++j){
			cout << a[i][j] << " ";
			sum += a[i][j];
		}
		cout << sum << endl;
	}
	for(int j=0;j<c;++j){
		sum=0;
		for(int i=0;i<r;++i){
			sum += a[i][j];
		}
		cout << sum << " ";
		haji += sum;
	}
	cout << haji << endl;
	return 0;
}

Measured memory_bytes: 1196
import math

N = int(input())
csf = [list(map(int, input().split())) for _ in range(N-1)]

for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        if t >= csf[j][1]:
            t = math.ceil(t/csf[j][2])*csf[j][2]+csf[j][0]
        else: t = csf[j][1] + csf[j][0]
    print(t)
print(0)

Measured memory_bytes: 3188
n,m=list(map(int, input().split()))
l = 0
r = float("inf")
for _ in range(m):
    a,b = list(map(int, input().split()))
    l = max(l,a)
    r = min(r,b)

ans = r-l+1
if r < l:
    print(0)
elif ans <= n:
    print(ans)
else:
    print(n)

Measured memory_bytes: 44120
#include <bits/stdc++.h>
#include <bitset>
#define ll long long
#define pb push_back
#define f first
#define s second
#define mod 10000000007
#define hurry ios::sync_with_stdio(false)
#define PI 3.141592654
#define xx (ll) 100+3

using namespace std;

int N,dp[3][xx];
string s;

int main()
{
    hurry;
    cin>>N;
    for(int i=1;i<=2;i++)
    {
        for(int j=1;j<=N;j++)
        {
            cin>>dp[i][j];
        }
    }
    for(int i=1;i<=2;i++)
    {
        for(int j=1;j<=N;j++)
        {
            dp[i][j]+=max(dp[i][j-1],dp[i-1][j]);
        }
    }
    cout<<dp[2][N]<<endl;
    return 0;
}


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

int main(){
    ll n, k; cin >> n >> k;
    vector<ll> a(n); rep(i,n) cin >> a[i];

    sort(all(a));

    ll ans = 0;
    rep(i,k) ans += a[i];

    cout << ans << endl;

}

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int x,y;cin >> x >> y;
    vector<int> a = {1,3,5,7,8,10,12};
    vector<int> b = {4,6,9,11};
    vector<int> c = {2};
    int cnt = 0;
    for(int z:a){
        if(z==x||z==y)cnt++;
    }
    if(cnt==2){
        cout << "Yes" << endl;
        return 0;
    }
    cnt=0;
    for(int z:b){
        if(z==x||z==y)cnt++;
    }
    if(cnt==2){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;

long long factorial(long long i){ // 階乗
 if(i > 0)
   return i * factorial(i-1);
 else
   return 1;
}

int main() {
	// snuke method
	const ll mod = 998244353;

	ll N;
	string S; //size 3N
	cin >> N >> S;
	ll cnt_r=0, cnt_g=0, cnt_b=0;
	ll ans = 1;
	rep(i, 3*N) {
		if(S[i]=='R') {
			if(cnt_r<cnt_g && cnt_r<cnt_b) {
				ans *= min(cnt_g, cnt_b);
				ans %= mod;
				cnt_g--; 
				cnt_b--;
			} else if(cnt_r>=cnt_g && cnt_r>=cnt_b) {
				cnt_r++;
			} else {
				ans *= max(cnt_g, cnt_b) - cnt_r;
				ans %= mod;
				cnt_r++;	
			}
		} else if(S[i]=='G') {
			if(cnt_g<cnt_r && cnt_g<cnt_b) {
				ans *= min(cnt_r, cnt_b);
				ans %= mod;
				cnt_r--; 
				cnt_b--;
			} else if(cnt_g>=cnt_r && cnt_g>=cnt_b) {
				cnt_g++;
			} else {
				ans *= max(cnt_r, cnt_b) - cnt_g;
				ans %= mod;
				cnt_g++;	
			}
		} else {
			if(cnt_b<cnt_g && cnt_b<cnt_r) {
				ans *= min(cnt_g, cnt_r);
				ans %= mod;
				cnt_g--; 
				cnt_r--;
			} else if(cnt_b>=cnt_g && cnt_b>=cnt_r) {
				cnt_b++;
			} else {
				ans *= max(cnt_g, cnt_r) - cnt_b;
				ans %= mod;
				cnt_b++;	
			}
		}
	}

	rep(i, N) {
		ans *= (i+1);
		ans %= mod;
	}

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

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    cout << (N - 1) / 2 << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3512
from itertools import combinations

N, M, Q = map(int, input().split())

ans = 0
List = []
for i in range(Q):
    List.append(tuple(map(int, input().split())))

List2 = []
for i in range(N + M - 1):
    List2.append(i)


for x in combinations(List2, M - 1):
    List3 = [1] * N
    n = 0
    an = 0
    for y in x:
        y -= n
        for iii in range(y, N):
            List3[iii] += 1
        n += 1
    for i in range(Q):
        a, b, c, d = List[i]
        if List3[b-1] - List3[a-1] == c:
            an += d
    ans = max(ans, an)

print(ans)


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

int main()
{
 	int a,b;
  	cin>>a>>b;
  	int total = 1;
  	int count = 0;
    while(total < b)
    {
        total = total + a-1;
        count++;
    }
    cout<<count;
}

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

template <typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}

struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }

    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }

    friend ostream& operator<<(ostream& s, ModInt a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt& a) {
        s >> a.x;
        return s;
    }
};

using mint = ModInt;

mint fact[3000];
mint factinv[3000];

void init() {
    fact[0] = 1;
    for (int i = 1; i < mod; i++) {
        fact[i] = fact[i - 1] * i;
    }
    factinv[mod - 1] = fact[mod - 1].inv();
    for (int i = mod - 2; i >= 0; i--) {
        factinv[i] = factinv[i + 1] * (i + 1);
    }
    assert(factinv[0] == 1);
}

mint ncr(int n, int r) { return fact[n] * factinv[r] * factinv[n - r]; }

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

    cin >> mod;
    init();
    vector<mint> bs(mod);
    for (int i = 0; i < mod; i++) {
        mint a;
        cin >> a;
        for (int j = 0; j < mod; j++) {
            mint cf = -ncr(mod - 1, j) * pow(mint(-i), mod - 1 - j);
            if (j == 0) cf += 1;
            bs[j] += a * cf;
        }
    }
    for (int i = 0; i < mod; i++) {
        cout << bs[i] << ' ';
    }
}


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

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> xy(n);
  for (int i = 0; i < n; i++) {
    cin >> xy.at(i).first >> xy.at(i).second;
  }
  vector<int> order(n);
  for (int i = 0; i < n; i++) {
    order.at(i) = i;
  }
  int cnt = 0;
  double sum = 0;
  do {
    double dist = 0;
    for (int i = 0; i < n - 1; i++) {
      int dx = xy.at(order.at(i)).first - xy.at(order.at(i + 1)).first;
      int dy = xy.at(order.at(i)).second - xy.at(order.at(i + 1)).second;
      dist += sqrt(dx * dx + dy * dy);
    }
    sum += dist;
    cnt++;
  } while (next_permutation(order.begin(), order.end()));
  printf("%.10f\n", sum / cnt);
  return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#ifdef DEBUG
#define line() cout << "[" << __LINE__ << "] ";
#define dump(i) cout << #i ": " << i << " ";
#define dumpl(i) cout << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    int n, m;
    cin >> n >> m;
    pair<ll, ll> p[n];
    rep(i, n) cin >> p[i].first >> p[i].second;
    sort(p, p + n);
    ll index = 0;
    ll ans = 0;
    rep(i, m)
    {
        if (p[index].second == 0)
            index++;
        ans += p[index].first;
        p[index].second--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792