akhauriyash/Code-Regression huggingface dataset:
public class Main {


  private static void solve() {
    long k = ni();
    long a = ni();
    long b = ni();
    
    long ret = 1 + k;

    long last = k - (a - 1);
    
    if (last >= 0) {
      ret = Math.max(ret, a + (b - a) * (last / 2) + last % 2);
    }
    System.out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

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

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 22996
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#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(v) v.begin(), v.end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main(){
  string s;
  cin >> s;
  int a = s.find("A");
  reverse(all(s));
  int z = s.find("Z");
  cout << s.size() - z - a << endl;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

typedef long long ll;

int solve(ll n)
{
    int cnt = 0;

    while (n / 10 != 0) {
        ll max_n = 0;

        for (int i = 10; n / i != 0; i *= 10) {
            ll tmp = (n / i) * (n % i);

            if (tmp > max_n)
                max_n = tmp;
        }
        n = max_n;
        cnt++;
    }

    return cnt;
}

int main()
{
    int q;

    cin >> q;
    while (q--) {
        ll n;

        cin >> n;
        cout << solve(n) << endl;
    }

    return 0;
}

Measured memory_bytes: 1172
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include<cassert>
#include<stack>
#include<fstream>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
ll h,w;
char c[110][110];
ll dp[110][110];
int main(){
	cin>>h>>w;
	rep(i,h)rep(j,w)cin>>c[i][j];
	rep(i,h)rep(j,w)dp[i][j]=1e17;
	dp[0][0]=(c[0][0]=='#');
	rep(i,h)rep(j,w){
		if(i+1<h)chmin(dp[i+1][j],dp[i][j]+(c[i][j]=='.'&&c[i+1][j]=='#'));
		if(j+1<w)chmin(dp[i][j+1],dp[i][j]+(c[i][j]=='.'&&c[i][j+1]=='#'));
	}
	cout<<dp[h-1][w-1]<<endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
string S;vector<pair<char,int> >x;
int main(){
	cin>>S;int t=1;
	for(int i=1;i<=(int)S.size();i++){
		if(i==(int)S.size() || S[i]!=S[i-1]){
			x.push_back(make_pair(S[i-1],t));t=1;
		}
		else{t++;}
	}
	int maxn=0;
	for(int i=0;i<=(int)x.size()-3;i++){
		if(x[i].first=='J' && x[i+1].first=='O' && x[i+2].first=='I'){
			if(x[i+1].second>x[i].second || x[i+1].second>x[i+2].second)continue;
			maxn=max(maxn,x[i+1].second);
		}
	}
	cout<<maxn<<endl;
	return 0;
}

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

using namespace std;
priority_queue<int> a;
int main() {
	int n, m, t;
	cin >> n >> m;
	for(int i = 0; i < n; i ++){
		cin >> t;
		a.push(t);
	}
	while(m --){
		t = a.top();
		a.pop();
		a.push(t / 2);
	}
	long long count = 0;
	while(!a.empty()) {
		count += a.top();
		a.pop();
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 892
### constant

MAX_INT = (1 << 30)

### subroutines

def get_times(nd0, nd1)
  return [0, 0] if $nbrs[nd1].length == 1

  tms = $nbrs[nd1].select{|k| k != nd0}.map{|k| get_times(nd1, k)}

  min_time = MAX_INT

  for i in (0...tms.length)
    time = (0...tms.length).inject(0){|s, j| s + tms[j][(i != j) ? 0 : 1]}
    min_time = time if min_time > time
  end

  b = $bridges[nd0][nd1]
  [ 2 * b + tms.inject(0){|s, tm| s + tm[0]}, b + min_time]
end

### main

while true
  $n = gets.strip.to_i
  break if $n == 0

  $bridges = $n.times.map{$n.times.map{nil}}
  $nbrs = $n.times.map{[]}

  ($n - 1).times do
    a, b, t = gets.strip.split(' ').map{|s| s.to_i}
    a -= 1
    b -= 1

    $bridges[a][b] = $bridges[b][a] = t
    $nbrs[a] << b
    $nbrs[b] << a
  end
  #p $bridges
  #p $nbrs

  min_time = MAX_INT
  tms = $nbrs[0].map{|k| get_times(0, k)}

  for i in (0...tms.length)
    time = (0...tms.length).inject(0){|s, j| s + tms[j][(i != j) ? 0 : 1]}
    min_time = time if min_time > time
  end

  puts min_time
end

Measured memory_bytes: 6144
from collections import Counter
N = int(input())
S = input()

C = Counter(S)
ans = C['R']*C['G']*C['B']

for w in range(1, (N+1)//2+1):
    for i in range(N-(w*2)):
        if S[i]!=S[i+w] and S[i]!=S[i+2*w] and S[i+w]!=S[i+2*w]:
            ans -= 1
print(ans)

Measured memory_bytes: 9460
#include <iostream>
using namespace std;
int main() {
    long long n, a[5];
    cin >> n;
    long long minA = n;
    for (int i = 0; i<5; i++) {
        cin >> a[i];
        minA = min(minA, a[i]);
    }
    cout << 5 + (n-1)/minA << endl;
}

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

int main() {
    int n;
    cin >> n;
    int count = 0;
    for(int i = 1; i < 10; i++){
        if(n % i == 0 && n / i <= 9){
            count++;
        }
    }
    if(count >= 1){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

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

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

    int mini1=0;
    int mini2=1000000000;
    while(mini1!=mini2){
        mini1 = mini2; //一個前のやつ
        for(int i=0;i<n;i++){
            if(a[i]<mini2 && a[i]!= 0)mini2=a[i];
        }
        if(mini2==mini1){break;break;}
        for(int i=0;i<n;i++){
            if(a[i]!=mini2)a[i] = a[i] % mini2;
        }
    }

    cout << mini2 << endl;

}

Measured memory_bytes: 640
n, m = [int(item) for item in input().split()]
xyz = [[int(item) for item in input().split()] for _ in range(n)]

values = [[0] * n for _ in range(8)]

sign = [[1,1,1],
        [1,1,-1],
        [1,-1,1],
        [-1,1,1],
        [-1,-1,1],
        [-1,1,-1],
        [1,-1,-1],
        [-1,-1,-1]]

for i, (x, y, z) in enumerate(xyz):
  for j in range(8):
    values[j][i] += x * sign[j][0]
    values[j][i] += y * sign[j][1]
    values[j][i] += z * sign[j][2]

if m == 0:
  print(0)
else:
  ans = 0
  for line in values:
    ans = max(ans, sum(sorted(line)[-m:]))
  print(ans)

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

typedef double f64;
typedef long long i64;
typedef int i32;
typedef pair<i32, i32> pi32;
typedef unsigned long long u64;
typedef unsigned int u32;
typedef vector<i32> vi32;
typedef deque<i32> di32;

#define all(c) (c).begin(), (c).end()
#define REP(i, a, b) for (auto i = a; i < b; i++)
#define REPA(i, a, b, acc) for (auto i = a; i < b; i += acc)
#define PB push_back
#define PF push_front
#define PRINT(x) cout << #x ": " << (x) << endl;
#define TR(c, it) for (auto(it) = (c).begin(); (it) != (c).end(); (it)++)
#define MAX_PRECISION cout << setprecision(numeric_limits<double>::max_digits10);

i64 dp[i32(1e5) + 1] = {};

i32 main() {
  ios::sync_with_stdio(false);  // Makes IO faster, remove this line if C style scanf/printf needed.

  i32 N, W;
  cin >> N >> W;
  REP(i, 0, N) {
    i32 w, v;
    cin >> w >> v;
    REP(i, 0, W - w + 1) {
      dp[W - i] = max(dp[W - i], dp[W - w - i] + v);
    }
  }

  cout << dp[W] << endl;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {

    int n, q;
    String s;
    char[] ts, ds;

    void run() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt(); q = sc.nextInt();
        s = " " + sc.next();
        ts = new char[q];
        ds = new char[q];

        for (int i = 0; i < q; i++) {
            ts[i] = sc.next().charAt(0);
            ds[i] = sc.next().charAt(0);
        }

        int l = 0, r = n + 1;
        for (;l + 1 < r;) {
            int mid = (l + r) / 2;
            if (ok(mid, true)) {
                l = mid;
            } else {
                r = mid;
            }
//            debug(mid, ok(mid, false));
        }
//        debug(l);
        int cnt = l;
        l = 0; r = n + 1;
        for (;l + 1 < r;) {
            int mid = (l + r) / 2;
            if (ok(mid, false)) {
                r = mid;
            } else {
                l = mid;
            }
//            debug(mid, ok(mid, false));
        }
//        debug(r);
        cnt += n - r + 1;
        System.out.println(n - cnt);
    }

    boolean ok(int pos, boolean isLeft) {
        for (int i = 0; i < q; i++) {
            if (ts[i] == s.charAt(pos)) {
                if (ds[i] == 'L') {
                    pos--;
                } else {
                    pos++;
                }
            }
            if (pos <= 0 || pos > n) {
                return isLeft ^ pos >= n;
            }
        }
        return false;
    }


    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

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


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

int main(){
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]--;
	}
	int ans=0;
	for(int i=0;i<n;i++){
		if(i==a[a[i]])ans++;
	}
	
	cout<<ans/2<<endl;
	return 0;
}

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

a.sort()

c = 0
s = []
for i in range(n):
  c+=a[i]
  s.append(c)
ng = 0
for i in range(1,n):
  if a[i] > 2*s[i-1]:
    ng = i
print (n-ng)

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

int main(){
  int N,K;
  string S;
  cin>>N>>K>>S;
  int s=S.at(K-1);
  if(s=='A')S.at(K-1)='a';
  else if(s=='B')S.at(K-1)='b';
  else if(s=='C')S.at(K-1)='c';
  cout<<S<<endl;
}

Measured memory_bytes: 256
// Reference https://atcoder.jp/contests/abc159/submissions/11140016
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
typedef pair<int, int > Pii;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
#define pb push_back
#define rs resize 
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define repll(i, a, b) for(ll i=(a); i<(b); i++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define COUT(a) cout << a << endl
#define ALL(a) (a).begin(),(a).end()
const long long int mod = 1e9 + 7;

ll choose2(ll n){
    return n*(n-1)/2;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false); 
    int n;
    cin >> n;
    Vi a(n);
    rep(i,0,n){
        cin >> a[i];
        a[i]--;
    }
    Vi cnt(n);
    rep(i,0,n) cnt[a[i]]++;
    ll tot=0;
    rep(i,0,n) tot += choose2(cnt[i]);
    rep(i,0,n){
        ll ans=tot;
        ans -= choose2(cnt[a[i]]);
        ans += choose2(cnt[a[i]]-1);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define pb push_back
#define in insert
#define ff first
#define ss second
#define mp make_pair
//#define int long long
#define uint unsigned long long
#define rep(i,x,m) for(int i=x;i<m;i++)
#define repr(i,x,m) for(int i=x;i>=m;i--)
#define MOD 1000000007
#define endl "\n"
using namespace std;
#define noob ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

void ram5564()
{
    string s;
    cin>>s;
    int q;
    cin>>q;
    int ok=1;
    //cout<<s<<endl;
    deque<char>v;
    for(int i=0;i<s.length();++i)
    	v.pb(s[i]);
    while(q--)
    {
    	int x;
    	cin>>x;
    	if(x==1)
    	{
    		ok+=1;
    	}
    	else 
    	{
    		int a;
    		char ch;
    		cin>>a>>ch;
    		if(a==1)
    		{
    			if(ok&1)
    				v.push_front(ch);
    			else
    				v.pb(ch);
    		}
    		else 
    		{
    			if(ok&1)
    			v.pb(ch);
    		    else 
    			v.push_front(ch);
    		}
    	}
    }
    //	cout<<s<<" "<<ok<<endl;
    if(ok%2==0)
    {
    	for(int i=v.size()-1;i>=0;--i)
    		cout<<v[i];
    	return;}
for(auto x:v)
	cout<<x;
}

signed main()
{
		noob
	
        
        int t=1;
        //cin>>t;
        while(t--)
        ram5564();
        return 0;
}

Measured memory_bytes: 976
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
        int r= Integer.parseInt(reader.readLine());
        System.out.println(2*Math.acos(-1)*r);
    }

}


Measured memory_bytes: 33016
import java.util.*;

//update 2020/1/1 23:01

public class Main{

  static Scanner sc = new Scanner(System.in);
  static StringBuilder sb = new StringBuilder();

  public static void main(String[] args) {

    int k = nextInt();

    int ans = 0;

    for(int i=1;i<=k;i++){
      for(int j=1;j<=k;j++){
        for(int c=1;c<=k;c++){
          ans += gcd(i,gcd(j,c));
        }
      }
    }

    System.out.println(ans);

  }

  static int gcd(int a,int b){
    if(a%b!=0){
      return gcd(b,a%b);
    }
    else{
      return b;
    }
  }


  /*
    static String toSmall(String s){
      char c = s.charAt(0);
      //if(Character.isUpperCase(c)){
      if(c<=90){
        c += 32;
      }
      return String.valueOf(c);
    }
    static String toBig(String s){
      char c = s.charAt(0);
      //if(Character.isLowerCase(c)){
      if(c>=97){
        c -= 32;
      }
      return String.valueOf(c);
    }
  */

  static String toSmall(String s){
    return s.toLowerCase();
  }

  static String toBig(String s){
    return s.toUpperCase();
  }

  static String next(){
    return sc.next();
  }

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

  static long nextLong(){
    return Long.parseLong(sc.next());
  }

  static double nextDouble(){
    return Double.parseDouble(sc.next());
  }

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char a){
    return a - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


Measured memory_bytes: 35692
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;  cin >> h >> w;
    char pic[h + 1][w + 1];
    FOR (i, 1, h + 1) {
      FOR (j, 1, w + 1) {
        cin >> pic[i][j];
      }
    }

    FOR (i, 1, 2 * h + 1) {
      FOR (j, 1, w + 1) {
        cout << pic[(i + 1) / 2][j];
      }
      cout << endl;
    }

    return 0;
}


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

int main(){
    string S;
    int count = 0, y;
    cin >> S;
    for(int i = 0; i < 3; i++){
        if(S[i] == 'o') count++;
    }
    y = 700 + 100 * count;
    cout << y << endl;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <string.h>
int main(){
    char S[30];
    char p1[30];

    scanf("%s",S);

    if(strcmp(S,"Sunny")==0){
        printf("Cloudy\n");
    }
    else if(strcmp(S,"Cloudy")==0){
        printf("Rainy\n");
    }
    else if(strcmp(S,"Rainy")==0){
        printf("Sunny\n");
    }

    

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <math.h>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <string.h>
#include <array>
#include <bitset>

using namespace std;

typedef long long ll;

ll n;


bool provjera(ll x){
	ll n1=n;
	while(n1%x==0){
		n1/=x;
	}
	if(n1%x==1){
		return 1;
	}
	return 0;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	if(n==2){
		cout << 1 << '\n';
		return 0;
	}
	int br=1;
	ll x=n-1;
	ll y;
	for(ll i=1; i*i<=x; i++){
		if(x%i==0){
			y=x/i;
			if(y<=sqrt(n)){
				break;
			}
			br++;
		}
	}
	for(ll i=2; i*i<=n; i++){
		if(provjera(i)){
			br++;
		}
	}
	cout << br << '\n';
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define MOD 1000000007
#define all(c) c.begin(), c.end()
#define peek(v)      \
	for (auto i : v) \
		cout << i << ' ';
#define rep(i, begin, end) \
	for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

string invert(string dir)
{
	string idir = "";
	for (char i : dir)
	{
		if (i == 'U')
			idir += "D";
		if (i == 'D')
			idir += "U";
		if (i == 'L')
			idir += "R";
		if (i == 'R')
			idir += "L";
	}
	return idir;
}

void solve()
{
	int xi, yi, xf, yf;
	cin >> xi >> yi >> xf >> yf;
	string dir1 = "";
	// at source
	if (yi > yf)
	{
		int d = yi - yf;
		while (d--)
			dir1 += "D";
	}
	else
	{
		int d = yf - yi;
		while (d--)
			dir1 += "U";
	}
	// at corner
	if (xi > xf)
	{
		int d = xi - xf;
		while (d--)
			dir1 += "L";
	}
	else
	{
		int d = xf - xi;
		while (d--)
			dir1 += "R";
	}
	// we are at the point
	dir1 += invert(dir1);
	string dir2 = "";
	// back to source
	if (xi > xf)
	{
		dir2 += "R";
	}
	else
	{
		dir2 += "L";
	}
	// shifted source
	if (yi > yf)
	{
		int d = yi - yf;
		while (d--)
			dir2 += "D";
		dir2 += "D";
	}
	else
	{
		int d = yf - yi;
		while (d--)
			dir2 += "U";
		dir2 += "U";
	}
	// we are at corner
	if (xi > xf)
	{
		int d = xi - xf;
		dir2 += "L";
		while (d--)
			dir2 += "L";
	}
	else
	{
		int d = xf - xi;
		dir2 += "R";
		while (d--)
			dir2 += "R";
	}
	// we are above the point
	if (yi > yf)
	{
		dir2 += "U";
	}
	else
	{
		dir2 += "D";
	}
	dir2 += invert(dir2);
	cout << dir1 + dir2;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	solve();
	cerr << "\n\n~" << 500 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}

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

int main() {
	int N, M;
	float Q = 0;
	cin >> N >> M;

	vector<int> A(N);

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

	sort(A.rbegin(), A.rend());

	if (A.at(M - 1) >= Q / (4 * M)) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int a,b;
    cin >> a >> b;
    if (b%a == 0) {
        cout << a + b << endl;
    }else{
        cout << b - a << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pr pair<ll,ll>
using namespace std;
const int mod = 313, INF = 1000000000;
ll cost[10005];
bool vis[10005];
vector<int> key;
int main() {
	int n, m,able=0;
	cin >> n >> m;
	for (int i = 0; i <= 10000; i++)cost[i] = INF;
	for (int i = 0; i < m; i++) {
		int b, p = 0;
		ll a;
		cin >> a >> b;
		for (int i = 0; i < b; i++) {
			int k;
			cin >> k;
			p |= (1 << (k - 1));
		}
		able |= p;
		key.push_back(p);
		vis[p] = 1;
		cost[p] = min(a,cost[p]);
	}
	if (able != (1 << n) - 1) {
		cout << -1;
		return 0;
	}
	for (int i = 0; i < key.size();i++) {
		for (int j = 0; j < key.size();j++) {
			int z= key[i] | key[j];
			if (!vis[z]) {
				key.push_back(z);
				vis[z] = 1;
			}
			cost[z] =min( cost[key[i]] + cost[key[j]], cost[z]);
		}
	}
	cout << cost[(1 << n) - 1];
	return 0;
}

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

int main(){
  int i, j, k;
  int q, w;
  int tempx, tempy, temp2, count;
  int N, M;
  char temp1;
  while(1){
    q = 10; w = 10; count = 0;
    int a[30][30] = {};
    cin>>N;
    if(N == 0) break;
    
    for(i = 0; i < N; i++){
      cin>>tempx>>tempy;
      a[tempx][tempy] = 1;
    }
    cin>>M;
    
    if(a[w][q] == 1)count++;
    
    for(i = 0; i < M; i++){
      cin>>temp1>>temp2;
      if(temp1 == 'N') {
	for(j = 1; j <= temp2; j++){
	  q++;
	  if(a[w][q] == 1){
	    count++;
	    a[w][q] = 0;
	  }
	}
      }else if(temp1 == 'S'){
	for(j = 1; j <= temp2; j++){
	  q--;
	  if(a[w][q] == 1){
	    count++;
	    a[w][q] = 0;
	  }
	}
	
      } else if(temp1 == 'E'){
	for(j = 1; j <= temp2; j++){
	  w++;
	  if(a[w][q] == 1){
	    count++;
	    a[w][q] = 0;
	  }
	}
	
      } else if(temp1 == 'W'){
	for(j = 1; j <= temp2; j++){
	  w--;
	  if(a[w][q] == 1){
	    count++;
	    a[w][q] = 0;
	  }
	  
	}
      }
    }
    
    
    
    if(count == N)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    
  }
  return 0;
}



Measured memory_bytes: 3076
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n, k = LI()
L = LI()

L.sort()
print(sum(L[-k:]))

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

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

int main() {
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < H; ++i) {
    string s;
    cin >> s;
    cout << s << endl;
    cout << s << endl;
  }
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		String str = String.format("%32s", Long.toBinaryString(x)).replace(' ', '0');
		System.out.println(str.substring(str.length() - 32, str.length()));
		str = String.format("%32s", Long.toBinaryString(~x)).replace(' ', '0').substring(32, 64);
		System.out.println(str.substring(str.length() - 32, str.length()));
		str = String.format("%32s", Long.toBinaryString(x << 1)).replace(' ', '0');
		System.out.println(str.substring(str.length() - 32, str.length()));
		str = String.format("%32s", Long.toBinaryString(x >> 1)).replace(' ', '0');
		System.out.println(str.substring(str.length() - 32, str.length()));
	}
}



Measured memory_bytes: 26456
from collections import deque
import sys
input = sys.stdin.readline

N = int(input())
adj = [[] for _ in range(N + 1)]
for _ in range(N-1):
    A, B = map(int, input().split())
    adj[A].append(B)
    adj[B].append(A)
K = int(input())
ans = [[-10 ** 10 + 0.5, 10 ** 10 + 0.5] for _ in range(N + 1)]
for _ in range(K):
    V, P = map(int, input().split())
    ans[V] = [P, P]


def check(par, chi):
    par_min, par_max = ans[par]
    chi_min, chi_max = ans[chi]
    if (par_min - chi_min) % 2 == 0:
        print('No')
        sys.exit()
    if par_min - 1 > chi_max or par_max + 1 < chi_min:
        print('No')
        sys.exit()
    ans[chi] = [max(par_min - 1, chi_min), min(par_max + 1, chi_max)]


que = deque()
que.append(V)
seen = [0] * (N + 1)
parent = [0] * (N + 1)
v_list = []
while que:
    v = que.pop()
    seen[v] = 1
    v_list.append(v)
    for u in adj[v]:
        if seen[u] == 0:
            parent[u] = v
            check(v, u)
            que.append(u)

v_list.reverse()
for v in v_list[:-1]:
    u = parent[v]
    check(v, u)

que = deque()
que.append(V)
seen = [0] * (N + 1)
while que:
    v = que.pop()
    seen[v] = 1
    for u in adj[v]:
        if seen[u] == 0:
            check(v, u)
            que.append(u)

print('Yes')
for i in range(1, N + 1):
    print(ans[i][0])


Measured memory_bytes: 111136
#include <bits/stdc++.h>
using namespace std;
#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 _GLIBCXX_DEBUG

int main(){
    int n, m;
    cin >> n;
    vector<string> s(n); 
    rep(i, n) cin >> s[i];
    cin >> m;
    vector<string> t(m);
    rep(i, m) cin >> t[i];

    int ans=0;
    rep(i, n){
        int tmp=0;
        rep(j, n) if(s[i] == s[j]) tmp++;
        rep(j, m) if(s[i] == t[j]) tmp--;
        if(tmp > ans) ans = tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3600
n = int(input())
l = list(map(int, input().split(' ')))
sorted_l = sorted(l)

base = int((n + 1) // 2) - 1
median = sorted_l[base]
for i in l:
    if i <= median:
        print(sorted_l[base + 1])
    else:
        print(sorted_l[base])


Measured memory_bytes: 25620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  long long N;
  cin >> N;
 
  int keta = 0;
  long long ban_min = 1;
  long long ban_max = 26;
 
  while(true){
    keta++;
    if(N <= ban_max){
      break;
    }else{
      ban_min = ban_max + 1;
      ban_max = (ban_max + 1) * 26;
    }
  }
 
 
 
  N -= ban_min;
  string s = "";
 
  long long beki;
  for(int i = keta; i > 0; i--){
    beki = 1;
    for(int j = 1; j < i; j++){
      beki *= 26;
    }
 
    s = s + char('a'+ (N / beki)) ;
    N = N % beki;
  }
  cout << s << endl;
}

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

int arr[60] = {};
int index = 1;

void calc(){
	arr[0] = 1;
	for(int i = 2; i < 1000; i++){
		int sum = i;
		for(int j = 1; ; j++){
			sum *= i;
			if(sum > 1000)
				break;
			else{
				arr[index++] = sum;
			}
		}
	}
}

void sort(){
	for(int i = 0; i < 50; i++){
		for(int j = 0; j < 50; j++){
			if(arr[j] > arr[j+1]){
				int temp = arr[j];
				arr[j] = arr[j+1];
				arr[j+1] = temp;
			}
		}
	}
}

void linSrc(int n){
	int a = 50;
	while(a >= 0){
		if(arr[a--] <= n){
			cout << arr[a+1] << endl;
			return;
		}
	}
}

int main(){
	calc();
	sort();
	int x;
//	for(int i = 0; i < 51; i++){
//		cout << arr[i] << " ";
//	}
	cin >> x;
//	cout << index << endl;
	linSrc(x);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>

using namespace std;

int main() {
 int n,x,t;
 cin >> n >> x >> t;

 if(n%x == 0) cout << t * n/x << endl;
 else cout << t * (n/x + 1) << endl;
}

Measured memory_bytes: 3624
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;
const int sz = 2e5 + 1;

int n, k;
ll fact[sz], inv_fact[sz];
ll a[sz];

ll bpow(ll x, ll p) {
	if (p == 0)
		return 1;
	if (p % 2)
		return (x * bpow(x, p - 1)) % mod;
	else {
		ll b = bpow(x, p / 2);
		return (b * b) % mod;
	}
}

ll inv(ll x) {
	return bpow(x, mod - 2);
}

void calc_fact() {
	fact[0] = 1;
	inv_fact[0] = 1;
	for (int i = 1; i < sz; i++) {
		fact[i] = (fact[i - 1] * i) % mod;
		inv_fact[i] = inv(fact[i]);
	}
}

ll cnk(ll nn, ll kk) {
	return fact[nn] * inv_fact[nn - kk] % mod * inv_fact[kk] % mod;
}

void solve() {
	calc_fact();
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ll cnt_min = ((n - i - 1 >= k - 1) ? cnk(n - i - 1, k - 1) : 0);
		ll cnt_max = ((i >= k - 1) ? cnk(i, k - 1) : 0);
		ans += (cnt_max * a[i]) % mod;
		ans -= (cnt_min * a[i]) % mod;
		ans += mod;
		ans %= mod;
	}
	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << endl;
	}
}

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

int main() {
	string s;
	cin >> s;
	int count = 0, ans = 0;
	for(int i = 0; i<s.size(); i++){
		count = 0;
		for(int j = i; j<s.size(); j++){
			if('A'==s[j] || 'C'==s[j] || 'G'==s[j] || 'T'==s[j]){
				count++;
			}
			else{
				break;
			}
		}
		ans = max(ans, count);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_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(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

ll f[1000100];

void calc() {
    f[0] = 1;
    for(ll i = 1; i < 1000100; i++) {
        f[i] = f[i - 1] * i;
        f[i] %= mod;
    }
}

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

ll inv_mod(ll a, ll m){
    return pow_mod(a, m - 2, m);
}

ll comb(ll n, ll r) {
    ll ret = f[n];
    (ret *= inv_mod(f[r], mod)) %= mod;
    (ret *= inv_mod(f[n - r], mod)) %= mod;
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    calc();
    ll N;
    cin >> N;
    ll cur = 0;
    ll ret = 0;
    for(ll score = (N + 1) / 2; score <= N - 1; score++) {
        ll ttmp = comb(score - 1, N - score - 1);
        (ttmp *= f[N - 1 - score]) %= mod;
        (ttmp *= f[score]) %= mod;
        ll tmp = (ttmp - cur) % mod;
        cur = comb(score - 1, N - score - 1) * f[N - 1 - score] % mod;
        (cur *= f[score]) %= mod;
        (tmp *= score) %= mod;
        (tmp += mod) %= mod;
//        cout << score << ":" << tmp << "," << cur << endl;
        (ret += tmp) %= mod;
    }
    output(ret);
    
    return 0;
}


Measured memory_bytes: 8064
//in the name of god
#include <bits/stdc++.h>
using namespace std;
#define MAX_N (int)1e5+20
#define INF 1e9+20
#define pb push_back
#define F first
#define S second
typedef long long LL;
typedef pair<int,int> pii;
const int delta=(int)1e9+7;
int n,m,ans; vector<int>G[70]; pii e[70];
bool dfs(int u,int v){
	int mark[70],x,y;
	fill(mark,mark+70,1);
	stack<int>s;
	s.push(u); mark[u]=0;
	while(s.size()){
		x=s.top(); s.pop();
		for(int i=0;i<G[x].size();++i){
			y=G[x][i];
			if(x==u && y==v) continue;
			if(mark[y]){
				s.push(y);
				mark[y]=0;
			}
		}
	}
	return mark[v];
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin>>n>>m;
	for(int i=0;i<m;++i){
		cin>>e[i].F>>e[i].S;
		G[e[i].F].pb(e[i].S); G[e[i].S].pb(e[i].F);
	}
	for(int i=0;i<m;++i){
		ans+=dfs(e[i].F,e[i].S);
	}
	cout<<ans;
	return cout<<endl,0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector> 
#include <math.h> 
#include <map>
#include <algorithm>
using namespace std;
int main(void){
    int N, M; cin >> N >> M;
    int i = 0;
    int index = 0;
    map<int, vector<int> > m;
    map<int, int> c;
    vector<int> p(M);
    vector<int> y(M);
    while(M > i){
        cin >> p[i] >> y[i];
        m[p[i]].push_back(y[i]);
        i++;
    }
    for (map<int, vector<int> >::iterator itr = m.begin(); itr != m.end(); itr++) {
        sort(itr->second.begin(), itr->second.end());
    }
    i = 0;
    while(M > i){
        string upper = to_string(p[i]);
        vector<int>::iterator itr;
        itr = find(m[p[i]].begin(), m[p[i]].end(), y[i]);
        string lower = to_string(distance(m[p[i]].begin(), itr) + 1);
        while (upper.length() < 6) {
            upper = "0" + upper;
        }
        while (lower.length() < 6) {
            lower = "0" + lower;
        }
        cout << upper + lower  << endl;
        i++;
    }
}


Measured memory_bytes: 14652
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> H(N);
    for(int i=0; i<N; i++)
        cin >> H[i];
    int ans = 0;
    for(int i=0; i<N; i++){
        bool ok = true;
        for(int j=0; j<i; j++){
            if(H[j] > H[i]){
                ok = false;
                break;
            }
        }
        if(ok)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using cd = complex<ld>;

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

  int n, T;
  cin >> n >> T;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int mx = 0;
  vector<int> best(n);
  for (int i = n - 1; i >= 0; i--) {
    mx = max(mx, a[i]);
    best[i] = mx;
  }
  int x = 0;
  for (int i = 0; i < n; i++) {
    x = max(x, best[i] - a[i]);
  }
  map<int, int> cnt;
  int res = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (best[i] - a[i] == x) {
      res += cnt[best[i]];
      cnt[best[i] - 1] += cnt[best[i]];
      cnt[best[i]] = 0;
    }
    cnt[a[i]]++;
  }
  cout << res;
  return 0;
}

Measured memory_bytes: 10924
#include <iostream>
using namespace std;
int main()
{
  int H, A;
  cin >> H >> A;

  int c;
  for(int i=0;i<100000;++i)
  {
    H -= A;
    if(H<=0)
    {c=i+1;break;}
  }

  cout << c << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class Main {
	// 幸福度X以上の握手の数
	static long numberOfHandshake(long X , long A[] ){
		int N = A.length;
		long ret = 0;
		for(int i = 0 ; i < N ; ++i){
			long Y = X - A[i];
			if(A[N - 1] < Y){
				continue;
			}
			if(A[0] >= Y){
				ret += N;
				continue;
			}
			int low = 0; // false
			int high = N - 1; // true
			while(low < high - 1){
				int mid = (low + high) / 2;
				if(A[mid] >= Y){
					high = mid;
				}else{
					low =  mid;
				}
			}
			ret += N - high;
		}
		return ret;
	}
	static long numberOfHandshake2(long X , long A[] ){
		int N = A.length;
		long S = 0;
		for(int i = 0 ; i < N ; ++i){
			long Y = X - A[i];
			for(int j = 0 ; j < N ; ++j){
				if(A[j] >= Y){
					++S;
				}
			}
		}
		return S;
	}

	static long totalHappiness(long X , long A[]){
		int N = A.length;
		long S[] = new long[N + 1];
		for(int i = 0 ; i < N ; ++i){
			S[i + 1] = S[i] + A[i];
		}
		long ret = 0;
		for(int i = 0 ; i < N ; ++i){
			long Y = X - A[i];
			if(A[N - 1] < Y){
				continue;
			}
			if(A[0] >= Y){
				ret += S[N] + N * A[i];
				continue;
			}
			int low = 0; // false
			int high = N - 1; // true
			while(low < high - 1){
				int mid = (low + high) / 2;
				if(A[mid] >= Y){
					high = mid;
				}else{
					low =  mid;
				}
			}
			ret += S[N] - S[high] + (N - high) * A[i];
		}
		return ret;
	}
	
	static long totalHappiness2(long X , long A[]){
		int N = A.length;
		long ret = 0;
		for(int i = 0 ; i < N ; ++i){
			long Y = X - A[i];
			for(int j = 0 ; j < N ; ++j){
				if(A[j] >= Y){
					ret += A[i] + A[j];
				}
			}
		}
		return ret;
	}

	static void test(){
		Random rand = new Random();
		for(int rep = 0 ; rep < 1000 ; ++rep){
			int N = rand.nextInt(5) + 1;
			long M = rand.nextInt(N * N) + 1;
			long A[] = new long[N];
			for(int i = 0 ; i < N ; ++i){
				A[i] = rand.nextInt(10) + 1;
			}
			Arrays.sort(A);
			long low = 0;
			long high = A[N -1] * 2 + 1; 
			for(long i = low ; i < high ; i++){
				long n = totalHappiness(i, A);
				long n2 = totalHappiness2(i, A);
				if(n != n2){
					System.out.println(n+" "+n2+" "+i+" "+Arrays.toString(A));
				}
			}
		}
	}
	public static void main(String[] args) {
//		test();
//		System.exit(0);
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long M = sc.nextLong();
		long A[] = new long[N];
		for(int i = 0 ; i < N ; ++i){
			A[i] = sc.nextLong();
		}
		Arrays.sort(A);
		long low = 0; // true
		long high = A[N - 1] * 2 + 1; // false
		while(low < high){
			long mid = (low + high) / 2;
			long c = numberOfHandshake(mid , A);
			if(c <= M){
				high = mid;
			}else{
				low = mid + 1;
			}
		}
		long c = numberOfHandshake(high, A);
		long h = totalHappiness(high, A);
		if(c != M){
			h += (high - 1) * (M - c);
		}
		System.out.println(h);
	}
}


Measured memory_bytes: 60024
#include <bits/stdc++.h>
using namespace std;
#define ld double
#define ll long long
#define pb emplace_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) x.begin(),x.end()
ll power(ll a, ll b) {ll res = 1; a = a % mod; while (b) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b /= 2;} return res;}
ll invmod(ll a) {return power(a, mod - 2);}
int main(void)
{
	FIO
	int t = 1;
	// cin >> t;
	while (t--)
	{
		ll n, m, sm = 0, cnt = 0;
		cin >> n >> m;
		ll arr[n];
		for (auto &i : arr) cin >> i, sm += i;
		for (auto i : arr) {
			if (sm <= 4 * i * m) cnt++;
		}
		if (cnt >= m) cout << "Yes\n";
		else cout << "No\n";
	}
	return 0;
}

Measured memory_bytes: 3624
abcd = gets.chomp.chars.join("+")

(3**2).times do |x|
  dup = abcd.dup
  (0..2).each do |i|
    if x & (1 << i) == 0
      dup[i*2+1] = '-'
    end
  end
  if eval(dup) == 7
    puts "#{dup}=7"
    exit
  end
end



Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <class T> using oset = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

void usaco(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(name.size())
    {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

#define int long long

int32_t main()
{
    usaco();
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a*d, a*c, b*c, b*d});
}


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

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

  int cnt = 0;

  for (int i = 1; i < N; i++) {
    if (S.at(i - 1) == S.at(i)) cnt++;
  }

  cout << min(cnt + K * 2, N - 1) << "\n";
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<bitset>
#include<math.h>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int C[30];
string xyz="abcdefghijklmnopqrstuvwxyz";

int main(){
  int N,temp=1;
  cin>>N;

  while(temp*2<=N){
    temp*=2;
  }
  cout<<temp<<endl;
}


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

int a[MAXN+10];
multiset<int> s;
map <int,int> b;

inline bool cmp(int x,int y){
	return y<x;
}
inline int get(int now){
	int x=pow(2,(int)(log2(now)));
	x*=2;	return x-now;
}

int ans;

int main(){

	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]),b[a[i]]++;
	sort(a+1,a+1+n,cmp);
	
	for(int i=1;i<=n;i++){
		int qwq=get(a[i]);
		
		if(a[i]==qwq&&b[qwq]<2)	continue;
		if(b[a[i]]&&b[qwq])	ans++,b[a[i]]--,b[qwq]--;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 19840
import java.util.*;

public class Main{
    Scanner in = new Scanner(System.in);
    long MOD = 1000000007;

    long[] l = new long[1001];
    void solve(){
        int n = in.nextInt();
        for(int i = 1; i <= n; i++){
            fn(i);
        }
        long ans = 1;
        for(int i = 2; i <= n; i++){
            ans = ans * (l[i] + 1) % MOD;
        }
        System.out.println(ans);
    }

    void fn(int x){
        for(int i = 2; i * i <= x; i++){
            if(x % i == 0){
                fn(i);
                fn(x / i);
                return;
            }
        }
        l[x]++;
    }

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

Measured memory_bytes: 21844
package main

import "fmt"

var INF = 100100100100

func main() {
	var n, m, x int
	fmt.Scan(&n, &m, &x)
	c := make([]int, n)
	a := make(map[int][]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&c[i])
		a[i] = make([]int, m)
		for j, _ := range a[i] {
			fmt.Scan(&a[i][j])
		}
	}

	//全探索
	ans := INF
	for i := 0; i < 1<<uint(n); i++ {
		price := 0
		exp := make([]int, m)
		for j := 0; j < n; j++ {
			if i>>uint(j)&1 == 1 {
				price += c[j]
				for k := 0; k < m; k++ {
					exp[k] += a[j][k]
				}
			}
		}
		ok := true
		for j := 0; j < m; j++ {
			if exp[j] < x {
				ok = false
			}
		}
		if ok {
			ans = min(ans, price)
		}

	}
	if ans == INF {
		fmt.Println(-1)
	} else {
		fmt.Println(ans)
	}
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

Measured memory_bytes: 2216
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <sstream>

using namespace std;

int main(){
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A;
    A.resize(N);
 
    // input
    for(int i = 0; i < N; i++)
    {
        cin >> C[i];

        A[i].resize(M);
        for(int j = 0; j < M; j++)
        {
            cin >> A[i][j];
        }
    }

    // 検索
    // for(auto it = C.begin(); it != C.end(); ++it)
    // {
    //     cout << it->first << ", " << it->second << endl;
    // }

    // bit全探索
    int ans = 11111111;
    int init = ans;
    // 2^N
    for(int n=0; n < (1<<N); n++)
    {

        int cost = 0;
        vector<int> sums(M);

        for(int i=0; i<N; i++)
        {
            if (n>>i&1)
            {
                cost += C[i];
                for(int j=0; j<M; j++)
                {
                    sums[j] += A[i][j];
                }
            }
        }
        bool ok = true;
        for(int j=0; j<M; j++)
        {
            if(sums[j] < X)
            {
                ok = false;
            }
        }
        if(ok)
        {
            ans = ans<cost? ans: cost;
        }
    }

    if(ans == init)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << ans << endl;
    }
    
    return 0;
}

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

const ll inf = 0x3f3f3f3f3f3f3f3f;
ll d[105][105];

int main() {
    int v, e; cin >> v >> e;
    for (int i = 0; i < v; i++) for (int j = 0; j < v; j++) d[i][j] = inf;
    for (int i = 0; i < e; i++) {
        int a, b, w; cin >> a >> b >> w;
        d[a][b] = w;
    }
    for (int k = 0; k < v; k++) for (int i = 0; i < v; i++) for (int j = 0; j < v; j++)
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    for (int i = 0; i < v; i++) if (d[i][i] < 0) {
        cout << "NEGATIVE CYCLE" << endl;
        return 0;
    }
    for (int i = 0; i < v; i++) d[i][i] = 0;
    for (int i = 0; i < v; i++)
        for (int j = 0; j < v; j++)
            cout << (d[i][j] >= inf / 2 ? string("INF") : to_string(d[i][j])) << " \n"[j + 1 == v];
}



Measured memory_bytes: 3284
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i< (int)(n); i++)
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define pb(e) push_back(e)
#define foreach(c, i) for(iter(c) i = (c).begin(); i != c.end(); ++i)
#define mp(a, b) make_pair(a, b)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;
const int nmax = 1000;

ll memo[8][nmax+1][2][2];

ll comb(int n, int r){
  if(n < r) return 0;
  ll res = 1;
  r = min(n - r, r);
  rep(i, r) res = res * (n - i) / (i + 1);
  return res;
}


ll p(int n){
  ll res = 1;
  rep(i, n) res *= (i + 1);
  return res;
}

ll h(int n, int r){
  return comb(n + r - 1, r - 1);
}

ll calc(int num, int pos, int limit, bool can1, bool can2){
  if(num == 0) return 1;
  if(pos == limit) return 0;
  if(pos == limit - 1) can2 = false;
  
  if(memo[num][pos][can1][can2] != -1) return memo[num][pos][can1][can2];
  ll &res = memo[num][pos][can1][can2] = calc(num, pos + 1, limit, true, true);
  if(can1) res += calc(num - 1, pos + 1, limit, false, true);
  if(can2) res += calc(num - 1, pos + 1, limit, true, false);
  return res;
}

int main(){
  int N;
  while(cin >> N && N){
    if(N % 2){
      cout << h(N - 16, 8) * p(7) * N << endl;
    }else{
      memset(memo, -1, sizeof(memo));
      cout << calc(7, 1, N / 2, false, true) * p(7) * N << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1412