akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	int[] p = new int[181];
	int[] oddp = new int[46];
	
	int[] memo = new int[1000001];
	int[] oddmemo = new int[1000001];
	
	int calc(int n) {
		if (memo[n] == 0) {
			int index = 180;
			while (n < p[index]) index--;
			if (index == 0) memo[n] = n;
			else {
				if (n == p[index]) memo[n] = 1;
				else {
					int min = 1000000;
					for (int i = index; i >= 0; i--) {
						if (min >= n/p[i])
							min = Math.min(min, calc(n-p[i]));
					}
					memo[n] = min+1;
				}
			}
		}
		return memo[n];
	}
	
	int calcodd(int n) {
		if (oddmemo[n] == 0) {
			int index = 45;
			while (n < oddp[index]) index--;
			if (index == 0) oddmemo[n] = n;
			else {
				while (n < oddp[index]) index--;
				if (n == oddp[index]) oddmemo[n] = 1;
				else {
					int min = 1000000;
					for (int i = index; i >= 0; i--) {
						if (min >= n/oddp[i])
							min = Math.min(min, calcodd(n-oddp[i]));
					}
					oddmemo[n] = min+1;
				}
			}
		}
		
		return oddmemo[n];
	}
	
	void run() {
		int n;
	
		
		for (int i = 0; i < 181; i++) {
			p[i] = (i+1)*(i+2)*(i+3)/6;
			if (i % 4 == 0) {
				oddp[i/4] = (i+1)*(i+2)*(i+3)/6;
			}
		}
		
		while (true) {
			n = sc.nextInt();
			if (n == 0) break;

			out.printf("%d %d\n", calc(n), calcodd(n));
		}
		
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 33488
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
#define ALL(x) (x).begin(), (x).end()
LL POW(LL a,LL p,LL M){ if(!p) return 1LL;LL T = POW(a,p/2,M);T = T*T%M; if(p&1) T=T*(a%M)%M; return T; }
LL SQRT(LL a) { LL b = (LL)sqrtl(((double)a)+0.5); while(b*b<a) ++b; while(b*b>a) --b; return (b*b==a)?b:-1; }
//endl
//<------------------------edits---------------------------------------------->
const LL MOD = 1e9+7;//998244353
// #define LOCAL LDD
// #define int LL

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);cout << fixed;
#ifdef LOCAL
  freopen("input.txt", "rt", stdin);
#endif
  LL a,b,c;cin >> a >> b >> c;
  LL d = c-a-b;
  LL od = d;
  d *= d;
  if(4*a*b<d && od>0) cout << "Yes\n";
  else cout << "No\n"; 
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
  return 0;
}

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


int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>>A(n,vector<int>(m));
    vector<int>B(m);
    int x=0;
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin >> A.at(i).at(j);
        }
    }
    for(int i=0; i<m; i++){
        cin >> B.at(i);
    }
    for(int i=0; i<n; i++){
        int x=0;
        for(int j=0; j<m; j++){
            x+=(A[i][j]*B[j]);
        }
        cout << x << endl;
    }

}


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

using namespace std;
using ll = long long;

int main() {
    int n;
    cin>>n;
    vector<int> l(n);
    vector<int> r(n);
    for(int i = 0;i < n;++i) {
        cin>>l[i]>>r[i];
    }
    sort(l.begin(),l.end());
    sort(r.rbegin(),r.rend());
    if(n%2==1){
        int lans=l[n/2];
        int rans=r[n/2];
        cout<<rans-lans+1<<endl;
    }
    else{
        int lans=l[n/2]+l[n/2-1];
        int rans=r[n/2]+r[n/2-1];
        cout<<rans-lans+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 4792
<?php
$count = trim(fgets(STDIN));
$out = 0;
for ($i = 0; $i < $count; $i++) {
    $n = trim(fgets(STDIN));
	$out = $out + isprime($n);
}
	print($out);
function isprime($n) {
	if ($n == 2) {
		return 1;
	} else if ($n % 2 == 0) {
		return 0;
	} else {
		$x = floor(sqrt($n));
		for ($i = 3; $x >= $i; $i+=2) {
			if ($n % $i == 0) {
				return 0;
				break;
			}
		}
		return 1;
	}
}
?>

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

int main(){
  long long N;
  cin >> N;
  vector<long long> divisor;
  long long ans=1000000000001;
  for(long long i=1; i*i<=N; i++){
    if(N%i==0){
      divisor.push_back(i);
      if(i*i!=N) divisor.push_back(N/i);
    }
  }
  for(long long i=0; i<divisor.size(); i++){
    ans=min(ans, divisor.at(i)+N/divisor.at(i)-2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
	
	public static void insertionSort(int[] A,int N) {
		
		for(int i=1;i<=N-1;i++) {
			int v = A[i];
			int j = i - 1;
			
			while(j >= 0 && A[j] > v) {
				A[j+1] = A[j];
				j--;
				A[j+1] = v;
			}
			
			int count = 0;
			for(int k : A) {
			System.out.print(k);
				if(count != N-1) {
					System.out.print(" ");
				}
				count++;
			}
			System.out.println();
		}
	}
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	
    	int N = sc.nextInt();
    	
    	int card[] = new int[N];
    	
    	for(int i=0;i<N;i++) 
    		card[i] = sc.nextInt();
    	
    	int count = 0;
    	for(int k : card) {
    			System.out.print(k);
    		if(count != N-1) {
    			System.out.print(" ");
    		}
    		count++;
    	}
    	System.out.println();
    	insertionSort(card,N);
    	
    }
}


Measured memory_bytes: 34164
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int i,j,k,l,n,m;
  cin>>n;
  int a[n];
  int dp[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
     dp[i]=-1;
  }
  dp[0]=0;
  dp[1]=abs(a[1]-a[0]);
  for(i=2;i<n;i++)
  {
    dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
  }
  cout<<dp[n-1];
  return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 1
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

lli dp[20030];

signed main(){

	REP(i,0,20030)dp[i]=INF;

	lli h,n;
	cin>>h>>n;

	dp[0]=0;

	REP(i,0,n){
		lli a,b;
		cin>>a>>b;
		REP(j,0,h+10){
			dp[j+a] = min(dp[j+a],dp[j]+b);
		}
	}

	lli ans=INF;
	for(lli i=h;i<=20020;i++)ans = min(ans,dp[i]);
	cout<<ans<<endl;

	return 0;
}

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

int main(void){
    int H, W;
        
    string hori;
    int i;
    while(!cin.eof()){
        cin >> H >> W;
        if(!H && !W) return 0;
        hori = string(W, '#');
        
        for(i = 0; i < H; i++){
            cout << hori << endl;
        }
        
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3088
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <set>
#include <queue>
#include <string>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int>  pii;
template<class T>
void read(T &res)
{
    res = 0;
    char c = getchar();
    T f = 1;
    while(c < '0' || c > '9')
    {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9')
    {
        res = res * 10 + c - '0';
        c = getchar();
    }
    res *= f;
} 
map<int,int> mm;
const ll mod = 1e9+7;
int gcd(int a,int b){return b == 0? a : gcd(b,a % b);}
ll getpow(ll a,ll b)
{
	ll ans = 0;
	while(b)
	{
		if(b & 1)
			ans = ans * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ans;
}

const int maxn = 2e5 + 5;
 
int main()
{
	int n;
	read(n);
	ll ans = 0;
	for (int  i= 1; i <= n; i ++ )
	{
		for (int j = 1; j <= n; j ++ )
		{
			for (int k = 1; k <= n; k ++ )
			{
				ans += gcd(i,gcd(k,j));
			}
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 3164
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn solve() {
    let n = get();
    let mut a: Vec<(i64, usize)> = Vec::new();
    for i in 0 .. n {
        let q = get();
        a.push((q, i));
    }
    a.sort();
    a.reverse();
    let mut cum = vec![0; n];
    cum[n - 1] = a[n - 1].0;
    for i in (0 .. n - 1).rev() {
        cum[i] = cum[i + 1] + a[i].0;
    }
    let mut cnt = 1;
    for i in 1 .. n {
        if a[i - 1].0 <= 2 * cum[i] {
            cnt += 1;
        } else {
            break;
        }
    }
    println!("{}", cnt);
    
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const double eps = 1e-9;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ")
{ if (!v.size()) puts(""); rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

lint k = in();
vector<lint> a(50);

signed main() {
  rep(i, 50) {
    a[i] = k / 50;
    if (i < k % 50) a[i]++;
  }

  rep(i, 50) {
    lint d = a[i];
    a[i] *= 50;
    a[i] += 49 - (k - d);
  }

  cout << 50 << endl;
  print(a);
}


Measured memory_bytes: 256
/**
  * Created by ui on 2016/02/07.
  */
object PrintARectangle2 {

  def run = {
    var x: Int = 0
    var y: Int = 0
    val sc = new java.util.Scanner(System.in)
    y = sc.nextInt
    x = sc.nextInt
    while (x != 0 || y != 0) {
      val s = "".padTo(x, '#')
      for (i <- 0 until y) println(s)
      println
      y = sc.nextInt
      x = sc.nextInt
    }
  }
}
/**
  * Created by ui on 2016/02/04.
  */
object Main {
  def main(args: Array[String]): Unit = {
    PrintARectangle2.run
  }
}

Measured memory_bytes: 45296
n = int(input())
x = list(map(int, input().split()))
x_max = max(x)
x_min = min(x)
sum_dif_ls =[]
for i in range(x_min, x_max+1):
    sum_dif = 0
    for j in x:
        dif = (i - j)**2
        sum_dif += dif
    sum_dif_ls.append(sum_dif)

print(min(sum_dif_ls))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define ll long long
const ll MOD=1000000007;
const long double PI=3.14159265358979323846264;
const ll MAX=0;

//void bfs(vector<vector<ll>> &G,ll x,ll &michi[]){
  

int main() {
  ll N,M;
  cin>>N>>M;
  vector<vector<ll>> G(N,vector<ll>(0));
  for(int i=0;i<M;i++){
    ll a,b;
    cin>>a>>b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  ll michi[N];
  for(int i=0;i<N;i++){
    michi[i]=0;
  }
 // bfs(G,0,michi);
 // michi[0]=1;
  queue<ll> q;
  q.push(0);
  while(!q.empty()){
    ll r=q.front();
    q.pop();
    for(int nr:G[r]){
      //ll nr=G[i];
      if(michi[nr]!=0){
        continue;
      }
      q.push(nr);
      michi[nr]=r+1;
    }
  }
  
  
  ll c=1;
  for(int i=1;i<N;i++){
    if(michi[i]==0){
      c=0;
      break;
    }
  }
  if(c){
    cout<<"Yes"<<endl;
    for(int i=1;i<N;i++){
      cout<<michi[i]<<endl;
    }
  }
  else{
    cout<<"No";
  }
       
}


Measured memory_bytes: 12996
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
       int sum = x;
       int ans = 1;
       while(sum%360!=0){
           sum+=x;ans+=1;
       }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35748
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
  int n; cin >> n;
  auto a = make_v(3 * n, 0LL);

  priority_queue<ll, vector<ll>, greater<ll>> p;
  priority_queue<ll> q;

  ll psum = 0, qsum = 0;
  REP(i, 3 * n){
    cin >> a[i];
    if(i < n){
      p.push(a[i]);
      psum += a[i];
    }
    if(2 * n <= i && i < 3 * n){
      q.push(a[i]);
      qsum += a[i];
    }
  }

  map<int, ll> pm, qm;
  pm[0] = psum; qm[0] = qsum;

  REP(i, n){
    p.push(a[n + i]); psum += a[n + i];
    psum -= p.top(); p.pop();
    pm[i + 1] = psum;

    q.push(a[2*n - 1 - i]); qsum += a[2* n - 1 - i];
    qsum -= q.top(); q.pop();
    qm[i + 1] = qsum;
  }

  ll ans = numeric_limits<ll>::min();
  FOR(i, 0, n+1){
    ll tmp = pm[i] - qm[n - i];
    ans = max(ans, tmp);
  }
  
  cout << ans << endl;

  return 0;
}


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


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);
}
bool root(string s){
    int n=s.length();
    if(n==2){
        if(s[0]==s[1]){
            return true;
        }
        else return false;
    }
    if(n==3){
        if(s[0]==s[2]){
            return true;
        }
        else return false;
    }
 
    return false;
}
 
 
//深さ優先
vector<int> seen;
vector<ll> h;
 
//普通の深さ優先探索seenを返す感じ
void dfs(const Graph &G,int v){
    seen[v] = 0; //v探索済み
 
    P good=make_pair(v,h[v]);
    for(auto next_v :G[v]){
        if(seen[next_v]!=-1) continue;//もう探索していた
        if(h[next_v]>good.second){
            good=make_pair(next_v,h[next_v]);
        }
        dfs(G,next_v);
    }
 
    if(!(h[v]==good.second && v==good.first)){
        seen[good.first]=1;
    }
}
 
signed main(){
    /*
    int n,m;
    cin>>n>>m;
 
    h.assign(n,0);
    rep(i,0,n) cin>>h[i];
 
    Graph G(n);
    rep(i,0,m){
        int a,b; cin>>a>>b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
 
    seen.assign(n,-1);
 
    rep(i,0,n){
        if(seen[i]==-1){
            dfs(G,i);
        }
    }
 
    int sum=accumulate(all(seen),0);
 
    cout<<sum<<endl;*/
 
    int x,y;
    cin>>x>>y;
    int ans=1;
    int pred=x;

    while(pred*2<=y){
        ans++;
        pred=pred*2;
    }

    cout<<ans<<endl;

}   

Measured memory_bytes: 256
import math
# print(math.ceil(float_var)) 切り上げ
# print(math.floor(float_var)) 切り捨て
a,b = map(int,input().split())
a_st = math.ceil(a /0.08) 
a_ed = math.ceil((a+1) /0.08) #含まない
b_st = 10*b
b_ed = 10*(b+1) #含まない
a_lis = list(range(a_st,a_ed))
b_lis = list(range(b_st,b_ed))
aandb = list(set(a_lis) & set(b_lis))
if len(aandb) == 0:
    print('-1')
else:
    print(min(aandb))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, m;
    cin >> n >> m;
    ll t = (n - m) * 100 + m * 1900;
    rep(i, m) t *= 2;
    cout << t << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void)
{
	int N, p, p_max = 100, p_sum = 0;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> p;
		if (p > p_max) p_max = p;
		p_sum += p;
	}
	p_sum -= p_max;
	p_sum += p_max / 2;
	cout << p_sum << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader

fun main(a: Array<String>) {
    val reader = BufferedReader(InputStreamReader(System.`in`))
    val args = reader.readLine().split(" ")
    val list = (0..2).map { args[it] }
    list.forEachIndexed { index, s ->
        if (list.count { it == list[index] } == 2) {
            println("Yes")
            return
        }
    }
    println("No")
}

Measured memory_bytes: 35756
#include<iostream>

int main(){

    long long a, b, c;
    std::cin >> a >> b >> c;

    if((c - a - b) > 0 && 4 * a * b < (c - a - b) * (c - a - b)){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int h, w;
char board[50][50];
int main(){
  cin >> h >> w;
  rep(i, h) rep(j, w) cin >> board[i][j];
  
  rep(i, h) rep(j, w){
    if(board[i][j] == '.'){
      int cnt = 0;
      for(int k = -1; k <= 1; k++){
        for(int l = -1; l <= 1; l++){
          if(k == 0 && l == 0) continue;
          if(i+k < 0 || i+k >= h || j+l < 0 || j+l >= w) continue;
          if(board[i+k][j+l] == '#') cnt++;
        }
      }
      board[i][j] = char(cnt + 48);
    }
  }
  rep(i, h){
    rep(j, w) cout << board[i][j];
    cout << endl;
  }
}

Measured memory_bytes: 256
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int dp[100000+10];
LL h[100000+10];
int n;
int main(){
	int res=-INF;
	cin>>n;
	rb(i,1,n) cin>>h[i];
	rl(i,n,1) {
		if(h[i]>=h[i+1]){
			dp[i]=dp[i+1]+1;
		}
		else{
			dp[i]=1;
		}
//		cout<<dp[i]<<" ";
		res=max(res,dp[i]);
	} 
	cout<<res-1<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <climits>

using namespace std;

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

  int cnt = 0;
  int min = INT_MAX;
  while (n--) {
    int tmp;
    cin >> tmp;
    if (min < tmp)
      continue;
    min = tmp;
    ++cnt;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    int H, W;
    cin >> H >> W;
    string S[H];

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

    int sum[H][W];

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            sum[i][j] = 0;
        }
    }

    for (int i = 0; i < H; i++) {
        int count = 0;
        int start = -1;
        for (int j = 0; j < W; j++) {
            if (S[i][j] == '.') {
                if (start < 0) start = j;
                count++;
            } else {
                if (start >= 0) {
                    for (int k = start; k < j; k++) {
                        sum[i][k] = count;
                    }
                }
                start = -1;
                count = 0;
            }
        }
        if (start >= 0) {
            for (int k = start; k < W; k++) {
                sum[i][k] = count;
            }
        }
    }

    for (int j = 0; j < W; j++) {
        int count = 0;
        int start = -1;
        for (int i = 0; i < H; i++) {
            if (S[i][j] == '.') {
                if (start < 0) start = i;
                count++;
            } else {
                if (start >= 0) {
                    for (int k = start; k < i; k++) {
                        sum[k][j] += count;
                    }
                }
                start = -1;
                count = 0;
            }
        }
        if (start >= 0) {
            for (int k = start; k < H; k++) {
                sum[k][j] += count;
            }
        }
    }

    int maximum = 0;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            maximum = max(maximum, sum[i][j] - 1);
        }
    }

    cout << maximum << endl;

    return 0;
}


Measured memory_bytes: 19968
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// 秒単位の時間 S が与えられるので、h:m:s の形式へ変換して出力してください。ここで、h は時間、m は 60 未満の分、s は 60 未満の秒とします。
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		int m = s/60%60;
		int h = s/3600;
		s = s%60;
		System.out.println(h + ":" + m + ":" + s);
	}
}

Measured memory_bytes: 17320
n=int(input())

A = list(map(int, input().split()))
l = [0] * len(A)

ans=0

for i in range(n-1):
  if A[i]>=A[i+1]:
    l[i+1]=A[i]-A[i+1]
    A[i+1]=A[i]
  else:
    l[i+1]=0
  ans=ans+l[i+1]  
print(ans)  


Measured memory_bytes: 32160
#AGC031-A
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
B=IL()
ans=[]
while True:
    flag=False
    for i in range(len(B)):
        if len(B)-i==B[-1-i]:
            ans=[B[-i-1]]+ans
            flag=True
            B.remove(B[-i-1])
            break
    if not flag:
        break
if len(ans)!=n:
    print(-1)
else:
    for i in range(n):
        print(ans[i])

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(), q=sc.nextInt();
		sc.nextLine();
		String str=sc.nextLine();
		char[] s=str.toCharArray();
		int cntAC[]=new int[n], prev=0;
		for(int i=0, cnt=0; i<n; i++) {
			if(s[i]=='A')
				prev=1;
			else if(s[i]=='C') {
				if(prev==1)
					cnt++;
				prev=0;
			}
			else
				prev=0;
			cntAC[i]=cnt;
		}
		for(int i=0; i<q; i++) {
			int l=sc.nextInt()-1, r=sc.nextInt()-1;
			System.out.println(cntAC[r]-cntAC[l]);
		}
	}
}

Measured memory_bytes: 67344
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int INF = 1e9 + 5;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
const ll mx = 1e9 + 7;
int main()
{
    int h, w;
    cin >> h >> w;
    char in[h + 1][w + 1];
    for(int i = 0; i < h; i++)
        scanf("%s",in[i]);
    ll dp[h + 1][w + 1] = {};
    dp[0][0] = 1;
    for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++)
        {
            if(in[i][j] != '#' && in[i + 1][j] != '#')
            {
                dp[i + 1][j] += dp[i][j];
                if(dp[i + 1][j] >=  mx /*- dp[i][j]*/) dp[i + 1][j] -= mx;
                   // dp[i + 1][j] += dp[i][j];
            }
            if(in[i][j] != '#' && in[i][j + 1] != '#')
            {
                dp[i][j + 1] += dp[i][j];
                if(dp[i][j + 1] >= mx/* - dp[i][j]*/) dp[i][j + 1] -= mx;
                //dp[i][j + 1] += dp[i][j];
            }
        }
    /*for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
            cout << dp[i][j] << ' ';
        cout << '\n';
    }*/
    cout << dp[h - 1][w - 1];
}


Measured memory_bytes: 9088
import sys
N, M, X = map(int, sys.stdin.readline().split())
D = 12*100001
m = D
Clst = []

for i in range(N):
    Ci = list(map(int, sys.stdin.readline().split()))
    Clst.append(Ci)

for i in range(2**N):
    ch = True
    buy = []
    total = 0
    for j in range(N):
        if ((i>>j)&1):
            buy.append(Clst[j])
            total += Clst[j][0]
            if total >= m:
                ch = False
                break

    if ch:
        for l in range(1,M+1):
            skill = 0
            for k in buy:
                skill = skill + k[l]

            if skill < X:
                ch = False
                break
    
    if ch:
        m = total
    

if m == D:
    print(-1)
else:
    print(m)

Measured memory_bytes: 9204
N = int(input())
A = [int(x) for x in input().split()]
B = sorted([A[i]-i for i in range(N)])
b = B[(N-1)//2] if N % 2 != 0 else (B[N//2-1]+B[N//2])//2
print(sum(abs(B[i]-b) for i in range(N)))


Measured memory_bytes: 25196
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

X = int(input())


def IsPrime(x: int) -> bool:
    i = 2
    while i ** 2 <= x:
        if x % i == 0:
            return False
            break
        i += 1
    else:
        return True


while not IsPrime(X):
    X += 1

print(X)


Measured memory_bytes: 9108
s = gets.chomp.to_s.split(//)
n = s.size
ary = Array.new(n + 1, 0)

i = 0
while i < n
  if s[i] == "<"
    ary[i+1] = ary[i] + 1
  end
  i += 1
end

i = n - 1

while i >= 0
  if s[i] == ">"
    ary[i] = [ary[i+1] + 1, ary[i]].max
  end
  i -= 1
end
puts ary.inject(:+)


Measured memory_bytes: 49412
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int l[m], r[m], d[m];
  for (int i = 0; i < m; i++) cin >> l[i] >> r[i] >> d[i];
  vector<P> info[n];
  for (int i = 0; i < m; i++) {
    info[l[i] - 1].push_back(P(r[i] - 1, d[i]));
    info[r[i] - 1].push_back(P(l[i] - 1, -d[i]));
  }
  int x[n];
  memset(x, -1, sizeof(x));
  string res = "Yes";
  for (int i = 0; i < n; i++) {
    queue<int> q;
    if (x[i] != -1) continue;
    else {
      x[i] = (int) 1e9;
      q.push(i);
    }
    while (q.size()) {
      int v = q.front();
      q.pop();
      for (auto p : info[v]){
        int u = p.first;
        if (x[u] == -1) {
          x[u] = x[v] + p.second;
          q.push(u);
        } else {
          if (x[u] != x[v] + p.second) {
            cout << "No" << "\n";
            return 0;
          }
        }
      }
    }
  }
  cout << res << "\n";
  return 0;
}

Measured memory_bytes: 11776
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<map>
#include<utility>
using namespace std;

class UnionFind
{
public:
	UnionFind(int sz) : size(sz), table(size, 0)
	{
		for(int i=0; i<size; i++)
			table[i] = i;
	};

	int f(int id)
	{
		if(id == table[id])
			return id;
		return table[id] = f(table[id]);
	};
	void u(int id1, int id2)
	{
		id1 = f(id1);
		id2 = f(id2);
		table[max(id1, id2)] = table[min(id1, id2)];
	};

private:
	const int size;
	vector<int> table;
};

int main(void)
{
	int N, K, L;
	cin >> N >> K >> L;

	UnionFind road(N);
	for(int i=0; i<K; i++)
	{
		int p, q;
		cin >> p >> q;

		p--;
		q--;
		road.u(p, q);
	}

	UnionFind train(N);
	for(int i=0; i<L; i++)
	{
		int r, s;
		cin >> r >> s;

		r--;
		s--;
		train.u(r, s);
	}

	map<pair<int, int>, int> table;
	for(int i=0; i<N; i++)
	{
		table[make_pair(road.f(i), train.f(i))]++;
	}

	cout << table.find(make_pair(road.f(0), train.f(0)))->second;
	for(int i=1; i<N; i++)
	{
		cout << " " << table.find(make_pair(road.f(i), train.f(i)))->second;
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 13568
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		char x = scn.next().charAt(0);
		switch(x){
		case 'A':
			System.out.println('T');
			break;
		case 'C':
			System.out.println('G');
			break;
		case 'G':
			System.out.println('C');
			break;
		case 'T':
			System.out.println('A');
			break;
		}
		scn.close();
	}
}

Measured memory_bytes: 21716
import sys
import math
import bisect
 
 
sys.setrecursionlimit(1000000000)
def input():
    return sys.stdin.readline().strip()
 
def iinput():
    return int(input())
 
def finput():
    return float(input())
 
def tinput():
    return input().split()
 
def rinput():
    return map(int, tinput())
 
def rlinput():
    return list(rinput())
 
def modst(a, s):
    res = 1
    while s:
        if s % 2:
            res *= a
        a *= a
        s //= 2
    return res

 
def main():
    a, b = rinput()
    if a >= 10 or b >= 10:
        print(-1)
    else:
        print(a * b)
main()

Measured memory_bytes: 38384
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int d4x[4] = {0,1,0,-1};
int d4y[4] = {1,0,-1,0};

int main(){
	int H,W;
	cin>>H>>W;
	char nap[H+2][W+2];
	REP(i,H)REP(j,W)cin>>nap[i][j];
	// REP(i,H){REP(j,W)cout<<nap[i][j];cout<<endl;}
	int ans = 0;
	REP(i,H)REP(j,W){
		if(nap[i][j] == '#')continue;
		vector<vector<int>> e_ans(H+2,vector<int>(W+2,inf));
		queue<ip> Q;
		Q.push(make_pair(i, j));
		e_ans[i][j] = 0;
		// cout<<"-------"<<endl;
		// REP(k,H){REP(l,W)cout<<e_ans[k][l];cout<<endl;}
		// cout<<"-------"<<endl;
		while(!Q.empty()){
			int y = Q.front().first, x = Q.front().second;
			Q.pop();
			rep(k,4){
				int dy = y + d4y[k], dx = x + d4x[k];
				if(nap[dy][dx] == '.' && e_ans[dy][dx] == inf){
					e_ans[dy][dx] = e_ans[y][x] + 1;
					Q.push(make_pair(dy, dx));
				}
			}
		}
		// cout<<"-------"<<endl;
		// REP(k,H){REP(l,W)cout<<e_ans[k][l];cout<<endl;}
		// cout<<"-------"<<endl;
		int t_ans = 0;
		REP(k,H)REP(l,W){
			if(e_ans[k][l] == inf)continue;
			t_ans = max(t_ans, e_ans[k][l]);
		}
		ans = max(ans, t_ans);
	}
	cout<<ans<<endl;
	return 0;
}

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

template <typename T>
class binary_heap {
	vector<T> data;
public:
	binary_heap() : data(1) {}
	int size() const {
		return data.size() - 1;
	}
	T top() const {
		assert(data.size() > 1);
		return data[1];
	}
	void push(T x) {
		int p = data.size(), t;
		data.push_back(x);
		while ((t = p >> 1) > 0 && data[t] < x) {
			data[p] = data[t];
			p = t;
		}
		data[p] = x;
	}
	void pop() {
		assert(data.size() > 1);
		data[1] = data.back();
		data.pop_back();
		if (data.size() == 1) return;
		int p = 1;
		while (true) {
			int t = p, l = p << 1, r = l + 1;
			if (l < (int)data.size() && data[t] < data[l]) t = l;
			if (r < (int)data.size() && data[t] < data[r]) t = r;
			if (t == p) break;
			swap(data[p], data[t]);
			p = t;
		}
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	char com[8];
	binary_heap<int> pq;
	while (scanf("%s", com), com[2] != 'd') {
		if (com[0] == 'i') {
			int val;
			scanf("%d", &val);
			pq.push(val);
		}
		else {
			int val = pq.top(); pq.pop();
			printf("%d\n", val);
		}
	}
	return 0;
}



Measured memory_bytes: 7012
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
const int mo=1000000007;
const int N=5005;
int n,a[N],f[2][N];
int fa[N],fl[N],sz[N];
int get(int x){
	return x==fa[x]?x:fa[x]=get(fa[x]);
}
int power(int x,int y){
	int s=1;
	for (;y;y/=2,x=1ll*x*x%mo)
		if (y&1) s=1ll*s*x%mo;
	return s; 
}
int main(){
	scanf("%d",&n);
	For(i,1,n) scanf("%d",&a[i]);
	For(i,1,n) fa[i]=i,fl[i]=0,sz[i]=1;
	For(i,1,n) if (a[i]!=-1){
		int x=get(i),y=get(a[i]);
		if (x!=y) fa[x]=y,sz[y]+=sz[x],fl[y]|=fl[x];
		else fl[x]|=1;
	}
	int sum=0,pre=0,suf=1;
	For(i,1,n) if (a[i]==-1) ++sum;
	int ans=1ll*power(n-1,sum)*n%mo;
	For(i,1,n) if (get(i)==i&&fl[i]==1)
		ans=(ans+mo-power(n-1,sum))%mo;
	//cout<<ans<<endl;
	f[0][0]=1;
	For(i,1,n) if (get(i)==i&&!fl[i]){
		//cout<<sz[i]<<' '<<i<<endl;
		memset(f[suf],0,sizeof(f[suf]));
		For(j,0,n){
			f[suf][j+1]=(f[suf][j+1]+1ll*f[pre][j]*sz[i])%mo;
			f[suf][j]=(f[suf][j]+1ll*f[pre][j]*(n-1))%mo;
		}
		swap(pre,suf);
	}
	if (sum) f[pre][1]=(f[pre][1]+mo-1ll*sum*power(n-1,sum-1)%mo)%mo;
	For(i,1,n){
		int val=f[pre][i];
		For(j,1,i-1) val=1ll*val*j%mo;
		ans=(ans+mo-val)%mo;
	}
	printf("%d\n",ans);
	
}

Measured memory_bytes: 3944
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n,k;
    cin >> n >> k;
    vi h(n);
    rep(i,n) cin >> h[i];
    sort(h.begin(),h.end());
    int ans=INF;
    for(int i=0;i+k-1<n;i++){
        ans = min(ans,h[i+k-1]-h[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace CaracalVSMonster
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();            
            long monsterHealth = long.Parse(input);
 
            List<long> monster = new List<long>();
            long monstersNumber = 1;
            long attacksMade = monsterHealth / 2;
            while (monsterHealth >= 1)
            {
                monsterHealth /= 2;
                monster.Add(monstersNumber);
                monstersNumber *= 2;                    
            } 
              
            Console.WriteLine(monster.Sum());
        }
    }
}

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

int main(void) {
    int H,W;
    vector<int> dx = {-1,0,0,1};
    vector<int> dy = {0,-1,1,0};
    bool check;

    cin >> H >> W;
    
    vector<string> s(H);
    for(int i=0;i<H;i++) {
        cin >> s[i];
    }

    
    for(int i=0;i<H;i++) {
        for(int j=0;j<W;j++) {
            if(s[i][j] == '#') {
                check = false;
                for(int k=0;k<4;k++) {
                    if((i+dx[k]) < 0 || (i+dx[k]) >= H || (j+dy[k]) < 0 || (j+dy[k]) >= W) continue;
                    if(s[i+dx[k]][j+dy[k]] == '#')check = true;
                }
                if(!check) {
                    cout << "No\n";
                    return 0;
                }
            }
        }
    }

    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 256
import Control.Applicative

main = do xs <- map (map read . words) . lines <$> getContents
          putStr . unlines . filter (/= "") $ map solve xs

solve :: [Int] -> String
solve (n:x:_) | n==0 && x==0 = ""
              | otherwise = show $ sum [1| a<-[1..n],b<-[1..n],c<-[1..n],a<b && b<c , a+b+c == x]    

Measured memory_bytes: 5264
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;

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

int b = (X - K) + 1;
int a = (X + K) - 1;

for(int i = b; i <= a; i++) cout << i << ' ';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);
const int INF = numeric_limits<int>::max();



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

    set<int> count;

    for (int i = 1; i <= k; ++i){
        int d;
        cin >> d;
        for (int j = 1; j <= d; ++j){
            int a;
            cin >> a;
            count.insert(a);
        }
    }

    cout << n - count.size() << endl;

}

Measured memory_bytes: 3600
#include<stdio.h>
#include<math.h>

int main(void)
{
   int n, i, f, s, x=0, r;

   scanf("%d",&n);

   for(i=1;i<=n;i=i+2){
      s=0;
      r=sqrt(i);
      for(f=1;f<=r;f++)
         if(i%f==0)
            s++;
      if((s==4)&&(i!=r*r)){
         x++;
      }
   }

   printf("%d\n",x);
   return 0;
}

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

const int INF = 1001001001;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
int main() {
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    int ans = 0;
    rep(si, h)rep(sj, w){
        if (s[si][sj] == '#') continue;
        vector<vector<int>> dist(h, vector<int>(w, INF));
        queue<P> q;
        auto update = [&](int i, int j, int x) {
            if (dist[i][j] != INF) return;
            dist[i][j] = x;
            q.push(P(i,j));  
        };
        update(si, sj, 0);
        while (!q.empty())
        {
            int i = q.front().first;
            int j = q.front().second; q.pop();
            rep(dir, 4){
                int ni = i + di[dir], nj = j + dj[dir];
                if (ni<0 || ni>= h||nj<0||nj>=w) continue;
                if (s[ni][nj] == '#') continue;
                update(ni ,nj, dist[i][j]+1);
            }
        }
        rep(i,h)rep(j,w){
            if (dist[i][j] == INF) continue;
            ans = max(ans , dist[i][j]);
        }
    }
    cout << ans << endl;
    return 0; 
        
    
}

Measured memory_bytes: 256
import scala.io.{StdIn => in}

object Main extends App {
  val n = in.readLine.toLong

  def rec(i:Long, cnt:Long, b:Long): Long = {
    if(i < 10L) cnt
    else rec(i / b, cnt + i / 2L / b, b)
  }

  val ans = if(n % 2 == 1) 0 else rec(n, 0L, 5L)
  println(ans)
}

Measured memory_bytes: 25396
#include<bits/stdc++.h>
using namespace std;
int n,k;
long long f[2005][2005],fac[4000005],inv_fac[4000005];
inline long long C(int n,int m)
{ 
	return (((fac[m]*inv_fac[n])%1000000007)*inv_fac[m-n])%1000000007; 
}
long long power(long long x,int p)
{
    long long ans=1,m=x;
    while(p)
	{
        if(p%2==1) 
		{
        	ans*=m;
			ans%=1000000007;
		}
		p/=2;
		m*=m;
		m%=1000000007;
    }
    return ans;
}
int main()
{
    scanf("%d%d",&n,&k);
    if(k==1)
	{ 
		printf("%d\n",1); 
		return 0; 
	}
    fac[0]=1; 
	for(register int i=1;i<=4000005;i++) 
		fac[i]=(fac[i-1]*i)%1000000007;
    inv_fac[4000005]=power(fac[4000005],1000000005); 
	for(register int i=4000004;i>=0;i--) 
		inv_fac[i]=(inv_fac[i+1]*(i+1))%1000000007;
    f[0][0]=1;
    for(register int i=1;i<=n;i++)
	{
        for(register int j=0;j<=i;j++)
		{
            f[i][j]=f[i-1][j];
            if(!j) 
				continue;
            (f[i][j]+=f[i][j-1]*(n-j+1)%1000000007*C(k-2,n-i+(n-j+1)*(k-1)-1)%1000000007)%=1000000007;
        }
    }
    printf("%lld\n",f[n][n]);
    return 0;
}

Measured memory_bytes: 94080
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<cstring>
#include<climits>
#include<algorithm>
#define ll long long int
using namespace std;
int main(){
	ll ans=0;
	int k;
	cin>>k;
	for(int i=1;i<=k;i++){
		for(int j=1;j<=k;j++){
			for(int l=1;l<=k;l++){
				ans+=__gcd(i,__gcd(j,l));
			}
		}
	}
	cout<<ans<<endl;
	}

Measured memory_bytes: 3640
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#define mod 1000000007
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void write(int x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
struct node
{
	int x,y,next;
}a[10010];int len,last[5010];
inline void ins(int x,int y)
{
	len++;
	a[len].x=x;a[len].y=y;
	a[len].next=last[x];last[x]=len;
}
int n,f[2][5010],tot[5010],ans,p,cnt;
inline void dfs(int x,int fa)
{
	tot[x]=1;int mx=0;
	for(int k=last[x];k;k=a[k].next)
	{
		int y=a[k].y;
		if(y==fa)continue;
		dfs(y,x);
		tot[x]+=tot[y];
		mx=max(mx,tot[y]);
	}mx=max(mx,n-tot[x]);
	if(mx<ans)ans=mx,p=x,cnt=1;
	else if(mx==ans)cnt++;
}
inline void update(int x,int fa)
{
	tot[x]=1;
	for(int k=last[x];k;k=a[k].next)
	{
		int y=a[k].y;
		if(y==fa)continue;
		update(y,x);
		tot[x]+=tot[y];
	}
}
int fac[5010],inv[5010];
inline int C(int m,int n){return 1LL*fac[m]*inv[n]%mod*inv[m-n]%mod;}
inline int A(int m,int n){return 1LL*fac[m]*inv[m-n]%mod;}
inline int power(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}return ans;
}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    fac[0]=1;
    for(int i=1;i<=5000;i++)fac[i]=1LL*fac[i-1]*i%mod;inv[5000]=power(fac[5000],mod-2);
    for(int i=5000;i>=1;i--)inv[i-1]=1LL*inv[i]*i%mod;
    n=read();
	for(int i=1;i<n;i++)
	{
		int x=read(),y=read();
		ins(x,y),ins(y,x);
	}ans=n;
	dfs(1,0);
	if(cnt==2)pr2(1LL*fac[n/2]*fac[n/2]%mod);
	else
	{
		update(p,0);int now=1;
		f[0][0]=1;int he=0;
		for(int k=last[p];k;k=a[k].next)
		{
			int y=a[k].y;he^=1;
			memset(f[he],0,sizeof(f[he]));
			for(int i=now;i>=0;i--)
			{
				for(int j=0;j<=tot[y];j++)(f[he][i+j]+=1LL*f[he^1][i]*C(tot[y],j)%mod*A(tot[y],j)%mod)%=mod;
			}now+=tot[y];
		}
		for(int i=0;i<=now;i++)f[he][i]=1LL*f[he][i]*fac[now-i]%mod;
		int ans=0,id=1;
		for(int i=0;i<=now;i++)(ans+=(f[he][i]*id+mod)%mod)%=mod,id=-id;	
		pr2(ans);
	}
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,M[MAX][MAX];

void dijkstra()
{
  int minv;
  int d[MAX],color[MAX];

  for(int i=0;i<n;i++)
    {
      d[i]=INFTY;
      color[i]=WHITE;
    }

  d[0]=0;
  color[0]=GRAY;
  while(1)
    {
      minv=INFTY;
      int u=-1;
      for(int i=0;i<n;i++)
	{
	  if(minv>d[i]&&color[i]!=BLACK)
	    {
	      u=i;
	      minv=d[i];
	    }
	}
      if(u==-1)break;
      color[u]=BLACK;
      for(int v=0;v<n;v++)
	{
	  if(color[v]!=BLACK&&M[u][v]!=INFTY)
	    {
	      if(d[v]>d[u]+M[u][v])
		{
		  d[v]=d[u]+M[u][v];
		  color[v]=GRAY;
		}
	    }
	}
    }
  for(int i=0;i<n;i++)
    {
      cout<<i<<" "<<(d[i]==INFTY?-1:d[i])<<endl;
    }
}

int main()
{
  cin>>n;
  for(int i=0;i<n;i++)
    {
      for(int j=0;j<n;j++)
	M[i][j]=INFTY;
    }

  int k,c,u,v;
  for(int i=0;i<n;i++)
    {
      cin>>u>>k;
      for(int j=0;j<k;j++)
	{
	  cin>>v>>c;
	  M[u][v]=c;
	}
    }

  dijkstra();

  return 0;
}



Measured memory_bytes: 3128
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**8) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def find_last_one(n: int):
    nbin = bin(n)[2:]
    return 29 - nbin[::-1].index('1')

# 入力
n = ni()
a = [ni() for _ in range(n)]

# aiについて、1のbitともっとも下の1のbit記録
onebit = [0]*30
lastonebit = [0]*30

for ai in a:
    lastonebit[find_last_one(ai)] += 1
    for mask in range(30):
        if ai & (1<<mask):
            onebit[29-mask] += 1

# 上位桁から確定させていく
ans = 0
for digit in range(30):
    if onebit[digit] % 2 == 0:
        continue
    
    elif lastonebit[digit] == 0:
        ans = -1
        break
    
    else:
        ans += 1
        onebit[digit] -= 1
        for d in range(digit+1, 30):
            onebit[d] += 1
            
print(ans)
            

Measured memory_bytes: 7072
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Compaision5_1
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = Console.ReadLine();
            string b = Console.ReadLine();

            if (a == b)
            {
                Console.WriteLine("EQUAL");
            }

            if (a.Length == b.Length)
            {
                for (int i = 0; i < a.Length; i++)
                {
                    if (Convert.ToInt32(a[i]) > Convert.ToInt32(b[i]))
                    {
                        Console.WriteLine("GREATER");
                        break;
                    }
                    if (Convert.ToInt32(a[i]) < Convert.ToInt32(b[i]))
                    {
                        Console.WriteLine("LESS");
                        break;
                    }

                }
                
            }
                

                if (a.Length > b.Length)
                {
                    Console.WriteLine("GREATER");
                }
                if(a.Length < b.Length)
                {
                    Console.WriteLine("LESS");
                }
            

            
        }
    }
}


Measured memory_bytes: 13140
import java.util.Scanner;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int gcd;
        
        gcd = gojoho(x,y);
        System.out.println(gcd);
    }
        
    private static int gojoho(int x,int y){
        while(true){
            if(x >= y){
                x = x % y;
            }else{
                y = y % x;
            }
        	if(x == 0 || y == 0){
        		break;
        	}
        }
    	int gcd;
    	if(x == 0){
    		gcd = y;
    	}else{
    		gcd = x;
    	}
        return gcd;
    }
}


Measured memory_bytes: 26312
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<string> S(N);
  for(int i=0;i<N;++i) cin>>S[i];
  vector<vector<int> > edge(N);
  for(int i=0;i<N;++i){
    for(int j=0;j<N;++j){
      if(S[i][j]=='1') edge[i].push_back(j);
    }
  }
  queue<int> que, numque;
  int state, num;
  int ans = -1;
  int tmp;
  bool can = true;
  for(int i=0;i<N;++i){
    que.push(i);
    numque.push(1);
    map<int, int> amap;
    while(!que.empty()){
      state = que.front();que.pop();
      num = numque.front();numque.pop();
      if(amap[state]!=0) continue;
      amap[state] = num;
      for(int i=0;i<edge[state].size();++i){
        if(amap[edge[state][i]]!=0) {
          if(abs(amap[edge[state][i]]-num)!=1) can = false;
          continue;
        }
        que.push(edge[state][i]);
        numque.push(num+1);
      }
    }
    tmp = 0;
    for(int i=0;i<N;++i){
      tmp = max(tmp, amap[i]);
    }
    ans = max(ans, tmp);
  }
  if(can) cout<<ans<<endl;
  else cout<<-1<<endl;
}



Measured memory_bytes: 3928