akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int N,M;
    cin >> N >> M;
    vector<vector<edge<int>>> e(N);
    for(int i = 0; i < M; i++){
        int l,r,d;
        cin >> l >> r >> d;
        l--;r--;
        e[l].emplace_back(edge<int>(r,d));
        e[r].emplace_back(edge<int>(l,-d));
    }
    queue<pair<int,int>> q;
    int check[N];
    int dist[N];
    bool flag = true;
    for(int i = 0; i < N; i++) check[i] = dist[i] = 0;
    for(int i = 0; i < N; i++){
        if(check[i] == 1) continue;
        q.push(make_pair(0,i));
        while(!q.empty()){
            pair<int,int> p =  q.front();
            q.pop();
            for(auto temp : e[p.second]){
                if(check[temp.to] == 1){
                    if(p.first + temp.cost == dist[temp.to]) continue;
                    else flag = false;
                }
                else{
                    check[temp.to] = 1;
                    dist[temp.to] = p.first + temp.cost;
                    q.push(make_pair(dist[temp.to],temp.to));
                }
            }
            if(!flag){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 9984
n, a, b = map(int, input().split())
mod = 10**9 + 7
ans = pow(2, n, mod) - 1

nPa = 1
fac_a = 1
nPb = 1
fac_b = 1

for i in range(1, b + 1):
    if i <= a:
        nPa = nPa * (n - i + 1) % mod
        fac_a = fac_a * i % mod
    
    nPb = nPb * (n - i + 1) % mod
    fac_b = fac_b * i % mod

nCa = nPa % mod * pow(fac_a, mod - 2, mod) % mod
nCb = nPb % mod * pow(fac_b, mod - 2, mod) % mod

ans -= nCa + nCb

print(ans % mod)

Measured memory_bytes: 40300
local mfl, mce, mmi = math.floor, math.ceil, math.min
local SegTree = {}
SegTree.updateAll = function(self)
  for i = self.stagenum - 1, 1, -1 do
    for j = 1, self.cnt[i] do
      self.stage[i][j] = self.stage[i + 1][j * 2 - 1] + self.stage[i + 1][j * 2]
    end
  end
end
SegTree.create = function(self, n)
  self.emptyvalue = 0
  local stagenum, mul = 1, 1
  self.cnt, self.stage, self.size = {1}, {{}}, {}
  while mul < n do
    mul, stagenum = mul * 2, stagenum + 1
    self.cnt[stagenum], self.stage[stagenum] = mul, {}
  end
  for i = 1, stagenum do self.size[i] = self.cnt[stagenum + 1 - i] end
  self.stagenum = stagenum
  for i = 1, mul do self.stage[stagenum][i] = 0 end
  self:updateAll()
end
SegTree.getRange = function(self, left, right)
  if left == right then return self.stage[self.stagenum][left] end
  local start_stage, mul = 1, 1
  while right - left + 1 < self.size[start_stage] do
    start_stage = start_stage + 1
  end
  local ret = self.emptyvalue
  local tasks = {{start_stage, left, right}}
  local done = 0
  while done < #tasks do
    done = done + 1
    local task = tasks[done]
    local stage, l, r = task[1], task[2], task[3]
    local sz = self.size[stage]
    if (l - 1) % sz ~= 0 then
      local newr = mce((l - 1) / sz) * sz
      table.insert(tasks, {stage + 1, l, mmi(r, newr)})
      l = newr + 1
    end
    if sz <= r + 1 - l then
      local pos = mce(l / sz)
      ret = ret + self.stage[stage][pos]
      l = l + sz
    end
    if l <= r then
      table.insert(tasks, {stage + 1, l, r})
    end
  end
  return ret
end
SegTree.decValue = function(self, idx)
  self.stage[self.stagenum][idx] = self.stage[self.stagenum][idx] - 1
  for i = self.stagenum - 1, 1, -1 do
    local dst = mce(idx / 2)
    local rem = dst * 4 - 1 - idx
    self.stage[i][dst] = self.stage[i + 1][idx] + self.stage[i + 1][rem]
    idx = dst
  end
end
SegTree.inc = function(self, idx)
  self.stage[self.stagenum][idx] = 1 + self.stage[self.stagenum][idx]
end
SegTree.new = function(n)
  local obj = {}
  setmetatable(obj, {__index = SegTree})
  obj:create(n)
  return obj
end

local n, k = io.read("*n", "*n")
local sum, tmp, conv = {}, {}, {}
sum[1] = io.read("*n") - k
for i = 2, n do
  sum[i] = sum[i - 1] + io.read("*n") - k
end
sum[n + 1] = 0
for i = 1, n + 1 do tmp[i] = sum[i] end
table.sort(tmp)
local sumTypeCount = 1
local sumTypeList = {}
conv[tmp[1]] = 1
sumTypeList[1] = tmp[1]
for i = 2, n + 1 do
  if tmp[i] ~= sumTypeList[sumTypeCount] then
    sumTypeCount = sumTypeCount + 1
    conv[tmp[i]] = sumTypeCount
    sumTypeList[sumTypeCount] = tmp[i]
  end
end
local segtree = SegTree.new(sumTypeCount)
for i = 1, n do
  segtree:inc(conv[sum[i]])
end
segtree:updateAll()
local bias = 0
local cnt = 0
for i = 1, n do
  cnt = cnt + segtree:getRange(conv[bias], sumTypeCount)
  segtree:decValue(conv[sum[i]])
  bias = sum[i]
end
print(cnt)


Measured memory_bytes: 35244
#include<iostream>
#include<math.h>
#include<iomanip>
#include<string.h>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<algorithm>

using namespace std;

int cost = 0;

void mincost(int c[], int a[], int k, int mina){
  int minc = 10000;
  int sum = 0;
  for(int i = 0; i < k; i++){
    minc = min(a[c[i]], minc);
    sum += a[c[i]];
  }
  cost += min(sum + (k - 2) * minc, sum + minc + (k + 1) * mina);
}

int main(){

  int n, mina = 10000;
  cin >> n;

  int a[n], b[n], c[n];
  for(int i = 0; i < n; i++){
    cin >> a[i];
    b[i] = a[i];
    mina = min(mina, a[i]);
  }

  sort(b, b + n);

  int k = 0, i = 0, flag = 0;

  while(flag != n){


    c[k] = i;

    for(i = 0; i < n; i++){
      if(a[c[k]] == b[i]){
        k++;
        if(c[0] == i){
          if(k > 1) mincost(c, a, k, mina);
          for(int j = 0; j < k; j++){
            a[c[j]] = -1;
          }
          k = 0;

          flag  = 0;
          for(int l = 0; l < n; l++){
            if(a[l] == -1) flag++;
            else{
              i = l;
              break;
            }
          }
        }
        break;
      }
    }
  }





cout << cost << endl;

}



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

int main() {
    int r, g, b;
    cin >> r >> g >> b;
    int x = 100 * r + 10 * g + b;

    if(x % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

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

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

    int N = S.size();
    vector<int> a(N + 1);
    for (int i = 0; i < N; i++) {
        if (S[i] == '<') a[i + 1] = a[i] + 1;
    }
    for (int i = N - 1; i >= 0; i--) {
        if (S[i] == '>') a[i] = max(a[i], a[i + 1] + 1);
    }

    long long ans = 0;
    for (int x : a) ans += x;

    cout << ans << endl;
}

Measured memory_bytes: 5804
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort(key=lambda x:-x)
b.sort(key=lambda x:-x)
c.sort(key=lambda x:-x)
beauty=[]
index=0
for i in range(x):
    for j in range(y):
        for l in range(z):
            if (i+1)*(j+1)*(l+1)<=k:
                beauty.append(a[i]+b[j]+c[l])
            else:
                break
beauty.sort(key=lambda x:-x)
for i in range(k):
    print(beauty[i])


Measured memory_bytes: 13260
package main
import "fmt"
func main() {
  const infty int = 200000000
  var n,m int
  var a,b,c []int
  var d [][]int
  fmt.Scan(&n,&m)
  a = make([]int,m)
  b = make([]int,m)
  c = make([]int,m)
  d = make([][]int,n)
  for i:=0;i<n;i++ {
    d[i] = make([]int,n)
    for j:=0;j<n;j++ {
      d[i][j] = infty
    }
    d[i][i] = 0
  }
  for i:=0;i<m;i++ {
    fmt.Scan(&a[i],&b[i],&c[i])
    a[i],b[i] = a[i]-1,b[i]-1
    d[a[i]][b[i]] = c[i]
    d[b[i]][a[i]] = c[i]
  }
  for k:=0;k<n;k++ {
    for i:=0;i<n;i++ {
      for j:=0;j<n;j++ {
        if d[i][j] > d[i][k]+d[k][j] { d[i][j] = d[i][k]+d[k][j] }
      }
    }
  }
  var x int = m;
  for k:=0;k<m;k++ {
    var ok bool = false
    for i:=0;i<n;i++ {
      if d[i][a[k]]+c[k] == d[i][b[k]] {
        ok = true
        break
      }
    }
    if ok { x-- }
  }
  fmt.Println(x)
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int64_t INF = 1LL << 60;

int main() {
 int N,M;
 cin>>N>>M;
 int a[100];
 int b[100];
 int c[100];
 int d[100];
 for(int i=0;i<N;i++){
     cin>>a[i]>>b[i];
 }
 for(int i=0;i<M;i++){
     cin>>c[i]>>d[i];
 }
 for(int i=0;i<N;i++){
     int m=999999999;int r=0;;
     for(int j=0;j<M;j++){
      int h=abs(c[j]-a[i])+abs(d[j]-b[i]);
      if(m>h){r=j+1;m=h;}
     }
     cout<<r<<endl;
 }
 return 0;
}

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

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(M), B(M);
	for (int i = 0; i < M; i++)
	{
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
	}

	vector<long long> ans(M);
	ans[M - 1] = (long long)N * (N - 1) / 2;

	UnionFind Uni(N);

	for (int i = M - 1; i >= 1; i--)
	{
		ans[i - 1] = ans[i];

		//繋がってなかったのが繋がった時
		if (Uni.root(A[i]) != Uni.root(B[i])) {
			ans[i - 1] -= (long long)Uni.size(A[i]) * Uni.size(B[i]);
			Uni.connect(A[i], B[i]);
		}
	}

	for (int i = 0; i < M; i++)
	{
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int n,m;
bool G[10][10];
void solve(){
    vector<int> ord(n);
    for(int i=0 ; i<n ; i++)    ord[i] = i;

    int res = 0;

    do{
        if(ord[0] != 0) break;
        bool ok = true;
        for(int i=0 ; i+1<n ; i++){
            int from = ord[i];
            int to = ord[i+1];
            if(!G[from][to]) ok = false;
        }
        if(ok) res++;
    }while(next_permutation(ord.begin(), ord.end()));
    cout << res << endl;
}

int main(){
    cin >> n >> m;
    for(int i=0 ; i<m ; i++){
        int x,y;
        cin >> x >> y;
        --x;    --y;
        G[x][y] = G[y][x] = true;
    }
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define rep1(i,n)  for(ll i=1; i<=n; i++)
#define rrep1(i,n) for(ll i=n; 1<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using ll = long long;
using namespace std;

int main(int argc, char const *argv[]) {
  int a,b,c;  cin >> a >> b >> c;
  cout << min(b/a,c);
  return 0;
}


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

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let A: usize = read();
    let B: usize = read();
    let C: usize = read();
    let D: usize = read();
    let E: usize = read();
    let F: usize = read();
    let ans = solve((A, B), (C, D), E, F);
    println!("{} {}", ans.0, ans.1);
}

fn solve(
    waters: (usize, usize),
    salts: (usize, usize),
    disolve_max: usize,
    beaker_max: usize,
) -> (usize, usize) {
    use std::collections::VecDeque;
    let mut water_queue = VecDeque::new();
    let mut water_map: Vec<bool> = vec![false; beaker_max + 1];
    water_queue.push_front(0_usize);
    // 水が0はありえない
    water_map[0] = false;

    while let Some(g) = water_queue.pop_back() {
        let next_0 = g + waters.0 * 100;
        if next_0 <= beaker_max && !water_map[next_0] {
            water_queue.push_front(next_0);
            water_map[next_0] = true;
        }
        let next_1 = g + waters.1 * 100;
        if next_1 <= beaker_max && !water_map[next_1] {
            water_queue.push_front(next_1);
            water_map[next_1] = true;
        }
    }

    let mut salt_queue = VecDeque::new();
    let mut salt_map: Vec<bool> = vec![false; beaker_max + 1];
    salt_queue.push_front(0_usize);
    salt_map[0] = true;
    while let Some(g) = salt_queue.pop_back() {
        let next_0 = g + salts.0;
        if next_0 <= beaker_max && !salt_map[next_0] {
            salt_queue.push_front(next_0);
            salt_map[next_0] = true;
        }
        let next_1 = g + salts.1;
        if next_1 <= beaker_max && !salt_map[next_1] {
            salt_queue.push_front(next_1);
            salt_map[next_1] = true;
        }
    }
    let salt_possibles: Vec<usize> = salt_map
        .into_iter()
        .enumerate()
        .filter(|&v| v.1)
        .map(|v| v.0)
        .collect();
    let water_possibles: Vec<usize> = water_map
        .into_iter()
        .enumerate()
        .filter(|&v| v.1)
        .map(|v| v.0)
        .collect();
    let mut max_density = 0.0;
    let mut tuple = (100 * waters.0, 0);
    for &s in &salt_possibles {
        for &w in &water_possibles {
            if s + w > beaker_max {
                continue;
            }
            if s + w == 0 {
                continue;
            }
            if disolve_max * (w / 100) < s {
                continue;
            }
            let density = s as f64 / (w + s) as f64;
            if max_density < density {
                max_density = density;
                tuple = (s + w, s);
            }
        }
    }
    tuple
}


Measured memory_bytes: 4352
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int num = scan.nextInt();
        int	div1 = num / 500;
        int happy1 = div1 * 1000;
        int div2 = (num - (div1 * 500)) / 5;
        int happy2 = div2 * 5;
        int sum = happy1 + happy2;
        System.out.println(sum);
    }
 }


 

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

using namespace std;
typedef long long ll;
#define MOD 1000000007

int main()
{
  ll n;
  cin >> n;
  vector<ll> degs(n + 1, 0);
  vector<set<ll>> edges(n + 1, set<ll>{}); // ノードに何番目のedgeがつながっているか

  for (auto i = 0; i < n - 1; i++)
  {
    ll a, b;
    cin >> a >> b;
    edges[a].insert(i + 1);
    edges[b].insert(i + 1);
  }

  ll max_degree = 0;
  for (auto i = 1; i <= n; i++)
  {
    max_degree = max((long long)(edges[i].size()), max_degree);
  }

  // 色がついていないものを0とする
  vector<ll> colors(n, 0);
  set<ll> visited = {};
  queue<ll> q{};

  for (auto i = 1; i <= n; i++)
  {
    auto edge_list = edges[i]; // nodeにあるedges.
    set<ll> used_color = {};
    for (auto edge : edge_list)
    {
      used_color.insert(colors[edge]);
    }

    ll color_start = 1;
    for (auto edge : edge_list)
    {
      if (colors[edge] == 0)
      {
        for (auto j = color_start; j <= max_degree; j++)
        {
          if (used_color.count(j) == 0)
          {
            colors[edge] = j;
            used_color.insert(j);
            color_start = j + 1;
            break;
          }
        }
      }
    }
  }

  cout << max_degree << endl;
  for (auto i = 1; i <= n - 1; i++)
  {
    cout << colors[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 16128
def change_and_check(arr,rowarr,colarr,k):
	#l=arr[:][:]
	for i in range(len(rowarr)):
		ele=rowarr[i]
		for j in range(len(arr[0])):
			arr[ele][j]="r" 
	for i in range(len(colarr)):
		ele=colarr[i]
		for j in range(len(arr)):
			arr[j][ele]="r" 
	#print(arr)
	return count(arr)==k  
def count(arr):
	c=0 
	for i in range(len(arr)):
		for j in range(len(arr[0])):
			if arr[i][j]=="#":
				c+=1 
	return c
import itertools 
from copy import copy, deepcopy
frow=[] 
fcol=[] 
h,w,k=map(int,input().split()) 
a=[] 
f=list(range(h))
g=list(range(w))
for i in range(h):
	n=input()
	a.append(list(n))
for kk in range(h+1):
	l=list(map(list,itertools.combinations(f,kk)))
	frow+=l
for kk in range(w+1):
	l=list(map(list,itertools.combinations(g,kk)))
	fcol+=l 
#print(frow,fcol)
arr=deepcopy(a)
#print(arr)
cc=0 
#print(k)
for x in frow:
	for y in fcol:
		#print(a)
		if change_and_check(a,x,y,k):
			cc+=1 
		a=deepcopy(arr)
print(cc)









Measured memory_bytes: 9344
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), h[] = new int[n];
		long dp[] = new long[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
			dp[i] = Integer.MAX_VALUE;
		}
		dp[0] = 0;
		for (int i = 1; i < n; i++) {
			long a = Integer.MAX_VALUE;
			if (i - 1 >= 0)
				a = dp[i - 1] + Math.abs(h[i - 1] - h[i]);
			long b = Integer.MAX_VALUE;
			if (i - 2 >= 0)
				b = dp[i - 2] + Math.abs(h[i - 2] - h[i]);
			dp[i] = Long.min(a, b);
		}
		System.out.println(dp[n - 1]);
		sc.close();
	}
}


Measured memory_bytes: 60584
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;
bool bad[100005];
long long MOD=1e9+7;
long long dp[100005];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int N,M;
	cin>>N>>M;
	for(int i=1;i<=M;i++){
		int x;
		cin>>x;
		bad[x]=true;
	}
	dp[0]=1;
	for(int i=1;i<=N;i++){
		if(bad[i]) dp[i]=0;
		else{
			if(i>1) dp[i]=(dp[i-1]+dp[i-2])%MOD;
			else dp[i]=dp[i-1];
		}
	}
	cout<<dp[N];
}

Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();
        string s = sc.Next();

        long[] counts = new long[26];

        foreach (var c in s)
        {
            counts[c - 'a']++;
        }

        ModInt answer = 1;

        foreach (var count in counts)
        {
            answer *= (count + 1);
        }
        answer = answer - 1;

        Console.WriteLine(answer);
    }

    // ModInt
    class ModInt
    {
        public const long Mod = (int)1e9 + 7;

        public long num;

        public ModInt(long n) { num = n; }

        public override string ToString() { return num.ToString(); }
        public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; }
        public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; }
        public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); }
        public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); }

        public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }

        public static ModInt Pow(long v, long k)
        {
            long ret = 1;
            for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
                if ((k & 1) == 1) ret = ret * v % Mod;
            return new ModInt(ret);
        }

        public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

const int MAX = 200000;
int main() {
	int n, now, cng = -1;
	static int a[MAX];
	cin >> n;
	now = n / 2;
	if (n % 2) cng = 1;
	for (int i = 0;i < n;i ++) {
		cin >> a[now];
		now += cng;
		cng += cng > 0 ? 1 : -1;
		cng = -1 * cng;
	}
	cout << a[0];
	for (int i = 1;i < n;i ++) cout << ' ' << a[i];
	return 0;
}
// 1 2 3 4 5 6 7

// 1
// 2 1
// 3 1 2
// 4 2 1 3
// 5 3 1 2 4
// 6 4 2 1 3 5
// 7 5 3 1 2 4 6

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

using namespace std;

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

  vector<int> a;

  for (int i = 0; i < str.size(); i++) {
    if (str[i] == '0') {
      a.push_back(0);
    } else if (str[i] == '1') {
      a.push_back(1);
    } else if (a.size() > 0) {
      a.pop_back();
    }   
  }

  for (int j = 0; j < a.size(); j++) {
    cout << a[j];
  }
  cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(1){
		if(a<=0||c<=0)break;
		c-=b;
		if(a<=0||c<=0)break;
		a-=d;
	}
	if(c<=0)puts("Yes");
	else puts("No");
}

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

int digit(int N)
{
    if (N >= 10)
    {
        int tmp{};
        while (N > 0)
        {
            tmp += (N % 10);
            N /= 10;
        }
        N = tmp;
    }
    return N;
}

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

    x = digit(n);

    if (n%x==0)
    {
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;
int main(){
	ll mod=1e9+7;
	ll N,p=1;
	cin>>N;
	REP(i,1,N+1){
		p*=i;
		p%=mod;
	}
	cout<<p<<endl;
	return 0;
}



Measured memory_bytes: 256
h,w=gets.split.map &:to_i
o=[]
m=[]
h.times{|i|
  m<<gets.split.map(&:to_i)
  (w-1).times{|j|
    if m[i][j]%2==1
      o<<[i+1,j+1,i+1,j+2]*" "
      m[i][j]-=1
      m[i][j+1]+=1
    end
  }
}
(h-1).times{|i|
  if m[i][-1]%2==1
    o<<[i+1,w,i+2,w]*" "
    m[i][-1]-=1
    m[i+1][-1]+=1
  end
}

puts o.size,o


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

using namespace std;

int main(int argc, char const *argv[]) {
  long long a, b;

  cin >> a >> b;

  if (a * b % 2 == 0)
  {
    cout << "Even" << endl;
  }
  else
  {
    cout << "Odd" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
fun main(args:Array<String>) {
    val n = readLine()!!.toInt()
    val masu = readLine()!!.split(" ").map { it.toLong() }
    val move = masu.indices.map { 0 }.toMutableList()
    for(i in (0 until masu.size - 1).reversed()) {
        if(masu[i] >= masu[i+1]) {
            move[i] = move[i+1] + 1
        } else {
            move[i] = 0
        }
    }
    val ans = move.max()!!
    println(ans)

}


Measured memory_bytes: 59380
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

void put(int a,int b){
	cout << a + 1 << " " << b + 1 << endl;
}

signed main(){
	int n,a[60],ma = -1,mai;
	vector<P> vec;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		if(ma < abs(a[i])){
			ma = abs(a[i]);
			mai = i;
		}
	}
	if(!ma){
		cout << 0 << endl;
		return 0;
	}
	if(a[mai] < 0){
		for(int i = n - 1;i > mai;i--){
			vec.pb(P(mai,mai));
			vec.pb(P(mai,i));
		}
		vec.pb(P(mai,mai));
		for(int i = mai;i >= 1;i--){
			vec.pb(P(i,i - 1));
			vec.pb(P(i,i - 1));
		}
	}else{
		for(int i = 0;i < mai;i++){
			vec.pb(P(mai,mai));
			vec.pb(P(mai,i));
		}
		vec.pb(P(mai,mai));
		for(int i = mai;i < n - 1;i++){
			vec.pb(P(i,i + 1));
			vec.pb(P(i,i + 1));
		}
	}
	cout << vec.size() << endl;
	for(int i = 0;i < vec.size();i++) put(vec[i].first,vec[i].second);
	return 0;
}

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

using namespace std;

typedef long long LL;


int main() {
  string s;
  cin >> s;
  s = s.substr(0, 4) + " " + s.substr(4);
  cout << s << endl;
  return 0;
}


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

int main() {
  int n;
  int diameter;
  
  cin >> n;
  
  vector<int> appears = vector<int>(100,0);
  
  int sum = 0;
  for(int i=0; i<n; i++){
    cin >> diameter;
    if(appears[diameter]==0){
      appears[diameter]++;
      sum++;
    }
  }
  
  cout << sum <<endl;
  
}


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

int main()
{
    int k,x;
    cin >> k >> x;
    rep2(i,x-k+1,x+k) cout << i << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){
   string s;
   cin >> s;
   sort(s.begin(),s.end());

   bool flg = 1;
   rep(i,s.size()-1){
      if(s[i]==s[i+1]) flg = 0;
   }
   if(flg) cout << "yes" << endl;
   else cout << "no"  << endl;

   return 0;
}

Measured memory_bytes: 256
// 1_abc130_a
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, a;
    cin >> x >> a;
    if(x < a) cout << 0 << endl;
    else cout << 10 << endl;
    return 0;
}


Measured memory_bytes: 256
/*
Problem : https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_d
Algorithm : dp
Status : AC
*/
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const int MAXN = 200005;

int n,a[MAXN];
ll dp[MAXN][5],ans = INF;

int main() {
    scanf("%d",&n);
    for(int i = 1;i <= n;i++)
        scanf("%d",&a[i]);
    dp[0][1] = dp[0][2] = dp[0][3] = dp[0][4] = INF;
    for (int i = 1;i <= n;i++) {
        dp[i][0] = dp[i - 1][0] + a[i];
        dp[i][1] = min(dp[i - 1][0],dp[i - 1][1]) + (a[i] ? (a[i] & 1) : 2);
        dp[i][2] = min(min(dp[i - 1][1], dp[i - 1][2]),dp[i - 1][0]) + ((a[i] & 1) ^ 1);
        dp[i][3] = min(dp[i - 1][2],dp[i - 1][3]) + (a[i] ? (a[i] & 1) : 2);
        dp[i][4] = min(std::min(dp[i - 1][1],dp[i - 1][2]),min(dp[i - 1][3],dp[i - 1][4])) + a[i];
    }
    for(int i = 0;i < 5;i++)
        ans = min(ans,dp[n][i]);
    printf("%lld\n", ans);
}


Measured memory_bytes: 8832
l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[int(input())-1])

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b) {if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b) {if(a<b) a=b;}

bool judge(int x, vector<int> d) {
    bool flag = true;
    while(x>0 && flag) {
        if(find(ALL(d),x%10) != d.end()) {
            flag = false;
        }
        x /= 10;
    }
    return flag;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k; cin >> n >> k;
    vector<int> d(k);
    REP(i,k) cin >> d[i];
    int ans = 0, idx = 1;
    FOR(i,n,1000000) {
        if(judge(i,d)) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    ans = 0
    prevdish = -1
    for i in range(n):
        dish = a[i]
        ans += b[dish-1]
        if prevdish == dish-1:
            ans += c[dish-2]
        prevdish = dish
    print(ans)
resolve()

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};



int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n;
    string s;
    cin >>n>>s;
    
    rep(i,n-2){
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
            ans++;
        }
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout<<ans<<endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<string>
#include<math.h>

using namespace std;

typedef long long ll;
const ll mod = 1e9 + 7;
ll N;

ll find(ll a,ll b){
	ll sum=1;
	while(b){
		if(b&1) sum=(sum*a)%mod;
		a=(a*a)%mod;
		b=b/2;
	}
	return sum;
}

int main(){
	scanf("%lld",&N);

	ll ans=find(10,N)-find(9,N)-find(9,N)+find(8,N);
	printf("%lld",(ans%mod+mod)%mod);

	return 0;
}

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

int main(){
    long long int N;

    //入力
    cin >> N;
    long long int a=1;
    long long int b=1;
    long long int c=1;
    for(long long int i=0;i<N;i++){
        a = (a*9)%1000000007;
        b = (b*8)%1000000007;
        c = (c*10)%1000000007;
    }

    long long int ans = (c-2*a+b)%1000000007;
    ans= (ans+1000000007)%1000000007;
    cout << ans << endl;
}

Measured memory_bytes: 3628
module Main where

import Control.Applicative

mygcd x 0 = x
mygcd 0 y = y
mygcd x y
    | x >= y    = gcd y $ mod x y
    | otherwise = gcd x $ mod y x

main = do
    (x:y:[]) <- (map read . words) <$> getLine
    print $ mygcd x y



Measured memory_bytes: 3624
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_BOOK_MAX		200005									// 最大本数

// 内部変数
static FILE *szpFpI;											// 入力
static long long sl1A[D_BOOK_MAX];								// 合計時間(A)
static long long sl1B[D_BOOK_MAX];								// 合計時間(B)
static int siACnt;												// 本数(A)
static int siBCnt;												// 本数(B)
static int siMax;												// 最大時間

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 最大値 - 取得
int
fGetMaxI(
	int piVal1					// <I> 値１
	, int piVal2				// <I> 値２
)
{
	if (piVal1 > piVal2) {
		return piVal1;
	}
	else {
		return piVal2;
	}
}

// 実行メイン
int
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// 本数・ - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d%d", &siACnt, &siBCnt, &siMax);

	// 合計時間(A) - 取得
	for (i = 1; i <= siACnt; i++) {
		fscanf(szpFpI, "%lld", &sl1A[i]);
		sl1A[i] += sl1A[i - 1];
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);

	// 合計時間(B) - 取得
	for (i = 1; i <= siBCnt; i++) {
		fscanf(szpFpI, "%lld", &sl1B[i]);
		sl1B[i] += sl1B[i - 1];
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);

	// 最大本数 - 取得
	int liMax = 0;
	int liBCnt = siBCnt;
	for (int liACnt = 0; liACnt <= siACnt; liACnt++) {

		// 本数(B)を調整
		while (liBCnt >= 0) {
			long long llSum = sl1A[liACnt] + sl1B[liBCnt];
			if (llSum <= (long long)siMax) {
				break;
			}
			else {
				liBCnt--;
			}
		}
		if (liBCnt < 0) {
			break;
		}

		// 最大本数 - 更新
		liMax = fGetMaxI(liMax, liACnt + liBCnt);
	}

	return liMax;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 出力
	sprintf(lc1Buf, "%d\n", liRet);
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 4900
process.stdin.resume();
process.stdin.setEncoding('utf8');
var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});
process.stdin.on('end', function() {
    main(g_input.split(/\r?\n/));
});
function fn(input){
  var f = false
  for(var i=0;i<input.length;i++){
    if(!input[i].match(/\#/)){
      input.splice(i,1)
      i--
      f = true
    }
  }
  for(var i=0;i<input.length;i++){
    input[i] = input[i].split("")
  }
  for(var i=0;i<input[0].length;i++){
    var flag = true
    for(var j=0;j<input.length;j++){
      if(input[j][i]=="#") flag=false
    }
    if(flag){
      for(var j=0;j<input.length;j++){
        input[j].splice(i,1)
      }
      j--
      f = true
    }
  }
  for(var i=0;i<input.length;i++){
    input[i] = input[i].join("")
  }
  input = input.join("\n")
  return [f,input]
}

function main (input){
  input.splice(0,1)
  var a = fn(input)
  
  while(a[0]){
    a = fn(input)
  }
  
  console.log(a[1])
}

Measured memory_bytes: 21192
def resolve():
    import sys
    input = sys.stdin.readline
 
    n = input().rstrip()
    past_a = 0
 
    ans = 0
    for a in input().rstrip().split(" "):
        a = int(a)
        #print(a)
        ans += a * past_a
        #print(ans)
        past_a += a
        #print(past_a)
 
    x = 1000000007
 
    ans = ans % x
 
    print(ans)
 
if __name__ == "__main__":
    resolve()


Measured memory_bytes: 82716
#include <iostream>
#include <cmath>
using namespace std;
bool is_prime_number(int n)
{
    if (n == 1)
    {
        return false;
    }
    if (n == 2)
    {
        return true;
    }
    else if (n % 2 == 0)
    {
        return false;
    }
    int i = 3;
    while (i <= sqrt(n))
    {
        //もし割り切れたら素数ではない
        if (n % i)
        {
            i += 2;
        }
        else
        {
            return false;
        }
    }
    return true;
}
int main()
{
    int N;
    cin >> N;

    int pn = 0;
    for (int i = 0; i < N; i++)
    {
        int n;
        cin >> n;
        if (is_prime_number(n))
        {
            pn++;
        }
    }

    cout << pn << endl;
}
//map?
//配列にtrue false



Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll int,ll int>
#define PI 2*acos(0)
//#define mx 100005
#define INF LONG_LONG_MAX
using namespace std;
const ll int p=1000000007;
//vector<ll > prime;
//bool mark[mx];
ll int mod(ll int a,ll int b)
{
    ll int m=a%b;
    if(m<0) m=(b<0)?(m-b):(m+b);
    return m;
}
ll maxpow(ll n)
{
    return (n & (~(n-1)));
}
bool isPrime(ll n)
{
    if(n<2) return false;
    if(n==2) return true;
    if(n%2==0) return false;
    for(ll i=3;i*i<=n;i+=2){
        if(n%i==0) return false;
    }
    return true;
}
/*void init()
{
    mark[1]=1;
    int i,j,limit=sqrt(mx*1.0)+2;
    prime.push_back(2);
    for(i=4;i<mx;i+=2) mark[i]=1;
    mark[2]=0;
    for(i=3;i<mx;i+=2){
        if(!mark[i]){
            prime.push_back(i);
            if(i<=limit){
                for(j=i*i;j<mx;j+=2*i){
                    mark[j]=1;
                }
            }
        }
    }
}*/
/*
ll maxdiv(ll n)
{
    ll i,ans=1;
    for(i=0;i<prime.size();i++){
        if(n%prime[i]==0){
            ans=n/prime[i];break;
            //return ans;
        }
    }
    return ans;
}*/
ll lcm(ll a,ll b)
{
    ll ans=a*b;
    return (ans/__gcd(a,b));
}
// ax+by and a>b
ll gcd(ll a,ll b,ll &x,ll &y)
{
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1,y1;
    ll d=gcd(b,mod(a,b),x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return d;
}
ll abso(ll a)
{
    if(a>=0) return a;
    return -a;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    int d[n][2];
    for(int i=0;i<n;i++) cin>>d[i][0]>>d[i][1];
    bool found=0;
    for(int i=0;i+2<n;i++){
        if(d[i][0]==d[i][1] && d[i+1][0]==d[i+1][1] && d[i+2][0]==d[i+2][1]){
            found=1;
            break;
        }
    }
    if(found) cout<<"Yes";
    else cout<<"No";
    return 0;
}
//1028C


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
	long double l;
	cin>>l;
	long long a,b;
	a=(l/3)*(l/3)*(l/3);
	b=((l/3)*(l/3)*(l/3)-a)*1000000000;
	if(((l/3)*(l/3)*(l/3)-a)!=b/1000000000){
		cout<<a<<"."<<"0"<<b<<endl;
	}
	else
	cout<<a<<"."<<b<<endl;
  return(0);
}

Measured memory_bytes: 256
import scala.io.StdIn
import scala.collection.mutable._

object Main extends App {

  val Array(n, m) = StdIn.readLine.split(" ").map(_.toInt)
  val graph = Array.fill(n+1)(ListBuffer.empty[Int])
  Iterator.continually(StdIn.readLine)
    .take(m)
    .map(_.split(" ").map(_.toInt))
    .foreach(e => graph(e(0)) += e(1))

  val visit = Array.ofDim[Boolean](n+1)
  def dfs(pos:Int, cnt:Int):Unit = {
    if(cnt < 0) return
    visit(pos) = true
    if(visit(n)) return
    // print(pos + " ")
    for(i <- graph(pos)) {
      dfs(i, cnt-1)
    }
  }

  dfs(1,2)
  val ans = if(visit(n)) "POSSIBLE" else "IMPOSSIBLE"
  println(ans)
}

Measured memory_bytes: 83324
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

const int MAX_N = 100010;
int n;
int a[MAX_N];
map<int, int> cnt;

void input(){
    cin >> n;
    for(int i=0;i<n;i++) cin >> a[i];
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    int ans = 0;
    for(int i=0;i<n;++i) cnt[a[i]]++;
    for(auto c: cnt){
        int val = c.first;
        int num = c.second;
        if (num < val) ans += num;
        else ans += (num - val);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5120
import java.util.*;
class Main{
  public static void main(String[] a ){
    Scanner sc=new Scanner(System.in);
String s=sc.next();
for(int i=0;i<s.length();i++){
System.out.print(s.charAt(i)=='1'?'9':(s.charAt(i)=='9'?'1':s.charAt(i)));}System.out.println();}}  

Measured memory_bytes: 22228
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
vector <ll> v[200005];
ll ans=1000005;
ll cnt=0;
ll cnt1=0;
bool vis[200005];
void dfs(ll src)
{
	vis[src]=true;
	cnt++;
	for(auto it:v[src])
	{
		if(!vis[it])
		{
			dfs(it);
		}
	}
}
 
int32_t main() 
{
	fastIO;
	ll n,a,b,q,m,c,y,x,i,j,k,arr[200005];
	cin>>n>>m;
	while(m--)
	{
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	memset(vis,false,sizeof(vis));
	dfs(1);
	for(i=2;i<=n;i++)
	{
		if(!vis[i])
		{
			cnt1++;
			dfs(i);
		//	ans=min(ans,cnt);
		}
	}
	cout<<cnt1<<endl;
	return 0;
}

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

int main(void) {
    int n;
    cin >> n;
    int a[110];
    int b[110];
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];

    int max = 0;
    for (int i = 0; i < n; i++) {
        int sum = 0;
        for (int j = 0; j <= i; j++) {
            sum += a[j];
        }
        for (int j = i; j < n; j++) {
            sum += b[j];
        }
        if (sum > max) max = sum;
    }
    cout << max << endl;
    return 0;
}

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

void swap(int *i, int *j) {
    int z;
    z = *i;
    *i = *j;
    *j = z;
}

int main() {
    int N;
    cin >> N;
    int d[101]={};
    for(int i=0; i<N; ++i) {
        cin >> d[i];
    }
    int c = 0;
    for(int i = 0; i < N-1; ++i) {
        for(int j = i+1; j < N; ++j) {
            if(d[i] < d[j]) {
                swap(d+i, d+j);
            }
        }
    }
    for(int i = 0; i < N; ++i) {
        if(d[i] != d[i+1]) {
            ++c;
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<stdlib.h>
#include<limits>

using namespace std;

static const int MAX=100;
static const int INFTY=numeric_limits<int>::max();

typedef enum {
    WHITE,
    GRAY,
    BLACK,
}Color;

int n,M[MAX][MAX];

void Dijkstra(){
    int minv;
    int d[MAX];
    Color color[MAX];

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

    for(int i=0;i<n;i++){
        cout<<i<<' '<<(d[i]==INFTY ? -1 : d[i])<<endl;
    }
}

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

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

    Dijkstra();

    return 0;
}



Measured memory_bytes: 3124
import java.util.Scanner;
class Main {
  
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int[] x = new int[n];
        int[] y = new int[n];
        for(int i = 0; i < n; i++) {
            x[i] = stdIn.nextInt();
        }
        for(int i = 0; i < n; i++) {
            y[i] = stdIn.nextInt();
        }
        for(int p = 1; p <= 3; p++) {
            double dis = 0.0;
            for(int i = 0; i < n; i++) {
                dis += Math.pow(Math.abs(x[i] - y[i]),p);
            }
            System.out.println(Math.pow(dis, 1.0/p));
        }
        int max = 0;
        for(int i = 0; i < n; i++) {
            max = Math.max(max, Math.abs(x[i] - y[i]));
        }
        System.out.println(max);
        
        stdIn.close();
    }
}



Measured memory_bytes: 26600