akhauriyash/Code-Regression huggingface dataset:
n=int(input())
for h in range(1,(3*n)//4+1):
  for j in range(1,3501):
    if (4*h*j-j*n-n*h)>0 and 3500>=(n*h*j)/(4*h*j-j*n-n*h)>0 and ((n*h*j)/(4*h*j-j*n-n*h)).is_integer():
      print(h,j,(n*h*j)//(4*h*j-j*n-n*h))
      exit()


Measured memory_bytes: 43152
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let h:u128 = read();
    let mut ans = 2;
    while ans <= h {
        ans *= 2;
    }
    println!("{}", ans - 1);
}


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

using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  long long al = 0;
  for (int i = 0; i < n; i++) {
    long long tmp;
    cin >> tmp;
    a[i] = tmp;
    al = al ^ tmp;
  }
  vector<long long> ans(n, 0);
  for (int i = 0; i < n; i++) {
    ans[i] = a[i] ^ al;
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i];
    if (i != n - 1) cout << " ";
  }

  return 0;
}


Measured memory_bytes: 6404
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
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; }

struct Sieve{
  int n;
  vector<int> f,primes;
  Sieve(int n=1):n(n),f(n+1){
    f[0] = f[1] = -1;
    for(int i = 2; i <= n;++i){
      if(f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for(int j = i*i;j <= n;j += i){
        if(!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x){return f[x] == x;}
  vector<int> factorList(int x){
    vector<int> res;
    while(x != 1){
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x){
    vector<int> fl = factorList(x);
    if(fl.size() == 0) return {};
    vector<P> res(1,P(fl[0],0));
    for(int p:fl){
      if(res.back().first == p){
        res.back().second++;
      }
      else{
        res.emplace_back(p,1);
      }
    }
    return res;
  }
};

signed main(){
  int n;
  cin >> n;
  vint cnt(110);
  Sieve tree(150);
  rep(i,1,n+1){
    auto m = tree.factor(i);
    for(auto p : m){
      cnt[p.first] += p.second;
    }
  }
  // rep(i,0,n) cout << cnt[i] << endl;
  vint ans(100);
  for(auto p:cnt){
    if(p >=74 ) ans[74]++;
    if(p >=24 ) ans[24]++;
    if(p >=14 ) ans[14]++;
    if(p >=4 ) ans[4]++;
    if(p >=2 ) ans[2]++;
  }
  int ANS = 0;
  ANS += ans[74];
  // [2]に[24]の分も含まれているのでそれを引いている
  ANS += ans[24]*(ans[2] - 1);
  ANS += ans[14]*(ans[4] - 1);
  // まずは[2]のみを満たしているものから計算
	ANS += (ans[4] * (ans[4] - 1)) / 2 * (ans[2] - ans[4]);
  // 最後に[4]を満たしているものから考える
	ANS += (ans[4] * (ans[4] - 1)) / 2 * (ans[4] - 2);
  cout << ANS << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

int main()
{	
	int K, X;
	cin >> K >> X;

	if (500 * K >= X)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < i; j++) {
			res += A[i] * A[j];
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
s=input()
count_1=0
count_2=0
for i in range(len(s)):
  if i%2 == 0 and s[i] == '0':
    count_1+=1
  if i%2 == 1 and s[i] == '1':
    count_1+=1
for i in range(len(s)):
  if i%2 == 0 and s[i] == '1':
    count_2+=1
  if i%2 == 1 and s[i] == '0':
    count_2+=1
if count_1 < count_2:
  print(count_1)
else:
  print(count_2)

Measured memory_bytes: 3188
#include <iostream>
using namespace std;
int main() {
	const string G = "GREATER";
	const string E = "EQUAL";
	const string L = "LESS";
	string A, B;
	cin >> A >> B;
	if (A.size() < B.size()) cout << L;
	else if (A.size() > B.size()) cout << G;
	else {
		if (A < B) cout << L;
		else if (A > B) cout << G;
		else cout << E;
	}
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedInputStream
import java.io.InputStream
import java.util.StringTokenizer

fun solve(N: Int, A: Int, B: Int, C: Int, l: IntArray) {
    fun calcScore(a: Int, b: Int, c: Int) =
        listOf(A - a, B - b, C - c).sumBy { Math.abs(it) }
    // 0: no use, 1: A, 2: B, 3: C
    val pattern = listOf(0, 1, 2, 3)
    val choices = product(*Array(N) { pattern })
    var ans = 10000000
    for (choice in choices) {
        val aa = choice.mapIndexed { index, value -> if (value == 1) l[index] else 0 }
        val bb = choice.mapIndexed { index, value -> if (value == 2) l[index] else 0 }
        val cc = choice.mapIndexed { index, value -> if (value == 3) l[index] else 0 }
        val asize = aa.count { it != 0 }
        val bsize = bb.count { it != 0 }
        val csize = cc.count { it != 0 }
        if (asize < 1 || bsize < 1 || csize < 1) continue
        ans = Math.min(
            ans,
            calcScore(aa.sum(), bb.sum(), cc.sum()) + (asize + bsize + csize - 3) * 10
        )
    }
    println(ans)
    return
}

fun <T> product(vararg lists: List<T>): Sequence<List<T>> {
    fun <T> productTwoList(left: List<T>, right: List<T>): Sequence<List<T>> =
            left.asSequence().flatMap { leftElem -> right.asSequence().map { listOf(leftElem, it) } }

    fun <T> product2DListAnd1DList(list2D: Sequence<List<T>>, list1D: List<T>): Sequence<List<T>> =
            list2D.flatMap { seq -> list1D.asSequence().map { seq + it } }

    require(lists.size >= 2)
    return lists.asSequence()
            .drop(2)
            .fold(productTwoList(lists[0], lists[1])) { acc, suc -> product2DListAnd1DList(acc, suc) }
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val A = sc.next().toInt()
    val B = sc.next().toInt()
    val C = sc.next().toInt()
    val l = IntArray(N)
    for (i in 0 until N) {
        l[i] = sc.next().toInt()
    }
    solve(N, A, B, C, l)
}


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

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    ll N, D;  cin >> N >> D;
    D = D*D;
    int ans = 0;
    for(int i = 0 ; i < N ; i++){
      ll X, Y;  cin >> X >> Y;
      ll dist = X*X + Y*Y;
      if(dist <= D)  ans++;
    }

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


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

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

int main()
{
  int n;
  while (cin >> n){
    cout << 1 + (n * (n + 1) / 2) << endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
int main(void)
{
    int n;
    long long sum = 0;
    cin >> n;

    for(ll i = 1;i <= n;i++)
    {
        if(i% 3 == 0 || i % 5 == 0)
        {
            continue;
        }else
        {
            sum+=i;
        }
        
    }
    cout << sum;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vaector<long>
#define vll vector<long long int>
#define vC  vector<char>
#define FastIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
ll pow(ll x, ll y,ll m) { ll res = 1;x=x%m; while (y > 0) { if (y & 1) res = ((res%m) * (x%m))%m; y = y >> 1; x = ((x%m) * (x%m))%m; } return res%m; }
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
const ll INF = 0xFFFFFFFFFFFFFFFL;
clock_t time_p=clock();
void abhigyan10()
{time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}
ll seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline ll rnd(ll l=0,ll r=INF){return uniform_int_distribution<ll>(l,r)(rng);}
#define clrbuf cin.ignore(numeric_limits<streamsize>::max(),'\n');
#define preciset(x) cout<<setprecision(x)<<fixed;
const ll mod =1000000007;
int main()
{
    

        FastIO
        int n,i;
        cin>>n;
        vll a(n+1),b(n+1);
        ll ans=0,ans1=0,sum1=0,sum2=0;
        for(i=1;i<=n;i++)
        {
        	cin>>a[i];
        	b[i]=a[i];
        	if(a[i]==0)
        		{a[i]++;b[i]--;ans++;ans1++;}
        	
        	if(i&1)
        	{
        		sum1+=a[i];
        		sum2+=b[i];
        		if(sum1<=0)
        			{
        				ans+= (-1LL)*(sum1) +1LL;
        				sum1=1LL;
        			}

        		if(sum2>=0)
        		{
        			ans1+=sum2 +1;
        			sum2=-1LL;
        		}

        	}
        	else
        	{
        		sum1+=b[i];
        		sum2+=a[i];
        		if(sum2<=0)
        			{
        				ans1+= (-1LL)*(sum2) +1LL;
        				sum2=1LL;
        			}

        		if(sum1>=0)
        		{
        			ans+=sum1 +1LL;
        			sum1=-1LL;
        		}
        	}

        	
        }
        cout<<min(ans,ans1);
        return 0;
}

Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(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()


def main():
    A, B, C = LI()
    if A == B == C:
        ans = 'Yes'
    else:
        ans = 'No'
    return ans

print(main())

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

int main(void){
  while(1){
    int i=0, a[50000], n=0, c=0;
    double ave=0,sum=0;
    cin >> n;
    if(n == 0)
      break;
    for (i = 0; i <n; i++){
      cin >> a[i];
    }
    for(i = 0 ; i < n ; i++){
      sum = sum + a[i];
    }
    ave = sum / n;
    for(i = 0; i < n; i++){
      if(a[i] <= ave)
        c++;
    }
    cout << c << endl;
  }
}


Measured memory_bytes: 3052
#include<bits/stdc++.h>
#define ff(i, x, y) for(int i = x;i <= y;i++)
using namespace std;
typedef long long ll;
int n, sum, a[300010], dp[300010][2];
int main() {
	scanf("%d", &n);
	ff(i, 0, (1 << n) - 1) {
		scanf("%d", &a[i]);
	}
	dp[0][0] = 0;
	dp[0][1] = 0;
	if(a[1] > a[0])
	dp[1][0] = 1;
	else
	dp[1][1] = 1;
	ff(i, 2, (1 << n) - 1) {
		int id0, id1;
		if(a[0] > a[i]) {
			id0 = 0;
			id1 = i;
		}
		else {
			id0 = i;
			id1 = 0;
		}
		ff(bit, 0, n - 1) {
			if(i & (1 << bit)) {
				if(a[dp[i ^ (1 << bit)][1]] >= a[id0] && id0 != dp[i ^ (1 << bit)][1]) {
					id1 = id0;
					id0 = dp[i ^ (1 << bit)][1];
				}
				else if(a[dp[i ^ (1 << bit)][1]] > a[id1] && id0 != dp[i ^ (1 << bit)][1])
					id1 = dp[i ^ (1 << bit)][1];
				if(a[dp[i ^ (1 << bit)][0]] >= a[id0] && id0 != dp[i ^ (1 << bit)][0]) {
					id1 = id0;
					id0 = dp[i ^ (1 << bit)][0];
				}
				else if(a[dp[i ^ (1 << bit)][0]] > a[id1] && id0 != dp[i ^ (1 << bit)][0])
					id1 = dp[i ^ (1 << bit)][0];
			}
		}
		dp[i][0] = id0;
		dp[i][1] = id1;
	}
	int ans = 0;
	ff(i, 1, (1 << n) - 1) {
		ans = max(a[dp[i][0]] + a[dp[i][1]], ans);
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <map>
#include <cstring>
#include <vector>
using namespace std;

typedef long long int ll;
ll S[10001];
ll T[501];
int n,q;

int main(){

  cin>>n;
  for(int i=0;i<n;i++) cin>>S[i];
  cin>>q;
  for(int i=0;i<q;i++) cin>>T[i];

  int cnt = 0;
  for(int i=0;i<q;i++)
    for(int j=0;j<n;j++){
      if(T[i]==S[j]){
	cnt++;
	break;
      }
    }
  cout<<cnt<<endl;
  
 
  return 0;
}

Measured memory_bytes: 3128
#include <iostream>
#include <vector>

using namespace std;

int main()
{
  int N, T;
  cin >> N >> T;
  vector <int> c(N);
  vector <int> t(N);
  
  for( int i=0;i<N;i++ )
      cin >> c[i] >> t[i];

  int min_c = 10000;
  for( int i=0;i<N;i++ )
    {
      if( t[i]<= T )
	min_c = min(min_c, c[i]);
    }

  if( min_c == 10000 )
    cout << "TLE" << endl;
  else
    cout << min_c << endl;
  
  return 0;
}


Measured memory_bytes: 256
s = input() 
answer1 = '10'*50000
answer2 = '01'*50000 

count1 = 0
for i in range(len(s)):
    if s[i] != answer1[i]:
        count1 += 1

count2 = 0
for i in range(len(s)):
    if s[i] != answer2[i]:
        count2 += 1

print(count1) if count1 < count2 else print(count2)


Measured memory_bytes: 3316
#include <iostream>
#include <cstring> 
#include <algorithm>
#include <map>
#include <vector>
using namespace std;

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

  if ( K < 10 ) {
    cout << K << endl;
    return 0;
  }

  vector<long> BUF;
  BUF.push_back(1);
  BUF.push_back(2);
  BUF.push_back(3);
  BUF.push_back(4);
  BUF.push_back(5);
  BUF.push_back(6);
  BUF.push_back(7);
  BUF.push_back(8);
  BUF.push_back(9);

  int idx = 0;
  while ( true ) {
    long target = BUF[idx];
    int last = target % 10;

   if (last != 0 ) BUF.push_back( stol(to_string(target) + to_string(last-1)) );
   if ( K <= BUF.size() ) {break;}

    BUF.push_back( stol(to_string(target) + to_string(last)) );
   if ( K <= BUF.size() ) {break;}

    if (last !=9 ) BUF.push_back( stol(to_string(target) + to_string(last+1)) );
    if ( K <= BUF.size() ) {break;}

    ++idx;
  }

  cout << BUF[BUF.size()-1] << endl;


} 

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using Pt = pair<int, int>;

void ABC123A()
{
	int a[5], k;
	for (int i = 0; i < 5; ++i)
		cin >> a[i];
	cin >> k;
	for (int i = 0; i < 5; ++i)
	{
		for (int j = i + 1; j < 5; ++j)
		{
			if (abs(a[i] - a[j]) > k)
			{
				cout << ":(" << endl;
				return;
			}
		}
	}
	cout << "Yay!" << endl;
}


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

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;

namespace atcoder
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            string indata1;
            indata1 = Console.ReadLine();
            int c = int.Parse(indata1);
            List<string> resdata = new List<string>();
            resdata.Add("AC");
            resdata.Add("WA");
            resdata.Add("TLE");
            resdata.Add("RE");
            int[] res = new int[4];
            for (int i = 0; i < c; i++)
            {
                res[resdata.IndexOf(Console.ReadLine())]++;
            }
            Console.WriteLine("AC x " + res[0]);
            Console.WriteLine("WA x " + res[1]);
            Console.WriteLine("TLE x " + res[2]);
            Console.WriteLine("RE x " + res[3]);
        }
    }
}

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

int main() {
  int x,y,z;
  cin>>x>>y>>z;
  cout<<z<<" "<<x<<" "<<y<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
V<int> g[705];
int c[705];
int cnt_v,cnt_one;
void dfs(int cur,int cc){
    c[cur]=cc;
    cnt_v++;
    if(cc==1)cnt_one++;
    for(int v:g[cur]){
        if(c[v]!=-1){
            if(c[v]!=(cc^1)){
                cout<<-1<<"\n";
                exit(0);
            }
        }else{
            dfs(v,(cc^1));
        }
    }
}
bool dp[705][705]={};
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)c[i]=-1;
    set<P> s;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            s.insert(P(i,j));
        }
    }
    int a,b;
    for(int i=0;i<m;i++){
        cin>>a>>b;
        --a;--b;
        if(a>b)swap(a,b);
        s.erase(P(a,b));
    }
    for(auto p:s){
        g[p.fi].emplace_back(p.se);
        g[p.se].emplace_back(p.fi);
    }
    V<P> tmp;
    ll can=0;
    for(int i=0;i<n;i++){
        if(c[i]!=-1)continue;
        if(g[i].size()>0){
            cnt_v=0,cnt_one=0;
            dfs(i,1);
            tmp.emplace_back(cnt_v-cnt_one,cnt_one);
        }else{
            can++;
        }
    }
    auto f=[&](ll a){
        return a*(a-1)/2;
    };
    dp[0][0]=1;
    int siz=tmp.size();
    ll cannot=n-can;
    for(int i=0;i<siz;i++){
        for(int j=0;j<n;j++){
            if(dp[i][j]){
                dp[i+1][j+tmp[i].fi]=dp[i][j];
                dp[i+1][j+tmp[i].se]=dp[i][j];
            }
        }
    }
    ll ans=inf;
    for(ll i=0;i<=cannot;i++){
        if(!dp[siz][i])continue;
        ll mi=min(cannot-i,i),ma=max(cannot-i,i);
        if(ma-mi>can){
            mi+=can;
        }else{
            ll rem=can-(ma-mi);
            mi=ma;
            mi+=rem/2;
            ma+=(rem+1)/2;
        }
        chmin(ans,f(mi)+f(ma));
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 21376
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

int main(){
   double a,b,h,m;
   cin >> a >> b >> h >> m;
   double sita1= (h+m/60)/12 * 2*M_PI;
   double sita2= m/60 * 2*M_PI;
   int hx,hy,mx,my;
   double aa = a*sin(sita1)-b*sin(sita2);
   double bb = a*cos(sita1)-b*cos(sita2);
   double ans = sqrt(pow(aa,2)+pow(bb,2)); 
   printf("%.10lf\n",ans);
   return 0;
}

Measured memory_bytes: 4148
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define MAX 10000001

bool isPrime[MAX];
vector<int> res;

void calc() {
    for (int i = 5; i < MAX - 8; i += 2) {
        if (isPrime[i] && isPrime[i + 2] && isPrime[i + 6]
            && isPrime[i + 8]) {
            res.push_back(i + 8);
        }
    }
}

void eratos() {
    fill(isPrime, isPrime + MAX, true);
    for (int i = 2; i < MAX; i++) {
        if (!isPrime[i]) continue;
        for (int j = i + i; j < MAX; j += i) {
            isPrime[j] = false;
        }
    }
}

int main() {
    eratos();
    calc();
    while (true) {
        int n;
        cin >> n;
        if (!n) return 0;
        for (int i = 0; i < res.size(); i++) {
            if (res[i] > n) {
                cout << res[i - 1] << endl;
                break;
            }
            if (i == res.size() - 1) {
                cout << res[i] << endl;
            }
        }
    }
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int N, K;
ll A[1100];
std::vector<ll> v;

ll f(int b, ll prefix){
    if(b == -1){
        return prefix;
    }

    int cnt = 0;
    for(int i=0;i<(int)v.size();++i){
        if((v[i] & prefix) == prefix){
            cnt += v[i] >> b & 1;
        }
    }

    if(cnt >= K){
        return f(b - 1, prefix | (1ll << b));
    }
    return f(b - 1, prefix);
}

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

    std::cin >> N >> K;

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

    for(int i=1;i<N;++i){
        A[i] += A[i - 1];
    }

    for(int i=0;i<N;++i){
        for(int j=i;j<N;++j){
            ll sum = A[j] - (i > 0 ? A[i - 1] : 0);
            v.emplace_back(sum);
        }
    }

    ll res = f(42, 0);
    std::cout << res << std::endl;
}


Measured memory_bytes: 6384
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#endif

#define ITER(c)         __typeof__((c).begin())
#define FOREACH(it, c)  for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)        __typeof__((c).rbegin())
#define RFOREACH(it, c) for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)       REPEAT(i, 0, n)
#define REPEAT(i, k, n) for (int i = (k); i < (n); ++i)
#define REVREP(i, n)    for (int i = ((n)-1); i >= 0; --i)
#define FIND(c, n)      std::find((c).begin(), (c).end(), (n));
#define BSEARCH(c, n)   std::binary_search((c).begin(), (c).end(), (n))
#define LLPOW(p1,p2)    ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)      (sizeof(A)/sizeof((A)[0]))
#define MIN(p1,p2)      (((p1)<(p2))?(p1):(p2))
#define MAX(p1,p2)      (((p1)>(p2))?(p1):(p2))
#define CIN_NO_SYNC     do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)       fgets((p), sizeof(p), stdin)
#define CHOMP(p)        do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n') *_q = 0; } while(0)


int cnt[4][3][10];

int main(){
    int n;
    cin >> n;
    int b, f, r, v;
    REP(i,n){
        cin >> b >> f >> r >> v;
        cnt[b-1][f-1][r-1] += v;
    }
    for(int bb = 0; bb < 4; bb++){
        for(int ff = 0; ff < 3; ff++){
            for(int rr = 0; rr < 10; rr++){
                cout << " " << cnt[bb][ff][rr];
            }
            cout << endl;
        }
        if(bb < 4-1){
            cout << "####################" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define va first
#define vb second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int N;
int par[100010];
vector<pair<pii, int>> A, B;

int Find(int a) {
	if (par[a] == a) return a;
	return par[a] = Find(par[a]);
}
void Union(int a, int b) {
	if (Find(a) == Find(b)) return;
	par[Find(b)] = Find(a);
}

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);
	cin >> N;
	for (int i=1; i<=N; i++) {
		int x, y; cin >> x >> y;
		A.emplace_back(pii(x, y), i);
	}

	sort(A.begin(), A.end(), [&](auto x, auto y) {
		if (x.va.va == y.va.va) return x.va.vb < y.va.vb;
		return x.va.va < y.va.va;
	});
	for (int i=1; i<N; i++) {
		B.emplace_back(pii(A[i-1].vb, A[i].vb), A[i].va.va - A[i-1].va.va);
	}

	sort(A.begin(), A.end(), [&](auto x, auto y) {
		if (x.va.vb == y.va.vb) return x.va.va < y.va.va;
		return x.va.vb < y.va.vb;
	});
	for (int i=1; i<N; i++) {
		B.emplace_back(pii(A[i-1].vb, A[i].vb), A[i].va.vb - A[i-1].va.vb);
	}

	sort(B.begin(), B.end(), [&](auto x, auto y) {
		return x.vb < y.vb;
	});

	for (int i=1; i<=N; i++) par[i] = i;
	ll ans = 0;
	for (auto edge : B) {
		int u = edge.va.va, v = edge.va.vb;
		if (Find(u) == Find(v)) continue;
		Union(u, v); ans += edge.vb;
	}

	cout << ans;
}

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

int main() {
  unsigned long n, red = 0, count = 0;
  string c;
  cin >> n >> c;
  
  // 最後の赤を最初の白と交換していく
  // 赤を数える
  for (unsigned long i = 0; i < n; i++) if (c[i] == 'R') red++;
  // 赤の数分の左側のもののうち白の数を数える
  // その白を赤と交換すればよい
  for (unsigned long i = 0; i < red; i++) if (c[i] == 'W') count++;
  
  cout << count;
  
  return 0;
}

Measured memory_bytes: 3708
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static PrintWriter out;

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

    private static void run() {
        out = new PrintWriter(new BufferedOutputStream(System.out));
        Scanner sc = new Scanner(System.in);
        int s = Integer.parseInt(sc.next());
        ArrayList<Integer> list = new ArrayList<>();
        list.add(s);
        for (int i = 1, answer = 0;; i++) {
            answer = Main.calcF(list.get(i - 1));
            if (list.contains(answer)) {
                out.println(i + 1);
                break;
            }
            list.add(answer);
        }
        out.close();
        sc.close();
    }

    private static int calcF(int pnum) {
        int n = pnum;
        if (n % 2 == 0) {
            return n / 2;
        } else {
            return 3 * n + 1;
        }
    }
}


Measured memory_bytes: 35716
#include <iostream>
#include <vector>
#include <cstdio>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int MAX_N = 1000001;
bool prime[MAX_N];
vector<int> p;

void make_prime (void )
{
	fill (prime, prime+MAX_N, true );
	prime[0] = false;
	prime[1] = false;
	rep (i, MAX_N ){
		if (prime[i] ){
			for (int j = 2*i; j < MAX_N; j += i ){
				prime[j] = false;
			} // end for
		} // end if
	} // end rep

	p.clear();
	rep (i, MAX_N ){
		if (prime[i] ){
			p.push_back (i );
		} // end if
	} // end rep
}

int main()
{
	make_prime ();
	int a, d, n;
	while (scanf ("%d %d %d", &a, &d, &n ) && a && d && n ){
		int res = 0;
		int an = a;
		for (;;){
			if (prime[an] ){
				res++;
			} // end if
			if (res == n ) break;
			an += d;
		} // end for
		printf ("%d\n", an );
	} // end while
		
	return 0;
}

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

int main()
{
	auto is_prime = [](__int128_t n) {
		if (n < 2)
		{
			return false;
		}
		for (__int128_t i = 2; i * i <= n; i++)
		{
			if (n % i == 0)
			{
				return false;
			}
		}
		return true;
	};
	int64_t n, p;
	cin >> n >> p;
	map<int64_t, int64_t> mp;
	while (p != 1)
	{
		if (is_prime(p))
		{
			mp[p]++;
			p = 1;
		}
		for (int64_t i = 2; i * i <= p; i++)
		{
			while (p % i == 0)
			{
				mp[i]++;
				p /= i;
			}
		}
	}
	int64_t ans = 1;
	for (auto &q : mp)
	{
		while (n <= q.second)
		{
			ans *= q.first;
			q.second -= n;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from fractions import Fraction


def rec(s):
  if s[0] == 'n':
    if len(s) > 5:
      t = rec(s[5:])
      return [(t[0] - 45) * 2, t[1] + 1]
    else:
      return [0, 0]
  else:
    if len(s) > 4:
      t = rec(s[4:])
      return [(t[0] + 45) * 2, t[1] + 1]
    else:
      return [90, 0]

while True:
  s = input()
  if s == "#":
    break
  
  [n, d] = rec(s)
  d = 2 ** d
  ans = Fraction(n, d)
  print(ans)

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

int main(){
	int x,y;
	cin >> x >> y;
	switch(x){
	case 2:
		if(x==y){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
		break;
	case 4:
	case 6:
	case 9:
	case 11:
		switch(y){
		case 4:
		case 6:
		case 9:
		case 11:
			cout << "Yes" << endl;
			break;
		default:
			cout << "No" << endl;
		}
		break;
	default:
		switch(y){
		case 2:
		case 4:
		case 6:
		case 9:
		case 11:
			cout << "No" << endl;
			break;
		default:
			cout << "Yes" << endl;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int MAX_N = 102345;
int n, k, stone[MAX_N], f[MAX_N];

int main() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> stone[i];
    f[1] = 0;
    for (int i = 2; i <= n; i++) {
        int j = i - 1;
        f[i] = f[j] + abs(stone[i] - stone[j]);
        j--;
        while (j > 0 && j >= i - k) {
            if (f[j] + abs(stone[i] - stone[j]) < f[i])
                f[i] = f[j] + abs(stone[i] - stone[j]);
            j--;
        }
    }
    cout << f[n] << endl;
    return 0;
}

Measured memory_bytes: 4416
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    string s;
    cin >> s;
    int l = s.size();
    int ans = INF;
    rep(i, l - 2) {
        int value = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
        value = abs(753 - value);
        ans = min(ans, value);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
use std::io;
//use std::collections::HashMap;
//use std::collections::BinaryHeap;
//use std::collections::HashSet;
//use std::mem; // mem::swap(&mut x,&mut y);
use std::cmp; // cmp::max,cmp::min

// Rust memo: https://hackmd.io/i0lQY1OKTDW1t66TECOmiw?both

#[allow(dead_code)]
fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn read_charvec() -> Vec<char> {
    read_line().chars().collect()
}

#[allow(dead_code)]
fn read_ints() -> Vec<i64> {
    let s = read_line();
    let split: Vec<&str> = s.split(" ").collect();
    split
        .iter()
        .map(|&x| x.to_string().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_int() -> i64 {
    read_ints()[0]
}

#[allow(dead_code)]
fn reverse(s: &String) -> String {
    s.chars().rev().collect::<String>()
}

#[allow(dead_code)]
fn read_lines(n: i64) -> Vec<String> {
    let mut xs = Vec::new();

    for _i in 0..n {
        xs.push(read_line());
    }

    xs
}

#[allow(dead_code)]
fn read_ints2(n: i64) -> Vec<i64> {
    read_lines(n).iter().map(|x| x.parse().unwrap()).collect()
}

#[allow(dead_code)]
fn arange(start: i64, end: i64, step: i64) -> Vec<i64> {
    let mut ret = Vec::new();
    let mut i = start;

    while i < end {
        ret.push(i);
        i += step;
    }

    ret
}

#[allow(dead_code)]
const DXS: [i64; 4] = [0, 0, 1, -1];
#[allow(dead_code)]
const DYS: [i64; 4] = [1, -1, 0, 0];
#[allow(dead_code)]
const INF: i64 = 99999999999;
#[allow(dead_code)]
const N_PRIME: i64 = 1000000007;

////////////////////////////////////////////////

fn main() {
    let s = read_charvec();

    if s.len() % 2 == 1 {
        println!("No");
        return;
    }

    for (i, c) in s.into_iter().enumerate() {
        if i % 2 == 0 && c == 'h' {

        } else if i % 2 == 1 && c == 'i' {

        } else {
            println!("No");
            return;
        }
    }

    println!("Yes");
}


Measured memory_bytes: 4352
package main

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

func main() {
	var N, M int
	fmt.Scanln(&N, &M)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	var maxL, minR int
	minR = 1 << 31
	for i := 0; i < M; i++ {
		sc.Scan()
		L, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		R, _ := strconv.Atoi(sc.Text())

		maxL = max(maxL, L)
		minR = min(minR, R)
	}

	var ans int
	if maxL <= minR {
		ans = minR - maxL + 1
	}
	fmt.Println(ans)
}

func max(a, b int) int {
	return int(math.Max(float64(a), float64(b)))
}

func min(a, b int) int {
	return int(math.Min(float64(a), float64(b)))
}


Measured memory_bytes: 1792
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine()
            .Split(' ')
            .Select(txt => int.Parse(txt))
            .ToList();
        var s = inputs[0];
        var w = inputs[1];
        Console.WriteLine(s <= w ? "unsafe" : "safe");
    }
}

Measured memory_bytes: 28316
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
inline double sq(double a) { return a*a; }

int bitcount(int b) { int c = 0; while(b) { b &= b-1; c++; } return c; }

int n, x[64], y[64], r[64], c[64], g[64];
bool vis[1<<24];

int solve() {
    memset(vis, 0, sizeof(vis));
    memset(g, 0, sizeof(g));
    rep(i, n) for(int j=i+1; j<n; j++) {
        if(sqrt(sq(x[i]-x[j])+sq(y[i]-y[j]))<r[i]+r[j]) g[i] |= 1<<j;
    }
    vector<int> cs[4];
    rep(i, n) cs[c[i]-1].push_back(i);
    int ans = 0;
    queue<int> q;
    q.push(0);
    vis[0] = true;
    while(!q.empty()) {
        int x = q.front();
        q.pop();
        ans = max(ans, bitcount(x));
        int can = ~x;
        rep(i, n) if((x&(1<<i))==0) can &= ~g[i];
        rep(k, 4) rep(i, cs[k].size()) if(can&(1<<cs[k][i])) {
            rep(j, i) if(can&(1<<cs[k][j])) {
                const int nx = x|(1<<cs[k][i])|(1<<cs[k][j]);
                if(!vis[nx]) q.push(nx), vis[nx] = true;
            }
        }
    }
    return ans;
}

int main() {
    for(;;) {
        scanf("%d", &n);
        if(n==0) return 0;
        rep(i, n) scanf("%d%d%d%d", x+i, y+i, r+i, c+i);
        printf("%d\n", solve());
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<int,int> P;
#define Mod 1000000007


int main(){
    ll i,j;
    ll k;
    ll l;
    ll n;
    cin>>n;

    ll b[3];
    for(i=0;i<3;i++) b[i]=0;

    
    for(i=0;i<n;i++){
        ll x;
        cin>>x;
        b[x-1]++;
    }
    ll sum=b[0]+b[1]+b[2];


    vector <vector <vector<double> > >  dp(303,vector <vector<double> >(303,vector<double> (303,0)));

    for(i=1;i<3*302;i++){
        for(k=0;k<302;k++){
            for(j=0;j<302;j++){
        
            ll l=i-j-k;
            if(l>=0&&l<302) {
                
                dp[l][j][k]=(double)sum/i+(dp[max((ll)0,l-1)][j][k]*l+dp[l+1][max((ll)0,j-1)][k]*j+dp[l][j+1][max((ll)0,k-1)]*k)/i;
            }

        }
    }
    }


    printf("%.11lf\n",dp[b[0]][b[1]][b[2]]);

    
    return 0;
}

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

int main() {
    long long N;
    cin >> N;
    vector <long long> H(N);
    long long ans = 0;
    long long cnt = 0;
    cin >> H.at(0);
    for (long long i=1; i<N; i++) {
        cin >> H.at(i);
        if (H.at(i)<=H.at(i-1)) cnt++;
        else {
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    ans = max(ans, cnt);
    cout << ans << endl;
}

Measured memory_bytes: 1152
import math
from collections import deque
from collections import defaultdict

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

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

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

		if x==y:
			return

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

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

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

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

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

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

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

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq

t = readChar()

t = t.replace("?","D")

print(t)


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

// types
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpl;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[9] = {-1, 0, 1, 0, -1,-1,1,1,0};
const int dy[9] = {0, -1, 0, 1, -1,1,-1,1,0};


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

  ll h,w,n;
  cin >> h >> w >> n;
  vll a(n), b(n);
  map<pll, ll> m;
  REP(i, n){
    cin >> a[i] >> b[i];

    REP(k, 9){
      pll cur;
      cur.FI = a[i]+dx[k];
      cur.SE = b[i]+dy[k];
      if(cur.FI<=1 || h<=cur.FI || cur.SE<=1 || w<=cur.SE)
        continue;

      m[pll(cur.FI, cur.SE)] += 1;
    }

  }

  map<ll, ll> ans;
  map<pll, ll> visited;
  REP(i, n){
    REP(j, 9){
      pll c;
      c.FI = a[i]+dx[j];
      c.SE = b[i]+dy[j];
      if(c.FI<=1 || h<=c.FI || c.SE<=1 || w<=c.SE || visited[pll(c.FI, c.SE)] != 0)
        continue;

      visited[pll(c.FI, c.SE)] += 1;
      ll sum = m[pll(c.FI, c.SE)];
      ans[sum] += 1;
    }
  }

  ll s = 0;
  REP(i, 10)
    s += ans[i];

  ans[0] = max(0LL,(h-2))*max(0LL,(w-2))-s;
  REP(i, 10)
    cout << ans[i] << endl;


}


Measured memory_bytes: 114304
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}

using namespace std;

typedef long long ll;

typedef pair<int,int> P1;
typedef pair<int,P1> P2;
const ll inf=100000000000000;
struct edge{
	int to,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

#define MAX_N 100002
int dp[MAX_N]={};
bool d[MAX_N]={};
int pa[MAX_N];
vector<edge> G[MAX_N];
P1 cost[MAX_N]={};
vector<int> child[MAX_N];
vector<int> ra[MAX_N];
priority_queue<P2,vector<P2>,greater<P2>> que;
ll a[100001]={};
ll k[100001]={};
int main() {
	ll n;
	cin>>n;
	ll ak=0;
	bool flg=true;

	rep(i,n){
		cin>>a[i];
		ak+=a[i];
	}
	if((ak*2)%(n*(n+1))>0)flg=false;
	ak=(ak*2)/(n*(n+1));
	rep(i,n){
		k[i]=(ak+a[i]-a[(i+1)%n])/n;
		if((ak+a[i]-a[(i+1)%n])%n>0)flg=false;
		if(k[i]<0)flg=false;
	}
	rep(i,n){
		ak-=k[i];
	}
	if(ak!=0)flg=false;
	yesno(flg);
	return 0;

}





Measured memory_bytes: 10496
use proconio::{input, marker::Usize1};

fn main() {
    input!(n: usize, q: usize, c: [Usize1; n], lr: [(Usize1, usize); q]);
    let mut queries: Vec<_> = lr
        .into_iter()
        .enumerate()
        .map(|(i, (l, r))| (l, r, i))
        .collect();
    let k = (n as f64).sqrt() as usize;
    queries.sort_by_key(|&(l, r, _)| (l / k, if l / k % 2 == 0 { r } else { n - r }));
    let mut mul = vec![0; n];
    let mut kind = 0;
    fn add(i: usize, c: &[usize], kind: &mut usize, mul: &mut [usize]) {
        if mul[c[i]] == 0 {
            *kind += 1;
        }
        mul[c[i]] += 1;
    }
    fn sub(i: usize, c: &[usize], kind: &mut usize, mul: &mut [usize]) {
        mul[c[i]] -= 1;
        if mul[c[i]] == 0 {
            *kind -= 1;
        }
    }
    let mut i = 0;
    let mut j = 0;
    let mut ans = vec![None; q];
    for (l, r, query_id) in queries {
        while j < r {
            add(j, &c, &mut kind, &mut mul);
            j += 1;
        }
        while l < i {
            i -= 1;
            add(i, &c, &mut kind, &mut mul);
        }
        while r < j {
            j -= 1;
            sub(j, &c, &mut kind, &mut mul);
        }
        while i < l {
            sub(i, &c, &mut kind, &mut mul);
            i += 1;
        }
        ans[query_id] = Some(kind);
    }
    for x in ans.iter().copied().map(Option::unwrap) {
        println!("{}", x);
    }
}


Measured memory_bytes: 39316
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x,i;
	cin >> x;
	for(i=1; ;i++)
    {
        if(x==0)
            break;
        else
        {
            cout << "Case " << i <<": " << x << endl;
        }
        cin>>x;
    }

}





Measured memory_bytes: 3072
N = int(input())
p = list(map(int, input().split()))


def check(s):
    flag = 0
    for i in range(0, len(s) - 1):
        if s[i] > s[i + 1]:
            flag = 1
            break
    return flag


flag = check(p)
if flag == 0:
    print('YES')
else:
    for i in range(0, len(p) - 1):
        if p[i] > p[i + 1]:
            break
    for j in range(i + 1, len(p) - 1):
        if p[j] > p[j + 1]:
            break
    temp = p[j + 1]
    p[j + 1] = p[i]
    p[i] = temp

    flag = check(p)
    if flag == 0:
        print('YES')
    else:
        print('NO')


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	string s; cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'C') {
			for (int j = i; j < s.size(); j++) {
				if (s[j] == 'F') {
					cout << "Yes" << endl;
					return 0;
				}
			}
			break;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    p_list = []
    for i in range(N):
        input_raw = read_func().strip().split()
        [p]= [int(input_raw[0])]
        p_list.append(p)

    p_list.sort(reverse = True)
    print p_list[0]/2 + sum(p_list[1:])


if __name__ == '__main__':
    main()

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

int main(){
	int x,n;
	cin>>x>>n;
	int p[n];
	if(n==0){
		cout<<x;
		return 0;
	}
	vector<int> v(102,0);
	for(int i=0;i<n;i++){
		cin>>p[i];
		v[p[i]]++;
	}
	int min=INT_MAX,ans;
	for(int i=0;i<102;i++){
		if(v[i]==0 && abs(x-i)<min){
			min=abs(x-i);
			ans=i;
		}
	}
	cout<<ans;
}

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

int main(void){
	int n,m,x,y;
	cin>>n;
	vector<int> a;
	for(int i=0;i<n;i++)cin>>x,a.push_back(x);
	cin>>m;
	vector<int> b;
	for(int i=0;i<m;i++)cin>>x,b.push_back(x);
	cout<< (a<b) <<endl;
	
}



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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	deque<int> d;
	rep(i,n) {
		int p = lower_bound(d.begin(), d.end(), a[i]) - d.begin();
		if(p==0){
			d.push_front(a[i]);
		}
		else d[p-1] = a[i];
	}
	int ans = d.size();
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
n, k, c = map(int, input().split())
s = input()

workL = [0] * (n + 1)
workR = [0] * (n + 1)

cnt = 0
left = 0

while left < n:
    if s[left] == 'o':
        workL[left + 1] += 1
        cnt += 1
        left += c
    left += 1

cnt = 0
right = n - 1
while right >= 0:
    if s[right] == 'o':
        workR[right] += 1
        cnt += 1
        right -= c
    right -= 1

for i in range(n - 1):
    workL[i + 1] += workL[i]
for i in range(n - 1, 0, -1):
    workR[i - 1] += workR[i]


print("\n".join(
    map(str, [i + 1 for i in range(n) if workL[i] + workR[i + 1] < k])))


Measured memory_bytes: 47492
#include<iostream> 
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
#define N 200010
int a[N],n;
long long ans=0;
int main()
{
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	if (a[1]) ans=-1;
	else 
	for (int i=2;i<=n;i++) 
	if (a[i]>a[i-1]+1) {ans=-1;break;}
	else if (a[i]<=a[i-1]) ans+=a[i];
	else ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024