akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<vector>
#include<map>

using namespace std;

#define long long long
#define ft(i , a , b) for (long i = (long)a ; i <= (long)b ; i++)
#define fd(i , a , b) for (long i = (long)a ; i >= (long)b ; i--)
#define lt(i , a , b , c) for (long i = (long)a ; i <= (long)b ; i += (long)c)
#define ld(i , a , b , c) for (long i = (long)a ; i >= (long)b ; i -= (long)c)

#define X first
#define Y second

#define pb push_back
#define mp make_pair

const int mxN = 1e5 + 5;
const long oo = 1e15;
const long MOD = 1e9 + 7;
const int base = 311;

long TestCase;
long n , x , u , v , Max;
long a[mxN] , st[4 * mxN];

void build(int id , int l , int r) {
    if (l == r) {   
        st[id] = l * a[l];
    }
    else {
        int mid = (l + r) / 2;
        build(id * 2 , l , mid);
        build(id * 2 + 1, mid + 1 , r);
        st[id] = st[id * 2] + st[id * 2 + 1];
    }
}

void update(int id , int l , int r , int pos , int val) {
    if (l == r) {
        a[pos] += val;
        st[id] = pos * a[pos];
    }
    else {
        int mid = (l + r) / 2;
        if (pos <= mid) update(id * 2 , l , mid , pos , val);
        else update(id * 2 + 1 , mid + 1 , r , pos , val);
        st[id] = st[id * 2] + st[id * 2 + 1];
    }
}

void Solve() {
    cin >> n;
    ft(i , 1 , n) {
        cin >> x;
        a[x]++;
        Max = max(Max , x);
    }
    build(1 , 1 , 1e5);
    int q;
    cin >> q;
    while(q--) {
        cin >> u >> v;
        x = a[u];
        update(1 , 1 , 1e5 , u , -a[u]);
        update(1 , 1 , 1e5 , v , x);
        cout << st[1] << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
    //cin >> TestCase;
    TestCase = 1; 
    while(TestCase--)
        Solve();
    return 0;
}

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

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	int a[n];
	for(int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a+n);
	int ans[k+1];
	ans[0] = 1;
	for(int i = 1; i < k+1; i++)
	{
		ans[i] = 1;
		int j = i - a[0], count = 0;
		while(j >= 0 && count < n)
		{
			count++;
			if(ans[j] == 1)
			{
				ans[i] = 0;
				break;
			}
			else
			{
				j = i-a[count];
			}
		}
	}
	if(ans[k] == 0)
		cout << "First";
	else
		cout << "Second";
}

Measured memory_bytes: 640
n=int(input())
e=[[int(i) for i in input().split()] for j in range(n)]
dp=[[0,0,0] for i in range(n)]
for i in range(3):
    dp[0][i]=e[0][i]

for i in range(1,n):
    dp[i][0]=e[i][0]+max(dp[i-1][1],dp[i-1][2])
    dp[i][1]=e[i][1]+max(dp[i-1][2],dp[i-1][0])
    dp[i][2]=e[i][2]+max(dp[i-1][0],dp[i-1][1])

ans=dp[n-1][0]
for i in range(1,3):
    if ans < dp[n-1][i]:
        ans = dp[n-1][i]
        
print(ans)

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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	int N, max=INT_MAX, ans=0, a; 
	cin >> N;
	REP(i, 0, N){
		cin >> a;
		if(a < max){
			ans++;
			max = a;
		}
	}
	cout << ans;

}


Measured memory_bytes: 256
import sys, re
from math import ceil, floor, sqrt, pi, factorial#, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    s = s_input()

    print(s.count('+')-s.count('-'))

if __name__ == '__main__':
    main()


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

int kakuketa(int x){
    int ans=0;
    while(x){
        ans+=x%10;
        x/=10;
    }
    return ans;
}

int main(){
    int N;
    cin>>N;
    int M=N-1;
    int ans=100000000;
    while(M){
        if(N%10==0){
            ans=10;break;
        }
        ans=min(ans,kakuketa(M)+kakuketa(N-M));
        M/=10;
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
a, b, c, d = map(int, input().split())

l = c // b
if c % b !=0:
  l += 1
  
m = a // d
if a % d !=0:
  m += 1
  
if l == m:
  print("Yes")
elif l < m:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9184
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

const long long MOD = (long long)1e9 + 7;
long long dp[1 << 21];

int pop_count(long long bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main(){
    int n, ans = 0;
    cin >> n;
    dp[0] = 1;
    for(int i = 0; i < n; i++){
        vector<int> a(n);
        for(int j = 0; j < n; j++){
            cin >> a[j];
        }
        for(int j = 0; j < (1 << n); j++){
            if(pop_count(j) != i) continue;
            for(int k = 0; k < n; k++){
                int mask = 1 << k;
                if((j & mask) || a[k] == 0) continue;
                dp[j | mask] += dp[j];
                dp[j | mask] %= MOD;
            }
        }
    }
    cout << dp[(1 << n) - 1] << endl;
    return 0;
}


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

int main()
{
	int a, b; cin >> a >> b;
	if (b != 2) {
		if (a != 2) {
			if (a == 4 || a == 6 || a == 9 || a == 11) {
				if (b == 4 || b == 6 || b == 9 || b == 11) {
					cout << "Yes";
				}
				else {
					cout << "No";
				}
			}
			else {
				if (b == 4 || b == 6 || b == 9 || b == 11) {
					cout << "No";
				}
				else {
					cout << "Yes";
				}
			}
		}
		else {
			cout << "No";
		}
	}
	else {
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <string.h>
using namespace std;

uint64_t comb(int n, int k) {
    static uint64_t p[68][68];
    if (n < k || k < 0) return 0;
    if (p[0][0] == 0) {
        for (int i = 0; i < 68; i++) {
            p[i][0] = 1;
            for (int j = 1; j <= i; j++) {
                p[i][j] = p[i - 1][j] + p[i - 1][j - 1];
            }
        }
    }
    return p[n][k];
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int64_t v[50];
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }

    sort(v, v + n, greater<>());

    int64_t s = 0;
    for (int i = 0; i < a; i++) {
        s += v[i];
    }
    
    int64_t r = 0;
    auto c = equal_range(v, v + n, v[a - 1], greater<>());
    for (int k = a; k <= b; k++) {
        if (v[k - 1] != v[a - 1]) break;
        r += comb(c.second - c.first, k - (c.first - v));
        if (v[0] != v[a - 1]) break;
    }

    printf("%.9f\n%lld\n", (double)s / a, r);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int ans=0;
  vector<int> a(3);
  for(int i=0;i<3;i++)
    cin>>a.at(i);
  while(a.at(0)!=a.at(1) || a.at(1)!=a.at(2) || a.at(0)!=a.at(2)){
    sort(a.begin(),a.end());
    if(a.at(1)==a.at(2))
      a.at(0)+=2;
    else{
      a.at(0)++;
      a.at(1)++;
    }
    ans++;
  }
  cout<<ans<<endl;
}


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

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vv = vector<vector<ll>>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end());
#define MIN(vec) *std::min_element(vec.begin(), vec.end());
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define REV(T) greater<T>()

typedef pair<ll, ll> Pair;
bool pairCompare(const Pair &firstElof, const Pair &secondElof) {
  return firstElof.second > secondElof.second;
}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

ll factorial(int n) {
  ll ans = 1;
  for (int i = 2; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll P(int n, int m) {
  ll ans = 1;
  for (int i = m + 1; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll power(int n, int m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = power(n, m / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (n * power(n, m - 1)) % MOD;
  }
}
ll C(int n, int m) {
  return (P(n, n - m) * power(factorial(m), MOD - 2)) % MOD;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ll N;
  ll ans = 0;
  cin >> N;
  vector<pair<ll, pair<ll, ll>>> C(N);
  vector<ll> A, B;
  REP(i, N) {
    ll a, b;
    cin >> a >> b;
    ll m = a + b;

    C[i] = make_pair(m, make_pair(a, b));
  }
  sort(ALL(C));

  REP(i, N / 2) {
    ans += C[N - (i * 2) - 1].second.first - C[N - (i * 2) - 2].second.second;
  }
  if (N % 2 == 1)
    ans += C[0].second.first;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2560
use std::collections::HashMap;
fn main() {
    input! {
        n: usize,
        m: u64,
        a: [u64; n]
    }

    let mut cum = vec![0; n];
    cum[0] = a[0] % m;
    for i in 1..n {
        cum[i] = cum[i - 1] + a[i] % m;
        cum[i] %= m;
    }

    let mut a_map: HashMap<u64, u64> = HashMap::new();
    for i in cum {
        if a_map.contains_key(&i) {
            a_map.insert(i, a_map[&i] + 1);
        } else {
            a_map.insert(i, 1);
        }
    }

    let mut ans: u64 = 0;
    for v in a_map.values() {
        ans += v * (v - 1) / 2;
    }
    if let Some(v) = a_map.get(&0) {
        ans += v;
    }

    println!("{}", ans);
}

#[macro_export(local_inner_maccros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[macro_export(lcal_inner_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

#[macro_export(lcal_inner_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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


Measured memory_bytes: 7496
# 参考　https://tjkendev.github.io/procon-library/python/graph/lca-segment-tree.html

# N: 頂点数
# G[v]: 頂点vの子頂点 (親頂点は含まない)

import sys
sys.setrecursionlimit(10**7)

N = int(input())
G = [[] for _ in range(N)]
for v in range(N):
    for j, nv in enumerate(map(int, input().split())):
        if j == 0:
            continue
        G[v].append(nv)  

# Euler Tour の構築
S = []
F = [0]*N
depth = [0]*N
def dfs(v, d):
    F[v] = len(S)
    depth[v] = d
    S.append(v)
    for w in G[v]:
        dfs(w, d+1)
        S.append(v)
dfs(0, 0)

# 存在しない範囲は深さが他よりも大きくなるようにする
INF = (N, None)

# LCAを計算するクエリの前計算
M = 2*N
M0 = 2**(M-1).bit_length()
data = [INF]*(2*M0)
for i, v in enumerate(S):
    data[M0-1+i] = (depth[v], i)
for i in range(M0-2, -1, -1):
    data[i] = min(data[2*i+1], data[2*i+2])

# LCAの計算 (generatorで最小値を求める)
def _query(a, b):
    yield INF
    a += M0; b += M0
    while a < b:
        if b & 1:
            b -= 1
            yield data[b-1]
        if a & 1:
            yield data[a-1]
            a += 1
        a >>= 1; b >>= 1

# LCAの計算 (外から呼び出す関数)
def query(u, v):
    fu = F[u]; fv = F[v]
    if fu > fv:
        fu, fv = fv, fu
    return S[min(_query(fu, fv + 1))[1]]

ans_list = []

q = int(input())
for _ in range(q):
    u, v = map(int, input().split())
    ans = query(u, v)
    ans_list.append(ans)

print(*ans_list, sep="\n")


Measured memory_bytes: 138800
const BKRT = "\n";
const SPAC = " ";
const NOSP = "";

function Main(input){
	input = [].concat(...input.split(BKRT).map(a=>a.split(SPAC)));
  const strShift = ()=>input.shift();
  const intShift = ()=>~~input.shift();
  
  return ~~strShift().split(NOSP).map(a=>~~a).reduce((a,b)=>a+b);
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
101
`);

Measured memory_bytes: 11468
N,A,B  = map(int,input().split())
number = []
sum = 0

for i in range(1,N+1):
        digits_sum = 0
        for j in str(i):
            digits_sum += int(j)
        if A <= digits_sum <= B:
            number.append(i)
for k in range(len(number)):
    sum += number[k]

print(sum)


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

typedef long long ll;
using namespace std;

int main()
{
    char s[30];
    int a, b, c;
    cin >> s;

    a = (s[0] - '0')*1000 + (s[1] - '0')* 100 + (s[2]-'0')*10 + s[3] - '0';
    b = (s[5] - '0')*10 + s[6] - '0';
    c = (s[8]-'0')*10 + s[9]-'0';


    if(a <= 2019 && b <= 4 && c <= 30)cout << "Heisei" << endl;
    else cout << "TBD" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int n, k, a[N];
int main() {
    scanf("%d%d", &n, &k);
    int pos;
    for(int i = 1 ; i <= n ; ++ i) {
        scanf("%d", &a[i]);
        if(a[i] == 1) pos = i;
    }
    int ans = n;
    for(int i = max(1, pos - k + 1) ; i <= pos ; ++ i) {
        int j = i + k - 1;
        ans = min(ans, (i - 1 + k - 2) / (k - 1) + (n - j + k - 2) / (k - 1) + 1);
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
 
int n, m;
int vis[2000010];
int id[2000010];
int sum[2000010];

 
void solve() {
    for(int i = 1;i <= 1010000;i++) {
        if(vis[i + n] && vis[i + m] && id[i + m] - id[i + n] == 1) {
            cout << i << endl;
            return ;
        }
    }
}

int main() {
	memset(vis, 0, sizeof(vis));
	sum[0] = 0;
	for(int i = 1;i <= 1111;i++) {
		sum[i] = sum[i - 1] + i;
		vis[sum[i]] = 1;
		id[sum[i]] = i;
	}
	while(~scanf("%d%d", &n, &m)) {
		solve();
	}
}

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os<<"("<<p.first<<","<<p.second<<")";
    return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os<<"{";
    rep(i, v.size()) {
        if (i) os<<",";
        os<<v[i];
    }
    os<<"}";
    return os;
}

int main() {
	int X, Y;
	cin >> X >> Y;
	int ans = 0;
	if (X == 3) {
		ans += 100000;
	} else if (X == 2) {
		ans += 200000;
	} else if (X == 1) {
		ans += 300000;
	}
	if (Y == 3) {
		ans += 100000;
	} else if (Y == 2) {
		ans += 200000;
	} else if (Y == 1) {
		ans += 300000;
	}

	if (X + Y == 2) {
		ans += 400000;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define LL long long
#define NUM 200000
using namespace std;

int main()
{
  LL N,A[NUM],i,maxval,next_max,maxvc;
 
  scanf("%lld",&N);
 	
  for(i=0;i<N;i++){
    scanf("%lld\n",&A[i]);
  }
  
  //最大値の取得
  maxval = A[0];
  for(i=0;i<N;i++){
    if(maxval<A[i]){
    	maxval=A[i];
    }
  }
  //最大値の個数を取得
  maxvc=0;
  for(i=0;i<N;i++){
    if(A[i]==maxval){
      maxvc++;
    }
  }
  
    
  //最大値の次に大きな値の取得
  next_max = A[0];
  //next_maxの値が最大値でないかどうかの確認
  if(next_max==maxval){
    
  	next_max=A[1];
    i=1;
    for(i;i<N;i++){
      if(next_max<A[i]){
          next_max=A[i];
      }
    }

  }else{
    
  	i=0;
	for(i;i<N;i++){
      if(next_max<A[i]&&A[i]!=maxval){
          next_max=A[i];
      }
 	}
  
  
  }
  
  
  
  //出力
  for(i=0;i<N;i++){
    if(A[i]!=maxval){
    	printf("%lld\n",maxval);
    }else{
      if(maxvc==1){
      	printf("%lld\n",next_max);
      }else{
      	printf("%lld\n",maxval);
      }
    	
    }
  }
  
 	
  	return 0;
  
}

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

int main(){
  int N,i,j,S1=0,S2=0,dif;
  cin >> N;
  vector<int> W(N);

  for(i=0;i<N;i++)
  cin >> W.at(i);

  for(i=0;i<N;i++){
    S1=0;
    S2=0;
    for(j=0;j<N;j++){
      if(j<=i)
      S1 += W.at(j);
      else
      S2 += W.at(j);
    }
    if(i==0){
      if(S1<=S2)
      dif = S2 - S1;
      else
      dif = S1 - S2;
    }else{
      if(S1<=S2)
      dif = min(dif,S2-S1);
      else
      dif = min(dif,S1-S2);
    }
  }
  cout << dif << endl;
}

Measured memory_bytes: 256
import numpy as np
from itertools import permutations
import copy

n,m = map(int, input().split())

adj = np.zeros((n,n))

for _ in range(m):
	a,b = map(int, input().split())
	adj[a-1,b-1] = 1
	adj[b-1,a-1] = 1

cnt = 0
for p in permutations(range(n)):
	if p[0]!=0:
		continue
	tmp_adj = copy.deepcopy(adj)
	for i in range(n-1):
		if tmp_adj[p[i],p[i+1]] != 1:
			# print('invalid:',p)
			break
	else:
		# print('valid:',p)
		cnt += 1

print(cnt)
		

Measured memory_bytes: 12472
def main():
    from fractions import gcd
    n=int(input())
    ans=[]
    cnt=0
    i=2
    while cnt<n-1:
        if i%2==0 or i%3==0:
            ans.append(i)
            cnt+=1
        i+=1
    a=sum(ans)
    for j in range(30000,0,-1):
        if gcd(j,a)>1 and gcd(a+j,2)>1 and gcd(a+j,3)>1:
            print(*(ans+[j]))
            return 0
main()

Measured memory_bytes: 7304
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 200005;
bool isPrime[MAXN];
vector<int> pr;
vector<int> ans;
void sieve()
{
    memset(isPrime, 1, sizeof isPrime);
    isPrime[0] = isPrime[1] = 0;

    for (int i = 2; i * i <= MAXN; i += 1 + (i & 1))
    {
        if (isPrime[i])
        {

            for (int j = i * i; j < MAXN; j += i)
                isPrime[j] = 0;
        }
    }
    for(int i=0; i<MAXN; i++)
    {
        if(isPrime[i])
        {

            ans.push_back(i);
        }
    }
}

ld power(ld x, ll y)
{
    ll temp;
    if (y == 0)
        return 1;
    temp = power(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
        return x * temp * temp;
}

void debug_out()
{
    cerr << endl;
}

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << H;
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int main()
{
    FAST
    int n;
    cin>>n;
    if(n>=400 && n<=599){
        cout<<"8"<<endl;
    }else if(n>=600 && n<=799){
        cout<<"7"<<endl;
    }else if(n>=800 && n<=999){
        cout<<"6"<<endl;
    }else if(n>=1000 && n<=1199){
        cout<<"5"<<endl;
    }else if(n>=1200 && n<=1399){
        cout<<"4"<<endl;
    }else if(n>=1400 && n<=1599){
        cout<<"3"<<endl;
    }else if(n>=1600 && n<=1799){
        cout<<"2"<<endl;
    } else if(n>=1800 && n<=1999){
        cout<<"1"<<endl;
    }

    return 0;
}


Measured memory_bytes: 3660
N = int(input())
if 2**6<= N:
    print(2**6)
elif 2**5<= N <2**6:
    print(2**5)
elif 2**4<= N <2**5:
    print(2**4)
elif 2**3<= N <2**4:
    print(2**3)
elif 2**2 <= N < 2**3:
    print(2**2)
elif 2**1 <= N < 2**2:
    print(2**1)
else:
    print(1)

Measured memory_bytes: 3060
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

int main() {
	int A, B;
	scanf("%d %d", &A, &B);
	printf("%s\n", ((A*B) % 2) ? "Odd" : "Even");
	return 0;
}

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

using namespace std;

using ll = unsigned long long;

ll length(ll num)
{
    ll len = 0;
    ll n = 1;
    while (num >= n) {
        len += num - n + 1;
        n *= 10;
    }
    n = 0;
    ll englen = 0;
    const ll engnum = (num / 3) + (num / 5);
    while (num >= n) {
        englen += ((num / 3) + (num / 5) - (num / 15)) - ((n / 3) + (n / 5) - (n / 15));
        n = n * 10 + 9;
    }
    return len - englen + engnum * 4;
}

string tostr(ll n)
{
    if (n % 15 == 0) {
        return "FizzBuzz";
    } else if (n % 3 == 0) {
        return "Fizz";
    } else if (n % 5 == 0) {
        return "Buzz";
    } else {
        return to_string(n);
    }
}

constexpr ll MAX = 1e17;
int main()
{
    ll s;
    cin >> s;
    if (s == 1) {
        cout << "12Fizz4BuzzFizz78Fiz" << endl;
        return 0;
    }
    s--;
    ll inf = 1;
    ll sup = MAX;

    while (inf < sup) {
        const ll mid = (inf + sup) / 2;
        const ll len = length(mid);
        if (len < s) {
            if (inf == mid) {
                break;
            }
            inf = mid;
        } else if (len > s) {
            sup = mid;
        } else {
            inf = mid;
            sup = mid;
            break;
        }
    }
    ll res = s - length(inf);

    ll rest = 20;
    ll next = inf + 1;
    const string str = tostr(next);
    for (int i = res; i < str.size(); i++) {
        cout << str[i];
        rest--;
    }
    while (rest > 0) {
        next++;
        const string str = tostr(next);
        if (rest >= str.size()) {
            cout << str;
            rest -= str.size();
        } else {
            const ll rest_ = rest;
            for (int i = 0; i < rest_; i++) {
                cout << str[i];
                rest--;
            }
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3260
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <cstring>
#include <stdio.h>
#include <complex>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef long double LD;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<string> VS;
typedef vector<VS> VSS;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next
#define prev fake_prev
#define left fake_left
#define right fake_right

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i, 0, t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))

const LD PI = acos(-1.0);
const LD EPS = 1e-6;
const LL INF = 1e9;
const LL LINF = 1e18;
const LL mod = 1000000007;
const LL MAX = 2000 + 7;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	
	LL a, b, ans = 0;
	cin >> a >> b;
	if (a == b)
	{
		cout << 1;
		return 0;
	}
	
	LL k = 0;
	RFOR(i, 61, 0)
	{
		if (a >= (1LL << i)) 
		{
			a -= (1LL << i);
			b -= (1LL << i);
		}
		if (b >= (1LL << i)) 
		{
			k = i;	
			break;
		}
	}

	b -= (1LL << k);
	LL u = 0;
	while (b >= (1LL << u))
		++u;

	LL f = a, to = 1LL << u;
	ans += (1LL << k) - f;

	if (to > f)
		ans += (1LL << k);
	else
		ans += (1LL << k) + to - f;

	cout << ans << endl;
	cin >> a;
	return 0;
}

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



int main(){
    int n,k;
    int ans=0;
    cin >> n >> k;
    rep(i,n){
        int x;
        cin >> x;
        ans+=min(x,k-x);
    }
    cout << ans*2 << endl;
   return 0;
}

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

int main(void) {

  long s;
  scanf("%ld", &s);
  long pow9 = pow(10,9);
  long pow18 = pow(10,18);
  if (s == pow18) {
    printf("0 0 %ld 0 0 %ld\n", pow9, pow9);
    return 0;
  }
  long a,b;
  a = pow9-s%pow9;
  b = s/pow9+1;
  printf("0 0 %ld 1 %ld %ld\n", pow9, a, b);

  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

int main(){
    int n;
    scanf("%d",&n);
    int a = n%10;
    n/=10;
    int b = n%10;
    n/=10;
    int c = n%10;
    n/=10;
    int d = n%10;
    if((a==b&&b==c)||(b==c&&c==d)){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<cstring>
#include<cmath>
#include<cstring>
#include<string>
#include<map>
#include<set>
#include<unordered_map>
#define db double
#define ui unsigned int
#define ll long long
#define ull unsiged ll
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l)for(int i=r;i>=l;i--)
#define boots ios::sync_with_stdio(0); cin.tie(0)
#define pb push_back
#define pp pop_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mod 1000000007
#define vii vector<int>
#define vll vector<ll>
#define vpp vector<pii>
#define inf  0x3f3f3f3f
#define lnf LLONG_MAX
#define mii map<int,int>
#define mll map<ll,ll>
#define mil map<int,ll>
#define umii unordered_map<char,int>
#define umll unordered_map<ll,ll>
#define umcc unordered_map<char,char>
#define si(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pf(n) printf("%lld\n",n)
#define sz size()
using namespace std;
const db pi = 3.1415926535898;
const int MX = 5e6 + 7;
const int esp = 1e-6;
ll INV2, INV6;
ll modulo(ll num, ll MOD = mod) { return ((num%MOD) + MOD) % MOD; }
ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a%b)); }
unordered_map<ui, ll>mp1, mp;
int p[MX];
int sum[MX];
char s[MX / 10];
vector<int> pri;
vector<bool> isp(MX, true);
int k;
ll qpow(ll a, ll b)
{
	ll ans = 1;
	while (b)
	{
		if (b & 1)
			ans = ans * a%mod;
		a = a * a%mod;
		b >>= 1;
	}
	return ans;
}
ll INV(ll n)
{
	return qpow(n, mod - 2);
}
ll get_sum(ll d)
{
	if (d == 1)return k - 1;
	return d * d%mod*(qpow(d, k )*INV(d) - 1) % mod*INV(d - 1) % mod;
}
ll get_sum2(int n)
{
	return n * (n + 1) % mod*(2 * n + 1) % mod*INV6%mod;
}
int main()
{
	boots;
	ll n;
	cin >> n;
	cout << (1 + n)*n / 2 - n << endl;
}

Measured memory_bytes: 896
import sys
import math
N,D=map(int,sys.stdin.readline().split())
x=[]
count=0
for i in range(N):
    x.append(list(map(int,sys.stdin.readline().split())))

for i in range(N):
    for j in range(i+1,N):

        diff=math.sqrt(sum([(a-b)**2 for a,b in zip(x[i],x[j])]))

        if diff-int(diff)==0:
            count+=1
print(count)


Measured memory_bytes: 3064
if __name__ == '__main__':
    key_in = input()
    data = key_in.split(' ')

    # ???????????? W, H, x, y, r ??????
    W = int(data[0])
    H = int(data[1])
    x = int(data[2])
    y = int(data[3])
    r = int(data[4])

    result = False
    if r <= x <= W-r and r <= y <= H-r:
        result = True

    if result is True:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 7656
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
    
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
//ll INF = 1LL<<40;
int INF = 1LL<<15;
int xv[4] = {-1, 1, 0, 0};
int yv[4] = {0, 0, -1, 1};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, M;
    cin >> N >> M;
    vector<vector<ll>> a(8);
    REP(i, N){
        ll X, Y, Z;
        cin >> X >> Y >> Z;
        a[0].push_back( X + Y + Z);
        a[1].push_back( - X + Y + Z);
        a[2].push_back(   X - Y + Z);
        a[3].push_back(   X + Y - Z);
        a[4].push_back( - X - Y + Z);
        a[5].push_back(   X - Y - Z);
        a[6].push_back( - X + Y - Z);
        a[7].push_back( - X - Y - Z);
    }
    REP(i,8){
        sort(a[i].begin(), a[i].end(), greater<ll>());
    }
    ll ans = 0;
    REP(i,8){
        ll sum = 0;
        REP(j,M){
            sum += a[i][j];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int h,n;
    cin>>h>>n;
    int ans[h+5];

    vector<pair<int,int> > a;
    
    for(int i=1;i<h+1;i++)
    {
        ans[i]=1000000000;
    }
    
    for(int i=0;i<n;i++)
    {
        int ai,bi;
        cin>>ai>>bi;
        
        a.push_back(make_pair(ai,bi));
    }
    
   ans[0]=0;
 
   for(int i=1;i<=h;i++)
    {
        for(int j=0;j<n;j++)
        {
            
            ans[i]= min(ans[i] , ans[max(i-a[j].first,0)] + a[j].second);
            
        }
    }
    
    cout<<ans[h]<<endl;
    return 0;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define debug(x) cerr << #x " = " << (x) << endl;
#define P(x) cerr << #x << endl;    
#define int long long
typedef pair<int, int> pii;
const int mod = 1000000007;


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(9);
    
	vector<string> days = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
	int n = days.size();
	string s;
	cin >> s;
	int i = 0;
	while(s != days[i]) ++ i;
	int first = i;
	++ i;
	//cout << i << '\n';
	while(days[i] != "SUN") ++ i;
	cout << i - first << '\n';
    
    
    return 0;
}






Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<String> list = new ArrayList<String>();
        String W = sc.nextLine();
        int sum = 0;
        while(true) {
            String line = sc.nextLine();
            if(line.equals("END_OF_TEXT")) {
                break;
            }
            String[] words = line.split(" ");
            for(int i = 0; i < words.length; i++) {
                String w = words[i].toLowerCase();
                if(W.equals(w)) {
                    sum += 1;
                }
            }
        }
        
        System.out.println(sum);
    }
 }


Measured memory_bytes: 26136
n,m,x = list(map(int, input().split()))
lst = [None for i in range(n)]
for i in range(n):
    lst[i] = list(map(int, input().split()))
ans = float("INF")

for i in range(2**n):
    lst_tent = [0 for i in range(m+1)]
    for j in range(n):
        if ((i >> j) & 1):
            for k in range(m+1):
                lst_tent[k] += lst[j][k]
    flag = 0
    for k in range(1,m+1):
        if lst_tent[k]<x:
            flag = 1
    if flag==0:
        ans = min(ans, lst_tent[0])

print(ans if ans!=float("INF") else -1)


Measured memory_bytes: 9132
#include <stdio.h>
int main() {
	int n, m, i, j, a[100][100] = { 0 }, b[100] = { 0 }, c[100] = { 0 };
	scanf("%d %d", &n, &m);
	for (i = 0;i < n;i++) {
		for (j = 0;j < m;j++) {
			scanf("%d", &a[i][j]);
		}
	}
	for (j = 0;j < m;j++) {
		scanf("%d", &b[j]);
	}
	for (i = 0;i < n;i++) {
		for (j = 0;j < m;j++) {
			c[i] += a[i][j] * b[j];
		}
			printf("%d\n", c[i]);
    }
	return 0;
}

Measured memory_bytes: 648
s = input()
# list関数を使う
n = len(s)
list_s = list(s)
list_s_part1 = list_s[0:(n - 1) // 2]
list_s_part2 = list_s[(n + 1) // 2:n]
# 各種listを逆順に並び替える
list_s_rev = list(reversed(list_s))
list_s_part1_rev = list(reversed(list_s_part1))
list_s_part2_rev = list(reversed(list_s_part2))
if ''.join(list_s) == ''.join(list_s_rev) and\
    ''.join(list_s_part1) == ''.join(list_s_part1_rev) and\
    ''.join(list_s_part2) == ''.join(list_s_part2_rev):
    print('Yes')
else: print('No')

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N), b(N), c(N), d(N);
  for (int i = 0; i < N; ++i)
    cin >> a[i] >> b[i];
  for (int i = 0; i < N; ++i)
    cin >> c[i] >> d[i];

  vector<pair<int, int>> red(N), blue(N);
  for (int i = 0; i < N; ++i)
    red[i] = make_pair(a[i], b[i]), blue[i] = make_pair(c[i], d[i]);
  sort(red.begin(), red.end()), sort(blue.begin(), blue.end());

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    int max_y = -1, max_j = -1;
    for (int j = 0; j < N; ++j)
      if (red[j] != make_pair(-1, -1) && red[j].first < blue[i].first &&
          red[j].second < blue[i].second && red[j].second > max_y)
        max_y = red[j].second, max_j = j;
    if (max_j != -1)
      ++ans, red[max_j] = make_pair(-1, -1);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
function myout(text){console.log(text);}//standard output
function Main(input) {
	//input = parseInt(input);
	//input = input.split(" ");
	input = input.split("\n");
	//input = input.split(" ").map((a)=>Number(a));
	//input = input.split("\n").map((a)=>Number(a));
  var S = input[0];
  var w = parseInt(input[1]);
  if(w == 1){
     myout(S);
    return;
     }
  S = S.split("");
  var list = [];
  while(S.length != 0){
    	var tmp = "";
        for(var i = 0; i < w; i++){
          if(S.length != 0){
          	tmp += S.shift();
          }
        }
    list.push(tmp);
  }
  var output = "";
  for(var i = 0; i < list.length; i++){
    output += list[i].slice(0,1);
  }
  myout(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 21060
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,k;
bool a[15];
bool Check(int x) {
	int m;
	while(x) {
		m=x%10;
		if(a[m])
			return false;
		x/=10;
	}
	return true;
}
int main() {
	int x;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;i++) {
		scanf("%d",&x);
		a[x]=1;
	}
	while(true) {
		if(Check(n)) {
			printf("%d\n",n);
			return 0;
		}
		n++;
	}
	return 0;
}


Measured memory_bytes: 128
import math
i = list(map(int, input().split()))
angle_M=6*i[3]
angle_H=30*i[2]+0.5*i[3]
angle_ans=abs(angle_M-angle_H)

ans=i[0]**2+i[1]**2-(2*i[0]*i[1]*math.cos(math.radians(angle_ans)))
print(math.sqrt(ans))

Measured memory_bytes: 9500
import math

N = int(input())
h = list(map(int, input().split()))

dp = list([math.inf for i in range(N)])  # dpテーブル
dp[0] = 0
for i in range(N):
    a = dp[i]
    b = dp[i - 1] + abs(h[i] - h[i - 1])
    if a > b:
        dp[i] = b
    else:
        dp[i] = a
    a = dp[i]
    if i > 1:
        b2 = dp[i - 2] + abs(h[i] - h[i - 2])
        if a > b2:
            dp[i] = b2
        else:
            dp[i] = a

print(dp[N - 1])


Measured memory_bytes: 20896
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

void Main()
{
	int A, B;
	std::cin >> A >> B;
	int i = 0;
	for (; (A - 1) * i + 1 < B; ++i);
	std::cout << i << std::endl;
}

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

Measured memory_bytes: 256
/**
 * File    : D.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-3-25 21:07:52
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int A, B;
bool ans[100][100];

void flush()
{
  cout << 100 << " " << 100 << endl;
  for (auto i = 0; i < 100; i++)
  {
    for (auto j = 0; j < 100; j++)
    {
      cout << (ans[i][j] ? '#' : '.');
    }
    cout << endl;
  }
}

int main()
{
  cin >> A >> B;
  for (auto i = 0; i < 50; i++)
  {
    for (auto j = 0; j < 100; j++)
    {
      ans[i][j] = true;
    }
  }
  for (auto i = 50; i < 100; i++)
  {
    for (auto j = 0; j < 100; j++)
    {
      ans[i][j] = false;
    }
  }
  int nowa = 1;
  while (nowa < A)
  {
    for (auto i = 1; i < 100; i += 2)
    {
      for (auto j = 1; j < 100; j += 2)
      {
        ans[i][j] = false;
        nowa++;
        if (nowa >= A)
        {
          break;
        }
      }
      if (nowa >= A)
      {
        break;
      }
    }
  }
  int nowb = 1;
  while (nowb < B)
  {
    for (auto i = 51; i < 100; i += 2)
    {
      for (auto j = 1; j < 100; j += 2)
      {
        ans[i][j] = true;
        nowb++;
        if (nowb >= B)
        {
          break;
        }
      }
      if (nowb >= B)
      {
        break;
      }
    }
  }
  flush();
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<math.h>
#include<algorithm>
#include<fstream>
using namespace std;
#define ll long long
#define endl '\n'
const int max_n = 2*1e5 + 3;
const int INF = 1e9+1;


int a;
int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin >> a;
	for (int i = 1; i <=9; i++)
	{
		if (a % i == 0 && a / i <= 9)
		{
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
}
 

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#include<map>
#include<set>
#define EPS 1e-10
using namespace std;
typedef long long llong;
vector<string>v(8);
void print_s() {
	for (int i = 0; i < 8; i++) {
		cout << v[i] << endl;
	}
}

void dfs(int x, int y) {
	v[x][y] = '0';
	int i = x-1, j = y,cnt=0;
	while (0 <= i&&i <= 7 && 0 <= j&&j <= 7 && cnt++ < 3) {
		if (v[i][j] == '1')dfs(i, j);
		i--;
	}
	i = x, j = y+1, cnt = 0;
	while (0 <= i&&i <= 7 && 0 <= j&&j <= 7 && cnt++ < 3) {
		if (v[i][j] == '1')dfs(i, j);
		j++;
	}
	i = x+1, j = y, cnt = 0;
	while (0 <= i&&i <= 7 && 0 <= j&&j <= 7 && cnt++ < 3) {
		if (v[i][j] == '1')dfs(i, j);
		i++;
	}
	i = x, j = y-1, cnt = 0;
	while (0 <= i&&i <= 7 && 0 <= j&&j <= 7 && cnt++ < 3) {
		if (v[i][j] == '1')dfs(i, j);
		j--;
	}
}

int main() {
	int n; cin >> n;
	for(int k=1;k<=n;k++) {
		for (int i = 0; i < 8; i++) {
			cin >> v[i];
		}
		int x, y;
		cin >> x >> y;
		x--; y--;
		dfs(y, x);
		cout << "Data " << k << ":" << endl;
		print_s();
	}
	return 0;
}

Measured memory_bytes: 3056
#include<stdio.h>
int main(){
  char s[1002]={0},t[1002]={0};
  int i,n,cnt_t=0,cnt_s=0,min,num;
  ///読み込み
  scanf("%s",&s);
  scanf("%s",&t);
  
  //tの文字数カウント
  for(i=0;t[i]!=0;i++,cnt_t++);
  //sの文字数カウント
  for(i=0;s[i]!=0;i++,cnt_s++);
  //最初の最小値は最悪の数字
  min = cnt_t;
  
  //メイン
  for(i=0;i+cnt_t-1<cnt_s;i++){//始点の制御
    num=0;//カウンター初期化
    for(n=0;n<cnt_t;n++){
      //printf("s:%d t:%d i+n:%d\n",i,n,i+n);
      if(s[i+n]!=t[n]){
        num++;//カウント
        
      }
    }
    //printf("%d\n",num);
    if(num<min){
      min = num;
      //printf("min=%d\n",min);
    }
  }
  printf("%d",min);
  return 0;
}

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

//最大公約数
ll gcd(ll m, ll n)
{
    if (m < n)
    {
        ll tmp = m;
        m = n;
        n = tmp;
    }

    while (1)
    {
        ll mod = m % n;
        if (mod == 0)
            return n;
        m = n;
        n = mod;
    }
}

//最小公倍数
ll lcm(ll m, ll n)
{
    return m * n / gcd(m, n);
}

int main()
{
    ll a,b;
    cin>>a>>b;
    cout<<lcm(a,b)<<endl;
    return 0;
}


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

int main(void){
  int X, N, p, min;
  scanf("%d %d", &X, &N);

  int arr[101] = {0};

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

  N = 0;
  min = X;

  for(int i=0; i<101; i++){
    if(arr[i] == 0){
      if(abs(i-X) < min){
        min = abs(i-X);
        N = i;
      }
    }
  }

  if(101-X < min) N = 101;

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

}

Measured memory_bytes: 2148
import java.util.Scanner;
import static java.lang.System.out;

class SmallLargeOrEqual {
    private String sign;

    SmallLargeOrEqual(int a, int b) {
        this.sign = (a == b) ? "==" : ((a > b) ? ">" : "<");
    }

    @Override
    public String toString() {
        return this.sign;
    }
}

public class Main {
    public static void main(String... args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();

        out.println("a " + new SmallLargeOrEqual(a, b) + " b");
    }
}

Measured memory_bytes: 26060
n = int(input())
a_i = list(map(int, input().split()))
ans = "APPROVED"
for id in range(n):
    if a_i[id] % 2 == 0:
        if a_i[id] % 3 == 0 or a_i[id] % 5 == 0:
            continue
        else: ans = "DENIED"
print(ans)


Measured memory_bytes: 2940
use petgraph::algo::dijkstra;
use petgraph::graph::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        n: usize,
        m: usize,
        ab: [(Usize1, Usize1); m],
    }
    let mut graph = Graph::new_undirected();
    for _ in 0..n {
        graph.add_node(());
    }
    for &(ai, bi) in &ab {
        graph.add_edge(node_index(ai), node_index(bi), ());
    }
    let distance = dijkstra(&graph, node_index(0), None, |_| 1);
    let mut color = vec![0; n];
    for i in 0..n {
        if distance[&node_index(i)] % 2 == 0 {
            color[i] = 1;
        }
    }
    if ab.iter().any(|&(ai, bi)| color[ai] == color[bi]) {
        println!("{}", n * (n - 1) / 2 - m);
    } else {
        let mut count = [0, 0];
        for i in 0..n {
            count[color[i]] += 1;
        }
        println!("{}", count[0] * count[1] - m);
    }
}


Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,a,s=0;
	cin>>n>>m;
	while(m--)
	{
		cin>>a;
		s=s+a;
	}
	if(s>n)
	cout<<"-1";
	else
	cout<<(n-s);
	return 0;
}

Measured memory_bytes: 3616
n, m = map(int, input().split())
adj = {}
indegrees = [0 for _ in range(n+1)]
for _ in range(m):
  cur, nxt = map(int, input().split())
  adj[cur] = adj.get(cur, []) + [nxt]
  indegrees[nxt] += 1
  
stack = []
for i in range(1, n+1):
  if indegrees[i] == 0:
    stack.append(i)
    
dp = [0 for _ in range(n+1)]
    
while stack:
  cur = stack.pop()
  for nxt in adj.get(cur, []):
    indegrees[nxt] -= 1
    if indegrees[nxt] == 0:
      stack.append(nxt)
    dp[nxt] = max(dp[nxt], dp[cur] + 1)
print(max(dp))

Measured memory_bytes: 71640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  int n;
  cin >> n;
  vint list(1101010);
  int sum = 0;
  rep(i,0,n){
    int num;
    cin >> num;
    list[num]++;
    sum += num;
  }
  int q;
  cin >> q;
  vint B(q),C(q);
  rep(i,0,q) cin >> B[i] >> C[i];
  rep(i,0,q){
    sum -= list[B[i]]*B[i];
    sum += list[B[i]]*C[i];
    list[C[i]] += list[B[i]];
    list[B[i]] = 0;
    cout << sum << endl;
  }
}

Measured memory_bytes: 13468