akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.Arrays;

public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
long n=scan.nextLong();
long m=scan.nextLong();
  
if(n==1||m==1){
  System.out.println(1);
}else if(n%2==0&&m%2==0){
  System.out.println(n*m/2);
}else if(n%2==1&&m%2==0){
  System.out.println(n*m/2);
}else if(n%2==0&&m%2==1){
  System.out.println(n*m/2);
}else if(n%2==1&&m%2==1){
  System.out.println((n*m+1)/2);
}  
  
}
}


Measured memory_bytes: 22608
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int a, b;
// vector<int> A;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> a >> b;
  // A.resize(N);
  // for (int i = 0; i < N; i++) {
  //   int tmp;
  //   cin >> tmp;
  //   A[i] = tmp;
  // }

  if (a <= b) {
    for (int i = 0; i < b; i++) {
      cout << a;
    }
    cout << endl;
  } else {
    for (int i = 0; i < a; i++) {
      cout << b;
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define ll long long
int main(){
    int n,k;
    cin >> n >> k;
    int count=0;
    int subk=k;
    while(n-k>=0){
        k*=subk;
        count++;
    }
    cout << count+1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long gcd(long long a, long long b) {
    if (a < 0) a = -a;
    if (b < 0) b = -b;
    if (a < b) swap(a, b);
    while (b > 0) { long long t = a; a = b; b = t % b; }
    return a;
}

int main() {
    int x; cin >> x;
    cout << 360 / gcd(x, 360) << endl;
}


Measured memory_bytes: 3592
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,k = map(int,ipt().split())
    ps = []
    ms = []
    n0 = 0
    for i in ipt().split():
        ii = int(i)
        if ii == 0:
            n0 += 1
        elif ii > 0:
            ps.append(ii)
        else:
            ms.append(-ii)

    pn = len(ps)
    mn = len(ms)
    if k <= pn*mn:
        ps.sort()
        ms.sort(reverse=True)
        l = -10**(18)
        r = -1
        while l < r:
            mid = l + (r-l)//2
            num = 0 #積がmid以下になる個数
            mi = 0
            for i in ps:
                for j in range(mi,mn):
                    if -i*ms[j] > mid:
                        break
                    mi += 1
                num += mi
            if num < k:
                l = mid+1
            else:
                r = mid
        print(l)

    elif k <= pn*mn+n0*(pn+mn)+n0*(n0-1)//2:
        print(0)

    else:
        k -= pn*mn+n0*(pn+mn)+n0*(n0-1)//2
        ps.sort()
        ms.sort()
        l = 1
        r = 10**18
        while l < r:
            mid = l + (r-l)//2
            num = 0 #積がmid以下になる個数
            mi = 0
            pi = 0
            for i,mk in enumerate(ms[::-1]):
                mi = min(mi,mn-i-1)
                for j in range(mi,mn-i-1):
                    if mk*ms[j] > mid:
                        break
                    mi += 1
                num += mi
            for i,pk in enumerate(ps[::-1]):
                pi = min(pi,pn-i-1)
                for j in range(pi,pn-i-1):
                    if pk*ps[j] > mid:
                        break
                    pi += 1
                num += pi
#            print(mid,num,k)
            if num < k:
                l = mid+1
            else:
                r = mid
        print(l)
    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 171680
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
//#define uint __int128_t
 
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
const ll MOD=1000000007,INF=1e18;

int N;
int a[200020],b[200020];
pint p[200020];

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    //MOD同士の引き算に注意
    cin>>N;
    rep(i,0,N){
        cin>>a[i];
        p[i]={a[i],0};
    }
    rep(i,N,2*N){
        cin>>b[i];
        p[i]={b[i],1};
    }
    sort(p,p+2*N);
    int ans=1,tmp=0,tmpans=0;
    rep(i,0,2*N){
        if(p[i].se){
            if(tmp>=0)tmp++;
            else{
                ans=ans*abs(tmp)%MOD;
                tmp++;
            }
        }
        else{
            if(tmp<=0)tmp--;
            else{
                ans=ans*abs(tmp)%MOD;
                tmp--;
            }
        }
    }
    cout<<ans<<endl;
    
    
    
    
    return 0;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define INF 1<<30
int main(){
  int N,K;
  cin>>N>>K;
  vector<int> H(N);
  rep(i,N) cin>>H[i];
  vector<int> dp(N);
  dp[0]=0;
  rep(i,N-1) dp[i+1]=INF;
  rep(i,N){
    rep(j,K){
      if(i>j) dp[i]=min(dp[i],dp[i-j-1]+abs(H[i]-H[i-j-1]));
    }
  }
  cout<<dp[N-1]<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <set>
using namespace std;
vector<pair<long long,int>> v;
multiset<int> s[2];
int main(){
    int i,x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    for(i=0;i<a;i++){
        long long p; cin >> p;
        v.push_back({p,0});
    }
    for(i=0;i<b;i++){
        long long q; cin >> q;
        v.push_back({q,1});
    }
    for(i=0;i<c;i++){
        long long  r; cin >> r;
        v.push_back({r,2});
    }
    sort(v.rbegin(),v.rend());
    int res = 0;
    long long ans = 0;
    for(i=0;i<v.size();i++){
        if(v[i].second==2){
            if(res<x + y){
                ans += v[i].first;
                res++;
            }
        }
        if(v[i].second==1){
            if(res<x + y && s[1].size()<y){
                ans += v[i].first;
                res++; s[1].insert(v[i].first);
            }
        }
        if(v[i].second==0){
            if(res<x + y && s[0].size()<x){
                ans += v[i].first;
                res++; s[0].insert(v[i].first);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 14568
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;

int main(){

  ll N;
  cin >> N;
  string S;
  map<string,ll>m;
  for (ll i = 0; i < N; i++) {
    cin >> S;
    m[S] += 1;
  }

  int maxv = 0;
  // for (const auto& x : m) {
  //   int v = x.second;
  //   if (v > maxv) maxv = v;
  // }
  for(auto i = m.begin(); i != m.end(); i++) {
      int v = i->second;
      if (v > maxv) maxv = v;
  }

  for(auto i = m.begin(); i != m.end(); i++) {
    if(i->second == maxv){
      cout << i->first << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 27008
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp);
void ipgraph(int m);
//void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
// vector<int>adj[100005];
// int dp[100005];
// bool vis[100005];
// int in_degree[100005];
// void dfs(int src){
//     vis[src]=true;    
//     for(auto it:adj[src]){
//         dp[it]=max(dp[it],dp[src]+1);
//         --in_degree[it];
//         if(in_degree[it]==0)dfs(it);
//         }
//
//
//
// }
//

ll int dp[200][30000];   
int main(){
ios_base::sync_with_stdio(0);
ll int t,n,i,j,k,m;
t=1;
// cin>>t;
int T;
Fo(T,1,t+1){
//  cout<<"Case #"<<T<<": ";
  cin>>n>>k;
 ll int a[n];
  fo(i,n){
      cin>>a[i];
  }
  fo(i,a[0]+1){
      dp[0][i]=1;
  }
  Fo(i,1,n){
      vi pref(k+1);
      pref[0]=dp[i-1][0];
      Fo(j,1,k+1){
          pref[j]=(pref[j-1]+dp[i-1][j])%mod;
      }
      fo(j,k+1){
          if(j>a[i])
              dp[i][j]=(pref[j]+mod-pref[j-a[i]-1])%mod;
          else dp[i][j]=pref[j];
      }
  }
  cout<<dp[n-1][k];


}
}


Measured memory_bytes: 28004
#include<iostream>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
using namespace std;
using ll=long long;

const ll SIZE=1e9;
const ll MAX_V=1e18;
void output(ll x0,ll y0,ll x1,ll y1,ll x2,ll y2){
    cout<<x0<<" "<<y0<<" "<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
}
int main(){
    ll s; cin>>s;    

    if(s==MAX_V){
        output(0,0,SIZE,0,0,SIZE);
        return 0;
    }

    ll u=s/SIZE+1;
    ll l=SIZE-s%SIZE;
    output(0,0,SIZE,1,l,u);
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 100000000000000000
signed main(void){
    int n;cin>>n;
    string s0,s1;cin>>s0>>s1;
    int ans=3;
    if(s0[0]!=s1[0])ans=6;
    for(int i=1;i<n;i++){
        if(s0[i]==s0[i-1])continue;
        else{
            if(s0[i]==s1[i]){
                if(s0[i-1]==s1[i-1])ans=ans*2%mod;
            }
            else{
                if(s0[i-1]==s1[i-1])ans=ans*2%mod;
                else ans=ans*3%mod;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;

main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n;cin>>n;
    const int N=1e6+7;
    int count[N]={0};
    int a[n];

    for(int i=0;i<n;i++){
        cin>>a[i];
        count[a[i]]+=1;
    }

    int gcd=a[0];
    for(int i=1;i<n;i++){
        gcd=__gcd(a[i],gcd);
    }

    int fail=0;
    for(int i=2;i<=1e6;i++){
        int have=0;
        for(int k=1;i*k<=1e6;k++){
            have+=count[k*i];
        }
        if(have>=2)  fail=1;
    }

    if(!fail){
        cout<<"pairwise coprime\n";
        return 0;
    }

    if(gcd==1){
        cout<<"setwise coprime\n";
        return 0;
    }
    cout<<"not coprime\n";
}


Measured memory_bytes: 11452
package main

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

func solution(n, x, m int) int {

	a := make([]int, 0)
	memo := make(map[int]int, m+1)
	f := func(a, b int) int {
		return a % b
	}
	a = append(a, x)
	memo[x] = 0
	cur := x

	start, last := 0, 0
	for i := 0; i < m; i++ {
		cur = f(cur*cur, m)
		a = append(a, cur)
		idx, ok := memo[cur]
		if ok {
			start = idx
			last = i + 1
			break
		} else {
			memo[cur] = i + 1
		}
	}

	// 繰り返しが始まるまでの和
	bsum := 0
	for i := 0; i < start; i++ {
		bsum += a[i]
	}
	// 繰り返し部分の和
	asum := 0
	for i := start; i < last; i++ {
		asum += a[i]
	}
	// 繰り返す部分の回数
	c := (n - start) / (last - start)
	// 端数
	mod := (n - start) % (last - start)
	csum := 0
	for i := start; i < start+mod; i++ {
		csum += a[i]
	}
	return bsum + asum*c + csum
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, x, m int
	fmt.Fscan(r, &n, &x, &m)
	fmt.Println(solution(n, x, m))
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()

int main() {
    ll L,R;
    cin >> L >> R;
    //iorjが2019で割り切れるなら0

    ll l = L/2019,r = R/2019;

    if(l!=r){
        cout << 0 << endl;
        return 0;
    }

    ll ans = 2019;

    for(ll i=L;i<R;i++){
        for(ll j=i+1;j<=R;j++){
            ans = min(ans,(i*j)%2019LL);
        }
    }

    cout << ans << endl;
    return 0;

}

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amin(T& a,T2 b){ if(a > b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	ll n, m;
	cin >>n >>m;
	
	if(n*2 <= m){
		cout << n + (m - 2*n)/4 <<"\n";
	}else{
		cout <<  m/2 <<"\n"; 
		
	}
	
	return 0;
}


Measured memory_bytes: 256
N = int(input())
s = [int(input()) for i in range(N)]
s.sort()
ans = sum(s)
if ans % 10 != 0:
  print(ans)
  exit()
else:
  for i in s:
    if i % 10 != 0:
      print(ans-i)
      exit()
print(0)

Measured memory_bytes: 2940
/**
*    created: 03.07.2020 15:14:15
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const long double pi = acos(-1.0);
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    char a, b;
    cin >> a >> b;
    if (a < b) cout << '<' << endl;
    else if (a == b) cout << '=' << endl;
    else cout << '>' << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>
using namespace std;
#define LL long long

int main() {
    string a, b;
    cin >> a >> b;
    int ans = 0;
    for (int i = 0; i < 3; i++) {
        if (a[i] == b[i]) {
            ans++;
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
def solve(h, k):
    dp = [0]
    for i in range(1, len(h)):
        best = float("inf")
        for j in range(1, min(i, k)+1):
            best = min(best, dp[i - j] + abs(h[i - j] - h[i]))
        dp.append(best)
    return dp[-1]


if __name__ == "__main__":
    n, k = map(int, input().split())
    h = [int(x) for x in input().split()]
    print(solve(h, k))


Measured memory_bytes: 56288
def main():
    EQ = 0
    LESS = 1

    *S, = map(int, input())
    L = len(S)
    K = int(input())

    dp = [[[0] * 2 for _ in range(K + 2)] for _ in range(L + 1)]
    dp[0][0][EQ] = 1

    for i, x in enumerate(S):
        for k in range(K + 1):  # ここをrange(K)にしてバグらせた
            if x == 0:
                dp[i + 1][k][EQ] += dp[i][k][EQ]  # x
            else:
                dp[i + 1][k + 1][EQ] += dp[i][k][EQ]  # x
                dp[i + 1][k + 1][LESS] += dp[i][k][EQ] * (x - 1)  # <x
                dp[i + 1][k][LESS] += dp[i][k][EQ]  # ==0
            dp[i + 1][k + 1][LESS] += dp[i][k][LESS] * 9  # !=0
            dp[i + 1][k][LESS] += dp[i][k][LESS]  # ==0

    print(sum(dp[L][K]))  # 全部0はK個の0でない数字を含まないので除去する必要がない


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int n = sc.nextInt();
            if ( n == 0 ) {
                break;
            }

            int[] a = new int[n];
            int sum = 0;
            for (int i = 0; i < n; i++) {
                a[i] = sc.nextInt();
                sum += a[i];
            }

            int avg = sum / n;
            int ans = 0;
            for (int i = 0; i < n; i++) {
                if ( a[i] <= avg ) {
                    ans++;
                }
            }
            System.out.println(ans);
        }
    }
}



Measured memory_bytes: 59592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		List<Integer> field = new ArrayList<>(Arrays.asList(0,0,0));
		long scoreCount = 0;
		int outCount = 0;
		try {
			int gameNumber = Integer.parseInt(br.readLine());
			while (0 < gameNumber) {
				String line = br.readLine();
				if(line.equals("HIT")) {
					if(field.get(2)==1) {
						scoreCount++;
					}
					field.remove(2);
					field.add(0, 1);
				}else if(line.equals("OUT")) {
					outCount++;
					if (outCount == 3) {
						System.out.println(scoreCount);
						scoreCount = 0;
						outCount = 0;
						field = new ArrayList<>(Arrays.asList(0,0,0));
						gameNumber--;
					}
				}else if(line.equals("HOMERUN")) {
					scoreCount += 1 + field.stream().filter(base -> base==1).count();
					field = new ArrayList<>(Arrays.asList(0,0,0));
				}
			}
			
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 30776
def calc()
  a, s, q = [0] * 100, [0] * 17, []
  loop.with_index do |_, t|
    s.each.with_index do |e, i|
      s[i] -= 1 if e > 0
    end
    q.push(t / 5) if t % 5 == 0
    while q[0]
      f = false
      g = q[0]
      n = g % 5 == 1 ? 5 : 2
      s.each_cons(n).with_index do |c, i|
        if c.all? { |e| e == 0 }
          n.times do |j|
            s[i + j] = 17 * (g % 2) + 3 * (g % 3) + 19
          end
          a[g] = t - g * 5
          return a if g == 99
          q.shift
          f = true
          break
        end
      end
      break unless f
    end
  end
end
1.times do
  a = calc
  loop do
    n = gets
    break unless n
    puts a[n.to_i]
  end
end

Measured memory_bytes: 8788
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <map>
#include <bitset>
using namespace std;
#define len(n) (int)n.length()
#define dump cout
#define pb push_back
#define ll long long

int CNT = 0;

vector<int> MakeG(int n)
{
	vector <int> g;
	g.pb(1);
	for (int i=1;;i++)
	{
		int elem = 3 * g[i-1] + 1;
		if (elem > n)
			break;
		g.pb(elem);
	}
	return g;
}

void InsertionSort(int* A, int n, int g)
{
	for (int i = g; i < n; i++) {
	    int v = A[i];
		int j = i - g;
		while ((j >= 0) && (v < A[j]))
		{
			A[j+g] = A[j];
			j -= g;
			CNT++;
		}
		A[j+g] = v;
	}
	
}

int main()
{
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	
	int *A = new int[n];
	for (int i = 0; i < n; i++) {
	    cin >> A[i];
	}
	
	vector<int> g = MakeG(n);
	
	cout << g.size() << endl;
	for (auto itr = g.rbegin(); itr != g.rend(); ++itr) {
	    InsertionSort(A, n, *itr);
		cout << *itr << " ";
	}
	cout << endl << CNT << endl;
	
	for (int i = 0; i < n; i++) {
	    cout << A[i] << endl;
	}
	
	
	delete[] A;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
ll n;
vl a;
/******* define variable end *******/
int solve() {
	cin >> n;
	a.resize(n);
	vector<ll> l(n);
	vector<ll> r(n);
	REP(i, n){
		cin >> a[i];
		l[i] = i + 1 - a[i];
		r[i] = a[i] + i + 1;
	}
	ll ans = 0;
	sort(ALL(l));
	sort(ALL(r));
	for(ll i = 1; i <= l[n-1]; i++){
		auto iterl = lower_bound(ALL(l), i);
		auto iterr = lower_bound(ALL(r), i);
		if(!(iterl == l.end()) & !(iterr == r.end())){
			ll countl = 0;
			ll countr = 0;
			for(auto j = iterl;; j++){
				if(l[j - l.begin()] != i){
					break;
				}
				countl++;
			}
			for(auto j = iterr;; j++){
				if(r[j - r.begin()] != i){
					break;
				}
				countr++;
			}
			ans += countl * countr;
		}
	}
	cout << ans << endl;
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


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

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

  if (count(S.cbegin(), S.cend(), 'R') > count(S.cbegin(), S.cend(), 'B')) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
    int N,M;
    cin >> N;
    map<int ,string> S;
    for(int i=0;i<N;i++){
        string s;
        cin >> s;
        S[i] = s;
    }
    cin >> M;
    map<int ,string> T;
    for(int i=0;i<M;i++){
        string t;
        cin >> t;
        T[i] = t;
    }
    int score;
    int best_score;
    for(int i=0;i<N;i++){
        string choice = S[i] ;
        score=0;
        for(int j=0;j<N;j++){
            if( S[j] == choice){
                score++;
            }
        }
        for(int k=0;k<M;k++){
            if( T[k] == choice){
                score--;
            }
        }
        if(i==0){
            best_score = score;
        }
        else{
            if( best_score < score){
                best_score = score;
            }
        }
    }
    if(best_score < 0){
        best_score = 0;  // そもそも存在しない文字列を言えば0のまま
    }
    cout << best_score << endl;


}

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

int main() {
  string s;
  int t,type,f;
  cin >> s;
  deque<char>d;
  for(auto const x : s) {
      d.push_back(x);
  }
  cin >> t;
  bool rev = false;
  while(t--) {
      cin >> type;
    if(type == 1) {
      rev = rev ? false : true;
    } else {
        char p;
        cin >> f >> p;
        if(f == 1) {
            if(rev) {
                d.push_back(p);
            } else {
                d.push_front(p);
            }
        } else {
            if(rev) {
                d.push_front(p);
            } else {
                d.push_back(p);
            }
        }
    }
  }
  string ans;
  while(!d.empty()) {
      ans += d.front();
      d.pop_front();
  }

  if(rev){
      reverse(ans.begin(), ans.end());
  }

  cout << ans;
}

Measured memory_bytes: 1412
package main

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

func solve() {
	n, k := getInt(), getInt()
	nums := make([]int, 100001)
	for i := 0; i < n; i++ {
		a, b := getInt(), getInt()
		nums[a] += b
	}

	ans := -1
	for i, num := range nums {
		k -= num

		if k <= 0 {
			ans = i
			break
		}
	}

	fmt.Fprintln(wr, ans)
}

// -----------------------------------------

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


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

int main(void) {
  int n;
  cin >> n;
  vector<vector<int>> ts(n + 1, vector<int>(3));
  ts[0] = { 0, 0, 0 };
  for (int i = 1; i < n + 1; i++) {
    cin >> ts[i][0] >> ts[i][1] >> ts[i][2];
  }

  for (int i = 1; i < n + 1; i++) {
    int dt = ts[i][0] - ts[i - 1][0];
    int dx = abs(ts[i][1] - ts[i - 1][1]);
    int dy = abs(ts[i][2] - ts[i - 1][2]);

    if (dt - dx - dy < 0 || (dt - dx - dy) % 2 == 1) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))

typedef long long ll;

int main() {
    int N, A, B;
    vector<int> nums;
    scnd1(N);
    int n;
    rep( i, N) {
        scnd1( n);
        nums.push_back(n);
    }
    
    sort( nums.begin(), nums.end());
    
    A = nums[N-1];
    B = nums[0];
    double d = A*1.0/2;
    
    int i = 1;
    while ( i<N-1 && abs(B-d) > abs(nums[i]-d)) {
        B = nums[i++];
    }
    cout2(A,B);
}

Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <map>

using namespace std;

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

  map<string, int> word;
  string str;
  string lon = "", w = "";
  int cmax = 0;

  while (cin >> str){
    if (str.size() > lon.size()){
      lon = str;
    }
    word[str]++;
  }

  map<string, int>::iterator it = word.begin();
  
  while (it != word.end()){
    if (cmax < (*it).second){
      cmax = (*it).second;
      w = (*it).first;
    }

    
    ++it;
  }

  cout << w << ' ' << lon << endl;

  return (0);
}

Measured memory_bytes: 1200
fun main(args : Array<String>) {
    val x = readLine()!!.toLong()

    if (x <= 6) {
        println(1)
        return
    }

    if (x % 11 == 0L) {
        println((x / 11) * 2)
    } else if (x % 11 <= 6) {
        println((x / 11) * 2 + 1)
    } else {
        println((x / 11) * 2 + 2)
    }
}

Measured memory_bytes: 34592
using System;
using System.Collections.Generic;
using System.Linq;

class A
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		var n = h[0];
		var es = new int[h[1]].Select(_ => Read()).ToArray();

		var map = Array.ConvertAll(new int[n + 1], _ => new List<int[]>());
		var indegree = new int[n + 1];
		foreach (var e in es)
		{
			map[e[0]].Add(e);
			indegree[e[1]]++;
		}

		var svs = Enumerable.Range(0, n + 1).Where(v => indegree[v] == 0).ToArray();
		var u = new bool[n + 1];
		var q = new Queue<int>();

		foreach (var sv in svs)
		{
			u[sv] = true;
			q.Enqueue(sv);

			while (q.Count > 0)
			{
				var v = q.Dequeue();
				foreach (var e in map[v])
				{
					if (--indegree[e[1]] > 0) continue;
					u[e[1]] = true;
					q.Enqueue(e[1]);
				}
			}
		}
		Console.WriteLine(u.Any(b => !b) ? 1 : 0);
	}
}



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

int main() {
  int N;
  cin >> N;
  vector A(N, 0);
  int n = 0, r, tmp = INT_MAX;
  for (int i = 0, a; cin >> a; i++) n = max(n, (A.at(i) = a));
  for (auto a : A) {
    if (a == n) continue;
    if (abs(a * 2 - n) < tmp) tmp = abs(a * 2 - n), r = a;
  }
  cout << n << " " << r << "\n";
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

int mod = 1000000007;

string ans = "";
char moji[] = {'R','U','L','D'};

void step(int dir, int num){
    rep(i, num) ans += moji[dir];
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
    step(0, tx-sx);
    step(1, ty-sy);
    step(2, tx-sx);
    step(3, ty-sy);
    step(3, 1);
    step(0, tx-sx+1);
    step(1, ty-sy+1);
    step(2, 1);
    step(1, 1);
    step(2, tx-sx+1);
    step(3, ty-sy+1);
    step(0, 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
        int ans = 0;
        int[] a = new int[25];
        int cnt4 = 0, cnt2 = 0, cnt24 = 0, cnt14 = 0, cnt74 = 0;
        for(int k = 2; k <= n; k++){
            int i = k;
            for(int j = 0; j < 25; j++){
                while(i > 1 && i % p[j] == 0){
                    a[j]++;
                    i = i / p[j];
                }
            }
        }
        for(int i = 0; i < p.length; i++){
            if(a[i] >= 4) cnt4++;
            if(a[i] >= 2) cnt2++;
            if(a[i] >= 14) cnt14++;
            if(a[i] >= 24) cnt24++;
            if(a[i] >= 74) cnt74++;
        }
        ans = cnt4 * (cnt4 - 1) * (cnt2 - 2) / 2 + cnt24 * (cnt2 - 1) + cnt74 + cnt14 * (cnt4 - 1);
        System.out.println(ans);
    }
} 

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

void factorize(vector<int> &factors){
    factors[1]=1;
    factors[2]=2;
    int no;
    for(int i=3;i<1000001;++i){
        no=2;
        for(int j=2;j*j<=i;j++){
            if(j*j==i){
                no+=1;
            } else if(i%j==0){
                no+=2;
            }
        }
        factors[i]=no;
    }
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	vector<int> factors(10e6+5);
	factorize(factors);
	
	int n,ans=0;
	cin>>n;
	for(int i=1;i<n;i++){
	    ans+=factors[n-i];
	}
	cout<<ans;
    
    
	return 0;
}


Measured memory_bytes: 42192
from bisect import bisect_left, bisect_right; from collections import Counter, defaultdict, deque, OrderedDict; from copy import deepcopy; from fractions import gcd; from functools import lru_cache, reduce; from math import ceil, floor; from sys import stdin, setrecursionlimit
import heapq as hq; import itertools as its; import operator as op


# globals
inf = float('inf')
input = stdin.readline


def main():
    n, x = get_li()
    L = get_li()
    P = [0] + list(its.accumulate(L))
    print(len(list(filter(lambda y: y<=x, P))))
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    setrecursionlimit(4100000)
    main()


Measured memory_bytes: 65388
n = int(input())
dic = {}
for _ in range(n):
    s = input()
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 0
top = []
laeger = 0
for v in dic.values():
    if v >= laeger:
        laeger = v

for k, v in dic.items():
    if v == laeger:
        top.append(k)
for i in sorted(top):
    print(i)


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

int main(void){
	int s,s1,s2,s3;
  	cin >> s;
  	s1 = s/100;
  	s3 = s % 10;
  	s2 = (s-s1*100)/10;
  	cout << s1+s2+s3 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> B(N-1);
    for(int i=0;i < N-1; i++){
        cin >> B[i];
    }
    int s = 0;
    for(int i=1;i < N-1; i++){
        if(B[i]<B[i-1]){
            s+=B[i];
        } 
        else{
            s+=B[i-1];
        }
    }
    cout << s+B[0]+B[N-2]<< endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    ll pre=0,res=0;
    rep(i,n){
        ll a;cin>>a;
        res+=min(pre,a);
        a-=min(pre,a);
        res+=a/2;
        pre=a%2;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <set>
#include <map>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  std::cin >> N;
  std::vector<int> w(N);
  range(i, N) std::cin >> w[i];
  int su = 0, le=0, ans=9999999;
  for(int i=0;i<N;i++){
    su+=w[i];
  }
  for(int i=0;i<N;i++){
    su-=w[i];
    le+=w[i];
    ans = min(ans, abs(su-le));
  }
  std::cout << ans << '\n';
  return 0;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[200005];
map<ll, ll> M;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> A[i];
        M[A[i]]++;
    }
    sort(A, A + N);
    ll ans = 0;
    for (ll i = N - 1; i >= 0; --i) {
        if (M[A[i]]-- <= 0)
            continue;
        ll p = 1;
        while (p < A[i])
            p <<= 1LL;
        if (p == A[i]) {
            if (M[A[i]]-- > 0)
                ans++;
        }
        else if (M[p - A[i]]-- > 0)
            ans++;

    }

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

Measured memory_bytes: 26880
a,b,m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

ans = float('inf')

for _ in range(m):
  x,y,c = map(int,input().split())
  ans = min(A[x-1] + B[y-1] - c,ans)
  
ans = min(ans, min(A)+min(B))

print(ans)

Measured memory_bytes: 67052
N = $stdin.gets.to_i
edges = {}
(N-1).times {
  a,b = $stdin.gets.split.map(&:to_i)
  edges[a] ||= {}
  edges[b] ||= {}
  edges[a][b] = 1
  edges[b][a] = 1
}

#p edges

backward = (0..N).map{ nil }
# find path 1 -> N

next_nodes = [1]
backward[1] = 1
while next_nodes.size > 0
  #p next_nodes
  next_nodes = next_nodes.map{ |k|
    ns = edges[k].keys.reject{ |i| backward[i] } || []
    ns.each{ |i| backward[i] = k }
    ns
  }.flatten
end

#p backward

st = [N]
while st[0] != 1
  st.unshift backward[st[0]]
end

PB = st[(st.size-1)/2]
PW = st[(st.size-1)/2+1]
edges[PB].delete(PW)
edges[PW].delete(PB)
#p st, [PB, PW]

def count_nodes!(es, froms)
  ans = 0
  while froms.size > 0
	ans += froms.size
    #p froms
    froms = froms.map{ |k| 
      ns = es.delete(k).keys
      ns.each{ |i| es[i].delete(k) }
      ns
     }.flatten
  end
  ans
end

n1 = count_nodes!(edges, [1]) 
n2 = count_nodes!(edges, [N])
#p [n1,n2]
puts n1 > n2 ? "Fennec" : "Snuke"


Measured memory_bytes: 48840
# coding: utf-8
# Your code here!
import numpy as np
import itertools

def main():
    length_of_sequence,maximum_value,number_of_query = map(int,input().split())
    
    sequences =  [ next_sequence+1 for next_sequence in range(maximum_value)]
    
    sequences_list = [sequence for sequence in itertools.combinations_with_replacement(sequences,length_of_sequence) if all([item <= sequence[item_suffix+1] for item_suffix,item in enumerate(sequence) if item_suffix < len(sequence) - 1])]
    
    query_information_list = []
    for query_number in range(number_of_query):
        query_information = list(map(int,input().split()))
        query_information_list.append(query_information)
    query_information_list = sorted(query_information_list,key=lambda x:x[3],reverse=True)
    result_list = []
    for sequences in sequences_list:
        result_list.append(sum([item[3] for item in query_information_list if sequences[item[1]-1] -  sequences[item[0]-1] == item[2]]))
    
    if result_list:
        print(max(result_list))
    else:
        print(0)
    
if __name__ == "__main__":
    main()    

Measured memory_bytes: 43404
#include"bits/stdc++.h"
using namespace std;

#define ll long long int
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define sz(a) int((a).size())
#define mod 1000000007
#define inf LLONG_MAX
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
template <typename T>
inline T gcd(T a, T b)
{
    while (b != 0) swap(b, a %= b);
    return a;
}

template <typename T>
inline void seethis(vector<T>vect)
{
    for(T x : vect)
        cout << x << " ";
    cout << "\n";
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
//LCM
int lcm(int a, int b)
{
    return a * (b / gcd(a, b));
}

//For sort by second
bool cmp(const pair<int, int> &a)
{
    return a.first < a.second;
}

//Tree
/* const int MAXN = 1e5 + 5;
vector<ll> adj[MAXN];*/

//ModPower
ll modpower(ll a, ll b, ll c)
{
    ll res = 1;
    while(b)
    {
        if(b & 1LL)
            res = (res * a) % c;
        a = (a * a) % c;
        b >>= 1;
    }
    return res;
}
ll dp[1 << 21];

void add(ll &a, ll b)
{
    a += b;
    if(a >= mod)
    {
        a -= mod;
    }
}
int main()
{
    FASTIO;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll n;
    cin >> n;

    vector<vector<int> >can(n, vector<int>(n,0));


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

    //Bottom up:

    dp[0] = 1;


   
        for(int woman_subset = 0; woman_subset < (1 << n)-1; woman_subset++)
        {
          int men=__builtin_popcount(woman_subset);
            for(int woman = 0; woman < n; woman++)
            {
                if(can[men][woman] and !(woman_subset & (1 << woman)))
                {
                    ll mask = woman_subset ^ (1 << woman);
                    add(dp[mask], dp[woman_subset]);
                }
            }
        }
    

    cout << dp[(1 << n) - 1] << "\n";
    return 0;
}

Measured memory_bytes: 20020
/*********************
*  Author: xuziyuan  * 
*********************/
 
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <LL,LL>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair
 
using namespace std;
 
const LL MOD=1e9+7;

int h,n,a[10010],b[10010],dp[20010],ans=1e9;

int main()
{
	cin>>h>>n;
	rep(i,n) cin>>a[i]>>b[i];
	rep(i,20005) dp[i]=1e9;
	dp[0]=0;
	rep(i,h)
	{
		if(dp[i]==1e9) continue;
		rep(j,n) dp[i+a[j]]=min(dp[i+a[j]],dp[i]+b[j]);
	}
	for(int i=h;i<=20001;i++) ans=min(ans,dp[i]);
	cout<<ans<<endl;
	return 0;
}

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

int main(){
	int a,b;
	cin>>a>>b;
	
	if(a>b){
		cout<<"a > b"<<endl;
	}
	if(a==b){
		cout<<"a == b"<<endl;
	}
	if(a<b){
		cout<<"a < b"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3076
// B - One Clue
package main

import "fmt"

func main() {
	var K, X int
	fmt.Scanf("%d %d", &K, &X)

	from := X - K + 1
	to := X + K - 1
	fmt.Print(from)
	for i := from + 1; i <= to; i++ {
		fmt.Printf(" %d", i)
	}
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

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

    int N;
    cin >> N;

    if (N >= 64) {
        cout << 64 << endl;
    } else if (N >= 32) {
        cout << 32 << endl;
    } else if (N >= 16) {
        cout << 16 << endl;
    } else if (N >= 8) {
        cout << 8 << endl;
    } else if (N >= 4) {
        cout << 4 << endl;
    } else if (N >= 2) {
        cout << 2 << endl;
    } else if (N >= 1) {
        cout << 1 << endl;
    }
    return 0;
}

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

#define REP(i,a,b) for(i=a; i<b; ++i)
#define rep(i,n) REP(i,0,n)

struct mobile {
  long long lm,rm;
  long long lc,rc,ll,rl;
  mobile(long long lc,long long rc,long long ll,long long rl)
  : lc(lc), rc(rc), ll(ll), rl(rl) {
    lm = rm = -1;
  }
};

long long gcd(long long a,long long b) {
  return b != 0 ? gcd(b, a%b) : a;
}

long long lcm(long long a,long long b) {
  return a/gcd(a,b)*b;
}

int dfs(int pos,vector<mobile> &vm) {
  mobile now = vm[pos];
  now.lm = (now.lc == -1) ? 1 : dfs(now.lc,vm);
  now.rm = (now.rc == -1) ? 1 : dfs(now.rc,vm);
  int g = lcm(now.ll*now.lm,now.rl*now.rm);
  now.rm = g / now.rl;
  now.lm = g / now.ll;
  return now.rm+now.lm;
}

int main() {
  int n,i,p,q,r,b;
  while(cin>>n, n) {
    vector<mobile> vm;
    vector<bool> isroot(n,true);
    rep(i,n) {
      cin>>p>>q>>r>>b;
      r--,b--;
      if(r >= 0) isroot[r] = false;
      if(b >= 0) isroot[b] = false;
      vm.push_back(mobile(r,b,p,q));
    }

    int root = -1;
    rep(i,n) if(isroot[i] == true) root = i;

    cout<<dfs(root,vm)<<endl;
  }
}

Measured memory_bytes: 0
s = int(input())

def calc(n):
  if n % 2:
    return 3 * n + 1
  else:
    return n // 2

if s == 1 or s == 2 or s == 4:
  print(4)
else:
  count = 1
  while s != 4:
    s = calc(s)
    count += 1
  print(count + 3)

Measured memory_bytes: 2940
#coding:utf-8
from collections import deque
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True

def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]


    n = II()
    s = input()
    a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    b = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
    ans = ""
    for i in range(len(s)):
        ans = ans + (b[a.find(s[i]) + n])
    print(ans)





if __name__ == '__main__':
    main()


Measured memory_bytes: 3436
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>
#include <iomanip>
 
#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;
 
using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0ULL); }

int main() {
  //std::cout << std::fixed << std::setprecision(10);
  int a, b;
  cin >> a >> b;

  cout << max({a+b, a-b, a*b}) << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,K=nm()
p=nl()
p.sort()
sum_m=0
for i in range(K):
    sum_m+=p[i]

print(sum_m)

    


Measured memory_bytes: 72724
S = input()
n = len(S)

a = S.count('a')
b = S.count('b')
c = n - a - b

n //= 3
for i in [a, b, c]:
    if n <= i <= n + 1:
        pass
    else:
        print('NO')
        exit()
else:
    print('YES')

Measured memory_bytes: 3188