akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>

using namespace std;

#define ll long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());




int main() {
    int N, K;
    string S;
    cin >> N >> K >> S;
    K--;
    S[K] = tolower(S[K]);


    cout << S << endl;


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;

int counter(int x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

int main(){
  int N;cin>>N;
  int A[N];
  int x[20][20];
  int y[20][20];
  int a;
  rep(i,N){
    cin>>A[i];
    rep(j,A[i]){
      cin>>a>>y[i][j];
      x[i][j]=a-1;
    }
  }
  int ans=0;
  rep(i,(1 << N)){
    bool ok=1;
    rep(j,N){
      if(!(i&(1<<j))) continue;
      rep(k,A[j]){
        if(y[j][k]==0 && (i&(1<<x[j][k]))){
          ok=0;
        }
        if(y[j][k]==1 && !(i&(1<<x[j][k]))){
          ok=0;
        }
      }
    }
    if(ok){
      ans=max(ans,counter(i));
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define x1 ahdhasd
#define x2 isdhfisdf
#define y1 osafoijsdgd
#define y2 sjbfdd

char A[8005], B[8005];
int sa[8005], sb[8005];
int n;
LL ans;

int tl[8005], tr[8005];

int getSumA(int l, int r){
	return sa[r] - (l?sa[l-1]:0);
}

int getSumB(int l, int r){
	return sb[r] - (l?sb[l-1]:0);
}

bool ada(int l, int r){
	if(l>r) swap(l,r);
	return getSumB(l,r)>0;
}

void prec(){
	tl[0] = 0;
	for(int i = 1; i < n*3; i++ ){
		if(B[i]=='1') tl[i] = 0;
		else tl[i] = tl[i-1]+1;
	}
	tr[n*3-1] = 0;
	for(int i = n*3-2; i >= 0; i-- ){
		if(B[i]=='1') tr[i] = 0;
		else tr[i] = tr[i+1]+1;
	}
}

vector<int> loc[8005];

void coba(int diff){
	// printf("now %d\n",diff);
	for(int i = 0; i < 8005; i++ ) loc[i].clear();
	// base: n
	vector<int> cand;
	vector<pair<int,int> > vcand;
	LL res = diff<0?-diff:diff;
	for(int i = n; i < n*2; i++ ){
		if(B[i+diff] == '1'){
			if(A[i] == '0'){
				res++;
			}
		}
		else{
			if(A[i] == '0'){
				// do nothing
			}
			else{
				if(ada(i,i+diff)){
					// update tengah jalan
					res++;
				}
				else{
					cand.push_back(i);
				}
			}
		}
	}
	if(cand.empty()){
		ans = min(ans,res);
		return;
	}
	// printf("res %lld\n",res);
	for(int i : cand){
		// printf("cand %d\n",i);
		int j = i+diff;
		if(diff>=0) vcand.emplace_back(tl[i], tr[j]);
		else{
			vcand.emplace_back(tr[i], tl[j]);
		}
	}
	for(auto i : vcand){
		// printf("vcand %d %d\n",i.first,i.second);
		loc[i.first].push_back(i.second);
	}
	LL mn = n;
	int r = 0;
	for(int l = n; l >= 0; l--){
		mn = min(mn, (LL)r+l);
		for(int i : loc[l]) r = max(r, i);
	}
	res += mn*2;
	// printf("mn %lld\n",mn);
	// printf("%d: %lld\n",diff,res);
	ans = min(ans,res + (LL)cand.size());
}

bool valid(){
	int na = 0, nb = 0;
	for(int i = 0; i < n; i++ ) na += A[i]-'0', nb += B[i]-'0';
	if(nb==0){
		if(na==0) return true;
		else return false;
	}
	return true;
}

int main(){
	ans = (LL)1e18;
	scanf("%s%s",A,B);
	n = strlen(A);
	if(!valid()){
		printf("-1\n");
		return 0;
	}
	for(int i = 0; i < n; i++ ){
		A[i+n] = A[i+n*2] = A[i];
		B[i+n] = B[i+n*2] = B[i];
		sa[i] = sa[i+n] = sa[i+n*2] = A[i]-'0';
		sb[i] = sb[i+n] = sb[i+n*2] = B[i]-'0';
	}
	for(int i = 1; i < n*3; i++ ){
		sa[i] += sa[i-1];
		sb[i] += sb[i-1];
	}
	prec();
	for(int i = -n+1; i < n; i++ ){
		coba(i);
	}

	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
      public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int element = scanner.nextInt();

int[] numbers = new int[element];

for(int i=0 ; i<=element-1; i++){
numbers[i] = scanner.nextInt();

}

int count = 0;
boolean isEven =true;

scanner = null;
System.gc();

while(isEven){
for(int i=0 ; i<=element-1; i++){
if(numbers[i]%2 == 0){
	numbers[i] = numbers[i]/2;

}else{
isEven = false;
}

if(i == element-1 && isEven){
count++;
}

}
}
System.out.println(count);

      }
}

Measured memory_bytes: 37972
#include <stdio.h>

int main(){
    int n, high, medium, low, ans;

    scanf("%d", &n);

    low = n % 10;
    n /= 10;
    medium = n % 10;
    n /= 10;
    high = n;

    if(high == 9)
        high = 1;
    else
        high = 9;
    
    if(medium == 9)
        medium = 1;
    else   
        medium = 9;

    if(low == 9)
        low = 1;
    else
        low = 9;

    ans = high * 100 + medium * 10 + low;

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#include <iomanip>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class BDigitalGifts {
public:
	void solve(istream& in, ostream& out) {
        int n; in >> n;
        vector<double> x(n);
        vector<string> u(n);
        rep(i,n) in >> x[i] >> u[i];

        double ans = 0;
        rep(i,n){
            if(u[i] == "JPY") ans += x[i];
            else ans += x[i] * 380000;
        }
        out << fixed << setprecision(10) << ans << endl;
	}
};

int main() {
	BDigitalGifts solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

int main(){
  ll n;
  cin >> n;
  ll now = n;
  string s;
  while(1){
    ll num = (now-1) % 26;
    s.push_back(char('a' + (num)));
    now -= num;
    now /= 26;
    if (now == 0) break;
  }
  reverse(s.begin(), s.end());
  cout << s << endl;
  
  return 0;
}

Measured memory_bytes: 3628
import sys

l = raw_input().split()
S = l[0]

l = len(S)

acgt = ['A', 'C', 'G', 'T']

def acgt_len(S):
    l = 0
    for s in S:
        if s not in acgt:
            return l
        l += 1
    return l

max_len = 0
for i in range(l):
    for j in range(l - i):
        l = acgt_len(S[j:])
        max_len = max(max_len, l)

print(max_len)


Measured memory_bytes: 2568
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,Q=map(int,input().split())
    E=[[] for _ in range(n)]
    for _ in range(n-1):
        u,v=map(int,input().split())
        u-=1; v-=1
        E[u].append(v)
        E[v].append(u)

    ans=[0]*n
    for _ in range(Q):
        v,x=map(int,input().split())
        v-=1
        ans[v]+=x

    # DFS で子に伝播させる
    Q=[(0,-1)]
    while(Q):
        v,p=Q.pop()
        for nv in E[v]:
            if(nv==p): continue
            ans[nv]+=ans[v]
            Q.append((nv,v))

    print(*ans)
resolve()

Measured memory_bytes: 97024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <iomanip>
using namespace std;

#define pi 3.141592653589

int main(){
	int H, W;
	while (cin >> H >> W)
	{
		if (H == 0 && W == 0) break;
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  bitset<1'000'000> bs;
  bs.set();
  bs[0] = bs[1] = false;
  for (int p = 2; p <= 1000; ++p) {
    for (int i = p * p; i < 1'000'000; i += p) bs[i] = false;
  }
  string s;
  while (getline(cin, s)) {
    int n = stoi(s);
    int res = 0;
    for (int i = 0; i <= n; ++i) res += bs[i];
    cout << res << '\n';
  }
}


Measured memory_bytes: 3320
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  int n;
  cin>>n;
  if(n<30)
    cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 3628
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
//#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
#include <math.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int64_t n, d;
  cin >> n >> d;
  vector<int64_t> x(n);
  vector<int64_t> y(n);
  rep(i, n) {
    int64_t xx, yy;
    cin >> xx >> yy;
    x.at(i) = xx;
    y.at(i) = yy;
  }
  int count = 0;
  rep(i, n) {
    if (x.at(i)*x.at(i) + y.at(i)*y.at(i) <= d*d) {
      count++;
    }
  }
  cout << count << endl;
  
}



Measured memory_bytes: 6424
fn read_line() -> String {
    use std::io::stdin;
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    s
}

use std::str::FromStr;
use std::fmt::Debug;

fn parse3<T: FromStr>(s: String) -> (T, T, T) where <T as FromStr>::Err: Debug {
    let mut it = s.split_whitespace();
    let a = it.next().unwrap().parse().unwrap();
    let b = it.next().unwrap().parse().unwrap();
    let c = it.next().unwrap().parse().unwrap();
    (a, b, c)
}

fn parse_all<T: FromStr>(s: String) -> Vec<T> where <T as FromStr>::Err: Debug {
    s.split_whitespace().map(|e| e.parse().unwrap()).collect()
}

const LARGE: usize = 100000 * 2000;

fn dfs(roads: &Vec<Vec<usize>>, targets: &Vec<usize>, visited: &mut Vec<bool>, arr: &mut Vec<usize>, depth: usize) -> usize {
    let r = arr.len();
    let mut best = LARGE;
    if depth == r {
        let mut x = 0;
        for i in 1..r {
            x += roads[arr[i-1]][arr[i]];
        }
        //println!("{:?}: {}", arr, x);
        return x;
    } else {
        for i in 0..r {
            if !visited[i] {
                visited[i] = true;
                arr[depth] = targets[i];
                let v = dfs(roads, targets, visited, arr, depth + 1);
                if v < best {
                    best = v;
                }
                visited[i] = false;
            }
        }
        return best;
    }
}

fn main() {
    let (n, m, r) = parse3::<usize>(read_line());
    let targets: Vec<usize> = parse_all(read_line());
    let mut roads: Vec<Vec<usize>> = vec![vec![LARGE; n+1]; n+1];
    for i in 1..n+1 {
        roads[i][i] = 0;
    }
    for _ in 0..m {
        let (a, b, c) = parse3::<usize>(read_line());
        roads[a][b] = c;
        roads[b][a] = c;
    }
    // Warshall-Floyd
    for k in 1..n+1 {
        for i in 1..n+1 {
            for j in 1..n+1 {
                if roads[i][j] > roads[i][k] + roads[k][j] {
                    roads[i][j] = roads[i][k] + roads[k][j];
                    roads[j][i] = roads[i][j];
                }
            }
        }
    }
    let mut visited = vec![false; r];
    let mut arr = vec![0; r];
    let result = dfs(&roads, &targets, &mut visited, &mut arr, 0);
    println!("{}", result);
}

Measured memory_bytes: 4352
#include <stdio.h>
int main(){
  int a=0,b=0,c=0,d=0;
  scanf("%d%d%d",&a,&b,&c);
  if((a>=b)&&(a>=c))d=10*a+b+c;
  if((b>=a)&&(b>=c))d=10*b+a+c;
  if((c>=a)&&(c>=b))d=10*c+a+b;
  printf("%d",d);
  
  return 0;
}


Measured memory_bytes: 128
import sys
input = sys.stdin.readline

_n = int(input())
_dlist = list(map(int, input().split()))


def chker(n, dlist):
    if dlist[0] != 0:
        print(0)
        return

    ds = dlist[1:]
    ds.sort()
    cntlist = [0] * n
    if ds[0] != 1:
        print(0)
        return

    cntlist[ds[0]] = 1
    for i in range(1, n - 1):
        if ds[i] <= ds[i - 1] + 1:
            cntlist[ds[i]] += 1
        else:
            print(0)
            return

    ans = 1
    for i in range(2, n):
        ans = (ans * cntlist[i - 1] ** cntlist[i]) % 998244353

    print(ans)


chker(_n, _dlist)


Measured memory_bytes: 13420
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <stdio.h>
#include <queue>
#include <cmath>
#include <utility>
#include <map>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<int> vecint;
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)

#define MAX_V 200
#define INF 1e+9

struct edge {
	int to;
	int cost;
};

typedef struct Edge {
	int cost;
	int to;
	int from;
};

bool operator < (Edge a, Edge b) {
	return a.cost > b.cost;


}
// <最短距離, 頂点の番号>
using P = pair<int, int>;

int V;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d + V, INF);
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;

		for (int i = 0; i < G[v].size(); ++i) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main() {
	int i, N, M, j,k;
	ll R;
	ll E;
	cin >> V >> E >> R;
	int r[10]  = { 1,2,50,4,100,6,7,199 };

	//V = 200; E = V * (V - 1) / 2;
	//int r[10]  = { 1,2,50,4,100,6,7,199 };
	//int A[200][200] = { {0} };
	//rep(i, 0, 200)rep(j, 0, 200) {
	//	A[i][j] = (i + 1)*(j + 1);
	//	if (i == j)
	//		A[i][j] = 0;
	//	edge e = { j, A[i][j]};
	//	G[i].push_back(e);
	//	e = { i,A[i][j] };
	//	G[j].push_back(e);
	//}
	//R = 8;
	rep(i, 0, R) {
		cin >> r[i];
		r[i] -= 1;
	}
	rep(i, 0, E) {
		int a, b,c;
		cin >> a >> b >> c;
		edge e = { --b,c };
		G[--a].push_back(e);
		e = { a,c };
		G[b].push_back(e);
	}
	int D[10][10];
	rep(i, 0, R)rep(j, 0, R)D[i][j] = INF;

	rep(i, 0, R) {
		dijkstra(r[i]);
		rep(j, 0, R) {
			D[i][j] = d[r[j]];
		}
	}
	G->clear();
	priority_queue<Edge> Q;
	rep(i, 0, R) {
		rep(j, i, R) {
			Edge E = { D[i][j],i,j };
			Q.push(E);
			
		}
	}
		
	ll ans = INF;
	vector<int> A;
	ll rr = 1;
	A.push_back(1);
	rep(i, 2, R + 1) {
		rr *= i;
		A.push_back(i);
	}
	for (i = 0; i < rr; i++) {
		ll temp = 0;
		next_permutation(A.begin(), A.end());
		for (j = 0; j < R - 1; j++) {
			temp += D[A[j]-1][A[j + 1]-1];

		}
		ans = MIN(ans, temp);

	}
	cout << ans;
	return 0;
}



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

using namespace std;

#define ll long long


int main() {
    cin.tie();
    ios_base::sync_with_stdio(false);
    string s, t;
    cin >> s ;

    for (int i = 0; i < s.length(); i++) cout << 'x';
    return 0;
}

Measured memory_bytes: 256
INF = 9999999999999999999999999999

h, w, d = gets.chomp.split.map(&:to_i)
matrix = Array.new(h) { gets.chomp.split.map(&:to_i) }
 
memos = Array.new(h * w + 1).tap do |y|
  matrix.each.with_index do |row, i|
    row.each.with_index do |num, j|
      y[num] = [i, j]
    end
  end
end

sums = Array.new(h * w + 1, 0)
(d+1..h*w).each do |i|
  x1, y1 = memos[i]
  x2, y2 = memos[i-d]
  sums[i] = sums[i-d] + (x1 - x2).abs + (y1 - y2).abs
end

tests = Array.new(gets.chomp.to_i) { gets.chomp.split.map(&:to_i) }
tests.each do |l, r|
  puts sums[r] - sums[l]
end


Measured memory_bytes: 18300
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		for(int a = 1;a>0;a++){
			int H = scan.nextInt();
			int W = scan.nextInt();
			if(H == 0 && W == 0){
				break;
			}
			for(int b = 0;b<H;b++){
				if(b==0 || b==(H-1)){
					for(int c =0;c<W;c++){
						System.out.print("#");
					}
				}else{
					for(int d = 0;d<W;d++){
						if(d == 0 || d == (W-1)){
							System.out.print("#");
						}else{
							System.out.print(".");
						}
					}
				}
				System.out.println("");
			}
			System.out.println("");
		}
	}
}

Measured memory_bytes: 25792
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

using namespace std;

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

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
	ll i, j;
	ll N;
	cin >> N;
	for (i = 1; i <= 9; i++) {
		for (j = 1; j <= 9; j++) {
			if (i * j == N) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;

	return 0;
}


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

using namespace std;

const int maxn=1e5;

int l[maxn], dp[maxn];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, k;
	cin >> n >> k;
	for(int i=0; i<n; i++){
		cin >> l[i];
		dp[i]=1e9;
	}
	dp[0]=0;
	for(int i=1; i<n; i++){
		for(int j=i-1; j>-1 && j>=i-k; j--){
			dp[i]=min(dp[i], dp[j]+abs(l[i]-l[j]));
		}
	}
	cout << dp[n-1] << '\n';
	return 0;
}

Measured memory_bytes: 1024
N,M = map(int, input().split())
ab = [tuple(map(int,input().split())) for i in range(N)]
cd = [tuple(map(int,input().split())) for i in range(M)]

ans = []
for i in range(N):
    tmp = 10**9
    idx = 0
    for j in range(M):
        dist = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])
        if dist < tmp:
            tmp = dist
            idx = j
    ans.append(idx+1)

for a in ans:
    print(a)

Measured memory_bytes: 3064
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        m: usize,
        danger_steps: [usize; m],
    };
    let mut steps = vec![0; n];
    for i in danger_steps {
        steps[i - 1] = 1;
    }

    let mut dp = vec![0; n];

    for i in 0..n {
        let ans: usize;
        if i == 0 {
            ans = if steps[0] == 1 { 0 } else { 1 };
        } else if i == 1 {
            ans = if steps[1] == 1 { 0 } else { dp[0] + 1 };
        } else if steps[i] == 1 {
            ans = 0;
        } else {
            ans = dp[i - 1] + dp[i - 2];
        };
        dp[i] = ans % 1000000007;
    }

    println!("{}", dp[n - 1] % 1000000007);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    rep(i,n){
        while(a[i] % 2 == 0){
            a[i] /= 2;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

s = [-1]*14
h = [-1]*14
c = [-1]*14
d = [-1]*14

for i in range(n):
    kind, num = input().split()
    if kind == 'S':
        s[int(num)] = 1
    elif kind == 'H':
        h[int(num)] = 1
    elif kind == 'C':
        c[int(num)] = 1
    else:
        d[int(num)] = 1

for i in range(1,14):
    if s[i]==-1:
        print("S " + str(i))

for i in range(1,14):
    if h[i]==-1:
        print("H " + str(i))

for i in range(1,14):
    if c[i]==-1:
        print("C " + str(i))

for i in range(1,14):
    if d[i]==-1:
        print("D " + str(i))

    


Measured memory_bytes: 5612
#include <iostream>
using namespace std;
int main()
{
	long long A, B, N, max=0;
	cin >> A >> B >> N;

	long long x = 0;

	if (N >= B)	x = B - 1;	
	else x = N;

	long long res = (A * x) / B;
	
	cout << res << endl;
}

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

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

// Mod int
ll extgcd(ll a, ll b, ll &x, ll &y) {
  auto d = a;
  if (b != 0) {d = extgcd(b, a%b, y, x); y -= (a/b)*x;} else { x = 1; y = 0;}
  return d;
}
ll minv(ll a, ll m) {
  ll x, y; extgcd(a, m, x, y); return (m + x%m)%m;
}
struct mint {
    ll x;
    mint():x(0){}
    mint(ll x):x((x%mod+mod)%mod){}
    mint& fix() { x = (x%mod+mod)%mod; return *this;}
    mint operator-() const { return mint(0) - *this;}
    mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
    mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
    mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
    mint& operator/=(const mint& a){ (x*=minv(a.x, mod))%=mod; return *this; }
    mint operator+(const mint& a)const{ return mint(*this) += a;}
    mint operator-(const mint& a)const{ return mint(*this) -= a;}
    mint operator*(const mint& a)const{ return mint(*this) *= a;}
    mint operator/(const mint& a)const{ return mint(*this) /= a;}
    bool operator<(const mint& a)const{ return x < a.x;}
    bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}

vector<mint> fact(1001);

mint mod_pow(mint a, long long x) {
  mint res = 1;
  while(x > 0) {
    if (x & 1) res = res * a;
    a = a * a; x >>= 1;
  }
  return res;
}

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

  int n, a, b, c, d; cin >> n >> a >> b >> c >> d;
  mint dp[n+1][n+1];

  rep(i, n+1) {
    rep(j, n+1) {
      dp[i][j] = 0;
    }
  }

  for(int i=0; i<a; i++) {
    dp[i][0] = 1;
  }

  fact[0] = 1;
  for(int i=1; i<=1000; i++) fact[i] = fact[i-1]*i;

  for(int i=a; i<=b; i++) {
    for(int j=0; j<=n; j++) {
      mint fik = mod_pow(fact[i],c);
      for(int k=c; k<=d; k++) {
        if (j-i*k<0) break;
        mint p = fact[n-j+i*k];
        p /= fik*fact[n-j]*fact[k];
        dp[i][j] += dp[i-1][j-i*k]*p;
        fik *= fact[i];
      }
      dp[i][j] += dp[i-1][j];
    }
  }

  cout << dp[b][n] << endl;

}

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

int main() {
  int n;
  bool Y = false;
  cin >> n;

  for(int i = 0; i < n ; i++){
    string s;
    cin >> s;

    if(s == "Y"){
      Y = true;
      break;
    }
  }

  if(Y)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;  
}


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

int main(){
  int N, K, x[110];
  cin >> N >> K;
  for(int i = 0; i < N; ++i) cin >> x[i];
  
  int dist = 0;
  for(int i = 0; i < N; ++i)
  {
    dist += min(x[i], abs(x[i]-K)) * 2;
  }
  
  cout << dist << endl;
}

Measured memory_bytes: 3632
read = input
n = int(read())
v = [[] for i in range(n+1)] # 邻接
used = [0 for i in range(n+1)] # 节点 1~n
def add(f,t,w):
    v[f].append((t, w))
for i in range(n-1):
    f,t,w = map(int, read().split())
    add(f,t,w)
    add(t,f,w)
# 从1出发，贪心即可，1画1，理论不会有回环，总是能画成二分图
from queue import Queue
q = Queue() # 队列
#def dfs(f, s, fa=-1):
#    if s % 2 == 0: 
#        used[f] = 1
#    for t, w in v[f]:
##         print('%d->%d->%d'%(fa, f, t,), s, w)
#        if t == fa:continue
#        dfs(t, w + s, f)
#
#
#dfs(1,0)
q.put_nowait((1, 0, -1)) #(目标节点号，根节点到目标节点的距离，与目标节点相连的上一个节点号)
while not q.empty():
    f, s, fa = q.get_nowait()
    if s % 2 == 0: 
        used[f] = 1 #used数组从1开始填充颜色
    for t, w in v[f]:
#         print('%d->%d->%d'%(fa, f, t,), s, w)
        if t == fa:continue  #fa为与目标节点相连的上一个节点号，防止成环。2->3则，3->2不能再遍历一遍
        q.put_nowait(
            (t, w + s, f)
        )
    
for i in used[1:]: #球号从1开始，故used[0]无意义
    print(used[i])

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

int main(){
    double dist[20][20];
    double L[20],a[20],b[20];
    int N,M;
    cin>>N>>M;
    if(M<=1){
        cout<<0<<endl;
        return 0;
    }
    for(int i=0;i<N;i++){
        cin>>L[i]>>a[i]>>b[i];
    }
    for(int i=0;i<N;i++){
        for(int j=i;j<N;j++){
            dist[i][j]=dist[j][i]=pow(L[i]-L[j],2)+pow(a[i]-a[j],2)+pow(b[i]-b[j],2);
        }
    }
    int comb = (1<<M) -1;
    double ans = 0;
    while(comb<(1<<N)){
        double D = 0;
        for(int i=0;(1<<i)<=comb;i++){
            if((1<<i)&comb)
            for(int j=0;j<i;j++){
                if((1<<j)&comb) D+=dist[i][j];
            }
        }
        ans = max(ans, D);
        int x=comb&-comb, y=comb+x;
        comb = ((comb&~y)/x>>1)|y;
    }
    cout<<fixed;
    cout.precision(6);
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3276
#include <stdio.h>
#define SIZE 110

int main(void){
	int i, j, k, temp, A[SIZE], N;
	scanf("%d", &N);

	for(i = 0; i < N; i++){
		scanf("%d", &A[i]);
	}

	for(i = 0; i < N; i++){
		temp = A[i];
		j = i - 1;
		while(j >= 0 && A[j] > temp){
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = temp;

		for(k = 0; k < N - 1; k++){
			printf("%d ", A[k]);
		}
		printf("%d\n", A[N - 1]);
	}
}

Measured memory_bytes: 1760
import itertools
n=int(input())
ans=0

for i in range(3,len(str(n))+1):
    for ptn in itertools.product((3,5,7),repeat=i):
        if (3 not in ptn) or (5 not in ptn) or (7 not in ptn):
            continue
        a=int("".join(list(map(str,ptn))))
        if a<=n:
            ans+=1
print(ans)
        

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

int main(){
  long long L, R;
  cin >> L >> R; 

  R = min(R,  L + 4038);

  int ans = 2018;
  int x = 0;
  for(long long i = L; i <= R; i++){
    for(long long j = i+1; j <= R; j++){
      x = (i * j) % 2019;
      ans = min(ans, x);
    }
  } 

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

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

def cmb(n, r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % mod

N = pow(10, 6) + 10  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)

x, y = MAP()
ans = 0
if (x + y) % 3 == 0:
    a = (2 * y - x) // 3
    b = (2 * x - y) // 3
    ans = cmb(a + b, a)
print(ans)


Measured memory_bytes: 124160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v) v.begin(), v.end()
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second
const int N=100005;
const int mod=1000000007;
int dp[1005][1005]{};
void solve()
{
    ll n,k=1,m=0,i=1,j,x,y,l,r,z;
    ll ans=0,sum=0,value=0,weight;
    cin>>n>>m;
    vector<string> a(n+5);
    for(i=0;i<n;i++)
        cin>>a[i];
    if(a[0][0]=='#'||a[n-1][m-1]=='#')
    {
        cout<<0;
        return;
    }
    dp[1][1]=1;
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if(a[i][j]=='.')
            {
                dp[i+1][j+1]+=dp[i][j+1]+dp[i+1][j];
                dp[i+1][j+1]%=mod;
            }
            else dp[i+1][j+1]=0;
        }
    }
    cout<<dp[n][m];
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
     #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif 
    int t=1;
    //cin>>t;
    while(t--)solve();
    return 0;
}

Measured memory_bytes: 8532
import math
a,b=map(int,input().split())
x=max(a,b)
y=min(a,b)
p=abs(x-y)

P = 10**9 + 7
N = 1000000
inv_t = [0]+[1]
for i in range(2,N):
  inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

if (x+y)%3!=0:
    print(0)
elif x>y*2:
    print(0)
else:
    n=(x+y)//3
    q=(2*x-y)//3
    r=(2*y-x)//3
    
    #print(math.factorial(q+r)//math.factorial(q)//math.factorial(r)%(10**9+7))
    ans=1
    qq=1
    rr=1
    for i in range(1,q+r+1):
        ans*=i
        ans%=10**9+7
    for i in range(1,q+1):
        ans*=inv_t[i]
        ans%=10**9+7
    for i in range(1,r+1):
        ans*=inv_t[i]
        ans%=10**9+7
            
            
    print(ans)

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

int main(){
  int a; long long b,n; cin >>a >>b >>n;
  int x=floor(a*(b-1)*1.0/b);
  int y=floor(a*n*1.0/b);
  if(n>=b-1) cout <<x;
  else cout <<y;
return 0;}

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


typedef long long ll; // -9,223,372,036,854,775,808 から 9,223,372,036,854,775,807

template <class T> using vec = std::vector<T>;
template <class T> using vec2 = vec<vec<T>>;
template <class T> using vec3 = vec<vec<vec<T>>>;

#define DEBUG

void solve(long long N, std::vector<std::string> S){
    vec<ll> cnts(256);
    for(auto iter: S){
        cnts.at(iter.at(0))++;
    }

    ll res = 0;
    string march("MARCH");

    for(int i=0; i < 5; i++){
        for(int j=i+1; j < 5; j++){
            for(int k=j+1; k < 5; k++){
                res += cnts.at(march.at(i))*cnts.at(march.at(j))*cnts.at(march.at(k));
            }
        }
    }

    cout << res << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<std::string> S(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> S[i];
    }
    solve(N, std::move(S));
    return 0;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    string s,t;cin>>s>>t;
    ll ss=s.size();
    int ts=t.size();
    vvin alpha(26);
    rep(i,ss)alpha[s[i]-'a'].push_back(i);
    ll ans=(ll)0;int num=-1;int l,r,m;int tmp;
    rep(i,ts){
        tmp=t[i]-'a';
        if(alpha[tmp].size()==0){
            cout<<-1<<endl;
            return 0;
        }
        l=-1;r=alpha[tmp].size();
        while(r-l>1){
            m=(l+r)/2;
            if(alpha[tmp][m]<=num)l=m;
            else r=m;
        }
        if(r==alpha[tmp].size()){
            ans++;
            num=alpha[tmp][0];
        }
        else num=alpha[tmp][r];
    }
    cout<<ans*ss+(ll)num+(ll)1<<endl;
}

Measured memory_bytes: 4256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  bool f;
  foreach (i; 0..n/4 + 1) {
    foreach (j; 0..n/7 + 1) {
      if (4 * i + 7 * j == n) {
        f = true;
      }
    }
  }
  if (f) {
    writeln("Yes");
  } else {
    writeln("No");
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline int GCD(int a,int b){return !b?a:GCD(b,a%b);}
const int Primes[168]=
{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,
 97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,
 227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,
 367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,
 509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,
 661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,
 829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997};
const char common[]="not coprime",disjoint[]="pairwise coprime",several[]="setwise coprime";
char esc[1000000];
static inline int Divide(int x)
{
  if(!x){return 0;}
  rep(i,168)
  {
    if(Primes[i]*Primes[i]>x)break;
    if(x%Primes[i])continue;
    if(esc[Primes[i]-1])return 0;
    esc[Primes[i]-1]=1;
    while(x%Primes[i]==0&&x)x/=Primes[i];
  }
  if(x>1){if(esc[x-1])return 0;esc[x-1]=1;}
  return 1;
}
int main(void)
{
  int N=IN(),A=0,f=0,g=0,last=0,penultimate=0;
  rep(i,N)
  {
    A=IN();g=GCD(g,A);if(i&&g!=1){f=1;}if(!f&&penultimate&&GCD(penultimate,A)>1){f=1;}
    penultimate=last;last=A;if(f)continue;else{if(!Divide(A))f=1;}
  }
  if(g>1)return puts(common),0;else{if(f)return puts(several),0;else return puts(disjoint),0;}
}

Measured memory_bytes: 2444
//package abc128.B;

import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		String[] sp = new String[n];
		
		for (int i = 0; i < n; i++) {
			String s = sc.next();
			int p = sc.nextInt();
			sp[i] = s + '_' + (1100 - p) + '_' + (i + 1);
		}
		
		Arrays.sort(sp);
		
		for (int i = 0; i < n; i++) {
			String ans = sp[i].split("_")[2];
			System.out.println(ans);
		}
		
	}

}


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

bool valid(vector<long long> a)
{
    const int init = -1;
    int power_of_two = init;
    for (int aa : a)
    {
        int tmp = 0;
        while (aa % 2 == 0)
        {
            tmp++;
            aa >>= 1;
        }
        if (power_of_two == init)
        {
            power_of_two = tmp;
        }
        else
        {
            if (tmp != power_of_two)
            {
                return false;
            }
        }
    }
    return true;
}

template <typename T>
T calc_gcd(T x, T y)
{
    if (x < y)
    {
        swap(x, y);
    }
    T remain = x % y;
    while (remain != 0)
    {
        x = y;
        y = remain;
        remain = x % y;
    }
    return y;
}

template <typename T>
T calc_multi_gcd(vector<T> x)
{
    if (x.size() < 2)
    {
        if (x.size() == 1)
        {
            return x[0];
        }
        else
        {
            return -1;
        }
    }

    T gcd = calc_gcd(x[0], x[1]);
    for (long long i = 2; i < x.size(); i++)
    {
        gcd = calc_gcd(gcd, x[i]);
    }
    return gcd;
}

template <typename T>
T calc_lcm(T x, T y)
{
    if (x < y)
    {
        swap(x, y);
    }
    T ret = x / calc_gcd(x, y);
    return ret * y;
}

template <typename T>
T calc_multi_lcm(vector<T> x)
{
    if (x.size() < 2)
    {
        if (x.size() == 1)
        {
            return x[0];
        }
        else
        {
            return -1;
        }
    }

    T lcm = calc_lcm(x[0], x[1]);
    for (long long i = 2; i < x.size(); i++)
    {
        lcm = calc_lcm(lcm, x[i]);
    }
    return lcm;
}

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

    vector<long long> a(N);
    for (long long &aa : a)
    {
        cin >> aa;
        aa /= 2;
    }

    if (!valid(a))
    {
        cout << 0 << endl;
        return 0;
    }

    long long ans = ((M / calc_multi_lcm(a)) + 1) / 2;
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

const int maxN = 888;
char table[maxN][maxN];
int go[maxN][maxN];
bool used[maxN][maxN];


struct State {
    int I;
    int J;
    int Rem;
    int Act;
    State() {}
    State(int I, int J, int Rem, int Act) : I(I), J(J), Rem(Rem), Act(Act) {}
};

queue <State> q;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int n, m, k;

bool on_board(int i, int j) {
    return i >= 1 && i <= n && j <= m && j >= 1;
}

int d[maxN][maxN];

int main(void) {
    cin >> n >> m >> k;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> table[i][j];
            if (table[i][j] == 'S') {
                q.push(State(i, j, k, 0));
            }
        }
    }
    queue<pair <int, int> > q1;
    while (!q.empty()) {
        auto cur = q.front();
        q1.push(make_pair(cur.I, cur.J));
        q.pop();
        if (cur.I == n || cur.I == 1 || cur.J == 1 || cur.J == m) {
            cout << 1 << endl;
            return 0;
        }
        if (cur.Rem == 0) {
            continue;
        }
        for (int i = 0; i < 4; i++) {
            int nI = dx[i] + cur.I;
            int nJ = dy[i] + cur.J;
            if (!used[nI][nJ] && on_board(nI, nJ) && table[nI][nJ] == '.') {
                used[nI][nJ] = true;
                q.push(State(nI, nJ, cur.Rem - 1, 1));
            }
        }
    }
    while (!q1.empty()) {
        auto cur = q1.front();
        q1.pop();
        if (cur.first == n || cur.first == 1 || cur.second == 1 || cur.second == m) {
            cout << 1 + (d[cur.first][cur.second] + k - 1) / k;
            return 0;
        }
        for (int i = 0; i < 4; i++) {
            int nI = dx[i] + cur.first;
            int nJ = dy[i] + cur.second;
            if (!used[nI][nJ] && on_board(nI, nJ)) {
                q1.push({nI, nJ});
                used[nI][nJ] = true;
                d[nI][nJ] = d[cur.first][cur.second] + 1;
            }
        }
    }





    return 0;
}

Measured memory_bytes: 6400
#include<stdio.h>

int main(){
  int i,j,a[100],N,minj,n=0,tmp;

  scanf("%d",&N);
  for(i=0;i<N;i++)
    scanf("%d",&a[i]);

  for(i=0;i<N;i++){
    minj = i;
    for(j = i;j<N;j++){
      if(a[j]<a[minj]){
	minj = j;
      }
    }
    if(i != minj){
      tmp = a[i];
      a[i] = a[minj];
      a[minj] = tmp;
      n++;
    }
  }

  for(i=0;i<N-1;i++)
    printf("%d ",a[i]);
  printf("%d\n%d\n",a[N-1],n);

  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  ll x;
  cin >> x;

  ll cnt = 0;
  ll now = 100;

  while (1) {
    now = now * 1.01;
    cnt ++;
    if (now >= x) {
      cout << cnt << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{
    int x, h;
    while( cin >> x >> h ) {
        if ( x == 0 && h == 0 )
            break;

        auto const v = x * sqrt( 4 * h * h + x * x ) + x * x;
        cout << setprecision( 6 ) << fixed << v << endl;
    }
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 1000005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    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;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N,M;
int A[MAXN];
int cnt[MAXN],cov[MAXN],ans;
void Solve() {
    read(N);read(M);
    for(int i = 1 ; i <= N ; ++i) {
	read(A[i]);
	cnt[A[i]]++;
	cov[A[i] - cnt[A[i]] + 1]++;
    }
    for(int i = 1 ; i <= N ; ++i) {
	if(!cov[i]) ++ans;
    }
    int x,y;
    for(int i = 1 ; i <= M ; ++i) {
	read(x);read(y);
	if(A[x] - cnt[A[x]] + 1 >= 1) {
	    if(!--cov[A[x] - cnt[A[x]] + 1]) ++ans;
	}
	--cnt[A[x]];
	A[x] = y;
	++cnt[A[x]];
	if(A[x] - cnt[A[x]] + 1 >= 1) {
	    if(!cov[A[x] - cnt[A[x]] + 1]++) --ans;
	}
	out(ans);enter;
    }
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 10496
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int[] nums = new int[a];
         
        for(int i = a-1; i >= 0; i--){
            nums[i] = sc.nextInt();
        }
         
        StringBuilder str = new StringBuilder();
        for(int i = 0; i < nums.length; i++){
            if(i != nums.length-1) str.append(nums[i] + " ");
            else str.append(nums[i]);
        }
         
        System.out.println(str);
         
    }
 
}

Measured memory_bytes: 18284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

ll dp1[9], dp2[111][10];

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  
  dp1[0]=dp1[1]=1;
  for(int i=2;i<=8;i++){
    rep(bit,1<<(i-1)){
      int tmp[i-1]={},flag=1;
      rep(j,i-1) if((bit>>j)&1){
        tmp[j]++;
        if(j>0) if(tmp[j]&&tmp[j-1]) flag=0;
      }
      dp1[i]+=flag;
    }
  }
  
  int H,W,K; cin>>H>>W>>K;
  dp2[0][0]=1;
  rep(i,H) rep(j,W) if(dp2[i][j]){
    (dp2[i+1][j]+=dp2[i][j]*dp1[j]%MOD*dp1[W-j-1]%MOD)%=MOD;
    if(j>0){
      (dp2[i+1][j-1]+=dp2[i][j]*dp1[j-1]%MOD*dp1[W-j-1]%MOD)%=MOD;
    }
    if(j<W-1){
      (dp2[i+1][j+1]+=dp2[i][j]*dp1[j]%MOD*dp1[W-j-2]%MOD)%=MOD;
    }
  }
  cout<<dp2[H][K-1]<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int ans;
    if(n<10){
        ans=n;
    }else if(n<100){
        ans=9;
    }else if(n<1000){
        ans=9+(n-99);
    }else if(n<10000){
        ans=9+900;
    }else if(n<100000){
        ans=9+900+(n-9999);
    }else{
        ans=9+900+90000;
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
 
const ll INF = 1000000000000000009;
const ll MOD = 1000000007;
 
ll s[100005];
int ca[100005], cb[100005];
ll dpa[100005], dpb[100005];
 
int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    s[0] = -INF;
    for(int i = 1; i <= n; i++) cin >> s[i];
    for(int i = 1; i <= n; i++){
        ca[i] = ca[i - 1];
        cb[i] = cb[i - 1];
        if(s[i] - s[i - 1] >= a) ca[i]++;
        if(s[i] - s[i - 1] >= b) cb[i]++;
    }
    dpa[0] = dpa[1] = dpb[0] = dpb[1] = 1;
    for(int i = 2; i <= n; i++){
        if(ca[i] - ca[i - 1]) dpa[i] = (dpa[i - 1] + dpb[i - 1]) % MOD;
        else{
            int j = upper_bound(s, s + n + 1, s[i] - a) - s;
            if(cb[i - 1] - cb[j] == (i - 1) - j) dpa[i] = dpb[j];
        }
        if(cb[i] - cb[i - 1]) dpb[i] = (dpa[i - 1] + dpb[i - 1]) % MOD;
        else{
            int j = upper_bound(s, s + n + 1, s[i] - b) - s;
            if(ca[i - 1] - ca[j] == (i - 1) - j) dpb[i] = dpa[j];
        }
    }
    cout << (dpa[n] + dpb[n]) % MOD << endl;
}

Measured memory_bytes: 3328
#include <stdio.h>
int main()
{
	int n, flag = 0;
	scanf("%d", &n);
	for(int i = 1; i < 10; i++)
	{
		for(int j = 1; j < 10; j++)
		{
			int t = i * j;
			if(t == n)
			{
				flag = 1;
				break;
			}
		}
	}
	if(flag == 1)
	{
		printf("Yes\n");
	} else
	{
		printf("No\n");
	}
   return 0;
}

Measured memory_bytes: 1640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	Scanner sc=new Scanner(System.in);
    	int N=sc.nextInt();

    	int[] A=new int[N];

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

    	int ans=0;
    	for(int i=0;i<N;i++) {
    		if(A[A[i]]==i) {
    			ans++;
    		}
    	}

    	System.out.println(ans/2);

    }

}



Measured memory_bytes: 52992