akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


class Segtree<T>
{
    int n;
    T[] tree;
    Func<T, T, T> f;
    T exnum;
    public Segtree(int m, Func<T, T, T> f, T ex)
    {
        this.f = f;
        this.exnum = ex;
        n = 1;
        while (n < m) n <<= 1;

        tree = new T[(n << 1) - 1];
        for (int i = 0; i < tree.Length; i++) tree[i] = ex;
    }
    public Segtree(int m, T ini, Func<T, T, T> f, T ex)
    {
        this.f = f;
        this.exnum = ex;
        n = 1;
        while (n < m) n <<= 1;

        tree = new T[(n << 1) - 1];
        for (int i = 0; i < tree.Length; i++) tree[i] = ini;
        for (int i = 0; i < m; ++i) update(i, ini);
    }
    public void update(int j, T x)
    {
        int i = j + n - 1;
        tree[i] = x;
        while (i > 0)
        {
            i = (i - 1) >> 1;
            tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
        }
    }
    public T look(int i) { return tree[i + n - 1]; }

    // [s, t]
    public T run(int s, int t) { return query(s, t + 1, 0, 0, n); }
    T query(int s, int t, int k, int l, int r)
    {
        if (r <= s || t <= l) return exnum;
        if (s <= l && r <= t) return tree[k];

        return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r));
    }
}

namespace Codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int k = int.Parse(Console.ReadLine());

            char[] input_arr = input.ToCharArray();

            for(int i = 0; i < input.Length; i++)
            {
                if (i != input.Length - 1 && input_arr[i] == 'a') continue;
                if((26 - (input_arr[i] - 'a')) <= k)
                {
                    k -= (26 - (input_arr[i] - 'a'));
                    input_arr[i] = 'a';
                    if (k == 0) break;
                }

                if (i == input.Length - 1)
                {
                    input_arr[i] = (char)(((input_arr[i] - 'a') + k) % 26 + 'a');
                }
            }

            foreach (char c in input_arr) Console.Write(c);
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 3288
#include <stdio.h>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <limits.h>
#include <time.h>
#include <iostream>
#include <string.h>
#include <unordered_set>
using namespace std;
using ll = long long;
const int N = 1e5+5;

int main(){
	int n;
	scanf("%d", &n);
	unordered_map<int, int> m;
	for(int i=0;i<n;++i){
		int x; 
		scanf("%d", &x);
		++m[x];
	}
	int o=0,t=0;
	for(auto &kv: m){

		if(kv.second&1) ++o;
		else ++t;
	}
	if(t&1) --t;
	printf("%d\n", o+t);
	return 0;
}


Measured memory_bytes: 4388
#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++)
using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;

int main(){
  int n;
  cin >> n;
  VI t(n);
  rep(i,n) cin >> t[i];
  
  int m;
  cin >> m;
  VI p(m),x(m);
  rep(i,m) cin >> p[i] >> x[i];
  
  rep(i,m){
    int sum=0;
    rep(j,n){
      if(j==p[i]-1) sum += x[i];
      else sum += t[j];
    }
    cout << sum << endl;
  }
      
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

bool solv() {
  size_t N;
  std::cin >> N;

  for (size_t i=0; i<N; i++) {
    size_t a;
    std::cin >> a;
    if (a % 2 == 1) return true;
  }

  return false;
}


int main() {
  std::cout << (solv() ? "first" : "second") << std::endl;

  return 0;
}


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

#define int long long
#define PB push_back
#define PPB pop_back
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, int> psi;

static const int INF = 1LL << 60;
//static const int MOD = 1000000007;

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

    int n, l[205], ans = 0;
    cin >> n;
    for (int i = 0; i < 2 * n; ++i) cin >> l[i];
    sort(l, l + 2 * n);
    for (int i = 2 * n - 2; 0 <= i; i -= 2) ans += l[i];
    cout << ans << endl;
}

Measured memory_bytes: 256
import math
import copy
 
 
 
 
def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:
 
            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l
 
a=nCast(input().split());


def xor(n):
    if n==0:
        return 0
    if n%4==1:
        return 1
    if n%4==2:
        return n+1
    if n%4==3:
        return 0
    if n%4==0:
        return n
 
 
def func():
    return xor(a[1])^xor(a[0]-1)
print(func()) 

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

double f(double x){
  if(x < 0){x *= (-1);}
  return x;
}

int main(){
  unsigned long long n;
  cin >> n;
  vector<unsigned long long> v(n, 0);
  for(unsigned long long i = 0; i < n; i++){
    cin >> v[i];
  }
  bool f = false;
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  vector<unsigned long long> w(0);
  for(unsigned long long i = 0; i < n-1; i++){
    if(v[i] == v[i+1]){w.push_back(v[i]); i++;}
    if(w.size() == 2){break;}
  }
  //for(auto c : w){cout << c << endl;}
  if(w.size() >= 2){
    unsigned long long k = w[0] * w[1];
    cout << k << endl;
  }
  else{
    cout << 0 << endl;
  }
}       

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
struct P
{
    //string r;
    int x,y,z;

    bool operator<(const P &a)const{
       // if(y!=a.y)
       // return y>a.y;
       return x<a.x;
//        return z>a.z;
    }
};

vector<int> v[155];
//bitset<4001000> b;
int a,c,i,b,k,d,n,m;
long long e[100100];//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
long long l[1201010];
int o[1200150];
int dx[10]={0,1,0,-1},dy[10]={1,0,-1,0},dz[10]={0,0,0,0,1,-1};

long long x,y,z[200100],mod=1000000007;
P u[11];
long long j[200011];

stack<int> s;
queue<int> q;

//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int > p;
//list<int> l;
//string r[111],r2;
char r[510][555];


bool as(P a,P b)
{
   // if(a.x!=b.x)
        return a.x<b.x;
    //return a.y>b.y;
}



int main()
{
    scanf("%d %d",&a,&b);
    if(b)
    for(int t=b+1;t<=a;t++)
    {
        x+=max((long long)0,(long long)(t-1-b+1)*(a/t));
        x+=max(0,a%t-b+1);
    }
    else x=(long long)a*a;
    printf("%lld",x);
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<long long> V(n);
  for(int i=0;i<n;i++)
    cin>>V[i];
  long long product=1;
  long long val=1e18;
  sort(V.begin(),V.end());
  for(int i=0;i<n;i++)
  {
    if(V[i]==0)
    {
      cout<<0;
      return 0;
    }
    if(product<=(val/V[i]))
       product*=V[i];
    else
       {
         cout<<-1;
         return 0;
       }
  }
       cout<<product;
}

Measured memory_bytes: 4052
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<numeric>
#include<iomanip>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

ll factorial(ll a) {
	ll ans = 1;
	for (ll i = 1; i <= a; i++) {
		ans *= i;
	}
	return ans;
}

int main() {
	//答えは(条件Aを満たすもの)-(条件Bを満たさないが条件Aを満たすもの)である
	int n;
	string s;
	cin >> n >> s;
	ll times_R = 0;
	ll times_G = 0;
	ll times_B = 0;
	rep(i, n) {
		if (s[i] == 'R') {
			times_R++;
		}
		else if (s[i] == 'G') {
			times_G++;
		}
		else times_B++;
	}

	ll ans = times_R * times_G * times_B;

	//以下のループ内は条件Bを満たさないもの
	rep(start, n - 2) {
		for (int space = start + 1; space + (space - start) < n; space++) {
			if (
				s[start] != s[space]
				&& s[space] != s[space + (space - start)]
				&& s[start] != s[space + (space - start)]
				) ans--;
		}
	}

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

Measured memory_bytes: 3624
#include<cstdio>
#include<queue>
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<map>
#include<cmath>

using namespace std;

int N,d[100];
long long int dp[100][21] = {};

long long int ans(int n, int sum){
	if (sum > 20 || sum < 0)return 0;
	if (dp[n][sum] > 0)return dp[n][sum];
	if (n == N - 1){
		if (sum == 0)return 1;
		else return 0;
	}
	long long int ret = 0;
	ret = ans(n + 1, sum + d[n + 1]) + ans(n + 1, sum - d[n + 1]);
	return dp[n][sum]=ret;
}

int main(){
	scanf("%d", &N);
	for (int i = 0; i < N; i++){
		scanf("%d", &d[i]);
	}
	printf("%lld\n", ans(0, d[0]));
	return 0;
}

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

int main()
{
    long int n;
    cin >> n;
    long int min=n*2-2;
    for(int i=1;i<=sqrt(n);++i){
        if(n%i==0 && min>i+n/i-2){
            min = i+n/i-2;
        }
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 764
public class Main {

  private static void solve() {
    int mod = 2019;
    long l = nl();
    long r = nl();
    

    long min = Long.MAX_VALUE;
    outer: for (long i = l; i < r; i ++) {
      for (long j = i + 1; j <= r; j ++) {
        min = Math.min(min, i * j % mod);
        if (min == 0) break outer;
      }
    }
    System.out.println(min);

  }

  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: 21332
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fcking interest
*******************************
I'm standing on top of my Monopoly board
That means I'm on top of my game and it don't stop
til my hip don't hop anymore
https://www.a2oj.com/Ladder16.html
*******************************
300iq as writer = Sad!
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String hi[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         long X = Math.abs(Long.parseLong(st.nextToken()));
         long K = Long.parseLong(st.nextToken());
         long D = Long.parseLong(st.nextToken());
         long used = X/D;
         if(used >= K)
            System.out.println(X-K*D);
         else
         {
            long pos = X-used*D;
            long neg = pos-D;
            K -= used;
            if(K%2 == 0)
               System.out.println(Math.abs(pos));
            else
               System.out.println(Math.abs(neg));
         }
      }
   }

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 22;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n; cin >> n;
  int cnt = 0;
  int tmp;
  REP(i, n) {
    cin >> tmp;
    cnt ^= (tmp % 2);
  }
  
  if(cnt) cout << "NO" << endl;
  else cout << "YES" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if(A+B>=C){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
int main(){
	string s;
	cin>>s;
	int x = toInt(s.substr(0, 2));
	int y = toInt(s.substr(2, 4));
	if(x > 0 && y > 0 && x <= 12 && y <= 12){
		cout<<"AMBIGUOUS"<<endl;
		return 0;
	}
	if(x > 12 && y > 12){
		cout<<"NA"<<endl;
		return 0;
	}
	if(x >= 1 && x <= 12 && (y > 12 || y == 0)){
		cout<<"MMYY"<<endl;
		return 0;
	}
	if((x > 12 || x == 0) && y <= 12 && y >= 1){
		cout<<"YYMM"<<endl;
		return 0;
	}
	cout<<"NA"<<endl;	
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
/**
 * 境界部分には気をつける(そこだけ別で処理するというのもあり)
 * 逆再生することで簡単になることもある
 */
public class Main {
	public int cnt = 0;
	public static final BigDecimal TWO = new BigDecimal(2);
	public static final BigDecimal THREE = new BigDecimal(3);

    public Main() {
    }

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

    public void exec() {
        BufferedReader bf = null;
        try{
            bf = new BufferedReader(new InputStreamReader(System.in));
            exec_body(bf);
        } catch (IOException e) {
            e.printStackTrace();
        }
        finally{
            if( bf != null ) {
                try {
                    bf.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public int[] toList( String str ) {
        String[] elements = str.split(" ");
        int[] ret = new int [elements.length];
        for( int i = 0; i < elements.length; i++ ) {
            ret[i] = Integer.valueOf(elements[i]);
        }

        return ret;
    }

    public void print( int[] ary ) {
    		if( ary == null || ary.length == 0 ) {
    			return;
    		}

    		StringBuilder bd = new StringBuilder();
    		for( int i = 0; i < ary.length; i++ ) {
    			if( i != 0 ) {
    				bd.append(" ");
    			}
    			bd.append(ary[i]);
    		}

    		System.out.println(bd.toString());
    }

    public int partition( int[] ary, int p, int r ) {
    		int rVal = ary[r];
    		int changeIndex = p -1;
    		for( int ii = p; ii < r; ii++) {
    			if( ary[ii] <= rVal) {
    				changeIndex++;
    				int changeVal = ary[changeIndex];
    				ary[changeIndex] = ary[ii];
    				ary[ii] = changeVal;
    			}
    		}

    		changeIndex++;
    		ary[r] = ary[changeIndex];
    		ary[changeIndex] = rVal;

    		return changeIndex;
    }

    public void exec_body( BufferedReader bf ) throws IOException {
    		bf.readLine();
    		int[] ary = toList(bf.readLine());
    		int changeIndex = partition(ary,0,ary.length -1);
    		StringBuilder bd = new StringBuilder();
    		for( int ii = 0 ; ii < ary.length; ii++ ) {
    			if( ii != 0 ) {
    				bd.append(" ");
    			}

    			if( ii == changeIndex ) {
    				bd.append("[");
    				bd.append(ary[ii]);
    				bd.append("]");
    			} else {
    				bd.append(ary[ii]);
    			}
    		}
		System.out.println(bd.toString());
    }
}


Measured memory_bytes: 42280
#include <iostream>
#include <cstdio>
#include <cmath>
const int MAXN = 100000;
const int INF = 0x3f3f3f3f;
using namespace std;

inline void enableFileIO() {
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
}

inline int read() {
  int x = 0, w = 1;
  char c = ' ';
  
  while (c < '0' || c > '9') {
    c = getchar();
    if (c == '-') w = -1;
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return x * w;
}

int n, k, a[MAXN + 5];

void init() {
  //enableFileIO();
  
  n = read();
  k = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
}

int main() {
  init();
  
  int mn = INF;
  for (int i = 1; i <= n - k  + 1; ++i) {
    int j = i + k - 1;
    mn = min(mn, min(int(fabs(a[j])), int(fabs(a[i]))) + a[j] - a[i]);
  }
  printf("%d\n", mn);
  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void){
	int A, B, C;
	scanf("%d %d %d", &A, &B, &C);
	int number[3] = {A, B, C};
	int answer[3] = {5, 5, 7};
	
	int i, j, tmp;
	
	for (i=0; i<3; i++){
		for (j=i+1; j<3; j++){
			if (number[i] > number[j]){
				tmp = number[i];
				number[i] = number[j];
				number[j] = tmp;
			}
		}
	}

	if (number[0] == 5 && number[1] == 5 && number[2] == 7){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
	
	return 0;
}

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

using namespace std;

vector<int> group[100010];
int n, m;
int f[100010], z[100010], vis[100010], a[100010];
int fin(int x)
{
    return (f[x] == x) ?  x : (f[x] = fin(f[x]));
}
int main()
{
    scanf("%d%d", &n, &m);
    for(int i=1; i<=n; i++)
        scanf("%d", &z[i]);

    for(int i=1; i<=n; i++)
        f[i] = i;
    for(int i=1; i<=m; i++)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        int fx = fin(x);
        int fy = fin(y);
        if (fx != fy)
        {
            f[fy] = fx;
        }
    }

    for(int i=1; i<=n; i++)
        group[i].clear();
    for(int i=1; i<=n; i++)
    {
        int fx = fin(i);
        group[fx].push_back(i);
    }

    memset(vis, 0, sizeof(vis));
    int ans = 0;
    for(int i=1; i<=n; i++)
    {
        int l = group[i].size();
        if (l != 0)
        {
            for(int j=0; j<l; j++)
            {
                int x = group[i][j];
                vis[x] = i;
                a[j] = z[x];
            }
            for(int j=0; j<l; j++)
                if (vis[a[j]] == i) ans++;
        }
    }
    cout<<ans<<endl;
}


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

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

LL n,p;

int main(){
  cin>>n>>p;
  if(n==1){
    cout<<p<<endl;
    return 0;
  }
  LL m=2,p_=p,ret=1,tmp=0;
  while(m < 1000002){
    tmp=0;
    while(p_%m==0){
      p_/=m;
      tmp++;
      if(tmp>=n){
	tmp-=n;
	ret*=m;
      }
    }
    m++;
  }
  cout<<ret<<endl;
  return 0;
}


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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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; }


int main()
{
    int N,M,X;
    cin >> N >> M >> X;

    vector<int> A(M);
    rep(i,M) cin >> A[i];

    int ans = INF;
    
    int tmp_ans = 0;
    REP(i, X, N+1)
    {
        rep(j, M)
        {
            if( A[j] == i )tmp_ans++;
        }
    }
    chmin(ans, tmp_ans);
    tmp_ans = 0;

    for( int i = X; i > -1; i-- )
    {
        rep(j, M)
        {
            if( A[j] == i )tmp_ans++;
        }
    }
    chmin(ans, tmp_ans);

    cout << ans << endl;
}


Measured memory_bytes: 256
N,A,B = map(int,input().split())
S = 0
for i in range(N + 1):
    if i < 10:
        W = i
    elif i < 100:
        W = int(str(i)[0]) + int(str(i)[1])
    elif i < 1000:
        W = int(str(i)[0]) + int(str(i)[1]) + int(str(i)[2])
    elif W < 10000:
        W = int(str(i)[0]) + int(str(i)[1]) + int(str(i)[2]) + int(str(i)[3])
    else:
        W = 1
    
    if A <= W <= B:
        S += i

print(S)

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

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

constexpr ld eps = 1e-10;

constexpr int INF = 1e9;

constexpr int M = 1e9 + 7;

using graph = vector<vector<int>>;

int main() {
    string d;
    cin >> d;
    ll S = 0, P = 1;
    for(int i = 0; i < d.size(); ++i) {
        S += (d[i] - '0');
        P *= (d[i] - '0' + 1);
    }
    reverse(d.begin(), d.end());

    ll res = 0;
    map<tuple<int, ll, bool>, ll> dp; // (sum, prod, gt)
    dp[make_tuple(0, 1, false)] = 1;
    for(int i = 0; i < d.size(); ++i) {
        map<tuple<int, ll, bool>, ll> nxt;
        for(auto& t : dp) {
            int sum;
            ll prod;
            bool gt;
            tie(sum, prod, gt) = t.first;
            for(int j = 0; j <= 9; ++j) {
                int ns = sum + j;
                ll np = prod * (j + 1);
                bool ngt = (i == 0 ? true : gt) && (d[i] - '0') == j || (d[i] - '0') < j;
                if(ns > S || ns == S && np > P) {
                    continue;
                }
                nxt[make_tuple(ns, np, ngt)] += dp[t.first];
                if(i + 1 == d.size()) {
                    if(ns < S || ns == S && np < P || ns == S && np == P && !ngt) {
                        res += t.second;
                    }
                }
            }
        }
        dp = move(nxt);
    }
    cout << res << endl;
}


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

using namespace std;

int INF = 1e9 + 5;

int main() {
    int n;
    long long k;
    cin >> n >> k;
    vector<int> a(n+1), seen(n+1, -1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int pos = 1, cycle = -1, move = 0;
    for (; move < k; move++) {
        if (seen[pos] != -1) {
            cycle = move - seen[pos];
            break;
        }
        seen[pos] = move;
        pos = a[pos];
    }
    if (move < k) {
        k -= move;
        k %= cycle;
        for (int i = 0; i < k; i++) {
            pos = a[pos];
        }
    }
    cout << pos << endl;
    return 0;
}


Measured memory_bytes: 4848
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;

struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

signed main()
{
   int n; cin >> n;
   V<int> a(n);
   for (int i = 0; i < n; i++) {
      cin >> a[i];
   }
   V<int> s(n+1);
   for (int i = 0; i < n; i++) {
      s[i+1] = s[i] + a[i];
   }

   V<V<int>> dp(n, V<int>(n));
   for (int k = 1; k < n; k++) {
      for (int i = 0; i+k < n; i++) {
         int MIN = INF;
         for (int j = i; j < i+k; j++) {
            chmin(MIN, dp[i][j] + dp[j+1][i+k]);
         }
         dp[i][i+k] = MIN + s[i+k+1] - s[i];
      }
   }
   cout << dp[0][n-1] << endl;

   return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define nl cout<<"\n"
#define pb push_back
#define se second
#define fi first
typedef long long int ll;
const ll mod= 998244353;

int main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout); 
	long double a,b;
	cin>>a>>b;
	cout<<(ll)floor(a*b)<<endl;
	return 0;
}


Measured memory_bytes: 3696
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <iostream>
using namespace std;

int main() {
	int a[50],b[50],t,c,i=0,z=0,n;
	cin >> n;
	for (i = 0; i < n; i++)
		cin >> a[i];
	for (i = 0; i < n; i++)
		cin >> b[i];

	for (i = 0; i < n; i++) {
		if (a[i] - b[i] > 0) z = z + a[i] - b[i];
	}
		

	cout <<z;

	return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
long int x, N, f, A, B;
int main(){
  scanf("%ld%ld%ld",&A, &B, &N);
  if(N<B-1){
    f=A*N/B;
  }else{
    f=A*(B-1)/B;
  }
  printf("%ld",f);
  return 0;
}

Measured memory_bytes: 1684
k,a,b=map(int,input().split())
cnt=0
bis=1
yen=0
if b-a<3 or a>=k: print(1+k); exit()
if a>1:
  bis=a
  cnt=a-1
if k-cnt>1:
  bis=bis+(b-a)*((k-cnt)//2)
  if (k-cnt)%2==1: bis+=1
print(bis)

Measured memory_bytes: 61796
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n;
    cin >> n;
    yukari<int> honest(n), nkind(n);
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        while (a--)
        {
            int x, y;
            cin >> x >> y;
            if (y)
            {
                honest[i].push_back(x - 1);
            }
            else
            {
                nkind[i].push_back(x - 1);
            }
        }
    }
    int ans = 0;
    for (int s = 0; s < (1 << n); s++)
    {
        bool ok = 1;
        int one = 0, ia = 0;
        for (int i = 0; i < n; i++)
        {
            if (s >> i & 1)
            {
                for (int v : honest[i])
                {
                    one |= 1 << v;
                }
                for (int v : nkind[i])
                {
                    ia |= 1 << v;
                }
            }
        }
        if ((one & ia) || (s & ia) || (one != (one & s)))
        {
            ok = 0;
        }
        if (ok)
        {
            ans = max(ans, __builtin_popcount(s));
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define cinf(n,x) for(int i=0;i<(n);I++) cin >> x[i];

int main(){
  int a,b,c ;
  cin >> a >> b >> c;
  if(a == b && b == c)
    cout <<1;
  else if(a == b && b != c)
    cout << 2;
  else if(b == c && a != b)
    cout << 2 ;
  else if(c == a && a != b)
    cout << 2 ;
  else
    cout << 3;
  cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	static Scanner s=new Scanner(System.in);

	public static void main(String __[]){
		input();
		solve();
	}

	private static void input(){
	}

	private static void solve(){
		char c[] = s.nextLine().toCharArray();
		for(int i=0;i<c.length;i++)
			c[i]=c[i]<='Z'
			?Character.toLowerCase(c[i])
			:Character.toUpperCase(c[i]);
		System.out.println(String.valueOf(c));
	}
}

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

int main()
{
  string s,t;
  cin>>s>>t;
  
  for (int i=0;i<s.length();i++)
  {
    if (s[i]!=t[i])
    {
      cout<<"No";
      return 0;
    }
    
  }
  
  cout<<"Yes";
  
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
long long int l[87];
int main()
{
int n;
cin >> n;
 
 
l[0] = 2;
l[1] = 1;
 
for(int i = 2;i<=86;i++) l[i] = l[i-2] + l[i-1];
 
cout << l[n] << endl;
 
 
 
 
 
return 0;
}

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

// #undef LOCAL
#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);
  int N, M;
  cin >> N >> M;
  vector<int> x(M);
  vector<int> d;
  for (int i = 0; i < M; i++) {
    cin >> x[i];
  }
  sort(x.begin(), x.end());
  for (int i = 0; i < M - 1; i++) {
    d.push_back(abs(x[i + 1] - x[i]));
  }
  sort(d.begin(), d.end());
  dumpv(x);
  dumpv(d);
  int ans = 0;
  for (int i = 0; i < M - N; i++) {
    ans += d[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }

bool f[100010];
int c[100010];

int main() {
  

  FOR(i,2,50000){
    if(!f[i]) for(int j=i+i; j<=100000; j+=i) f[j]=true;
  }
  for(int i=3; i<=100000; i+=2){
    if(!f[i] && !f[(i+1)/2]) ++c[i];
  }
  FOR(i,3,100000){
    c[i] += c[i-1];
  }

  int n,l,r;
  cin >> n;

  FOR(i,0,n-1){
    cin >> l >> r;
    cout << c[r] - c[l-1] << endl;
  }
}



Measured memory_bytes: 1152
<?php
define('NUM', 26);
$arr = array_pad(array(), NUM, 0);
$arr2 = array_pad(array(), NUM, 0);
fscanf(STDIN, "%s", $S);
for ($i = 0; $i < strlen($S); $i++) {
    $code = ord($S[$i]) - ord('a');
    $arr[$code] = 1;
}
if (array_sum($arr) === NUM) {
    $cursor = -1;
    for ($i = NUM - 1; $i >=0; $i--) {
        $code = ord($S[$i]) - ord('a');
        if ($code < $cursor) {
            for ($j = $code + 1; $j <= NUM; $j++) {
                if ($arr2[$j] === 1) {
                    $ans = substr($S, 0, $i) . chr($j + ord('a'));
                    break;
                }
            }
            break;
        } else {
            $arr2[$code] = 1;
            $cursor = max($cursor, $code);
        }
    }
} else {
    for ($i = 0; $i < NUM; $i++) {
        if ($arr[$i] === 0) {
            $ans = $S . chr($i + ord('a'));
            break;
        }
    }
}
echo $ans ?? -1;


Measured memory_bytes: 4728
import sys
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    k,n = IL()
    a = list(IL())
    a.sort()
    m = 0
    for i in range(n):
        if i<n-1:
            m = max(m,a[i+1]-a[i])
        else:
            m = max(m,k-a[i]+a[0])
    print(k-m)
    return

if __name__=='__main__':
    Main()

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

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

const ll mod  = 1e9+7;
const db eps  = 1e-9 ;
const ll maxn = 1e5+1;
const ll inf = LLONG_MAX;

#define mp make_pair
#define pb push_back
#define endl "\n"
#define deb(x) cout << #x << " " << x << endl

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

    string s;
    cin >> s;

    if(s[0] == '7' || s[1] == '7' || s[2] == '7')
        cout << "Yes";
    else 
        cout << "No";
    
    return 0;
} 

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

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second　//pairの二つ目の要素


int main(){
    int n;
    cin>>n;
    vector<pair<int,int>> p(n);
    rep(i,n){
        int x,l;
        cin>>x>>l;
        p[i]=pair<int,int>(x+l, x-l);
    }
    sort(p.begin(),p.end());
    int ans=1;
    int t=p[0].first;
    for(int i=1;i<n;i++){
        if(p[i].second>=t){
            ans++;
            t=p[i].first;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
using std::max;
#define reg register
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
static char buf[100000],*p1=buf,*p2=buf;
inline int read(void){
	reg bool f=false;
	reg char ch=getchar();
	reg int res=0;
	while(ch<'0'||'9'<ch)f|=(ch=='-'),ch=getchar();
	while('0'<=ch&&ch<='9')res=10*res+ch-'0',ch=getchar();
	return f?-res:res;
}

int a,b;

int main(void){
	a=read(),b=read();
	printf("%d\n",max(a-(b<<1),0));
	return 0;
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toInt() }
    var c = 1
    var b = 0
    for(i in 0 until n){
        if(a[i] == c){
            c += 1
        }
        else b += 1
    }
    (if (c != 1) b else -1).let { println(it) }
}


Measured memory_bytes: 82844
n = int(input())
alp = 'abcdefghijklmnopqrstuvwxyz'

# 名前の長さを求める
min_n = 0
max_n = 26
l = 0
while min_n < n <= max_n:
    min_n += max_n
    max_n += max_n * 26
    l += 1

# n - min_n 番目の名前を求める <=> n - min_n - 1 を26進数に変換
m = n - min_n - 1
ans = ''
while m >= 26:
    ans = alp[m % 26] + ans
    m = m // 26 - 1
ans = alp[m] + ans

while len(ans) < l:
    ans = 'a' + ans

print(ans)

Measured memory_bytes: 9128
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ld long double
#define dd double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef vector<pll> vplll;
ll mod = 1e9+7;
const ld PI = 2 * acos(0.0);
const vector<ll> dx = {1, -1, 0, 0};
const vector<ll> dy = {0, 0, 1, -1};
#define round(x, y) ((x + y - 1) / y)
#define ce(x, y) ((x + y - 1) / y)
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define len(x) (ll) x.length()
#define sq(x) ((x) * (x))
#define cb(x) ((x) * (x) * (x))
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,t,n,m,k,q; 
    t = 1;
    // cin>>t;
    while(t--)
    {
    	cin>>n>>k;
    	// cout<<(n)*(n+1)/2 - k<<endl;;
    	// n++;k++;
    	a = ((n)*(n+1)*(n+2))/6 + n+1;
    	k--;
    	b = ((k)*(k+1)*(3*n-2*k+2))/6 + k;
    	// b = k*()
    	a %= mod;
    	b %= mod;
    	a = (a-b +mod)%mod;
    	// cout<<a<<" "<<b<<endl;
    	cout<<a<<endl;
    }
    return 0;
}

Measured memory_bytes: 3676
N = int(input())
yaku = 1
import math

if N % 2 == 0:
	yaku = 2
	
for i in range(3,int(math.sqrt(N))+1 ,1):
	if N % i == 0:
		yaku = i
		
		
yaku2 = int(N/yaku)

print(int(yaku2+yaku - 2))


Measured memory_bytes: 2940
import math
l, r = list(map(int, input().split()))

if (2019*math.ceil(l/2019) <= r):
    print(0)
else:
    minres = 2018

    for i in range(l, r+1):
        im = i % 2019
        for j in range(i+1, r+1):
            res = (im*(j%2019))%2019
            if res < minres:
                minres = res

    print(minres)

Measured memory_bytes: 9056
def candles(N: int, K: int, X: int)->int:
    min_d = float('inf')
    for i in range(N-K+1):
        xl, xr = X[i], X[i+K-1]
        min_d = min(min_d, abs(xl) + abs(xr - xl), abs(xr) + abs(xr - xl))

    return min_d


if __name__ == "__main__":
    N, K = map(int, input().split())
    X = [int(s) for s in input().split()]
    ans = candles(N, K, X)
    print(ans)


Measured memory_bytes: 14224
from collections import Counter

N = int(input())

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

count = dict(Counter(prime_factorize(N)))

ans = 0
for c in count.values():
    k = 1
    while c >= k:
        ans += 1
        c -= k
        k += 1

print(ans)


Measured memory_bytes: 9192
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

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


int main(){
    ll n;
    cin >> n;
    string alp = "abcdefghijklmnopqrstuvwxyz";
    string ans = "";
    
    while(n > 0){
        n--;
        ans += alp[n%26];
        n/=26;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
    return 0;
}

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

typedef long long int ll;

vector <ll> vec[100005];

ll n,m;
ll vis[100005];
ll par[100005];
ll s,t;
ll dp[100005][4];

struct point {
    ll first;
    ll second;
    ll third;
};



int main()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);


    cin>>n>>m;
    memset(dp,-1,sizeof(dp));
    for(ll i=0;i<m;i++){
        ll a,b;
        cin>>a>>b;
        vec[a].push_back(b);
        //vec[b].push_back(a);
    }

    cin>>s>>t;


    queue < struct point > que;

    que.push({s,1,0});
    ll ans = INT_MAX;
    map < pair <ll,ll> , ll> mp;
    while(que.size() > 0)
    {
        struct point te = que.front();
        que.pop();
        if(te.first == t and te.second == 1){
            ans = min(ans,te.third/3);continue;
        }
        ll u = te.first;
        if(mp[{te.first,te.second}] == 1)continue;
         mp[{te.first,te.second}] = 1;
        for(ll i=0;i<vec[u].size();i++)
        {
            ll v = vec[u][i];
            ll c = te.second+1;
            if(c==4)c = 1;

            que.push({v,c,te.third+1});

        }
    }
    if(ans>=INT_MAX){
        cout<<-1<<endl;return 0;
    }
    cout<<ans<<endl;


}


Measured memory_bytes: 29184
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextInt();
        long m = sc.nextInt();
        long d = sc.nextInt();

        double result =
                (d == 0) ? (double) (m - 1) / n
                        : (double) 2 * (n - d) * (m - 1) / (n * n) ;

        System.out.println(result);
    }
}


Measured memory_bytes: 22732
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

long long n, w, x[110], y[100010], dp[300][300110], ta;

signed main() {
	cin >> n >> w;
	rep(i, n)cin >> x[i] >> y[i];
	dp[0][x[0]] = y[0];
	for (int i = 1; i < n; i++) {
		for (int j = 0; j <= w; j++) {
			dp[i][j] = max(dp[i][j], dp[i - 1][j]);
			dp[i][j + x[i]] = max(dp[i][j + x[i]], dp[i - 1][j] + y[i]);
		}
	}
	for (int i = 0; i <= w; i++)ta = max(ta, dp[n - 1][i]);
	cout << ta << endl;
	ggr
}



Measured memory_bytes: 231680
import java.io.*;
public class Main {
	/**
	 * 公舎の入居者数を出力する
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//校舎の件数
		int n = Integer.parseInt(br.readLine());
		//トランプ全てのの配列
		int[][][] count = new int[4][3][10]; 
		//全ての部屋の人数を0人にする
		for(int i = 0; i < 4; i++){
			for(int l = 0; l < 3; l++){
				for(int k = 0; k < 10; k++){
					count[i][l][k] = 0;
				}//for
			}//for
		}//for
		//各棟、各部屋の人数を配列に入れる
		for(int i = 0; i < n; i++){
			String str  = br.readLine();
			String[] strs = str.split(" ");
			int b = Integer.parseInt(strs[0]) - 1;	//各棟
			int f = Integer.parseInt(strs[1]) - 1;	//階
			int r = Integer.parseInt(strs[2]) - 1;	//何番目
			int v = Integer.parseInt(strs[3]);
			count[b][f][r] += v;
		}//for
		//出力
		for(int i = 0; i < 4; i++){
			if(i != 0){
				System.out.println("####################");
			}
			for(int l = 0; l < 3; l++){
				for(int k = 0; k < 10; k++){
					System.out.print(" ");
					System.out.print(count[i][l][k]);
				}//for
				System.out.println();
			}//for
		}//for
	}
}

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

vector<pair<int64_t, int64_t>> prime_factorize(int64_t N)
{
  vector<pair<int64_t, int64_t>> res;
  for (int64_t a = 2; a * a <= N; a++)
  {
    if (N % a != 0)
      continue;
    int64_t ex = 0;
    while (N % a == 0)
    {
      ex++;
      N /= a;
    }
    res.push_back({a, ex});
  }
  if (N != 1)
    res.push_back({N, 1});
  return res;
}

int main()
{
  int64_t N;
  cin >> N;
  auto res = prime_factorize(N);
  cout << N << ":";
  for (pair<int64_t, int64_t> p : res)
  {
    for (int i = 0; i < p.second; ++i)
      cout << " " << p.first;
  }
  cout << endl;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long, long long>
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define pb push_back
#define MAXN 10000057
#define mod 1000000007
#define fr(i, s, e, st) for(ll (i) = (s); (i) < (e); (i) += (st))
#define fre(i, s, e, st) for(ll (i) = (s); (i) <= (e); (i) += (st))
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
using namespace std;

int main()
{
    fastio;
    ll T = 1;
    //cin >> T;
    while (T--)
    {       
        ll n; cin>>n;
        vector<long double> dp(n+1, 0);
        dp[0] = 1;
        long double d;
        fr(i, 1, n+1, 1) 
        {
            cin>>d;
            for(ll j = i; j>=0; j--) dp[j] = ((j == 0)? 0:dp[j-1] * d) + dp[j] * (1 - d);
        }
        d = 0;
        fr(i, n/2 + 1, n+1, 1) d += dp[i]; cout<<d<<endl;
    }       
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    int A[N + 1];
    for(int i = 1; i <= N; i++){
        cin >> A[i];
    }
    vector<int> r(N + 1); //球いれるかいれへんか
    for(int i = N; i > N/2; i--){
        r[i] = A[i];
    }
    for(int i = N/2; i >=1; i--){
        int rest = 0;
        int factor = 2;
        while(factor*i <= N){
            rest += r[factor*i];
            factor++;
        }
        r[i] = ((A[i] - rest)%2 + 2)%2;
    }
    vector<int> ans;
    for(int i = 0; i < r.size(); i++){
        if(r[i]) ans.push_back(i);
    }
    cout << ans.size() << endl;
    for(int i =0; i < ans.size(); i++){
        cout << ans[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <queue>
#include <map>
using namespace std;

#define BASE 10000
bool dpx[2][20000];
bool dpy[2][20000];

int main() {
    string s; cin >> s;
    int x,y; cin >> x >> y;

    vector<int> xx, yy;

    int k = 0;
    int a = 0, b = 0; // スタート地点
    for (; k<s.size() && s[k] == 'F'; k++) {
        a++; // 先に進ませる
    }
    int cnt = 0;
    int dir = 0; // 0 = x軸, 1 = y軸

    for (; k<s.size(); k++) {
        if (s[k] == 'T') {
            if (cnt > 0) {
                if (dir == 0) {
                    xx.push_back( cnt );
                } else {
                    yy.push_back( cnt );
                }
            }
            dir ^= 1;
            cnt = 0;
        } else {
            cnt++;
        }
    }
    if (cnt > 0) {
        if (dir == 0) xx.push_back( cnt );
        else          yy.push_back( cnt );
    }

    // x軸を確認する
    int curr = 0;
    bool okx = false;
    dpx[curr][a + BASE] = true;
    for (int i=0; i<xx.size(); i++) {
        // init
        for (int j=0; j<20000; j++) dpx[curr^1][j] = false;

        for (int j=0; j<20000; j++) {
            if (dpx[curr][j]) {
                if (j + xx[i] < 20000) {
                    dpx[curr^1][j + xx[i]] = true;
                }
                if (j - xx[i] > 0) {
                    dpx[curr^1][j - xx[i]] = true;
                }
            }
        }
        curr ^= 1;
    }
    if (dpx[curr][x + BASE]) okx = true;


    // y軸
    curr = 0;
    bool oky = false;
    dpy[curr][b + BASE] = true;
    for (int i=0; i<yy.size(); i++) {
        // init
        for (int j=0; j<20000; j++) dpy[curr^1][j] = false;

        for (int j=0; j<20000; j++) {
            if (dpy[curr][j]) {
                if (j + yy[i] < 20000) {
                    dpy[curr^1][j + yy[i]] = true;
                }
                if (j - yy[i] > 0) {
                    dpy[curr^1][j - yy[i]] = true;
                }
            }
        }
        curr ^= 1;
    }
    if (dpy[curr][y + BASE]) oky = true;


    cout << (okx && oky ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 384