akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define fr(i, a, b) for (ll i = a; i <= b; ++ i)
#define rf(i, a, b) for (ll i = a; i >= b; -- i)

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr << "Ready\n";
}

const int N = 4e6 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e17 + 7;
const ll P = 53;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);



int main () {
    to_pray();
    
    
    int n;
    cin >> n;
    
    if (n % 7 == 0 or n % 4 == 0)
    	return cout << "Yes", 0;
    
    for (int i = 4; i <= n; i += 4) {
    	for (int j = 7; j <= n; j += 7) {
    		if (n % (i + j) == 0 and (i + j) == n)
    			return cout << "Yes", 0;
    	}
    }
    
    cout << "No";
    
    //eprllf("%.18lf seconds\n", (double)clock() / CLOCKS_PER_SEC);
    cout << '\n';
    return 0;
}

Measured memory_bytes: 256
fn getline() -> String{
	let mut __ret=String::new();
	std::io::stdin().read_line(&mut __ret).ok();
	return __ret;
}

fn main(){
	let s=getline();
	let input:Vec<_>=s.trim().split(' ').collect();
	let a:i32=input[0].parse().unwrap();
	let b:i32=input[2].parse().unwrap();
	
	if(input[1] == "+"){
		println!("{}",a+b);
	}else{
		println!("{}",a-b);
	}
}

Measured memory_bytes: 4352
a,b,c = map(int,input().split())
ans = 0
if a == b:
    if a == c:
        ans = 1
    else:
        ans = 2
else:
    if a == c:
        ans = 2
    elif b == c:
        ans = 2
    else:
        ans = 3
print(ans)


Measured memory_bytes: 3064
import sys
S = list(input())
D = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
     'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for d in D:
    if not d in S:
        print(d)
        sys.exit()
print('None')

Measured memory_bytes: 9724
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;++i)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;
const int lim = 51;
const int INF = 3000;
char mp[lim][lim];
int d[lim][lim],h,w;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int bfs(){
    queue<P> que;
    que.push(P(1,1));
    d[1][1]=0;
    int nx,ny;
    while(que.size()){
        P p = que.front();que.pop();
        if(p.first==w&&p.second==h) break;
        fol(i,4){
            nx = p.first + dx[i],ny = p.second + dy[i];
            if(0<=nx&&nx<=w&&0<=ny&&ny<=h&&mp[ny][nx]!='#'&&d[nx][ny]==INF){
                que.push(P(nx,ny));
                d[nx][ny]=d[p.first][p.second]+1;
            }
        }
    }
    return d[w][h];
}
int main(){
    fol(i,lim)fol(j,lim){mp[i][j]='#';d[i][j]=INF;}
    int white=-1;cin>>h>>w;
    for(int i=1;i<=h;++i)for(int j=1;j<=w;++j){
            cin>>mp[i][j];
            if(mp[i][j]=='.') ++white;
        }
    int cost = bfs();
    if (cost==INF)cout << -1 << endl;
    else cout << white-cost << endl;
    return 0;
}


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

int main(){
  ll N, T;  cin >> N >> T;
  vector<ll> a(N);
  vector<ll> d(N);
  ll mi = 1e10;
  for(int i = 0; i < N; i++){
    cin >> a[i];
    mi = min(mi, a[i]);
    d[i] = a[i] - mi;
  }
  sort(d.begin(), d.end(), greater<ll>());
  ll ans = 1;
  ll ma = d[0];
  ll cnt = 1;
  while(d[cnt] == ma){
    ans++;
    cnt++;
  }
  cout << ans << endl;
}

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

int main(){
    ll k;
    cin >> k;
    vector<ll> s(k);
    rep(i,k){
        if(i==0) s[i]=7%k;
        else s[i]=(s[i-1]*10+7)%k;
    }
    rep(i,k){
        if(s[i]==0) {
            cout<<i+1<<endl;return 0;
        }
    }
    cout<<"-1"<<endl;
}

Measured memory_bytes: 11184
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	int ans = 0;
	rep(i, n) {
		while (a[i] % 2 == 0) {
			ans++;
			a[i] /= 2;
		}
	}
	print(ans);
}

Measured memory_bytes: 3696
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        TreeMap<Double,Integer> a = new TreeMap<>();
        for (int i=0;i<n;i++){
            double pr = sc.nextDouble();
            if (a.containsKey(pr)) a.put(pr,a.get(pr)+1);
            else a.put(pr,1);
        }
        for (int i=0;i<m;i++){
            double pr = a.lastKey();
            int num = a.lastEntry().getValue();
            if (num<=1)a.pollLastEntry();
            else a.put(pr,a.get(pr)-1);
            if (!a.containsKey(pr/2.0)) a.put(pr/2.0,1);
            else a.put(pr/2.0,a.get(pr/2.0)+1);
        }
        long ans = 0;
        while (!a.isEmpty()){
            double pr = a.lastKey();
            int num = a.pollLastEntry().getValue();
            ans+=(long)(Math.floor(pr))*num;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 70016
#include "bits/stdc++.h"

using namespace std;

const int maxn = 100005;

char s[maxn];

int main() {
    int cnt = 0;
    scanf("%s", s);
    for(int i = 1; i < (int)strlen(s); i++) {
        if(s[i] == s[i - 1]) {
            cnt++;
            if(s[i - 1] == '0')
                s[i] = '1';
            else s[i] = '0';
        }
    }    
    printf("%d", cnt);
}

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

int n;
vector<int> x, id, res, cnt;
queue<int> qu;

bool solve();

int main() {
  cin >> n;
  x.resize(n);
  cnt.assign(n, 0);
  for (auto& p : x) cin >> p;
  for (int i = 0; i < n; ++i) id.push_back(i);
  sort(id.begin(), id.end(), [](int l, int r) { return x[l] < x[r]; });
  if (solve()) {
    cout << "Yes" << endl;
    for (int i = 0; i < (n * n); ++i) cout << res[i] << " \n"[i == (n * n) - 1];
  } else
    cout << "No" << endl;
  return 0;
}

bool solve() {
  for (int i = 0; i < n; ++i) {
    int now = id[i];
    for (int j = 0; j < now; ++j) qu.push(now + 1);
  }
  for (int i = 0; i < n; ++i) {
    int now = id[i];
    while (res.size() + 1 < x[now]) {
      if (qu.empty()) return 0;
      res.push_back(qu.front());
      ++cnt[qu.front() - 1];
      qu.pop();
    }
    if (res.size() + 1 != x[now] || cnt[now] != now) return 0;
    res.push_back(now + 1);
    for (int j = 0; j < n - now - 1; ++j) qu.push(now + 1);
  }
  while (qu.size()) {
    res.push_back(qu.front());
    qu.pop();
  }
  return 1;
}

Measured memory_bytes: 4852
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int arr[n];
	for( int i=0;i<n;i++)
		arr[i]=0;
	for( int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		arr[--a]++;
		arr[--b]++;
	}
	for( int i=0;i<n;i++)
		cout<<arr[i]<<endl;

	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]

use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::{i32, i64, i128, u32, u64, u128, f64};
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};
use proconio::marker::{Isize1, Usize1, Bytes, Chars};

#[proconio::fastout]
fn main() {
    proconio::input!{
        n: i32,
    }
    println!("{}", if n % 1000 == 0 { 0 } else { 1000 - n % 1000 });
}


Measured memory_bytes: 2136
S=list(input())

N=len(S)
L=[0]*(N+1)
R=[0]*(N+1)

for i in range(N):
  if S[i]=="<":
    L[i+1]=L[i]+1
  else:
    L[i+1]=0
#print(L)

S=S[::-1]
for i in range(N):
  if S[i]==">":
    R[i+1]=R[i]+1
  else:
    R[i+1]=0
R=R[::-1]
#print(R)

answer=0
for i in range(N+1):
  answer+=max(L[i],R[i])
print(answer)

Measured memory_bytes: 34872
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string text;
    cin >> text;
    int num_command;
    cin >> num_command;
    
    for(int i = 0; i < num_command; i++){
        string command;
        cin >> command;
        
        int a, b;
        if(command == "replace"){
            string p;
            cin >> a >> b >> p;
            text.replace(a, b - a + 1, p);
            //cout << text << endl;
        }else if(command == "reverse"){
            cin >> a >> b;
            reverse(&text[a], &text[b + 1]);
            //cout << text << endl;
        }else if(command == "print"){
            cin >> a >> b;
            //cout << "  " << text << endl;
            cout << text.substr(a, b - a + 1) << endl;
        }else{
            continue;
        }
    }
}


/*
 print 1 8
 replace 5 5 o
 print 1 8
 reverse 3 7
 print 1 8
 replace 8 9 xy
 print 0 9
 reverse 3 8
 reverse 0 5
 print 0 9
 */



Measured memory_bytes: 3224
def main():
    a = int(input())
    b = int(input())
    c = int(input())
    d = int(input())

    if a <= b:
        train = a
    else:
        train = b
    if c <= d:
        bus = c
    else:
        bus = d
    print(train + bus)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define N 400010
int a,b,tp,st[N],r[N],n;
char s[N];
int q(int x,int y){
	printf("? %d %d\n",x,y);
	fflush(stdout);
	cin>>s;
	if(s[0]=='Y')return 1;
	else return 0;
}
int main(){
	cin>>a>>b;
	if(a<=b){
		puts("Impossible");
		return 0;
	}
	n=a+b;
	for(int i=0;i<n;i++){
		if(!tp)st[++tp]=i;
		else{
			int r=q(st[tp],i);
			if(r)st[++tp]=i;
			else tp--;
		}
	}
	for(int i=0;i<n;i++)
		r[i]=q(st[tp],i);
	printf("! ");
	for(int i=0;i<n;i++)
		printf("%d",r[i]);
	puts("");
}

Measured memory_bytes: 724
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
enum Owner { Fennec, Snuke, None };

struct Node {
  std::vector<int> to;
  Owner owner = None;
};

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  std::vector<Node> node(n + 1);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    node[a].to.push_back(b);
    node[b].to.push_back(a);
  }
  node[1].owner = Fennec;
  node[n].owner = Snuke;
  std::vector<int> FennecQueue;
  std::vector<int> SnukeQueue;
  FennecQueue.push_back(1);
  SnukeQueue.push_back(n);
  int fennec_score = 1, snuke_score = 1;
  while (!FennecQueue.empty() || !SnukeQueue.empty()) {
    std::vector<int> FennecSearch = FennecQueue;
    FennecQueue.erase(FennecQueue.begin(), FennecQueue.end());
    for (auto x : FennecSearch) {
      for (auto y : node[x].to) {
        if (node[y].owner == None) {
          FennecQueue.push_back(y);
          node[y].owner = Fennec;
          fennec_score++;
        }
      }
    }
    std::vector<int> SnukeSearch = SnukeQueue;
    SnukeQueue.erase(SnukeQueue.begin(), SnukeQueue.end());
    for (auto x : SnukeSearch) {
      for (auto y : node[x].to) {
        if (node[y].owner == None) {
          SnukeQueue.push_back(y);
          node[y].owner = Snuke;
          snuke_score++;
        }
      }
    }
  }
  if (snuke_score >= fennec_score) {
    cout << "Snuke";
  } else {
    cout << "Fennec";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 6656
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))

Int dp[108000];
Int a[108];
int n, k;
int main(){
  cin >> n >> k;
  for(int i = 0;i < n;i++)cin >> a[i];
  for(int i = 1;i <= k;i++){
    for(int j = 0;j < n;j++){
      if(a[j] <= i && dp[i-a[j]] == 0)dp[i] = 1;
    }
    //    cout << i << " " << dp[i] << endl;
  }
  if(dp[k])cout << "First" << endl;
  else cout << "Second" << endl;
  return 0;
}

Measured memory_bytes: 1024
import java.io.{BufferedReader, IOException, InputStream, InputStreamReader}
import java.util.StringTokenizer
import java.util.concurrent.atomic.AtomicInteger

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.ArrayBuffer

object Main {
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val K = sc.nextInt()
    val L = sc.nextInt()

    var i = 0
    val uf_road = new UnionFind(N + 1)
    i = 0
    while (i < K) {
//    (0 until K) foreach { _ =>
      uf_road.unite(sc.nextInt(), sc.nextInt())
      i += 1
    }

    val uf_rail = new UnionFind(N + 1)
    i = 0
    while (i < L) {
//    (0 until L) foreach { _ =>
      uf_rail.unite(sc.nextInt(), sc.nextInt())
      i += 1
    }

    val group = mutable.Map[(Int, Int), Int]() // key => group
    i = 1
    while (i <= N) {
//    (1 to N) foreach { i =>
      val k = (uf_road.find(i), uf_rail.find(i))
      group(k) = i
      i += 1
    }
    val i2g = Array.ofDim[Int](N + 1) // i => group
    i = 1
    while (i <= N) {
//    (1 to N) foreach { i =>
      val k = (uf_road.find(i), uf_rail.find(i))
      i2g(i) = group(k)
      i += 1
    }
    val count = Array.ofDim[Int](N + 1) // group => count
    i = 1
    while (i <= N) {
//    (1 to N) foreach { i =>
      count(i2g(i)) += 1
      i += 1
    }
    i = 1
    while (i <= N) {
//    (1 to N) foreach { i =>
      if (i > 1) print(" ")
      print(count(i2g(i)))
      i += 1
    }

//    val count = mutable.Map[(Int, Int), Int]()
//    var i = 1
//    while(i <= N) {
//      val k = key(i)
//      if (!(count contains k)) count(k) = 0
//      count(k) = count(k) + 1
//      i += 1
//    }
//
//    i = 1
//    while(i <= N) {
//      if (i > 1) print(" ")
//      print(count(key(i)))
//      i += 1
//    }
//    println()
//    val count = ((1 to N) map key).groupBy(identity).mapValues(_.size)
//    val ans = ((1 to N) map (key _).andThen (count(_))).mkString(" ")
//    println(ans)
  }

  def main(args: Array[String]): Unit = {
    solve()
  }



  class InputReader(val stream: InputStream) {
    val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

  class UnionFind(n: Int) {
    private val par = Array.iterate(0, n)(_ + 1)
    private val rank = Array.ofDim[Int](n)

    def find(x: Int): Int = {
      if (par(x) == x) x
      else {
        par(x) = find(par(x))
        par(x)
      }
    }

    def unite(x: Int, y: Int): Unit = {
      val x1 = find(x)
      val y1 = find(y)
      if (x1 != y1) {
        if (rank(x1) < rank(y)) {
          par(x1) = y1
        } else {
          par(y1) = x1
          if (rank(x1) == rank(y1)) rank(x1) += 1
        }
      }
    }
  }
}


Measured memory_bytes: 85024
from sys import stderr, setrecursionlimit
setrecursionlimit(2147483647)
def getInt():
    return int(input())
def getInts():
    return [int(i) for i in input().split()]
def getIntLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInt())
    return res
def getIntsLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInts())
    return res
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

n = getInt()
h = getInts()
ans = 0
l = 0
r = 0
while l < n:
    r = l
    while l < n and h[l] == 0:
        l += 1
        r += 1
    while r < n and h[r] != 0:
        r += 1
    if r == l:
        break
    tmp = min(h[l:r])
    ans += tmp
    h = h[:l] + list(map(lambda x:x-tmp, h[l:r])) + h[r:]
    debug(l, r, h)

print(ans)


Measured memory_bytes: 3064
import numpy

def main():
    n = int(input())
    d, x = map(int, input().split())
    
    y = []
    for i in range(0, n):
        Ai = int(input())
        y.append(int((d-1)/Ai) + 1)

    

    arr_numpy = numpy.array(y)
    print(numpy.sum(arr_numpy) + x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 20756
from sys import stdin
def input():
    return stdin.readline().strip()

n = int(input())
s = []
for _ in range(n):
    s.append(int(input()))

s.sort()

ans = sum(s)

if ans % 10 != 0:
    print(ans)
    exit()

for i in s:
    if i % 10 != 0:
        print(ans - i)
        exit()
else:
    print(0)

Measured memory_bytes: 61828
def jumpCost(array):
    size = len(array)
 
    memo = [99999999999] * (size)
 
    memo[0] = 0
 
    for i in range(size):
        j = i+1
 
        while j < i + 2 + 1 and j < size:
            memo[j] = min(memo[j], memo[i] + abs(array[i] - array[j]))
 
            j += 1
 
    return memo[size - 1]
 
 
if __name__ == '__main__':
    n = int(input())
 
    a = list(map(int, input().rstrip().split()))
    print(jumpCost(a))

Measured memory_bytes: 20460
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      long a = sc.nextInt();
      long b = sc.nextLong();
      long n = sc.nextLong();
      long left = 0, right = n;
      while(left <= right) {
        long mid1 = left + (right - left) / 3;
        long mid2 = right - (right - left) / 3;
        if(cal(mid1, a, b) <= cal(mid2, a, b)) {
          left = mid1 + 1;
        } else right = mid2 - 1;
      }
      System.out.println(cal(right < 0 ? 0 : right, a, b));
  }

  private static long cal(long x, long a, long b) {
    return (a * x) / b - a * (x / b);
  }
}

Measured memory_bytes: 27096
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        if self.parents[y] < self.parents[x]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
    
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    
    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def solve():
    N, M = map(int, input().split())
    a, b = [0] * M, [0] * M
    for i in range(M):
        a[i], b[i] = map(lambda x: int(x) - 1, input().split())
    
    ans = 0
    for i in range(M):
        uf_tree = UnionFind(N)
        for j in range(M):
            if i == j:
                continue
            
            uf_tree.union(a[j], b[j])
        if 1 < uf_tree.group_count():
            ans += 1
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main() {
    string s,t;
    cin>>s>>t;
    for(char a = 'a';a!='z';a++){
        if(s+a==t){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    if(s +'z' == t)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main() {
	string s, t;
	cin >> s >> t;
	ll n = s.size();
	ll ans = 0;
	for (ll i = 0; i < n; ++i) {
		if (s[i] != t[i])++ans;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3832
import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Scanner;

/**
 * Created by Harry on 5/3/20.
 */
public class Main {
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(new BufferedInputStream(System.in));
        int n = scanner.nextInt();
        int[] h = new int[n];
        for(int i=0; i<n; i++){
            h[i] = scanner.nextInt();
        }
        HashMap<Integer, Integer> freq = new HashMap();
        long res =0;
        for(int i=0; i<n; i++){
            int save = i+h[i];
            int find = i-h[i];
            freq.put(save, freq.getOrDefault(save, 0)+1);
            res += freq.getOrDefault(find, 0);

        }
        System.out.println(res);
    }
}


Measured memory_bytes: 64620
S  = str(input())
even_black = 0
even_white = 0
odd_black = 0
odd_white = 0
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == '0':
            even_black += 1
        else:
            even_white += 1
    else:
        if S[i] == '0':
            odd_black += 1
        else:
            odd_white += 1
bw = even_white + odd_black
wb = even_black + odd_white
print (min(wb, bw))

Measured memory_bytes: 3316
S = input()

n=len(S)
sm=0

for i in range(2**(n-1)):
    tmp = [False]*(n-1)

    for j in range(n-1):
        if i >> j &1:
            tmp[j]=True

    result_list = []
    for s_n in range(len(S)):
        result_list.append(S[s_n])
        if s_n < len(tmp) and tmp[s_n]:
            result_list.append("+")

    res=""
    for x in result_list:
        res+=x
    sm+=eval(res)

print(sm)

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
#define ll long long

using namespace std;
//        tmp = stoi(S.substr(i,3));
int main(){
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());
    ll N;
    ll A,B;

    cin >> N;
    if(N == 1)
    {
        cout << "Hello World" << endl;
    }
    else
    {
        cin >> A >> B;
        cout << A + B  << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
int mp[500][500];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int h,w;
  cin>>h>>w;
  rep(i,h) {
    rep(j,w) {
      cin>>mp[i][j];
    }
  }
  vector<tuple<int,int,int,int>> cmds;
  rep(i,h-1) {
    rep(j,w) {
      if(mp[i][j]%2==1) {
        cmds.push_back(make_tuple(i,j,i+1,j));
        mp[i+1][j]++;
      }
    }
  }
  rep(j,w-1) {
    if(mp[h-1][j]%2==1) {
      cmds.push_back(make_tuple(h-1,j,h-1,j+1));
      mp[h-1][j+1]++;
    }
  }
  cout << cmds.size() << endl;
  for(auto& t : cmds) {
    int a,b,c,d;
    tie(a,b,c,d) = t;
    cout << a+1 << " " << b+1 << " " << c+1 << " " << d+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 5232
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string s,t,u;
    int a,b;
    cin>>s>>t>>a>>b>>u;

    if(s==u){
        cout<<a-1<<" "<<b<<endl;
    }else{
    cout<<a<<" "<<b-1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

const int N = 11;
int a[N];
int n;

int main() {
    ios::sync_with_stdio(false);
    cout.precision(10);
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int ans = 0;
    for(int mask = 0; mask < (1 << (2 * n)); mask++) {
        bool ok = true;
        bool par = true;
        for(int i = 1; i <= n; i++) {
            int d1 = 1 << (i * 2 - 1);
            int d2 = 1 << (i * 2 - 2);
            int m1 = (mask & d1) > 0;
            int m2 = (mask & d2) > 0;
            int m = m1 * 2 + m2;
            if(m == 3) {
                ok = false;
                break;
            } else if(m == 0) {
                par &= a[i] - 1 & 1;
            } else if(m == 1) {
                par &= a[i] & 1;
            } else {
                par &= a[i] + 1 & 1;
            }
        }
        ans += ok && (!par);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll q, h, s, d; cin >> q >> h >> s >> d;
    ll n; cin >> n;

    ll q1 = q * 4;
    ll h1 = h * 2;

    ll low1 = min({q1, h1, s});
    ll low2 = min(low1 * 2, d);

    if (n >= 2) {
        ll ans = 0;
        if (n % 2 == 0) {
            ans += low2 * (n / 2);
        } else {
            ans += low2 * (n / 2) + low1;
        }

        cout << ans << endl;
    } else {
        cout << low1 << endl;
    }
}

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

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define maxn 100
#define int long long int
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

int lcm(int a, int b) { return a / gcd(a, b) * b; }

int mpow(int N, int P, int M)  //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0) {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}

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

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

bool IsPrime(int num) {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

signed main() {
    int A, B;
    cin >> A >> B;
    vector<int> l, r;
    for (int i = 2; i <= sqrt(A); i++) {
        while (A % i == 0) {
            l.push_back(i);
            A /= i;
        }
        if (A == 1) break;
    }
    if (A != 1) l.push_back(A);

    for (int i = 2; i <= sqrt(B); i++) {
        while (B % i == 0) {
            r.push_back(i);
            B /= i;
        }
        if (B == 1) break;
    }
    if (B != 1) r.push_back(B);

    int ans = 1;
    for (int i = 1; i <= l.size(); i++) {
        if ((i < l.size()) && (l[i] == l[i - 1])) {
            continue;
        }
        for (int j = 1; j <= r.size(); j++) {
            if ((j < r.size()) && (r[j] == r[j - 1])) {
                continue;
            }
            if (l[i - 1] == r[j - 1]) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl

int main() {
  IN(N);

  set<string> dic;
  REP(i, N) {
    string command, S;
    cin >> command >> S;
    if (command == "insert") {
      dic.insert(S);
    } else {
      OUT((dic.find(S) == dic.end() ? "no" : "yes"));
    }
  }

  return 0;
}



Measured memory_bytes: 32168
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}




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

  ll N , A, B ; cin >> N >>  A >> B ;
  string str ; cin >> str;

  ll a = 0, b= 0;
  
  rep(i,N){
    if(str[i] == 'a'){
      if((a + b) < (A+B)){
	cout << "Yes" << endl;
	a++;
      }
      else cout << "No" << endl;
    }
    else if(str[i] == 'b'){
      if(((a+b) < (A+B))  && (b<B)){
	cout << "Yes" << endl;
	b++;
      }
      else cout << "No" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
  
  //cout << fixed << setprecision(16) << ans << endl;
  
  return 0;
}


Measured memory_bytes: 848
#include<iostream>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#define LL long long
using namespace std;
int const maxn=2e5+10;
struct ed
{
    int to,next,before;
}e[2*maxn];
struct bkn
{
    int x,d;
    friend bool operator <(bkn a,bkn b)
    {
        return a.d>b.d;
    }
};
int head[maxn],tot=-1,dis[maxn];
priority_queue<bkn> q;
void add(int a,int b)
{
    e[tot].to=b;
    e[tot].next=head[a];
    head[a]=tot++;
}
LL a[60];
int main()
{
   LL k;
   cin>>k;
   int i;
   cout<<50<<endl;
   LL j=k%50;
   for (i=1;i<=50;i++)
       a[i]=49+k/50;
   for (i=1;i<=k%50;i++)
   {
       a[i]=50+k/50;
   }
   for (i=k%50+1;i<=50;i++)
   {
       a[i]-=k%50;
   }
   for (i=1;i<=50;i++)
       cout<<a[i]<<' ';
   cout<<endl;
}



Measured memory_bytes: 256
ord_list = []
str_in = input()
n = int(input())

for i in range(n):
    try:
        l = list(map(str,input().split()))
    except ValueError:
        l = list(map(str,input().split()))
    ord_list.append(l)

for l in ord_list:
    o = l[0]
    a,b = int(l[1]), int(l[2])
    if o == 'replace':
        str_in= str_in[:a] + l[3] + str_in[b+1:]
    elif o == 'reverse':
        str_in= str_in[:a] + str_in[a:b+1][::-1] + str_in[b+1:]
    elif o == 'print':
        print(str_in[a:b+1])

Measured memory_bytes: 7632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rp(i,n) for(int i=1;i<=(int)n;i++)
int main(){
int n,l;cin>>n>>l;
int s;
if(l+n-1<=0)s=l+n-1;
else if(l>=0)s=l;
else s=0;
int sum=0;
rp(i,n) sum=sum+(l+i-1);
cout<<sum-s<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 222;
const ll inf = 1e15;
ll dis[N][N];
ll dp[N][1<<8];
void MIN(ll &a, ll b) {if (a > b) a = b;}
int n, m, r;
int to[N], a[N];
int main() {
	scanf("%d%d%d", &n, &m, &r);
	
	for (int i = 1; i <= r; ++i) scanf("%d", &a[i]);
	sort(a + 1, a + r + 1);
	
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j) dis[i][j] = i == j ? 0 : inf;
	for (int i = 1; i <= m; ++i) {
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		MIN(dis[x][y], (ll)z);
		MIN(dis[y][x], (ll)z);
	}
	for (int k = 1; k <= n; ++k)	
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= n; ++j) MIN(dis[i][j], dis[i][k] + dis[k][j]);
			
	for (int i = 1; i <= n; ++i) to[i] = -1;
	for (int i = 1; i <= r; ++i) to[a[i]] = 1 << (i - 1);
	
	for (int i = 1; i <= r; ++i)
		for (int s = 0; s < (1 << r); ++s) dp[i][s] = inf;
	for (int i = 1; i <= r; ++i) dp[i][to[a[i]]] = 0;
	
	for (int s = 0; s < (1 << r); ++s) 
		for (int i = 1; i <= r; ++i)
		if (dp[i][s] != inf) {
			for (int j = 1; j <= r; ++j) {
				int pos = to[a[j]];
				if (~pos) MIN(dp[j][s | pos],dp[i][s] + dis[a[i]][a[j]]);
				else MIN(dp[j][s], dp[i][s] + dis[a[i]][a[j]]);
			}
		}
	ll mx = 1e15;
	for (int i = 1; i <= r; ++i) MIN(mx, dp[i][(1 << r) - 1]);
	cout << mx << endl;
	return 0;
} 

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF 1000000007
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define print(x) cout << x << "\n"
#define print2(x, y) cout << x << " " << y << "\n"
#define printv(vec) rep(lp, vec.size()) cout << vec[lp] << " "; print(""); 
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;

const int mod = 1000000007;
class mint {
public:
    ll x;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    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) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res /= a;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

ll modpow(ll a, ll n){
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

void Main(){
	
	ll N, Q;
	string S;
	cin >> N >> S >> Q;

	vector<set<ll>> v(26);
	rep(i, 26) v[i].insert(INF);
	rep(i, N) v[S[i] - 'a'].insert(i);

	rep(i, Q){
		
		ll in1;
		cin >> in1;
		
		if(in1 == 1){
			ll in2;
			char in3;
			cin >> in2 >> in3;
			in2 -= 1;
			v[S[in2] - 'a'].erase(in2);
			S[in2] = in3;
			v[in3 - 'a'].insert(in2);
		}
		
		else{
			ll in2, in3;
			cin >> in2 >> in3;
			in2 -= 1;
			in3 -= 1;
			ll ans = 0;
			rep(j, 26){
				auto itr = v[j].lower_bound(in2);
				if(*itr <= in3) ans += 1;
			}
			print(ans);
		}
	
	}		

}

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	Main();
	return 0;
	
}





Measured memory_bytes: 27240
#include<iostream>
int main(){
	int kane=100000,rishi,kiriage,n,i;
	std::cin>>n;
	for(i=0;i<n;i++){
		kane=kane*1.05;
		rishi=kane-100000;
		kiriage=rishi%1000;
		if(kiriage!=0){
			kiriage=1000-kiriage;
			}
		kane=kane+kiriage;
		}
	std::cout<<kane<<std::endl;
	return 0;
	}

Measured memory_bytes: 1160
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
xy = [inpl() for i in range(n)]
cnt = 0
for i in itertools.permutations(xy):
    for j in range(n-1):
        cnt += math.sqrt(abs(i[j+1][0] - i[j][0])**2+abs(i[j+1][1] - i[j][1])**2)
print(cnt/math.factorial(n))

Measured memory_bytes: 42092
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float('inf')

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse=False):
    data.sort(key=lambda x:x[col],reverse=revese)
    return data

def mymax(data):
    M = -1*float('inf')
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float('inf')
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def mydictvaluesort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[1] )

def mydictkeysort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[0] )

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(' ')
        elif type(ls[0])==str:
            print(' '.join(ls))
        elif type(ls[0])==int:
            print(' '.join(map(str,ls)))
        else:
            print('Output Error')
    else:
        if len(ls)==0:
            print('')
        elif type(ls[0])==str:
            print(''.join(ls))
        elif type(ls[0])==int:
            print(''.join(map(str,ls)))
        else:
            print('Output Error')

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

mod = 10**9 + 7

n,m = MI()

a = factorial(n)%mod
b = factorial(m)%mod

if n==m: 
    ans = a*b*2 % mod
elif (n+1)==m or (m+1)==n:
    ans = a*b % mod
else:
    ans = 0

print(ans)

Measured memory_bytes: 84332
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

  if(abs(N,M)>1){
    cout<<"0"<<endl;
    return 0;
  }

  ll ans=1;
  if(N==M)ans=2;

  FOR(i,1,N){
    ans=ans*i%MOD;
  }
  FOR(i,1,M){
    ans=ans*i%MOD;
  }
    cout<<ans<<endl;
    return 0;


}
 


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int N;
	cin >> N;
	vector<int> p;
	rep(i, 0, N) {
		int tmp;
		cin >> tmp;
		p.push_back(tmp);
	}

	vsort(p);
	int rsl = 0;
	rep(i, 0, N - 1) rsl += p[i];
	rsl += (p[N - 1] / 2);
	cout << rsl << endl;


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1,i,j;
    //cin>>t;
    while(t--)
    {
        int n,m,count=0,sum=0,maxi=0,mini=1e18;
        cin>>n;
      	int temp=n%10;
      if(temp==2 ||temp==4 ||temp==5 ||temp==7 ||temp==9 )
      {
        cout<<"hon";
    	}
      else if(temp==0 || temp==1 || temp==6 || temp==8)
      {
        cout<<"pon";
	  }
      else
      {
        cout<<"bon";
      }
    }
}

Measured memory_bytes: 3640
N = int(input())
H = list(map(int,input().split()))
for i in range(N-2,-1,-1):
  if H[i]>H[i+1] and H[i]-H[i+1]==1:
    H[i] = H[i]-1
  elif H[i]<=H[i+1]:
    H[i] = H[i]
  else:
    print("No")
    exit()
print("Yes")


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

int main() {

    int h,w;

    cin >> h >> w;

    int c[10][10];

    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            cin >> c[i][j];
        }
    }

    for (int k = 0; k < 10; k++) {
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }

    int ans = 0;

    int a;

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> a;
            if(a != -1){
                ans += c[a][1];
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
  string str;
  cin >> str;

  int count1,count2 = 0;
  for (int i = 0; i < str.size(); i++) {
    if (str.at(i) == 'A') {
      count1=i+1;
      break;
    }
  }
  for(int i=str.size()-1;i>0;i--){
    if(str.at(i)=='Z'){
      count2=i+1;
      break;
    }
  }
  cout<<count2-count1+1<<endl;
}
      




Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define reft0(i, j) setfill('0') << setw(i) << j

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

int main(){
    int H, W, h, w;
    cin >> H >> W >> h >> w;

    int max = H * W;
    int black = h * W + w * H - h * w;

    cout << max - black << endl;
    return 0;
}

Measured memory_bytes: 256
#include <string.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iomanip>

using namespace std;
#define INF 1e9
#define MAX 300005
#define MOD 1000000007
#define Q queue
#define PQ priority_queue
#define fr first
#define sc second
#define pb push_back
#define mp make_pair
#define FOR( i, L, U ) for(int i=(int)L ; i<(int)U ; i++ )
#define FORD( i, U, L ) for(int i=(int)U ; i>=(int)L ; i-- )
#define wa cout<<"Wa"<<endl
#define READ(filename)  freopen(filename, "r", stdin);
#define WRITE(filename)  freopen(filename, "w", stdout);

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int> > vvi;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<int, string> mis;
typedef map<int , vector<int> > mvi;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;

void base(){
	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);
}


int main(){
	base();
	int n,arr[MAX];
	vi v;
	cin>>n;
	FOR(i,1,n+1){
		cin>>arr[i];
	}
	if (n%2==0){
		for(int i=n;i>=1;i-=2){
			v.pb(arr[i]);
		}
		for(int i=1;i<=n;i+=2){
			v.pb(arr[i]);
		}
	}else {
		for(int i=n; i>=1; i-=2){
			v.pb(arr[i]);
		}
		for(int i=2;i<=n;i+=2){
			v.pb(arr[i]);
		}
	}
	bool flag = false;
	FOR(i,0,v.size()){
		if (flag) cout<<" ";
		flag = true;
		cout<<v[i];
	}
	return 0;
}



Measured memory_bytes: 3956