akhauriyash/Code-Regression huggingface dataset:
def solve(dat):
    H = len(dat)
    W = len(dat[0])

    for i in range(H):
        for j in range(W):
            if dat[i][j] == "@":
                si, sj = i, j

    tmp = [[0 for _ in range(W)] for _ in range(H)]
    di = [-1,1,0,0]
    dj = [0,0,-1,1]
    pool = [(si, sj)]

    while len(pool) > 0:
        # print pool, i, j
        i, j = pool.pop()
        tmp[i][j] = 1
        for k in range(4):
            ni = i + di[k]
            nj = j + dj[k]
            if ni in range(H) and nj in range(W) and dat[ni][nj] == "." and tmp[ni][nj] == 0:
                pool.append((ni, nj))
    cnt = sum([sum(tmp[i]) for i in range(H)])
    return cnt


while True:
    W, H = map(int, raw_input().split(" "))
    if W == H == 0:
        break
    dat = [raw_input() for _ in range(H)]
    print solve(dat)


Measured memory_bytes: 4304
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<Integer> pointlist = new ArrayList<Integer>();

		int n = sc.nextInt();
		int k = sc.nextInt();
		sc.nextLine();

		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			pointlist.add(a);
		}


		for (int a = 0; a < pointlist.size() - k; a++) {
			if (pointlist.get(a)<pointlist.get(a+k)) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}

	}

}

Measured memory_bytes: 64900
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
#define fin {cout<<"No"<<endl;return 0;}
//template

//main
signed main(){
  string s;cin>>s;
  map<char,int> m;
  for(char p:s)m[p]++;
  for(auto p:m)if(p.second!=2)fin;
  cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>

int main(void){
	char R[256],S[256];
	scanf("%s\n",R);scanf("%s\n",S);

	strncat(R,R,strlen(S));

	if(strstr(R,S)) printf("Yes\n");
	else printf("No\n");

	return 0;
}



Measured memory_bytes: 2112
inp = input().split(" ")
h = int(inp[0])
w = int(inp[1])

grid = []

for i in range(h):
	grid.append(list(input()))

for i in range(h):
	for j in range(w):
		c = grid[i][j]
		if c == ".":
			total = 0
			adj = []
			if i > 0:
				adj.append(grid[i-1][j])
			if j > 0:
				adj.append(grid[i][j-1])
			if i < h-1:
				adj.append(grid[i+1][j])
			if j < w-1:
				adj.append(grid[i][j+1])
			if i > 0 and j > 0:
				adj.append(grid[i-1][j-1])
			if i > 0 and j < w-1:
				adj.append(grid[i-1][j+1])
			if i < h-1 and j > 0:
				adj.append(grid[i+1][j-1])
			if i < h-1 and j < w-1:
				adj.append(grid[i+1][j+1])
			for k in adj:
				if k == "#":
					total += 1
			grid[i][j] = str(total)

for i in grid:
	print("".join(i))


Measured memory_bytes: 3188
def main():
    s_input = input()

    n_s = len(s_input) - 1

    result_sum = 0
    for i in range(2 ** n_s):
        add_op = [''] * n_s
        for j in range(n_s):
            if ((i >> j) & 1):
                add_op[(n_s - 1) - j] = '+'

        formula = '0+'
        for k_ in range(len(s_input)):
            if k_ == 0:
                formula += s_input[0]
            else:
                formula += (add_op[k_ -1] + s_input[k_])

        result_sum += eval(formula)

    print(result_sum)

if __name__ == "__main__":
    main()


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

using namespace std;

int main(){

    //freopen("data.in","r",stdin);
    //freopen("data.out","w",stdout);

    ios :: sync_with_stdio(false);
    cin.tie(0);

    int a,b,c,d,k;

    cin >> a >> b >> c >> d >> k;

    int l = a * 60 + b;
    int r = c * 60 + d;

    r -= k;

    int res = max(0,r - l);

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    string s, t;
    cin >> s >> t;
    string x = s;
    if (s == t)
    {
        cout << s.size() << endl;
        return 0;
    }
    for (int i = 1; i <= N; i++)
    {
        if (s.substr(N - i, i) == t.substr(0, i))
        {
            s += t.substr(i, N - i);
        }
    }
    if (x != t && s == x)
    {
        s += t;
    }
    cout << s.size() << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.Map.Entry;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] t = sc.next().toCharArray();
        char[] s = sc.next().toCharArray();
        HashMap<Character, ArrayList<Integer>> map = new HashMap<>();
        for (int i = 0; i < t.length; i++) {
            if(map.containsKey(t[i])) map.get(t[i]).add(i);
            else{
                map.put(t[i], new ArrayList<>());
                map.get(t[i]).add(i);
            }
        }
        HashMap<Character, int[]> tm = new HashMap<>();
        for(Entry<Character, ArrayList<Integer>> e : map.entrySet()){
            int[] tmp = new int[e.getValue().size()];
            for (int i = 0; i < e.getValue().size(); i++) {
                tmp[i] = e.getValue().get(i);
            }
            tm.put(e.getKey(), tmp);
        }
        long ans = 0L;
        boolean able = true;
        int pre = -1;
        int len = t.length;
        for (int i = 0; i < s.length; i++) {
            if(tm.get(s[i]) == null){
                able = false;
                break;
            }
            int[] tmp = tm.get(s[i]);
            int ins = Arrays.binarySearch(tmp, pre+1);
            if(ins < 0){
                ins = -(ins + 1);
                if(tmp.length-1 < ins){
                    ans += len - pre + tmp[0];
                    pre = tmp[0];
                }else{
                    ans += tmp[ins] - pre;
                    pre = tmp[ins];
                }
            }else{
                ans += tmp[ins] - pre;
                pre = tmp[ins];
            }
        }
        System.out.println(able ? ans : -1);
        sc.close();

    }

}


Measured memory_bytes: 31040
import java.util.*;
public class Main {
	int [][] setted;
	int [] xcard;
	int [] ycard;
	int ans;

	private boolean isRange(int x, int y){
		if(x < 0 || x >= 4 || y < 0 || y >= 4){
			return false;
		}
		else{
			return true;
		}
	}

	private void solve(int deep){
		if(deep == 9){
			ans++;
			return ;
		}
		for(int i=0; i < 4; i++){
			for(int j=0; j < 4; j++){
				if(setted[i][j] == 0){
					for(int k=0; k < 4; k++){
						int xdis = xcard[k] + j;
						int ydis = ycard[k] + i;
						if(isRange(xdis, ydis)  && (setted[ydis][xdis] == 0)){
							setted[i][j] = deep;
							setted[ydis][xdis] = deep;

							solve(deep + 1);

							setted[i][j] = 0;
							setted[ydis][xdis] = 0;
						}

					}
					return ;
				}
			}
		}
		return ;
	}

	public void doIt(){
		Scanner sc = new Scanner(System.in);
		while(true){
			xcard = new int[4];
			ycard = new int[4];
			setted = new int[4][4];
			ans = 0;

			int n = sc.nextInt();
			if(n  > 4){
				break;
			}
			xcard[0] = n;
			ycard[0] = sc.nextInt();
			for(int i=1; i < 4;i++){
				xcard[i] = sc.nextInt();
				ycard[i] = sc.nextInt();
			}
			solve(1);
			System.out.println(ans);
		}
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();
	}
}

Measured memory_bytes: 12000
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}

int A[200000];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N = getint();
	int saidai = 1;
	rep(i, N) {
		A[i] = getint();
		if (A[i] > saidai) saidai = A[i];
	}
	nth_element(A, A + N / 2, A + N);

	if (N % 2) {
		ll kotae = -A[N / 2] - saidai;
		for (int i = N / 2; i < N; i++) {
			kotae += 2 * A[i];
		}
		printf("%lld\n", kotae);
	}
	else {
		ll kotae = - saidai;
		for (int i = N / 2; i < N; i++) {
			kotae += 2 * A[i];
		}
		printf("%lld\n", kotae);
	}


	Would you please return 0;
}

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


int MOD=1000000007;

int main(void){
    double a;
    cin >> a;
    int b;
    b=a;
    if(b%2==0) cout << 0.5000000000 << endl;
    else if(b==1) cout << 1.0000000000 << endl;
    else cout << (b/2+1)/a << endl;
}


Measured memory_bytes: 256
#define _'			'
A[_];long P[_],M=1e9+7,F[_],I[_],X;i,j,k,t;p(a,b){return b?p(a%M*a%M,b/2)*(b%2?a:1L)%M:1;}f(a,b){return F[a+b]*I[a]%M*I[b]%M;}main(s){for(*I=1;++X<_;~scanf("%d",A+i)&&i++%2&&gets(P))I[X]=p(s=F[X]=X*s%M,M-2);for(qsort(A,i/2,8,"H\x8b\6H+\7t\bH\xc1\xe8?\1\xc0\xff\xc8\xc3");j<i;P[j++-1]=X)for(X=f(t=--A[++j],s=--A[k=j]);k;X=s<A[k-=2]?X:(X-f(s-A[k],t-A[k+1])*P[k]%M+M)%M);printf("%d",X);}

Measured memory_bytes: 14336
n, m = (int(i) for i in input().split()) 
py = [[int(i) for i in input().split()] for i in range(m)]
cnt = [0]*(n+1)
ids = {}
for p,y in sorted(py, key=lambda x: x[1]):
  cnt[p] += 1
  ids[y] = '%06d%06d' % (p, cnt[p])
for _, y in py:
  print(ids[y])

Measured memory_bytes: 37632
# Binary Indexed Treeを各アルファベットについてもつ (それぞれN+1の空間を保持し、1-indexで考える)
N = int(input())
S = list(input())
BITS = [[0]*(N+1) for _ in range(26)]
# 初期化を行おうと思ったが、これ自体に関数が必要である
# 値の加算


def ctoi(alphabet):
    return ord(alphabet)-97


# 1~idxまでの文字に各文字がどれだけ出現するか
def BIT_query(idx):
    res = [0]*26
    for i in range(26):
        p = idx
        tmp = 0
        while p > 0:
            tmp += BITS[i][p]
            p -= p & (-p)
        res[i] = tmp
    return res


def BIT_update(idx, alphabet, x):  # idx: int, alphabet: str, x: int
    while idx <= N:
        BITS[ctoi(alphabet)][idx] += x
        idx += idx&(-idx)


# 初期化を行う
for i in range(N):
    BIT_update(i+1, S[i], 1)

# クエリを受け取っていく
Q = int(input())
for _ in range(Q):
    type, a, b = map(str, input().split())
    if type == "1":  # 更新のクエリなら
        # このとき、aはindex, bは変更後の文字(str)である
        a = int(a)
        if S[a-1] == b:
            continue
        BIT_update(a, S[a-1], -1)  # 減らす処理
        BIT_update(a, b, 1)  # 増やす処理
        S[a-1] = b
    elif type == "2":  # 回答する必要があるクエリ
        # このとき、aは左端, bは右端
        a, b = int(a), int(b)
        cnt1 = BIT_query(a-1)
        cnt2 = BIT_query(b)
        ans = 0
        for i in range(26):
            if cnt2[i] > cnt1[i]:
                ans += 1
        print(ans)


Measured memory_bytes: 165956
//includes
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#include<assert.h>
#include<cstring>
#include<unordered_map>
#include<bitset>

//macros and consts
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define FORE(i,a) for(auto &i : a)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define accm accumulate
#define Fi first
#define Se second
#define INF 1e9
#define llINF (1LL<<60)
#define mINF -1e9
#define mllINF -(1LL<<60)
#define endl "\n"
#define CONT continue
#define BRK break
#define modulo(n, m) (((n)%(m)+(m))%m)

//shorter types
using namespace std;
using ll = long long;
using vi = std::vector<int>;
using vc = std::vector<char>;
using vll = std::vector<long long>;
using vs = std::vector<string>;
using Mi = map<int,int>;
using Mll = map<ll,ll>;
using UMi = unordered_map<int,int>;
using UMll = unordered_map<ll,ll>;
using Pi = pair<int,int>;
using Pll = pair<ll,ll>;
using vPi = vector<Pi>;
using vPll = vector<Pll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using pqgi = priority_queue<int,vector<int>,greater<int>>;
using pqsi = priority_queue<int,vector<int>,less<int>>;
using pqgll = priority_queue<int,vector<int>,greater<int>>;
using pssll = priority_queue<int,vector<int>,less<int>>;
template<class T>
using vec = vector<T>;
#define int long long


//here begins your code
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int A,B,K;
  cin >> A >> B >> K;
  if(A >= K){
  	cout << A-K << " " << B << endl;
  }
  else{
  	if(B >= (K - A)){
  		cout << 0 << " " << B - (K - A) << endl;
  	}
  	else{
  		cout << 0 << " " << 0 << endl;
  	}
  }


  //check types
  //do not eb if you resize
  //resize before you access by idx
  return 0;
} 

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

int main(){
  int n; cin>>n;
  vector<int> a(n,0),b(n,0),c(n-1,0);
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++)cin>>b[i];
  for(int i=0;i<n-1;i++)cin>>c[i];
  
  int ans=0;
  for(int i=0;i<n;i++){
    ans+=b[a[i]-1];
    if(i==0)continue;
    if(a[i-1]+1==a[i])ans+=c[a[i-1]-1];
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
R,G,B,n=map(int, input().split())
ans=0

for r in range(n+1):
    if r%R==0:
        for g in range(n+1-r):
            b = n-r-g
            if b%B==0 and r%R==0 and g%G==0:
                ans+=1

print(ans)


Measured memory_bytes: 40796
import java.util.*;

class Main{
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long a[]=new long[n];
		long b[]=new long[n];
		long d[]=new long[n];
		long total=0;
		
		for(int i=0;i<n;++i) {
			a[i]=sc.nextLong();
		}
		for(int i=0;i<n;++i) {
			b[i]=sc.nextLong();
			d[i]=a[i]-b[i];
			total=total+d[i];
		}
		if(total<0) {
			System.out.println(-1);
			return;
		}
		
		Arrays.sort(d);
		long credit=0L;
		int counter=0;
		int num=0;
		for(int i=0;i<n;++i) {
			if(d[i]<0) {
				++num;
				while (-d[i]>=credit) {
					++counter;
					credit=credit+d[n-counter];
				}
				credit=credit+d[i];
			}
			else {
				break;
			}
		}
		System.out.println(counter+num);
		
		
	}
}


Measured memory_bytes: 89444
#include <stdio.h>
 
char a[51][51];
char b[51][51];
 
int main(void){
	int n, m;
	int i, j, k, l, f = 0;
	
	scanf("%d %d", &n, &m);
	
	for (i = 0; i < n; i++){
		scanf("%s", a[i]);
	}
	
	for (i = 0; i < m; i++){
		scanf("%s", b[i]);
	}
	
	/*printf("a\n");
	for (i = 0; i < n; i++){
		printf("%s\n", a[i]);
	}
	
	printf("b\n");
	for (i = 0; i < m; i++){
		printf("%s\n", b[i]);
	}*/
	
	//printf("%d\n", n-m);
	
	for (i = 0; i <= n-m; i++){
		for (j = 0; j <= n-m; j++){
			if (a[i][j] == b[0][0]){
				f = 1;
				//printf("%d %d\n", i, j);
				for (k = 0; k < m; k++){
					for (l = 0; l < m; l++){
						if (a[i+k][j+l] != b[k][l]){
							f = 0;
							//printf("%d %d\n", i+k, j+l);
							break;
						}
					}
					if (f == 0) break;
				}
			}
			if (f == 1) break;
		}
		if (f == 1) break;
	}
	
	if (f) printf("Yes\n");
	else printf("No\n");
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    vector<pair<int, int>> v(6);
    vector<int> a;
    for (int i = 0; i < 6; ++i) {
        cin >> v[i].first >> v[i].second;
        if(v[i].first > v[i].second) swap(v[i].first, v[i].second);
        a.emplace_back(v[i].first);
        a.emplace_back(v[i].second);
    }
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());
    if(a.size() >= 4) {
        puts("no");
        return 0;
    }
    sort(v.begin(),v.end());
    for (auto &&i : a) {
        for (auto &&j : a) {
            for (auto &&k : a) {
                vector<pair<int, int>> v2{minmax(i, j), minmax(i, j), minmax(k, j), minmax(k, j), minmax(i, k), minmax(i, k)};
                sort(v2.begin(),v2.end());
                if(v == v2) {
                    puts("yes");
                    return 0;
                }
            }
        }
    }
    puts("no");
    return 0;
}


Measured memory_bytes: 3148
N, S = map(int,input().split())
A = list(map(int,input().split()))
mod = 998244353
dp = [[0 for j in range(S + 1)] for i in range(N + 1)]
dp[0][0] = 1
for i in range(N) : 
    for j in range(S + 1) : 
        dp[i + 1][j] += 2 * dp[i][j]
        dp[i + 1][j] %= mod 
        if j + A[i] <= S : 
            dp[i + 1][j + A[i]] += dp[i][j]
            dp[i + 1][j + A[i]] %= mod
print(dp[N][S])


Measured memory_bytes: 147248
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>

int main()
{
	unsigned long long N, R;
	std::cin >> N >> R;

	unsigned long long ans = R;
	if (N < 10) {
		ans = R + 100 * (10 - N);
	}

	std::cout << ans << std::endl;

	return 0;
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
//const int mod = 1000000007;
const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  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++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  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;
  }
 
  // for prime mod
  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;
  }
};


int main()
{
  int n; cin >> n;
  cout << n*n*n << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#define int long long
using namespace std;

#define fin(i,n) for (int i = 0; i < n; i++)
#define fin2(i,a,b) for (int i = a; i < b; i++)
#define ford(i,n) for (int i = n-1; i >= 0; i--)
#define ford2(i,a,b) for (int i = a-1; i >= b; i--)
 
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define mod 1000000007
#define PI 3.1415926535897932384626
#define EXP1 2.718281828459045
#define BIG 1000000000000000000

#define sl(n) scanf("%lld", &n)
#define sll(n,m) scanf("%lld %lld", &n, &m)
#define slll(n,m,k) scanf("%lld %lld %lld", &n, &m, &k)
#define sllll(n,m,k,o) scanf("%lld %lld %lld %lld", &n, &m, &k, &o)
#define sd(n) scanf("%lf", &n)
#define sdd(n,m) scanf("%lf %lf", &n, &m)
#define sddd(n,m,k) scanf("%lf %lf %lf", &n, &m, &k)
#define sc(c) scanf(" %c", &c)
#define ss(s) scanf("%s", s)
#define sal(t,n) fin(iz,n) { scanf("%lld", &t[iz]); }
#define sad(t,n) fin(iz,n) { scanf("%lf", &t[iz]); }
#define gl(t) scanf(" %[^\n]", t);

#define pc(n) printf("%c\n", n)
#define ps(s) printf("%s\n", s)
#define pss(s) printf("%s\n", s.c_str())
#define pl(n) printf("%lld\n", n)
#define pll(n,m) printf("%lld %lld\n", n, m)
#define plll(n,m,k) printf("%lld %lld %lld\n", n, m, k)
#define pd(n) printf("%lf\n", n)
#define pdd(n,m) printf("%lf %lf\n", n, m)
#define pal(t,n) fin(rz,n) { printf("%lld ", t[rz]); } printf("\n")
#define pad(t,n) fin(rz,n) { printf("%lf ", t[rz]); } printf("\n")

#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
 
#define OK ps("OK")
#define OK1 ps("OK1")
#define OK2 ps("OK2")

#define ll int
#define vl vector<ll>
#define vvl vector<vl>
#define vvvl vector<vvl>

#define dll pair<ll, ll>
#define vdll vector<dll>
#define vvdll vector<vdll>

#define vb vector<bool>
#define vvb vector<vb>
#define vd vector<double>
#define vvd vector<vd>
#define vc vector<char>
#define vvc vector<vc>

#define all(v) v.begin(), v.end()
#define vlen(v) (int)(v.size())
#define pb push_back
#define fi first
#define se second

signed main()
{
    int n;
    sl(n);
    vl h(n), dp(n);
    sal(h, n);
    ford(i, n) {
        if (i < n-1) dp[i] = abs(h[i] - h[i+1]) + dp[i+1];
        if (i < n-2) chmin(dp[i], abs(h[i] - h[i+2]) + dp[i+2]);
    }
    pl(dp[0]);
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
using namespace std ;

int n ;

int main() {
	scanf("%d", &n) ;
	ll ansx = 1, ansy = 1, x, y ;
	rep(i, 1, n) {
		scanf("%lld%lld", &x, &y) ;
		ansx = ((ansx - 1) / x + 1) * x ;
		ansy = ((ansy - 1) / y + 1) * y ;
		ansy = max(ansy, ansx / x * y) ;
		ansx = max(ansx, ansy / y * x) ;
	}
	printf("%lld\n", ansx + ansy) ;
	return 0 ; 
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=10000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 1000000007
#define eps 1e-8
int n;
ll k;
struct Matrix{
	ll x[52][52];
	void init()
	{
		rep(i,1,n) rep(j,1,n) x[i][j]=(i==j);
	}
}a,e;

Matrix mul(Matrix a,Matrix b)
{
	Matrix c;
	rep(i,1,n) rep(j,1,n) c.x[i][j]=0;
	rep(i,1,n)
		rep(j,1,n)
			rep(k,1,n)
				c.x[i][j]=(c.x[i][j]+a.x[i][k]*b.x[k][j]%maxd)%maxd;
	return c;
}

int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int main()
{
	n=read();scanf("%lld",&k);
	rep(i,1,n) rep(j,1,n) a.x[i][j]=read();
	e.init();
	while (k)
	{
		if (k&1) e=mul(e,a);
		a=mul(a,a);k>>=1;
	}
	ll ans=0;
	rep(i,1,n) rep(j,1,n) ans=(ans+e.x[i][j])%maxd;
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main()
{
    char mychar;
    cin>>mychar;
    if(mychar=='e' or mychar=='o' or mychar=='a' or mychar=='i' or mychar=='u')
        cout<< "vowel\n";
    else
        cout<<"consonant\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
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; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)



int main(){
    char c[3][3];
    rep(i,3) rep(j,3) cin>>c[i][j];
    for(int i=0;i<3;i++){
        cout<<c[i][i];
    }
    cout<<endl;
}

Measured memory_bytes: 3508
import collections
n,m = list(map(int,input().split()))

a = [] #1つのリストに格納
for i in range(n):
    tmp = list(map(int,input().split()))
    a += tmp[1:]

c = collections.Counter(a) #それぞれの要素の個数を辞書にして返す

ans = 0
for val in c.values():
    if val == n: #value値が人数に一致した場合を選択
        ans += 1

print(ans)

Measured memory_bytes: 3444
def main():
    n = int(input())
    h_list = list(map(int, input().split()))
    for i in range(n - 1)[::-1]:
        if h_list[i] == h_list[i + 1] + 1:
            h_list[i] = h_list[i] - 1
        elif h_list[i] > h_list[i + 1] + 1:
            print("No")
            return
    print("Yes")

main()

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int

using namespace __gnu_pbds;

typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;


#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
#define mod 1000000007
/* Precode Start Here *\


power of 2 less than or equal to N

ll largest_power(ll N)
{
    //changing all right side bits to 1.
    N = N (N>>1);
    N = N| (N>>2);
    N = N| (N>>4);
    N = N| (N>>8);


//as now the number is 2 * x-1, where x is required answer, so adding 1 and dividing it by
 2.
            return (N+1)>>1;

}


     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}




/* Precode Ends */
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);

 ll n;
 cin>>n;
 string a,b,ans;
 cin>>a>>b;
 for(int i=0;i<n;i++)
 {
     ans+=a[i];
     ans+=b[i];
 }
 cout<<ans<<endl;
return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

void run(void){
  int n,x;
  scanf("%d%d",&n,&x);
  if(x==1 || x==2*n-1){
    printf("No\n");
    return;
  }
  printf("Yes\n");
  int k=2;
  int i;
  for(i=1;i<n-1;i++){
    if(k==x) k++;
    printf("%d\n",k++);
  }
  if(k-1<x){
    printf("%d\n%d\n%d\n",2*n-1,x,1);
  } else {
    printf("%d\n%d\n%d\n",1,x,2*n-1);
  }
  for(i=n+2;i<=2*n-1;i++){
    if(x==k) k++;
    printf("%d\n",k++);
  }
  return;
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 1408
//
//取り組んだ問題:平安京
//プロ怖い
//
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <list>
#define rep(i,n) for(int i = 0; i < n;i++)

using namespace std;

int main(){
    int gx,gy;
    int x1,y1,x2,y2;
    int p;
    int dataset;
    cin >> dataset;
    rep(xxxxx,dataset){
        int map[20][20]={};
        int dp[20][20]={};
        dp[0][0]=1;
        cin >> gx >> gy;
        cin >> p;
        rep(xxxxxxx,p){
            cin >> x1 >> y1  >> x2 >> y2;
            if(x1 == x2){
                if(y1 > y2){
                    map[x1][y2] += 2;
                }else{
                    map[x1][y1] += 2;
                }
            }else{
                if(x1 > x2){
                    map[x2][y1] += 1;
                }else{
                    map[x1][y1] += 1;
                }
            }
        }
        for(int i = 0;i <= gx;i++){
            for(int j = 0;j <= gy;j++){
                if(map[i][j] == 0 || map[i][j] == 1)
                dp[i][j+1] += dp[i][j];
                if(map[i][j] == 0 || map[i][j] == 2)
                    dp[i+1][j] += dp[i][j];
            }
        }        if(dp[gx][gy]==0){
            cout << "Miserable Hokusai!" << endl;
        }else{
            cout << dp[gx][gy] << endl;
        }
    }
}

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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin >> n;
    vector<int> st(9);
    st[0] = 111, st[1] = 222, st[2] = 333, st[3] = 444,st[4] = 555,st[5] = 666,st[6] = 777,st[7] = 888,st[7] = 999;    
    cout << st[lower_bound(st.begin(), st.end(), n) - st.begin()] << "\n";
    return 0;        
}

Measured memory_bytes: 256
n = int(input())
ans = 1
lst = list(map(int, input().split()))
flg = 0
if 0 in lst:
    print(0)
else:
    for _ in lst:
        ans *= _
        if ans > 10**18:
            print(-1)
            flg = 1
            break
    if not flg :
        print(ans)

Measured memory_bytes: 21480
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
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 long double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
 
	int H, W, K;
	cin >> H >> W >> K;
	char C[H][W];
	rep(i,H){
		rep(j,W){
			cin >> C[i][j];
		}
	}
	int ans = 0;
	for(int bit1=0;bit1<(1<<H);++bit1){
		for(int bit2=0;bit2<(1<<W);++bit2){
			int cnt = 0;
			rep(i,H){
				if(bit1 & (1<<i)){
					rep(j,W){
						if(bit2 & (1<<j)){
							if(C[i][j] == '#'){
								cnt++;
							}
						}
					}
				}
			}
			if(cnt == K) ++ans;
	}
		}
	cout << ans << endl;
}

Measured memory_bytes: 3648
#include<stdio.h>
 

 int S = 0;
 int h = 0,m = 0,s = 0;
int main() {
   
    scanf("%d", &S);
	h = S / 3600;
	m = S % 3600 / 60;
	s = S % 60;
	printf("%d:%d:%d\n", h, m, s);
}


Measured memory_bytes: 2740
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

typedef struct{
    int num;
    char s[20];
    int p;
}restaurant_s;

int ssort(const void *A, const void *B){
    long long P = strcmp(((restaurant_s*)A)->s, ((restaurant_s*)B)->s);
    long long Q = ((restaurant_s*)B)->p-((restaurant_s*)A)->p;
    if(P != 0){
        return P;
    }else if(Q!=0){
        return Q;
    }else{
        return 0;
    }
}

int main(){
    int N;
    int i, j, k;
    restaurant_s rest[200];

    scanf("%d", &N);

    for(i=0; i<N; i++){
        scanf("%s %d", &rest[i].s, &rest[i].p);
        rest[i].num = i+1;
    }

    qsort(rest, N, sizeof(restaurant_s), ssort);

    for(i=0; i<N; i++){
        printf("%d\n", rest[i].num);
    }

    return 0;
}

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

using lint = long long;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;
template <typename T> using VVV = vector<vector<vector<T>>>;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define repu(i, a, b, s) for(int i = int(a); i < int(b); i += int(s))
#define repd(i, a, b, s) for(int i = int(a); i > int(b); i += int(s))
#define endl "\n"
constexpr lint INF = 2e18;
constexpr lint MOD = 1e9 + 7;

void solve() {
    int N, K;
    cin >> N >> K;

    int ans;
    if(N % K == 0) {
        ans = 0;
    } else {
        ans = 1;
    }
    cout << ans << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}

Measured memory_bytes: 3660
import scala.io.StdIn.readLine;
object Main {
    def main(args: Array[String]): Unit = {
        val map = readLine.split("").toList;
        val ret = areas(map);
        println(ret.sum);
        if (ret == Nil) {
             println(ret.length);
        } else {
            println(ret.length + " " + ret.mkString(" "));
        }
    }
    
    def areas(map: List[String]): List[Int] = {
        // stack1 : "\" を格納しておき、対応する "/" が出現したときにその面積を求まる
        // stack2 : 水たまりの開始位置(start)と現時点での面積(area)を格納しておく。(start, area)
        def go1(map: List[String], cnt: Int, stack1: List[Int], stack2: List[(Int, Int)]): List[Int] = {
            map match {
                case Nil => stack2.map(_._2).reverse;
                case "_" :: restMap => go1(restMap, cnt + 1, stack1, stack2);
                case "\\" :: restMap =>go1(restMap, cnt + 1, cnt :: stack1, stack2);
                case "/" :: restMap => {
                    stack1 match {
                        case Nil => go1(restMap, cnt + 1, stack1, stack2);
                        case start :: rest =>{
                            go1(restMap, cnt + 1, rest, go2(stack2, start, cnt - start));
                        }
                    }
                }
                case _ :: restMap => go1(restMap, cnt, stack1, stack2);;
            }
        }
        def go2(ret: List[(Int, Int)], start: Int, area: Int): List[(Int, Int)] = {
            ret match {
                case Nil => (start, area) :: ret;
                case (prevStart, prevArea) :: rest =>  if (start < prevStart) go2(rest, start, prevArea + area) else (start, area) :: ret;
            }
        }
        go1(map, 0, Nil, Nil);
    }
}


Measured memory_bytes: 48172
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;

map<pair<int, int>, vector<pair<int, int>>> edg;
set<pair<int, int>> used;

int main() {
	int n, m; cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int p, q, c; cin >> p >> q >> c;
		--p; --q;
		pair<int, int> pp(p, c), qq(q, c);
		if (edg.count(pp) == 0) edg[pp] = vector<pair<int, int>>{ { p, -1 } };
		if (edg.count(qq) == 0) edg[qq] = vector<pair<int, int>>{ { q, -1 } };
		edg[pp].push_back(qq);
		edg[qq].push_back(pp);
		edg[{p, -1}].push_back(qq);
		edg[{q, -1}].push_back(pp);
	}

	priority_queue<pair<int, pair<int, int>>> que;
	que.push({ 0,{ 0, -1 } });
	while (!que.empty()) {
		int d = -que.top().first; pair<int, int> pos = que.top().second;
		que.pop();
		if (pos.first == n - 1 && pos.second == -1) {
			cout << d << endl;
			return 0;
		}
		if (used.count(pos) == 1) continue;
		used.insert(pos);
		vector<pair<int, int>> &v = edg[pos];
		if (pos.second == -1) {
			for (int i = 0; i < (int)v.size(); ++i) {
				if (used.count(v[i]) == 1)continue;
				que.push({ -d - 1, v[i] });
			}
		}
		else {
			for (int i = 0; i < (int)v.size(); ++i) {
				if (used.count(v[i]) == 1)continue;
				que.push({ -d, v[i] });
			}
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 67252
a;f(H,W){for(long i=H,x,y,z,t;i--;a=t<a?t:a)x=(H-i)*W,y=W/2*i,z=(W+1)/2*i,t=x>z?x-y:x<y?z-x:i;}main(H,W){scanf("%d%d",&H,&W);printf("%d\n",H%3&&W%3?a=H<W?H:W,f(H,W),f(W,H),a:0);}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            new Main().solve(sc);
        }
    }

    void solve(Scanner sc) {
        int N = sc.nextInt();
        int W = sc.nextInt();
        Long[] dp = new Long[W + 1];
        Arrays.fill(dp, 0L);
        for (int i = 0; i < N; i++) {
            int w = sc.nextInt();
            int v = sc.nextInt();
            for (int j = W; j >= w; j--) {
                dp[j] = Math.max(dp[j], dp[j - w] + v);
            }
        }
        Long max = Collections.max(Arrays.asList(dp));
        System.out.println(max);
    }
}


Measured memory_bytes: 98380
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long m,k;
  cin >> m >> k;
  if(m==0){
    if(k==0){
      cout << "0 0\n";
    }else{
      cout << "-1\n";
    }
  }else if(m==1){
    if(k==0){
      cout << "0 0 1 1\n";
    }else{
      cout << "-1\n";
    }
  }else{
    if(pow(2ll,m)<=k){
      cout << "-1\n";
    }else{
      for(int i=0;i<pow(2,m);i++){
        if(i!=k){
          cout << i << ' ';
        }
      }
      cout << k << ' ';
      for(int i=pow(2,m)-1;i>=0;i--){
        if(i!=k){
          cout << i << ' ';
        }
      }
      cout << k << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
int cnt[7];
int main(){
    int i,n,k,ans,sum;
    int a[100001];
    cin>>n>>k;
    for(i=0;i<n;i++) cin>>a[i];
    sum=k;
    ans=1;
    while(n>sum){
        sum+=(k-1);
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
fun main(args: Array<String>) {
    a101(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

fun a101(args: Array<String>) {
    if (args.size != 1) {
        throw IllegalArgumentException()
    }
    val plus = args[0].toCharArray().count { it == '+' }
    val minus = args[0].toCharArray().count { it == '-' }
    println(plus - minus)
}



Measured memory_bytes: 31732
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

int main(){
	
	int N;
	cin>>N;
	
	vector<int> cnt(1000001,0);
	for(int i=0;i<N;i++){
		int A;
		cin>>A;
		cnt[A] ++;
	}
	
	vector<bool> F(1000001,false);
	
	for(int i=0;i<cnt.size();i++){
		if(cnt[i]>=1){
			for(int j=2*i;j<F.size();j+=i){
				F[j] = true;
			}
		}
	}
	
	int ans = 0;
	for(int i=0;i<cnt.size();i++){
		if(cnt[i]==1&&!F[i])ans++;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 7136
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

const int MX = 200010;
int p1[MX], p2[MX];
int root(int *p, int x){
	if(p[x] == x) return x;
	return p[x] = root(p, p[x]);
}
void merge(int *p, int a, int b){
	a = root(p, a); b = root(p, b);
	if(a != b) p[b] = a;
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n, m1, m2; cin >> n >> m1 >> m2;
	map<pi, vi> v;
	vi ans(n);
	
	rep(i, n) p1[i] = p2[i] = i;
	rep(i, m1){
		int a, b; cin >> a >> b; a--; b--;
		merge(p1, a, b);
	}
	rep(i, m2){
		int a, b; cin >> a >> b; a--; b--;
		merge(p2, a, b);
	}
	
	rep(i, n){
		int r1 = root(p1, i);
		int r2 = root(p2, i);
		v[pi(r1, r2)].pb(i);
	}
	for(const auto &p : v){
		for(int i : p.second) ans[i] = p.second.size();
	}
	rep(i, n) cout << ans[i] << (i==n-1?"\n":" ");
	
	return 0;
}

Measured memory_bytes: 23040
def main():
    buttons = int(input())
    next_lighten_up = [int(input()) for _ in range(buttons)]
    searched = [False] * (buttons + 1)
    answer = 1
    index = 1
    while True:
        if next_lighten_up[index - 1] == 2:
            break
        elif searched[next_lighten_up[index - 1]]:
            answer = -1
            break
        else:
            searched[next_lighten_up[index - 1]] = True
            answer += 1
            index = next_lighten_up[index - 1]
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 7852
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>

#define LP(i,n) for(int i=0;i<n;i++)
#define Mset(x,v) memset(x,v,sizeof(x))

using namespace std;
using LL=long long;

int pk[10];
char D[10][5]={
    {'*','*','*','*','*'},
    {'.',',','!','?',' '},
    {'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','*'}
};

int main(){
    int n,curk=0;
    string s;
    cin>>n;
    for(int i=0;i<n;i++){
        string r;
        Mset(pk,0);
        cin>>s;
        for(int j=0;j<s.size();j++){
            switch(s[j]){
                case '1':
                    curk=1;
                    pk[1]++;
                    if(pk[1]>5) pk[1]=1;
                    break;
                case '2':
                    curk=2;
                    pk[2]++;
                    if(pk[2]>3) pk[2]=1;
                    break;
                case '3':
                    curk=3;
                    pk[3]++;
                    if(pk[3]>3) pk[3]=1;
                    break;
                case '4':
                    curk=4;
                    pk[4]++;
                    if(pk[4]>3) pk[4]=1;
                    break;
                case '5':
                    curk=5;
                    pk[5]++;
                    if(pk[5]>3) pk[5]=1;
                    break;
                case '6':
                    curk=6;
                    pk[6]++;
                    if(pk[6]>3) pk[6]=1;
                    break;
                case '7':
                    curk=7;
                    pk[7]++;
                    if(pk[7]>4) pk[7]=1;
                    break;
                case '8':
                    curk=8;
                    pk[8]++;
                    if(pk[8]>3) pk[8]=1;
                    break;
                case '9':
                    curk=9;
                    pk[9]++;
                    if(pk[9]>4) pk[9]=1;
                    break;
                case '0':
                    if(curk){
                        r+=D[curk][pk[curk]-1];
                        pk[curk]=0;
                        curk=0;
                    }
            }
        }
        cout<<r<<endl;
    }
    return 0;
}



Measured memory_bytes: 3136
#![allow(unused)]

use std::io::{Read, StdinLock};
use std::iter::{FromIterator, Iterator};
use std::str::{FromStr};
use std::string::String;

macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

pub fn read_bytes<T: FromIterator<char>>(s: &mut StdinLock) -> T {
    s.bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<T>()
}

pub fn reads(s: &mut StdinLock) -> String {
    read_bytes::<String>(s)
}

pub fn read<T: FromStr>(s: &mut StdinLock) -> T {
    reads(s).parse().ok().unwrap()
}

//==============================================================================
//
// Problem specific code
//
//==============================================================================

fn main() {
    let sin = std::io::stdin();
    let mut sin = sin.lock();

    let n: usize = read(&mut sin);
    let k: usize = read(&mut sin);

    if (n % k) < k - (n % k) {
        println!("{}", n % k);
    } else {
        println!("{}", k - (n % k));
    }
}

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

const int MAXN=200005;

int n,a[MAXN];

bool check(int x)
{
	for (int i=1;i<n;i++)
	{
		if ((a[n-i]>=x)==(a[n-i+1]>=x))
			return a[n-i]>=x;
		if ((a[n+i]>=x)==(a[n+i-1]>=x))
			return a[n+i]>=x;
	}
	return (a[n]>=x)^(n-1&1);
}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<2*n;i++)
		scanf("%d",&a[i]);
	int l=1,r=2*n-1;
	while (l<=r)
	{
		int m=l+r>>1;
		if (check(m))
			l=m+1;
		else
			r=m-1;
	}
	printf("%d",r);
	return 0;
}

Measured memory_bytes: 1024
import re
s, t = input().replace('?', '.'), input()
l, m = len(s), len(t)

if l < m:
    print("UNRESTORABLE")
    exit()

can = []  # candidates
for i in range(l - m + 1):
    if re.match(s[i:i + m], t):
        can.append((s[:i] + t + s[i + m:]).replace('.', 'a'))
print(min(can) if can else "UNRESTORABLE")

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n; cin>>n;
    string s1,s2; cin>>s1>>s2;
    int i=1;
    long sum=3;
    if(s1[0]!=s2[0]){
        i++;
        sum*=2;
    }
    while(i<n){
        bool jud=(s1[i-1]==s2[i-1]);
        if(s1[i]==s2[i]){
            if(jud)
                sum*=2;
            i++;
        }
        else{
            if(jud)
                sum*=2;
            else
                sum*=3;
            i+=2;
        }
        sum%=(int)(1e9+7);
    }
    cout<<sum;
}

Measured memory_bytes: 256