akhauriyash/Code-Regression huggingface dataset:
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, char) => {
        read_value!($next, String).chars().collect::<Vec<char>>()[0]
     };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
    ($next:expr, isize1) => {
        read_value!($next, isize) - 1
    };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}
#[allow(dead_code)]
const MOD: usize = 1000000007;
#[allow(dead_code)]
fn to_num(c: char) -> i64 {
    c as i64 - 48
}


fn main() {
    input!{
        x: usize,
    }
    let ans = 2 * (x / 11) + if x % 11 == 0 { 0 } else if x % 11 > 6 { 2 } else { 1 };
    println!("{}", ans);
}

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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int n, l; cin >> n >> l;

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

    sort(s.begin(), s.end());

    string ans = "";
    for (int i = 0; i < n; ++i) {
        ans += s[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
a = input()
i = 0
m = 0
s = 0
while i < len(a) :
    if a[i] == "R" :
        s = s + 1
    if a[i] == "S" :
        if m < s :
            m = s
        s = 0
    i = i + 1
if m < s :
    m = s
print(m)



Measured memory_bytes: 9020
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード

    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断

    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]


N, M = map(int, input().split())

uf = UnionFind(N)
ans = N

for _ in range(M):
    X, Y, Z = map(int, input().split())
    if not uf.isSameGroup(X, Y):
        uf.Unite(X, Y)
        ans -= 1

print(ans)


Measured memory_bytes: 7748
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
  
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk
#define prev fhsgfhjf
#define plus fsghsf
#define minus ytryr
  
using namespace std;
  
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
  
const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const ld eps = 1e-12;
const double pi = atan2(0, -1);
const int ABC = 26;

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 10.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n, k, s;
    cin >> n >> k >> s;
    if (s == 1000000000) {
        rep(i, 0, k) {
            cout << s << " ";
        }
        rep(i, 0, n - k) {
            cout << s - 1 << " ";
        }
    } else {
        rep(i, 0, k) {
            cout << s << " ";
        }
        rep(i, 0, n - k) {
            cout << s + 1 << " ";
        }
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>

int main(){

	int n,i,a[100];	
	scanf("%d\n",&n);
	
	for(i=0; i<n; i++){
		scanf("%d\n",&a[i]);
	}
	for(i=n-1; i>=0; i--){
		printf("%d",a[i]);
		if(i!=0)
			printf(" ");
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 604
import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    count = 0
    for i in range(1, N):
        if A[i] == A[i-1]:
            count += 1
            A[i] = -1
    print(count)


    return 0

if __name__ == "__main__":
    solve()

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

int main(){
    int a,b;
    cin >> a >> b;

    if(a>b) cout << "a > b" << endl;
    else if(a==b) cout << "a == b" << endl;
    else if(a<b) cout << "a < b" << endl;

    return 0;
}


Measured memory_bytes: 3104
#include<cstdio>
#include<iostream>
#include<algorithm>

#define P 998244353
#define X 716070898

using namespace std;

int read(){
	int x=0;
	char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x;
}

const int N = 100005;

int n,m[3];
struct node{
	int v;
	node *nxt;
}pool[N*3],*h[3][N];
int cnt;
void addedge(int ty,int u,int v){
	node *p=&pool[++cnt];
	p->v=v;p->nxt=h[ty][u];h[ty][u]=p;
}

int mx[3],sum[3][N],used[N],sg[N],mul[N];
int Plus(int x,int y) { return x+y>=P ? x+y-P : x+y; }
void cal(int ty){
	for(int i=0;i<=m[ty];i++) used[i]=0;
	int cur=0;
	sg[n]=0; sum[ty][0]=Plus(sum[ty][0],mul[n]);
	for(int i=n-1;i>0;i--){
		++cur;
		for(node *p=h[ty][i];p;p=p->nxt) used[sg[p->v]]=cur;
		sg[i]=-1;
		for(int j=0;j<=mx[ty];j++) 
			if(used[j]!=cur){ sg[i]=j; break; }
		if(sg[i]==-1) sg[i]=++mx[ty];
		sum[ty][sg[i]]=Plus(sum[ty][sg[i]],mul[i]);
	}
}

int main()
{
	int u,v;
	n=read();
	for(int i=0;i<3;i++){
		m[i]=read();
		for(int j=0;j<m[i];j++){
			u=read(); v=read();
			if(u>v) swap(u,v);
			addedge(i,u,v);
		}
	}
	
	mul[0]=1;
	for(int i=1;i<=n;i++) mul[i]=1ll*mul[i-1]*X%P;
	cal(0); cal(1); cal(2);
	
	int ans=0;
	for(int i=0;i<=mx[0];i++)
		for(int j=0;j<=mx[1];j++){
			if((i^j)>mx[2]) continue;
			ans=Plus(ans,1ll*sum[0][i]*sum[1][j]%P*sum[2][i^j]%P);
		}
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 8704
H,W = map(int, raw_input().split(" "))
N = int(raw_input())
a = map(int, raw_input().split(" "))

ans = [[0]*W for i in xrange(H)]

x = 0
y = 0
for i in xrange(len(a)):
    for j in xrange(a[i]):
        ans[y][x] = i + 1
        if x < W - 1:
            x += 1
        else:
            x = 0
            y += 1

for i,l in enumerate(ans):
    for j in l if(i%2==0)else l[::-1]:
        print j,
    print ""



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

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

typedef pair<int, int> pint;

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front

#define MOD (1000 * 1000 * 1000 + 7)

signed main() {
    int n, m;
    string s;

    cin >> n >> m;
    cin >> s;

    vector<int> ok_list;
    {
        int one_max = 0;
        int now = 0;
        REP(i, n+1) {
            if (s[i] == '1') {
                now++;
                one_max = max(one_max, now);
            } else {
                now = 0;
                ok_list.pb(i);
            }
        }

        if (one_max >=  m) {
            cout << -1 << endl;
            return 0;
        }
    }

    int now = n;
    vector<int> pos;
    pos.pb(now);
    while (now != 0) {
        decltype(ok_list)::iterator it = std::upper_bound(ok_list.begin(), ok_list.end(), now - m - 1);
        now = *it;
        pos.pb(now);
    }

    int _size = SZ(pos);
    RREP(i, _size-1) {
        cout << (pos[i] - pos[i+1]);
        if (i != 0) cout << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1592
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
using namespace std;

int main(int argc, char** argv)
{
	/*
	問題文
英大文字からなる文字列 S が与えられます。S の部分文字列 (注記を参照) であるような最も長い ACGT 文字列 の長さを求めてください。
ここで、ACGT 文字列とは A, C, G, T 以外の文字を含まない文字列です。

注記
文字列T の部分文字列とは、T の先頭と末尾から0 文字以上を取り去って得られる文字列です。
例えば、ATCODER の部分文字列には TCO, AT, CODER, ATCODER,  (空文字列) が含まれ、AC は含まれません。
	*/

	// input = 文字列
	string S;
	cin >> S;

	// S の最大の長さを教えてくださいます？
	// 変数にしなくても構いませんわ
	// ただ計算量を見積もりたいだけです//
	
	/*
	制約S は長さ 1 以上 10 以下の文字列である。
	S の各文字は英大文字である。
	*/
	// ありがとう
	// これなら O(n^2) でも余裕ですわね
    //  その通りですわ
	int ans=0;
	int b = ans;
	char acgt[4] = { 'A', 'C', 'G', 'T' };
	//std::set<char> acgtm = { 'A', 'C', 'G', 'T' };
	// タイが曲がっていてよ、だった
	// https://dic.nicovideo.jp/a/%E5%B0%8F%E7%AC%A0%E5%8E%9F%E7%A5%A5%E5%AD%90
	for (int i = 0; i < S.length(); i++) {
		for (int j = 0; j < 4; j++) {
			if (S[i] == acgt[j]) {
				ans++;
				b = max(b, ans);
				break;
			}
			if (j == 3) {
				ans = 0;
			}
		}
	}
	// std::max と衝突しますことよ
	
	
	// はやくしてくださいます？
	// output = 部分文字列の長さ
	std::cout << b << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int ans = -1;
    int ax;
    int bx;
    for(int i = 1; i <= 1000; i++){
       ax = (int) (i*0.08);
       bx = (int) (i*0.1);
       if(ax == a && bx == b){
         ans = i;
         break;
       }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23636
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int[] P = new int[N];
            int[] Q = new int[N];
            for (int i = 0; i < N; i++) {
                P[i] = sc.nextInt();
            }
            for (int i = 0; i < N; i++) {
                Q[i] = sc.nextInt();
            }

            ArrayList<String> list = new ArrayList<>();
            dfs(0, N, new boolean[N + 1], "", list);
            Collections.sort(list);

            String sp = "";
            for (int i = 0; i < N; i++) {
                sp += P[i];
            }

            String sq = "";
            for (int i = 0; i < N; i++) {
                sq += Q[i];
            }

            int a = 0;
            int b = 0;
            for (int i = 0; i < list.size(); i++) {
                if (list.get(i).equals(sp)) {
                    a = i;
                    break;
                }
            }
            for (int i = 0; i < list.size(); i++) {
                if (list.get(i).equals(sq)) {
                    b = i;
                    break;
                }
            }

            System.out.println(Math.abs(a - b));
        }
    }

    private static void dfs(int i, int N, boolean[] used, String s, ArrayList<String> list) {
        if (i >= N) {
            list.add(s);
            return;
        }

        for (int n = 1; n <= N; n++) {
            if (used[n]) {
                continue;
            }
            used[n] = true;
            dfs(i + 1, N, used, s + n, list);
            used[n] = !true;
        }
    }

}

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

 
using namespace std;

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

    int x[n][d];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            cin >> x[i][j];
        }
    }

    int diff, sum, cnt = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            sum = 0;
            for (int k = 0; k < d; k++) {
                diff = abs(x[i][k] - x[j][k]);
                sum += (diff * diff);
            }

            for (int k = 0; k <= sum; k++) {
                if (k * k == sum) {
                    cnt++;
                    break;
                }
            }
        }
    }
    cout << cnt << endl;

    return 0;
}

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

int main() {
  int n,m;
  cin>>n>>m;
  vector<vector<int>>c(m,vector<int>(3));
  for(int i=0;i<m;i++){
    cin>>c[i][0]>>c[i][1];
    c[i][2]=i;
  }
  sort(c.begin(),c.end());
  vector<string>ans(m);
  int now=0;
  int pre=c[0][0];
  for(int i=0;i<m;i++){
    if(pre==c[i][0]){
      now++;
      string s2=to_string(now);
      int x=6-s2.size();
      for(int j=0;j<x;j++){
        s2="0"+s2;
      }
      string s1=to_string(c[i][0]);
      int y=6-s1.size();
      for(int j=0;j<y;j++){
        s1="0"+s1;
      }
      ans[c[i][2]]=s1+s2;
    }
    else{
      now=1;
      pre=c[i][0];
      string s2=to_string(now);
      int x=6-s2.size();
      for(int j=0;j<x;j++){
        s2="0"+s2;
      }
      string s1=to_string(c[i][0]);
      int y=6-s1.size();
      for(int j=0;j<y;j++){
        s1="0"+s1;
      }
      ans[c[i][2]]=s1+s2;
    }
  }
  for(int i=0;i<m;i++) cout<<ans[i]<<endl;
}

Measured memory_bytes: 12416
class UnionFind_size:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.size = [1] * (n+1)
    
    # 根を検索する関数
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.find(self.par[x])
  
    # 結合(unite)する関数
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.size[x] < self.size[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
           
    # 同じグループに属するかを判定する関数
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
    
    # 要素が属する木のサイズを返す関数
    def get_size(self, x):
        return self.size[self.find(x)]
    
    # グループ数を返す関数
    def group_sum(self):
        c = 0
        for i in range(len(self.par)):
            if self.find(i) == i:
                c += 1
        return c


if __name__ == "__main__":
    N,M = map(int, input().split())
    uf = UnionFind_size(N)

    A, B = [0] * M, [0] * M
    for i in range(M):
        A[i], B[i] = [int(j) for j in input().split()]

    total = int(N * (N-1) / 2)
    ans = [total]
    for i in range(M-1):
        if uf.same_check(A[-(i+1)], B[-(i+1)]):
            ans.append(ans[i])
        else:
            ans.append(ans[i] - uf.get_size(A[-(i+1)]) * uf.get_size(B[-(i+1)]))
        uf.unite(A[-(i+1)], B[-(i+1)])
    
    for i in (reversed(ans)):
        print(i)

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

int main() {
  int N, A, B, sum=0;
  cin >> N >> A >> B;
  
  for (int i=1; i<=N; i++){
    int n = i/10000 + (i%10000)/1000 + (i%1000)/100 + (i%100)/10 + i%10;
    if (A <= n && n <=B){
      sum += i;
    }
  }
  
  cout << sum << endl;
    
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

	int[] head;
	int[] next;
	int[] to;
	
	void addEdge(int v, int u, int idx) {
		to[idx] = u;
		next[idx] = head[v];
		head[v] = idx;
	}
	
	int dfs(int v, int p) {
		int ret = 0;
		for (int e = head[v]; e >= 0; e = next[e]) {
			int u = to[e];
			if (u != p) {
				ret ^= dfs(u, v) + 1;
			}
		}
		return ret;
	}
	
	void submit() {
		int n = nextInt();
		head = new int[n];
		Arrays.fill(head, -1);
		next = new int[2 * n - 2];
		to = new int[2 * n -2];
		
		for (int i = 0; i < n - 1; i++) {
			int v = nextInt() - 1;
			int u = nextInt() - 1;
			addEdge(v, u, 2 * i);
			addEdge(u, v, 2 * i + 1);
		}
		
		int ret = dfs(0, -1);
		out.println(ret == 0 ? "Bob" : "Alice");
	}

	void preCalc() {

	}

	void stress() {

	}

	void test() {

	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		//stress();
		//test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}


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

using namespace std;

int N, L, A[100010];

int main() {
	scanf("%d %d", &N, &L);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	for (int i = 0; i < N; i++) {
		if (A[i] + A[i + 1] >= L) {
			puts("Possible");
			for (int j = 0; j < i; j++) {
				printf("%d\n", j + 1);
			}
			for (int j = N - 2; j >= i; j--) {
				printf("%d\n", j + 1);
			}
			return 0;
		}
	}
	puts("Impossible");
}


Measured memory_bytes: 1152
<?php
fscanf(STDIN, "%d %d", $A, $B);

$minAns = $B * 10;
$maxAns = ($B + 1) * 10;

for($i = $minAns; $i < $maxAns; $i++) {
	if(intval($i * 8 / 100) == $A) {
		echo "{$i}\n";
		exit;
	}
}
echo "-1\n";


Measured memory_bytes: 4728
while True:
  n=int(input())
  if n==0:
    break
  lists=[]
  for i in range(n):
    lists.append(int(input()))
  a=max(lists)
  b=min(lists)
  x=int(len(lists))
  average=(sum(lists)-a-b)/(x-2)
  print(int(average))


Measured memory_bytes: 5596
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
ll dp[10005][105][2],d;
void llialize(){
	for(ll i=0;i<10005;i++){
		for(ll j=0;j<105;j++){
			dp[i][j][0]=-1;
			dp[i][j][1]=-1;
		}
	}
}
ll digit(ll inx,ll sum,ll tem,vector<ll> &v){
	if(inx<0){
		if(sum%d==0)return 1LL;
		return 0LL;
	}
	if(dp[inx][sum][tem]!=-1&&tem==0)
	return dp[inx][sum][tem];
	ll k,res=0;
	k=(tem==1?v[inx]:9);
	for(ll dig=0;dig<=k;dig++){
		ll ntem=(dig==v[inx])?tem:0;
		res=(res+digit(inx-1,(sum+dig)%d,ntem,v))%hell;
	}
	if(!tem)dp[inx][sum][tem]=res;
	return res;
}
ll solve(string &x){
	vi v;
	for(ll i=x.size()-1;i>=0;i--){
		v.pb(x[i]-'0');
	}
	return digit(v.size()-1,0,1,v);
}
int main(){
	ios;
	ll t=1;
	llialize();
	while(t--){
		string r;cin>>r>>d;
		cout<<(solve(r)-1+hell)%hell<<endl;
	}
}


Measured memory_bytes: 17840
# -*- coding: utf-8 -*-

if __name__ == '__main__':
    l = list(map(int, input().split()))
    N = int(l[0])
    X = int(l[1])
    T = int(l[2])
    
    if N%X == 0:
        print((N//X) * T)
    else:
        print((N//X + 1) * T)


Measured memory_bytes: 9164
#include <iostream>

using namespace std;

int main() {
	int n;
	int *S;
	int q;
	int *T;
	cin >> n;
	S = new int[n];
	for (int i = 0; i < n; ++i) {
		cin >> S[i];
	}

	cin >> q;
	T = new int[q];
	for (int i = 0; i < q; ++i) {
		cin >> T[i];
	}

	int count = 0;
	
	for (int i = 0; i < q; ++i) {
		int key = T[i];
		int from = 0;
		int to = n - 1;
		do {
			int mid = (from + to) / 2;
			if (key == S[mid]) {
				++count;
				break;
			}
			else if (key < S[mid]) {
				to = mid - 1;
			}
			else {
				from = mid + 1;
			}
		} while (from <= to);
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 1764
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

const int INF = 1001001001;

int main(){
  int h, n;
  cin >> h >> n;
  vector<pair<int, int>> vp(n);
  rep(i, n){
    int a, b;
    cin >> a >> b;
    vp.at(i) = {a, b};
  }
  vector<int> dp(h+1, INF);
  dp.at(0) = 0;
  for(auto [a, b] : vp){
    rep(i, h+1){
      int add = 0;
      if(i - a > 0) add = dp.at(i-a);
      dp.at(i) = min(dp.at(i), add+b);
    }
  }
  cout << dp.at(h) << endl;
  return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define endl "\n"
#endif
using namespace std;
typedef unsigned long long int lu;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> v;
typedef vector<lu> vu;
typedef vector<v> vv;
typedef vector<vu> vvu;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
typedef vector<set<ll>> vsll;
typedef set<pair<ll, ll>> spll;
typedef vector<spll> vspll;
typedef vector<pll> vpll;
typedef pair<lu, lu> puu;
typedef vector<puu> vpuu;
const ll MOD = 1e9 + 7;
const ld PI = 2 * acos(0.0);
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
#define round(x, y) ((x + y - 1) / y)
#define ce(x, y) ((x + y - 1) / y)
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define sz(x) (ll) x.size()
#define sq(x) ((x) * (x))
#define cb(x) ((x) * (x) * (x))
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define yesno(f) \
    if (f)       \
        yes else no;
#define noo \
    { no return; }

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template <typename T = ll>
vector<T> ga(ll n, bool oneIndexed = false) {
    vector<T> a = vector<T>(n + oneIndexed);

    for (ll i = 0; i < n; i++) {
        T p;
        cin >> p;
        a[i + oneIndexed] = p;
    }

    return move(a);
}

template <typename T, typename A>
void pa(vector<T, A> const &a, ll begin = 0, ll end = -1) {
    if (end == -1)
        end = sz(a) - 1;
    for (ll i = begin; i <= end; i++) {
        cout << a[i] << " ";
    }
    cout << endl;
}

void solve() {
    ll n;
    cin >> n;
    string s;
    cin >> s;

    // [pos][dig at this posn]
    vv dp(n + 1, v(n + 1, 0));
    dp[1][1] = 1;

    for (ll pos = 2; pos <= n; pos++) {
        char sign = s[pos - 2];

        ll s1 = 0;
        ll s2 = 0;

        for (ll dig = 1; dig <= n; dig++) {
            s2 += dp[pos - 1][dig];
        }

        s2 %= MOD;

        for (ll dig = 1; dig <= pos; dig++) {
            switch (sign) {
                case '<':
                    if (dig > 1)
                        dp[pos][dig] += s1;
                    break;
                case '>':
                    if (dig < pos)
                        dp[pos][dig] += s2;
                    break;
            }

            s1 += dp[pos - 1][dig];
            s2 -= dp[pos - 1][dig];
            s2 += MOD;

            s1 %= MOD;
            s2 %= MOD;

            dp[pos][dig] %= MOD;
        }
    }

    ll x = 0;
    for (ll i = 1; i <= n; i++) {
        x += dp[n][i];
    }
    x %= MOD;
    cout << x;
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // freopen("file", "r", stdin);
    // freopen("file", "w", stdout);

    solve();
    return 0;
}

Measured memory_bytes: 70784
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A[] = new int[10];
		for (int i=0;i<4;i++) {
			int temp = sc.nextInt();
			if (temp!=1&&temp!=9&&temp!=7&&temp!=4) {
				System.out.println("NO");
				return ;
			}
			A[temp]++;
			if (A[temp]>1) {
				System.out.println("NO");
				return ;
			}
		}
		System.out.println("YES");
	}
}


Measured memory_bytes: 22100
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

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

      for (int i=0; 4*i <= N; i++){
            for (int j=0; 4*i + 7*j <= N; j++){
                  if (4*i+7*j == N){
                        cout << "Yes" << endl;
                        exit(0);
                  }
            }
      }
      cout << "No" << endl;
      exit(0);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int n,m;
		int[] width,height;
		int[] w,h;
		int c;
		while(true) {
			n = sc.nextInt();
			if(n==0) {break;}
			m = sc.nextInt();

			c = 0;
			
			width = new int[n+1];
			height = new int[m+1];

			w = new int[1500001];
			h = new int[1500001];

			for(int i=0; i<n; i++) {
				width[i+1] = sc.nextInt() + width[i];
			}
			for(int i=0; i<m; i++) {
				height[i+1] = sc.nextInt() + height[i];
			}

			for(int w0=0; w0<n; w0++) {
				for(int w1=w0; w1<n+1; w1++) {
					w[width[w1]-width[w0]]++;
				}
			}

			for(int h0=0; h0<m; h0++) {
				for(int h1=h0; h1<m+1; h1++) {
					h[height[h1]-height[h0]]++;
				}
			}
			
			for(int j=1; j<1500001; j++) {
				c += w[j] * h[j];
			}
			System.out.println(c);
		}
		sc.close();
	}

}



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

int main(){
    int n; cin >> n;
    int D[n];
    for(int i = 0; i < n; i++) cin >> D[i];
    int ans = 0;
    for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
            ans += D[i] * D[j];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int EOorder(int i);
int main(){
	int a,b;
	cin>>a>>b;
	if(a<=9&&b<=9){
		cout<<a*b<<endl;
	}
	else cout<<"-1"<<endl;
}
int EOorder(int i){
	if(i%2==1){
		i++;
	}
	i=i/2;
	return i;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

int main(){

    int k;
    int x;
    cin >> k >> x;

    if(k * 500 >= x) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define FF first
#define SS second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define PLL pair<ll, ll>
#define inf 100000001
#define mod 1000000007
#define LP lower_bound
#define UP upper_bound
#define MP make_pair
#define rep1 for(i=1;i<=n;i++)
#define VLL vector<ll>
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define UMP unordered_map
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll myXOR(unsigned long long int x, unsigned long long int y)
{
    return (x|y)&(~x|~y);
}
ll powerLL(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    }
    return result; 
}
int main()
{
    fastio
    ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r, t,u,w,x,y,z;
    string str, ss, str1;
    ll res;
    cin>>res;
    ll amount = 100.0;
    ll ans=0;
    while(amount<res)
    {
        amount += (amount/100);
        ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 3648
#include <iostream>

using namespace std;

int main()
{
    char c;

    cin >> c;
    if ( c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o' ) {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
n,d = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
ans = 0
for i in range(n):
    for j in range(i+1,n):
        norm = 0
        for k in range(d):
            diff = abs(x[i][k] - x[j][k])
            norm += diff**2
        flag = 0
        for k in range(norm+1):
            if k**2 == norm:
                flag = 1
        if flag:
            ans += 1
print(ans)

Measured memory_bytes: 3064
# https://atcoder.jp/contests/cf17-final-open/tasks/cf17_final_b
from collections import Counter

S = input()
counter = Counter(S)
most_common = list(counter.items())
while len(most_common) < 3:
    most_common.append(('x', 0))
    
most_common.sort(key=lambda x:x[1] ,reverse=False)
# print(most_common)
ret = 'YES' if most_common[1][1] <= most_common[0][1]+1 and most_common[2][1] <= most_common[0][1]+1 else 'NO'
print(ret)

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

using namespace std;

int main(){
	
	int n;
	cin>>n;
	long double a[n];
	for (int i=1;i<=n;i++){
		cin>>a[i];
	}
	long double dp[n+2][n+2];
	for (int i=0;i<=n;i++){
		for (int j=0;j<=n;j++){
			dp[i][j]=0;
		}
	}
	dp[1][1]=a[1];
	dp[0][0]=0;
	dp[0][1]=1-a[1];
	for (int i=0;i<=n;i++){
		for (int j=0;j<=n;j++){
			if (i==j&&i!=1&&i!=0){
				dp[i][j]=dp[i-1][j-1]*a[i];
			}
			if (i==0&&j!=0&&j!=1){
				dp[i][j]=dp[i][j-1]*(1-a[j]);
			}
		}
	}
	for (int i=1;i<=n;i++){
		for (int j=i+1;j<=n;j++){
			dp[i][j]=dp[i-1][j-1]*a[j]+dp[i][j-1]*(1-a[j]);
			//cout<<dp[i][j]<<" ";
		}
		//cout<<endl;
	}
//	for (int i=0;i<=n;i++){
//		for (int j=0;j<=n;j++){
//			//dp[i][j]=dp[i-1][j-1]*a[j]+dp[i][j-1]*(1-a[j]);
//			cout<<dp[i][j]<<" ";
//		}
//		cout<<endl;
//	}
	long double ans=0;
	int q=0;
	q=(n+1)/2;
	for (int i=q;i<=n;i++){
		ans+=dp[i][n];
		//cout<<dp[i][n]<<" ";
	}
	//cout<<endl;
	cout<< fixed << setprecision(10)<<ans;
	//cout<<dp[n][n];
	
}

Measured memory_bytes: 144480
const N,K=map(x->parse(Int,x),split(readline()))
const X=Float64[]
const Y=Float64[]
const C=Float64[]
for _=1:N
	x,y,c=map(x->parse(Float64,x),split(readline()))
	push!(X,x)
	push!(Y,y)
	push!(C,c)
end
function check(M)
	A=Pair{Float64,Float64}[]
	for i=1:N
		push!(A,X[i]=>Y[i])
	end
	r=[M/c for c=C]
	for i=1:N,j=i+1:N
		d=sqrt((X[i]-X[j])^2+(Y[i]-Y[j])^2)
		ri=r[i]
		rj=r[j]
		if d-1e-10<abs(ri-rj)||ri+rj-1e-10<d
			continue
		end
		a=acos((ri^2+d^2-rj^2)/(2*ri*d))
		t=atan2(Y[j]-Y[i],X[j]-X[i])
		push!(A,X[i]+ri*cos(t+a)=>Y[i]+ri*sin(t+a))
		push!(A,X[i]+ri*cos(t-a)=>Y[i]+ri*sin(t-a))
	end
	ret=false;
	for (x,y)=A
		cnt=0
		for i=1:N
			if sqrt((X[i]-x)^2+(Y[i]-y)^2)<r[i]+1e-10
				cnt+=1
			end
		end
		if cnt>=K
			ret=true
		end
	end
	ret
end
function main()
	L=0
	R=1e9
	for _=1:100
		M=(L+R)/2
		if check(M)
			R=M
		else
			L=M
		end
	end
	println(R)
end
main()


Measured memory_bytes: 123460
#include <string>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
typedef long long ll;
const int mod=1000000007;

#define lol(i,n) for(int i=0;i<n;i++)

using namespace std;
int f[50];

int main(){
    int n;
    cin >>n;
    f[0]=1;f[1]=1;
    for(int i=2;i<=n;i++){
        f[i]=f[i-1]+f[i-2];
    }
    cout << f[n] << endl;
}



Measured memory_bytes: 3096
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <time.h>
#define _USE_MATH_DEFINES
#define LL long long
#define UN unsigned
using namespace std;
const double PI = acos(-1.0);

int max_num(int ary[], int length) {
	int max = ary[0];
	for (int i = 1; i < length; i++)
		if (max < ary[i]) max = ary[i];
	return max;
}

int max_ord(int ary[], int length) {
	int max;
	max = max_num(ary, length);
	for (int i = 0; i < length; i++) {
		if (ary[i] == max) return i;
	}
	return -1;
}

int min_num(int ary[], int length) {
	int min = ary[0];
	for (int i = 1; i < length; i++)
		if (min > ary[i]) min = ary[i];
	return min;
}

int min_ord(int ary[], int length) {
	int min;
	min = min_num(ary, length);
	for (int i = 0; i < length; i++) {
		if (ary[i] == min) return i;
	}
	return -1;
}

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



	cout << "ABC" << n << endl;
}

Measured memory_bytes: 256
# パスカルの三角形
N, K = map(int, input().split())

m = 1000000007

n = max(K, N - K + 1)
c = [[0] * (n + 1) for _ in range(n + 1)]
c[0][0] = 1
for i in range(1, n + 1):
    c[i][0] = 1
    for j in range(1, i + 1):
        c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % m

result = []
for i in range(1, K + 1):
    result.append(c[K - 1][i - 1] * c[N - K + 1][i] % m)
print('\n'.join(str(i) for i in result))


Measured memory_bytes: 103988
d = {}
n = int(input())
for _ in range(n):
    e = input()
    if e not in d:
        d[e] = 1
    else:
        d[e] += 1
m = int(input())
for _ in range(m):
    e = input()
    if e not in d:
        d[e] = -1
    else:
        d[e] -= 1

print(max(max(d.values()), 0))


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int c1 = 0, c2 = 0;
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (i & 1) {
      c1 += s[i] != '1';
      c2 += s[i] != '0';
    } else {
      c1 += s[i] != '0';
      c2 += s[i] != '1';
    }
  }
  cout << min(c1, c2) << '\n';
  return 0;
}

Measured memory_bytes: 512
/*Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.

My little horse must think it queer
To stop without a farmhouse near
Between the woods and frozen lake
The darkest evening of the year.

He gives his harness bells a shake
To ask if there is some mistake.
The only other sound’s the sweep
Of easy wind and downy flake.

The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=0,p=0;string s;
    cin>>n;
    vector<pair<pair<string, int>, int> > vpp;
    for(int i=0;i<n;++i)
    {
        cin>>s>>p;
        vpp.pb({{s,-p},i});
    }
    sort(vpp.begin(),vpp.end());
    for(auto i: vpp)
    {
        cout<<i.se+1<<endl;
    }
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        x: [i64; n],
    };
    let mut a = x
        .iter()
        .enumerate()
        .map(|(i, &x_i)| (x_i, i))
        .collect::<Vec<(i64, usize)>>();
    a.sort();
    let m1 = a[n / 2 - 1].0;
    let m2 = a[n / 2].0;
    let mut b = a
        .iter()
        .enumerate()
        .map(|(j, &(_, i))| (i, if j < n / 2 { m2 } else { m1 }))
        .collect::<Vec<(usize, i64)>>();
    b.sort();
    for &(_, m_i) in b.iter() {
        println!("{}", m_i);
    }
}


Measured memory_bytes: 13400
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define vi vector<int>
#define vl vector<long>
#define vll vector<long long int>
#define vC  vector<char>
#define FastIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

/*ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}*/
int main()
{
 FastIO
 int n, i;
 cin>>n;
 vll a(n),b(n),c(n),ma(n),mb(n),mc(n);
 for(i=0;i<n;i++)
 {
     cin>>a[i]>>b[i]>>c[i];
 }
 ma[0]=a[0];
 mb[0]=b[0];
 mc[0]=c[0];
 for(i=1;i<n;i++)
 {
     ma[i]=max(mb[i-1],mc[i-1])+a[i];
     mb[i]=max(ma[i-1],mc[i-1])+b[i];
     mc[i]=max(ma[i-1],mb[i-1])+c[i];
 }
 cout<<max(ma[n-1],max(mb[n-1],mc[n-1]));
}


Measured memory_bytes: 4992
# -*- coding: utf-8 -*-


import sys
import math

# 1整数
# n = int(input())

# 空白区切り2整数
a, b, k = list(map(int, input().split()))

# 空白区切りリスト
# a=list(map(int, input().split()))
count = 0
num = min(a, b) + 1
while count < k:
    num -= 1
    if a % num == 0 and b % num == 0:
        count += 1

print(num)


Measured memory_bytes: 2940
import itertools
n, m, x = map(int, input().split())
books = []

for i in range(n):
    line = list(map(int, input().split()))
    c, a = line[0], line[1:]
    books.append((c, a))

ans = 1e+10
for item in itertools.product([0, 1], repeat=n):
    understand = [0] * m
    cost = 0
    for idx, buy in enumerate(item):
        if buy:
            c, a = books[idx]
            cost += c
            for i in range(m):
                understand[i] += a[i]
    if min(understand) >= x:
        ans = min(ans, cost)

print(ans if ans != 1e+10 else -1)


Measured memory_bytes: 68716
import sys

sys.setrecursionlimit(100000)

import numpy as np


def main():
    n_num, m_num = map(int, input().split())
    # road = np.zeros((n_num, n_num), dtype='int32')
    c_map = []
    for _ in range(n_num):
        c_map.append([])
    # print(c_map)

    for _ in range(m_num):
        a, b = map(int, input().split())
        if a > b:
            a, b = b, a
        # road[a-1][b-1] = 1
        c_map[a-1].append(b-1)
        c_map[b-1].append(a-1)
    # print(c_map)

    city_info = np.zeros(n_num, dtype='int32')
    land_city = 0

    def move(a, b):
        if a in c_map[b]:
            return 1
        else:
            return 0

    def recr(c):
        city_info[c] = 1
        for n in c_map[c]:
            if city_info[n] == 0:
                if move(c, n) == 1:
                    recr(n)

    for n in range(n_num):
        if city_info[n] == 0:
            land_city += 1
            recr(n)
    # print(c_map)
    # print(city_info)
    print(land_city - 1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 73988
#define _CRT_SECURE_NO_WARNINGS

//#include "stdafx.h"
#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "list"
#include "deque"
#include "complex"
#include "bitset"
#include "cmath"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include <ctime>
#include <cassert>
#include "numeric"
#include <cstdio>
#include "random"
#include "chrono"
#include "cstring"

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target_ans("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

//#define f(i,n) for(int i=0; i<n;i++)
//#define rf(i, n) for(int i=n-1;i>=0;i--)
//#define forn(i, j, n) for(int i=j; i<n; i++)
//#define ff(i, j, n) f(i, n)f(j, n)
#define pb push_back
#define maxi(a,b) a = max(a, b);
#define mini(a,b) a = min(a, b);
//#define endl '\n'

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;
//typedef long long ll;
typedef long double ld;

#define int long long
//#define int unsigned int
#define double ld
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<char> vc;
typedef vector<vi> vvi;

template<class T>
void show(const vector<T> &a)
{
	for (T x : a)
		cout << x << " ";
	cout << endl;
}

vi xx = { 1, 0, -1, 0 };
vi yy = { 0, 1, 0, -1 };
string dir = "LRUD";

const int N = 2e5 + 50, oo = 5e18 + 500;
const int mod = 998244353;
//const int mod = 1e9 + 7;
//const int mod = 1e9 + 9;
const double eps = 1e-6, PI = 2 * acos(0.0);
int n, m, k;
int cnt = 0;
int lg = 18;
vi g[N];
vi rg[N];
vi visit(N, 0);


signed main()
{
	ios::sync_with_stdio(0);
	cout.tie(0); cin.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	cin >> n;

	vi a(n);
	vi lft(n, -1), rgt(n, n);

	vpii st;
	st.pb({ -1, -1 });

	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		while (st.back().first > a[i])
		{
			st.pop_back();
		}

		lft[i] = st.back().second;
		st.pb({ a[i], i });
	}

	st = { { -1, n } };
	for (int i = n-1; i >= 0; i--)
	{
		while (st.back().first >= a[i])
		{
			st.pop_back();
		}

		rgt[i] = st.back().second;
		st.pb({ a[i], i });
	}

	for (int i = 0; i < n; i++)
	{
		cnt += (i - lft[i])*(rgt[i] - i)*a[i];
	}

	cout << cnt;
}



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

int main(void){
    string ans;
    char c;
    for(int i=0; i<9; i++){
        cin >> c;
        if(i%4 == 0){
            ans += c;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdint>
#include <cmath>

using namespace std;
typedef unsigned long long ll;

int n;

ll combination2(ll n, ll r)
{
  if (r == 0 || r == n)
    return (1);
  else if (r == 1)
    return (n);
  return (combination2(n - 1, r - 1) + combination2(n - 1, r));
}

ll combination(ll n, ll r)
{
  if (r * 2 > n)
    r = n - r;
  ll dividend = 1;
  ll divisor = 1;
  for (ll i = 1; i <= r; ++i)
  {
    dividend *= (n - i + 1);
    divisor = divisor * i;
  }
  return dividend / divisor;
}

ll resultr = 0;
ll resultn = 0;
ll Max = 0;
ll Max2 = 0;

int main()
{
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    Max2 = max(Max2, a[i]);
  }
  //////////////

  resultn = Max2;
  for (int i = 0; i < n; i++)
  {
    if (resultn - a[i] == 0)
    {
      continue;
    }

    if (fabs((double)resultn / 2 - resultr) > fabs((double)resultn / 2 - a[i]))
    {
      resultr = a[i];
    }
  }
  /*for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < n; j++)
    {
      if (i == j)
        continue;
      if (a[i] < a[j])
      {
        continue;
      }
      ll comb = combination(a[i], a[j]);

      if (Max < comb)
      {
        resultn = a[i];
        resultr = a[j];
        Max = comb;
      }
    }
  }*/

  cout << resultn << " " << resultr << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define fi first
#define se second
using namespace std;
typedef pair<int,int> ii;

const ll siz = 2e5 + 10;
const ll SIZ = 1e6 + 10;
const ll mod = 1e9 + 7;
const ll maxx = 2e9;
const ll MAXX = 1e18;
const ll base = 31;

int n;
int s;

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    freopen ("IN_3.INP", "r", stdin);
//    freopen ("OUT_3.OUT", "w", stdout);
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        if (i % 3 == 0 || i % 5 == 0) continue;
        s += i;
    }
    cout << s;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

bool compare(pair<int, int> a, pair<int, int> b) {
  return (double)a.first/(double)a.second > (double)b.first/(double)b.second;
}

const int MAX_H = 100005;
const ll inf = 1001001001;
int main() {
  int h,n;
  cin >> h >> n;
  vector<pair<ll,ll>> m(n);
  rep(i,n){
    cin >> m[i].first >> m[i].second;
  }
  
  ll dp[MAX_H];
  dp[0] = 0;

	for(int i=1; i<=MAX_H-1; ++i) dp[i] = inf;
	
	for(int i=0; i<=MAX_H-1; ++i){
		for(int j=0; j<n; ++j){
			if(i+m[j].first<MAX_H-1){
        dp[i+m[j].first] = min(dp[i+m[j].first],dp[i]+m[j].second);
			}
		}	
	}
  drep(i,MAX_H-2) mins(dp[i],dp[i+1]);

  
  cout<<dp[h]<<endl;
  return 0;
}

Measured memory_bytes: 1024