akhauriyash/Code-Regression huggingface dataset:
// atcoder/abc147/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b, c;
  while (cin >> a >> b >> c) {
    cout << (22 <= a + b + c ? "bust" : "win") << endl;
  }

  return 0;
}


Measured memory_bytes: 256
mod10_9p7 = 10**9 + 7

def main() :

    n = int(input())
    a_list = [int(i) for i in input().split()]

    sop = [0] * (n-1)
    sop[0] = a_list[0]

    for i in range(1,n-1):
        a = a_list[i]
        sop[i] = sop[i-1] + a

    # print(sop)

    res = 0
    # res = (a_list[0] * a_list[1]) % mod10_9p7
    for i in range(n-1) :
        res += (a_list[i+1] * sop[i]) % mod10_9p7
        res = res % mod10_9p7
    
    print(res)
        

main()

Measured memory_bytes: 31680
#include <iostream>
#include<cstring>
#include <string.h>
using namespace std;
int main(void){
    // Your code here!
    char str[10];
    char ans;
    int count = 0;
    int max = 0;
    cin >> str;
    int strl = strlen(str);
    for(int i = 0; i < strl; i++) {
        if (str[i] == 'A' || str[i] == 'C' || str[i] == 'G' || str[i] == 'T'){
            count++;
        } else {
            if(count >= max){
                max = count;
            }
            count = 0;
        }
    }
    if(count >= max){
        max = count;
    }
    cout << max;
}

Measured memory_bytes: 256
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define MX 10000000000
#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
void solve()
{
    int a, b;
    cin >> a >> b;
    int sol = a + b - 1;
    sol = sol / b;
    cout << sol;
}
int main()
{
	int t = 1;
//	cin >> t;
	while (t--)
	{
		solve();
	}
}


Measured memory_bytes: 256
<?php
$n = intval(fgets(STDIN));
$tArray = explode(" ", trim(fgets(STDIN)));
$m = intval(fgets(STDIN));
$sum = array_sum($tArray);
for($i = 0; $i < $m; $i++){
    list($q, $t) = explode(" ", trim(fgets(STDIN)));
    $s = $sum - $tArray[$q - 1] + $t;
    echo $s."\n";
}


Measured memory_bytes: 4604
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
#define INF 1e18
using namespace std;

//-----------------------------------------------------------------------

int V,E;
vector<int> G[10005];
int indeg[10005];

vector<int> tsort()
{
    stack<int> S;
    REP(i,V) if(indeg[i]==0) S.push(i);

    vector<int> res;
    while(!S.empty()){
        int v=S.top(); S.pop();
        res.push_back(v);
        for(auto u:G[v]){
            indeg[u]--;
            if(indeg[u]==0) S.push(u);
        }
    }
    return res;
}

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

    cin>>V>>E;
    REP(i,E){
        int a,b; cin>>a>>b;
        G[a].push_back(b);
        indeg[b]++;
    }

    vector<int> ans=tsort();
    REP(i,ans.size()) cout<<ans[i]<<endl;

}



Measured memory_bytes: 4200
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long int ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PLL, PLL> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const int inf = 1e9+9;
const int mod = 1e9+7;

#define maxn 1000100
int n, l, x, tab[maxn];

int main()
{
	boost;
	cin >> n >> l;
	FOR(i, 1, n) cin >> tab[i];
	FOR(i, 1, n-1)
	{
		if (tab[i] + tab[i + 1] >= l)
		{
			cout << "Possible\n";
			FOR(j, 1, i-1) cout << j << "\n";
			for (int j=n-1; j>=i; --j) cout << j << "\n";
			exit(0);
		}
	}
	cout << "Impossible";
	}


Measured memory_bytes: 1280
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
map<int,int> bfs;
int a[8];
int main(){
	bfs[342391]=0;
	queue<int>Q;
	Q.push(342391);
	while(Q.size()){
		int at=Q.front();
		Q.pop();
		int zero;
		for(int i=0;i<8;i++)if((at%(8<<(3*i))/(1<<(3*i)))==0)zero=i;
		if(zero%4){
			if(!bfs.count(at-(at%(8<<(3*(zero-1)))/(1<<(3*(zero-1))))*(1<<(3*(zero-1)))+(at%(8<<(3*(zero-1)))/(1<<(3*(zero-1))))*(1<<(3*zero)))){
				bfs[at-(at%(8<<(3*(zero-1)))/(1<<(3*(zero-1))))*(1<<(3*(zero-1)))+(at%(8<<(3*(zero-1)))/(1<<(3*(zero-1))))*(1<<(3*zero))]=bfs[at]+1;
				Q.push(at-(at%(8<<(3*(zero-1)))/(1<<(3*(zero-1))))*(1<<(3*(zero-1)))+(at%(8<<(3*(zero-1)))/(1<<(3*(zero-1))))*(1<<(3*zero)));
			}
		}
		if(zero%4!=3){
			if(!bfs.count(at-(at%(8<<(3*(zero+1)))/(1<<(3*(zero+1))))*(1<<(3*(zero+1)))+(at%(8<<(3*(zero+1)))/(1<<(3*(zero+1))))*(1<<(3*zero)))){
				bfs[at-(at%(8<<(3*(zero+1)))/(1<<(3*(zero+1))))*(1<<(3*(zero+1)))+(at%(8<<(3*(zero+1)))/(1<<(3*(zero+1))))*(1<<(3*zero))]=bfs[at]+1;
				Q.push(at-(at%(8<<(3*(zero+1)))/(1<<(3*(zero+1))))*(1<<(3*(zero+1)))+(at%(8<<(3*(zero+1)))/(1<<(3*(zero+1))))*(1<<(3*zero)));
			}
		}
		if(!bfs.count(at-(at%(8<<(3*(zero^4)))/(1<<(3*(zero^4))))*(1<<(3*(zero^4)))+(at%(8<<(3*(zero^4)))/(1<<(3*(zero^4))))*(1<<(3*zero)))){
			bfs[at-(at%(8<<(3*(zero^4)))/(1<<(3*(zero^4))))*(1<<(3*(zero^4)))+(at%(8<<(3*(zero^4)))/(1<<(3*(zero^4))))*(1<<(3*zero))]=bfs[at]+1;
			Q.push(at-(at%(8<<(3*(zero^4)))/(1<<(3*(zero^4))))*(1<<(3*(zero^4)))+(at%(8<<(3*(zero^4)))/(1<<(3*(zero^4))))*(1<<(3*zero)));
		}
	}
	while(~scanf("%d",a)){
		for(int i=1;i<8;i++)scanf("%d",a+i);
		//bfs.clear();
		int t=0;
		for(int i=0;i<8;i++){
			t*=8;
			t+=a[i];
		}
		printf("%d\n",bfs[t]);
	}
}

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

int main(){
  int D;
  long long G;
  cin >> D >> G;
  
  vector<int> p(D);
  vector<int> c(D);
  
  int ans = 1000;
  for(int i = 0;i < D; i++){
    cin >> p.at(i) >> c.at(i);
  }
  
  for(int b = 0; b < (1<<D); b++){
    long long sum = 0;
    int cnt = 0;
    for(int i = D; i > 0;i--){

      if(b & (1<<(i - 1))){
        for(int j = p.at(i-1); j > 0; j--){
          sum += 100 * i;
          cnt++;
          if(j == 1){
            sum += c.at(i - 1);
          }
          if(sum >= G){
            ans = min(ans, cnt);  
          }
        }
      }
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, K = map(int, input().split())

MOD = 998244353

P = [tuple(map(int, input().split())) for _ in range(K)]

E = [0] * N

def update(i, v):
	while i < N:
		E[i] = (E[i] + v) % MOD
		i |= i+1

def query(i):
	r = 0
	while i > 0:
		r += E[i-1]
		i &= i-1

	return r % MOD

update(0, 1)
update(1, -1)

for i in range(N-1):
	v = query(i+1)
	for L, R in P:
		if i + L < N:
			update(i+L, v)

			if i + R + 1 < N:
				update(i+R+1, -v)


print(query(N))


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

using namespace std;

const int MAXN = 5.1e5;

void Run() {
  int n;
  cin >> n;
  vector<int> deg(n);
  vector<int> freq(16);
  vector<int> remains;
  for (int i = 0; i < n - 1; ++i) {
    int u, v, a;
    cin >> u >> v >> a;
    deg[u] ^= a;
    deg[v] ^= a;
  }
  int nonzero = 0;
  for (int i = 0; i < n; i++)
    nonzero += (deg[i] > 0);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    freq[deg[i]] ^= 1;
    if (deg[i] > 0 && !freq[deg[i]]) {
      ans++;
    }
  }
  for (int i = 1; i <= 15; ++i) {
    if (freq[i]) {
      remains.push_back(i);
    }
  }
  const int N = remains.size();
  vector<int> dp(1 << N);
  for (int i = 0; i < (1 << N); ++i) {
    int cur = 0;
    for (int j = 0; j < N; ++j) {
      int bit = (i >> j) & 1;
      if (bit == 0) {
        cur ^= remains[j];
      }
    }
    for (int j = 0; j < N; ++j) {
      if (i & (1 << j)) {
        dp[i] = max(dp[i], dp[i ^ (1 << j)]);
      }
    }
    if (cur == 0 && __builtin_popcount(i) < N) {
      ++dp[i];
    }
  }
  ans += dp[(1 << N) - 1];
  cout << nonzero - ans << '\n';
}

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


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

public class Main {

	public static void main (String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		Integer[] fig = new Integer[n];

		for(int i = 0; i < n; i++) {
			fig[i] = sc.nextInt();
		}

		int min, max;
		long sum = 0;

		Arrays.sort(fig);
		min = fig[0];

		Arrays.sort(fig, Collections.reverseOrder());
		max = fig[0];

		for(int i = 0; i < fig.length; i++) {
			sum += fig[i];
		}

		System.out.println(min + " " + max + " " + sum);

	}

}





Measured memory_bytes: 43312
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
//	tmp = input[1].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var a = parseInt(input[0], 10);

    if(a==7||a==5||a==3){console.log('YES')}
    else{console.log('NO')}

	
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
   int n,m;
   cin >> n >> m;
   vector<pair<int,string>> v(m);
   rep(i,m){
      int a;
      string b;
      cin >> a >> b;
      pair<int,string> p=make_pair(a,b);
      v[i]=p;
   }
   int ans=0;
   bool f=true;
   for (int i=0;i < 1000;i++){
      f=true;
      string s;
      s=to_string(i);
      if (s.size()!= n) continue;
      else{
         for (int j=0;j < m;j++){
            pair<int,string> p=v[j];
            if (s[(p.first)-1] != p.second[0]) {
               f=false;
               break;
            }
         }
      }
      if (f){
         f=true;
         ans=i;
         cout << ans << endl;
         return 0;
      }
   }
   cout << -1 << endl; 
   return 0;
}


Measured memory_bytes: 256
import java.io.*;
 
public class Main {
     
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String s = br.readLine();
            String[] arr = s.split(" ");
            int a = Integer.parseInt(arr[0]);
            int b = Integer.parseInt(arr[1]);
            System.out.println(a * b + " " + (a + b) * 2);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
}

Measured memory_bytes: 24300
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        a: usize,
        b: usize,
        q: usize,
        s: [i64; a],
        t: [i64; b],
        q: [i64; q],
    }

    for q in q {
        let (si, ti) = if let Err(si) = s.binary_search(&q) {
            if let Err(ti) = t.binary_search(&q) {
                (si, ti)
            } else {
                unreachable!()
            }
        } else {
            unreachable!()
        };

        let mut ans = i64::max_value();
        use std::cmp::{max, min};

        if si > 0 && ti > 0 {
            let cur = q - min(s[si - 1], t[ti - 1]);
            ans = min(ans, cur);
        }

        if si > 0 && ti < t.len() {
            let cur = q - s[si - 1] + t[ti] - s[si - 1];
            ans = min(ans, cur);
            let cur = t[ti] - q + t[ti] - s[si - 1];
            ans = min(ans, cur);
        }

        if si < s.len() && ti > 0 {
            let cur = q - t[ti - 1] + s[si] - t[ti - 1];
            ans = min(ans, cur);
            let cur = s[si] - q + s[si] - t[ti - 1];
            ans = min(ans, cur);
        }

        if si < s.len() && ti < t.len() {
            let cur = max(t[ti], s[si]) - q;
            ans = min(ans, cur);
        }
        println!("{}", ans);
    }
}


Measured memory_bytes: 7420
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //b
  int n;
  cin >> n;
  vector<pair<long long, long long>> segs;
  for (int i = 0; i < n; i++) {
    long long x, l;
    cin >> x >> l;
    segs.emplace_back(x + l, x - l);
  }
  sort(segs.begin(), segs.end());
  for (int i = 0; i < n; i++) swap(segs[i].first, segs[i].second);
  int ans = 0;
  long long cur = -1e18;
  for (int i = 0; i < n; i++) {
    if (segs[i].first >= cur) {
      cur = segs[i].second;
      ans++;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 2420
import java.util.*;
import java.lang.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int n = sc.nextInt();
		int[] a = new int[n * 2];
		long current = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			a[i + n] = a[i] + k;
			if (i > 0) current += a[i] - a[i - 1];
		}

		long answer = current;
		for (int i = 0; i < n; i++) {
			current -= a[i + 1] - a[i];
			current += a[i + n] - a[i + n - 1];
			answer = Math.min(answer, current);
		}

		System.out.println(answer);
	}
}


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

int main() {
  int n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  int ans = 0;
  for(int i=0;i<n;i++){
    if(i == 0){
      if(s.at(i) == 'R' && s.at(i+1) == 'R'){
        ans++;
      }
    }
    else if(0<i && i<n-1){
      if(s.at(i) == 'R' && s.at(i+1) == 'R'){
        ans++;
      }
      else if(s.at(i) == 'L' && s.at(i-1) == 'L'){
        ans++;
      }
    }
    else {
      if(s.at(i) == 'L' && s.at(i-1) == 'L'){
        ans++;
      }
    }
  }
  
  if(ans + 2*k >= n-1){
    cout << n-1 << endl;
  }
  else {
    cout << ans + 2*k << endl;
  }
  
  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
int main(void){
    int H, W;
    int i, j;
    while(1){
        scanf("%d %d", &H, &W);
        if(H==0&&W==0){
            break;
        }
        for(i=0;i<H;i++){
            for(j=0;j<W;j++){
                if(i%2==j%2){
                    printf("#");
                }
                else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2104
import sys
from collections import Counter
import time

class Osa_k:
    def __init__(self, n):
        self.n = n
        self.min_factor = [int(x) for x in range(n+1)]
        
        self.is_prime = [True] * (self.n + 1)
        self.is_prime[0] = False
        self.is_prime[1] = False
        for j in range(4, self.n+1, 2):
            self.is_prime[j] = False
            self.min_factor[j] = 2
        for i in range(3, int(self.n**0.5) + 1, 2):
            if not self.is_prime[i]:
                continue
            for j in range(i * 2, self.n + 1, i):
                self.is_prime[j] = False
                if self.min_factor[j] >= i:
                	self.min_factor[j] = i
        


    def calculate(self, x):
        ans = []
        while x > 1:
            key = self.min_factor[x]
            while x%key == 0:
                ans.append(key)
                x //= key
        counter = Counter(ans)
        return counter

def main():
    input = sys.stdin.readline
    mod = pow(10,9)+7
    n = int(input())
    a = [int(x) for x in input().split()]
    prime_list = dict()
    osa_k = Osa_k(max(a))
    for i in range(n):
        primes = osa_k.calculate(a[i])
        for key, value in primes.items():
            if key in prime_list:
                if prime_list[key] < value:
                    prime_list[key] = value
            else:
                prime_list[key] = value
              
    L = 1
    for key, value in prime_list.items():
        L *= pow(key, value, mod)
        L %= mod
        
    ans = 0
    for i in range(n):
        ans += (L*pow(a[i], mod-2, mod))%mod
        ans %= mod
    print(ans)
            


if __name__ == "__main__":
    main()

Measured memory_bytes: 114796
#include <iostream>
#include <set>
#include<string>
using namespace std;

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#include <math.h>


using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define Rep(i, n) for(int i=n; i >= 0; i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える

int x, n;
vector<int> p;

bool flag(int y) {
	rep(i, n) {
		if (p[i] == y) {
			return false;
			return 0;
		}
	}
	return true;
}

int main() {
	cin >> x >> n;
	if (n == 0) {
		cout << x << endl;
		return 0;
	}
	p.resize(n);
	rep(i, n) cin >> p[i];
	sort(all(p));

	int eps = 100;
	int ans;
	rep(y, 102) {
		if (flag(y)) {
			int temp = abs(x - y);
			if (eps > temp) {
				eps = temp;
				ans = y;
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
 
vector<pair<int, int>> v;
vector<int> dsu, sz, fs;
 
int root(int i){
    return dsu[i] == i ? i : dsu[i] = root(dsu[i]);
}
void join(int i, int j){
    i = root(i), j = root(j);
    if(i == j)return;
    if(sz[i] > sz[j])swap(i, j);
    dsu[i] = j;
    sz[j] += sz[i];
}
signed main(){
    int n, maxa = 0, maxb = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        if(b > maxb)maxb = b;
        if(a > maxa)maxa = a;
        v.pb({a, b});
    }
    dsu.resize(maxb+1);
    iota(all(dsu), 0);
    sz.resize(maxb+1, 1);
    sz[0] = 0;
    fs.resize(maxa+1);
    sort(all(v));
    for(auto i: v){
        if(!fs[i.ff])
            fs[i.ff] = i.ss;
        else
            join(fs[i.ff], i.ss);
    }
    long long ans = 0;
    for(auto i: fs)
        ans += sz[root(i)];
    cout << ans-n << endl;
 
}

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

#define ll long long
#define ull unsigned long long
#define N 100005
#define mod 998244353 
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define mii unordered_map<int,int>
#define mll unordered_map<ll,ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi  first

#define se second
#define pb push_back
#define mp make_pair
#define pp pop_back
#define vii vector<int>
#define vll vector<ll>
#define vpp vector<pii>
#define all(c) c.begin(),c.end()
#define tr(it,c) for(it = c.begin() ; it!=c.end() ; it++)
int inf = INT_MAX ;
ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),MOD-2,MOD); }
ll gcd(ll a,ll b){ return ((b==0) ? a:gcd(b,a%b));}

int is_pallindrome(string str,int i,int j){
	while(i<j){
		if(str[i]!=str[j])
			return 0;
		i++,j--;
	}
	return 1;
}

int main(){
	boost;
    string str;
    cin>>str;
    int n = str.size();
    int i = is_pallindrome(str,0,str.size()-1);
    int j = is_pallindrome(str,0,(n-1)/2-1);
    int k = is_pallindrome(str,(n+3)/2 - 1,n-1);

    if(i&j&k){
    	cout<<"Yes";
    }else{
    	cout<<"No";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

ll mod;

ll powll(ll x, ll y){
    x %= mod;
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

ll divll(ll x, ll y){
    return (x * powll(y,mod-2)) % mod;
}

int main() {
    ll p = in();
    mod = p;
    VL a(p);
    REP(i,p) a[i] = in();
    VL ans(p), pol(p);
    pol[0] = 1;
    FOR(j,1,p-1){
        VL tmp(p);
        REP(d,p-1){
            (tmp[d + 1] += pol[d]) %= mod;
            (tmp[d] += (p - (j * pol[d]) % p)) %= mod;
        }
        pol = tmp;
    }
    // REP(j,p) cout << pol[j] << " ";
    // cout << endl;
    REP(i,p){
        if (a[i]){
            ll d = 1;
            REP(j,p) if (i != j) d = (d * (i - j + p)) % p;
            d = divll(1, d);
            REP(j,p) ans[j] = (ans[j] + d * pol[j]) % p;
        }
        VL tmp(p);
        FORR(j,p-2,0){
            tmp[j] = pol[j + 1];
            pol[j + 1] = 0;
            (pol[j] += (i + 1) * tmp[j]) %= p;
        }
        pol = tmp;
        // cout << endl;
        // REP(j,p) cout << pol[j] << " ";
        // cout << endl;
        tmp.assign(p, 0);
        REP(j,p-1){
            (tmp[j + 1] += pol[j]) %= p;
            (tmp[j] += (p - ((i * pol[j]) % p))) %= p;
        }
        pol = tmp;
        // REP(j,p) cout << pol[j] << " ";
        // cout << endl;
    }
    REP(j,p) cout << ans[j] << " ";
    cout << endl;

    return 0;
}


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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007
#define rev(v) reverse(v.begin(), v.end());

bool comp(int a, int b){
    return (a<b);
}

int main(){
    int a, b, c, d; cin >> a >> b >> c >> d;
    string flag;
    bool end = true;
    while(end){
        c-=b;
        if(c<=0){
            flag = "Yes";
            end = false;
            break;
        }
        a-=d;
        if(a<=0){
            flag = "No";
            end = false;
            break;
        }
    }
    cout << flag << endl;
    return 0;
}

Measured memory_bytes: 3592
import sys

# import bisect
# import numpy as np
from collections import deque
# map(int, sys.stdin.read().split())



def input():
    return sys.stdin.readline().rstrip()


def main():
    N =int(input())
    V =list(map(int,input().split()))
    V.sort()
    sum =V[0]
    for i in range(1,N):
        sum = sum/2 +V[i]/2
    print(sum)



if __name__ == "__main__":
    main()


Measured memory_bytes: 64744
local n, m = io.read("*n", "*n")
local edge = {}
local asked = {}
for i = 1, n do
  edge[i] = {}
  asked[i] = false
end
for i = 1, m do
  local a, b = io.read("*n", "*n")
  table.insert(edge[a], b)
  table.insert(edge[b], a)
end

local src = 1
asked[1] = true
local forward = {}
while true do
  local found = false
  for j = 1, #edge[src] do
    local dst = edge[src][j]
    if not asked[dst] then
      asked[dst] = true
      table.insert(forward, dst)
      src = dst
      found = true
      break
    end
  end
  if not found then break end
end
local backward = {}
src = 1
while true do
  local found = false
  for j = 1, #edge[src] do
    local dst = edge[src][j]
    if not asked[dst] then
      asked[dst] = true
      table.insert(backward, dst)
      src = dst
      found = true
      break
    end
  end
  if not found then break end
end
local ret = {}
for i = #backward, 1, -1 do
  table.insert(ret, backward[i])
end
table.insert(ret, 1)
for i = 1, #forward do
  table.insert(ret, forward[i])
end
print(#ret)
print(table.concat(ret, " "))


Measured memory_bytes: 27192
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe

ll gcd(ll c, ll d) { return d ? gcd(d, c%d) : c;}
ll lcm(ll c, ll d) { return c / gcd(c,   d) * d;}
    
int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
ll a,b,c,d,u,v,w;
cin >> a >> b >> c >> d;
u = b/c-(a-1)/c;
v = b/d-(a-1)/d;
w = b/lcm(c,d)-(a-1)/lcm(c,d);
cout << b-a+1-(u+v-w) << 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 n;
		long k;
		int a[];
		int test = 0;

		if(test == 0) {
			n = sc.nextInt();
			k = sc.nextLong();

			a = new int[n+1];
			for(int i = 1; i < n+1; i++) {
				a[i] = sc.nextInt();
			}
		} else if(test == 1) {//テストデータ1
			n = 200000;
			n = 199999;
			k = 1000000000000000000l;
			k = 1000000000000000000l;
			k = 1;

			a = new int[n+1];
			for(int i = 1; i < n+1; i++) {
				a[i] = (i%n+1);
//				a[i] = (i%2+1);
			}
		} else if(test == 2) {//テストデータ2
			n = 2;
			k = 2;

			a = new int[n+1];
			for(int i = 1; i < n+1; i++) {
				a[i] = (i%n+1);
			}
		} else if(test == 3){//テストデータ3
			n = 5;
			k = 1;

			a = new int[n+1];
			for(int i = 1; i < n+1; i++) {
				a[i] = (i%n+1);
				if(i==5)a[i]=3;
			}
		} else {
			n = sc.nextInt();
			k = sc.nextLong();

			a = new int[n+1];
			for(int i = 1; i < n+1; i++) {
				a[i] = sc.nextInt();
			}
		}

		int s[] = new int[n+1];//町[1]からx回テレポートした先の町を示すショートカットデータ
		int sloop[] = new int[n+1];//町[1]からx回テレポートした先の町を示すショートカットデータ
		int passed[] = new int[n+1];//通過した町 何番目で通過したか
		for(int i = 1; i < n+1; i++) {
			passed[i] = 0;
		}
		int current_town = 1;
		int head = 0;
		int headCount = 0;
		int loop = n;
		boolean isSubLoop = false;
		s[0] = 1;
		passed[0] = 1;
		for(int i = 1; i < n+1; i++) {
			s[i] = a[current_town];
			if (passed[a[current_town]] > 0 || a[current_town] == current_town) {
				head = a[current_town];
				loop = i;
				break;
			}
			passed[current_town] = i;
			current_town = a[current_town];
		}
		current_town = 1;
		for(int i = 0; i < n+1; i++) {
			if (current_town == head) {
				headCount = i;
				break;
			}
			current_town = a[current_town];
		}
		loop -= headCount;

		current_town = head;
		for(int i = 0; i < n+1; i++) {
			sloop[i] = current_town;
			current_town = a[current_town];
			if (current_town == head) {
				break;
			}
		}

		int res;
		if(k < headCount) {
			res = s[(int)k];
		}else {
			int tmpK = (int)((k - headCount) % (long)loop);
			res = sloop[tmpK];
		}

		if (test != 0) {//print
			System.out.printf("n:%d k:%d\n", n,k);
			System.out.printf("head:%d headCount:%d loop:%d res:%d\n", head,headCount,loop,res);
			for(int i = 1; i < n+1; i++) {
				System.out.printf(" %d", a[i]);
				if(i>100) break;
			}
			System.out.println();
			for(int i = 0; i < n+1; i++) {
				System.out.printf(" %d", s[i]);
				if(i>100) break;
			}
			System.out.println();
			for(int i = 0; i < n+1; i++) {
				System.out.printf(" %d", sloop[i]);
				if(i>100) break;
			}
			System.out.println();
		}


		System.out.printf("%d", res);
	}
}


Measured memory_bytes: 60116
from itertools import *

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

aaa=[int(i) for i in range(1,m+1)]
a=list(combinations_with_replacement(aaa,n))

l=[list(map(int,input().split())) for i in range(q)]


ans=0

for i in a:
    aa=0
    for j in l:
        if i[j[1]-1]-i[j[0]-1]==j[2]:
            aa+=j[3]
    if aa>ans:
        ans=aa
print(ans)

Measured memory_bytes: 21512
// https://atcoder.jp/contests/abc140/tasks/abc140_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    cout << N * N * N << endl;

    return 0;
}


Measured memory_bytes: 3600
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def solve():
    s = input()
    if s == "ABC":
        print("ARC")
    else:
        print("ABC")

    return 0

if __name__ == "__main__":# {{{
    solve()

# vim: set foldmethod=marker: }}}


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

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

#define speedup_IO      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n)     for(ll i = a; i < n; i++)
#define ford(i,n,a)     for(ll i = n-1; i >= a; i--)
#define pb              push_back
#define lb              lower_bound
#define ub              upper_bound
#define pll             pair<ll,ll>
#define all(a)          (a).begin(),(a).end()
#define reset(a,x)      memset(a,x,sizeof(a))

ll mypow(ll base, ll exp) {ll res = 1; while (exp) {if (exp & 1) res = (res * base) % mod; exp >>= 1, base = (base * base) % mod;} return res;}
ll gcd(ll a, ll b)  { return b ? gcd(b, a % b) : a;            }
ll mult(ll a, ll b) { return ((a % mod) * (b % mod)) % mod;    }
ll add(ll a, ll b)  { return (a % mod + b % mod) % mod;        }
ll sub(ll a, ll b)  { return (a % mod + mod - b % mod) % mod;  }

const ll inf = 1e18;
const int nax = 1e5 + 5;

int main()
{
	speedup_IO;
	string s,t;
	cin>>s>>t;

	map<string,ll>Cnt;
	ll a,b;
	cin>>a>>b;

	Cnt[s] = a;
	Cnt[t] = b;

	string s1;
	cin>>s1;

	Cnt[s1]--;

	cout<<Cnt[s]<<" "<<Cnt[t];

	return 0;
}

Measured memory_bytes: 256
N = int(input())
AB = []
for i in range(N):
  AB_1,AB_2 = map(int,input().split())
  AB.append([AB_1,AB_2])
AB.sort(key=lambda AB: AB[1])
time = 0
count = 0
ans = "Yes"

for i in range(N):
  time += AB[i][0]
  if time > AB[i][1]:
    ans = "No"
print(ans)


Measured memory_bytes: 38084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define all(v) v.begin(),v.end()
#define PI acos(-1)
#define EPS 1e-15


int main() {
	int n, k;
	cin >> n >> k;
	vector<int> x(n);
	for(int i = 0; i < n; i++){
		cin >> x[i];
	}
	int res = 0;
	for(int i = 0; i < n; i++){
		res += min(x[i], abs(k - x[i])); 
	}
	cout << res * 2 << endl;
	return 0;
}





Measured memory_bytes: 256
class _Node {
  constructor(key, parent = null, left = null, right = null) {
    this.key = key;
    this.parent = parent;
    this.left = left;
    this.right = right;
  }

//   getChildrenNumber() {return (this.left && 1 || 0 ) + (this.right && 1 || 0 );}

  getChildrenNumber() {return Number(!!this.left) + Number(!!this.right);}


  isLeftChild() {
    if (this.parent === null) return null;
    return this.parent.left === this;
  }

  getLeftOrRight() {return this.isLeftChild() ? 'left' : 'right';}

  getSuccessor() {
    let n;
    if (this.right !== null) {
      n = this.right;
      while (n.left !== null) n = n.left;
    } else {
      n = this.parent;
      while (!n.isLeftChild && n.parent != null) n = n.parent;
    }
    return n;
  }
}

class BinaryTree {
  constructor() {
    this.root = null;
  }

  static get Node() { return _Node; }

  insert(key) {
    if (this.root === null) {
      this.root = new BinaryTree.Node(key);
      return;
    }
    let x = this.root, y;
    let newNode = new BinaryTree.Node(key);
    while (x !== null) {
      y = x;
      x = x[key < x.key ? 'left' : 'right'];
    }
    newNode.parent = y;
    y[key < y.key ? 'left' : 'right'] = newNode;
  }

  find(key, n = this.root) {
    if (n === null || n.key === key) return n;
    return this.find(key, n[key < n.key ? 'left' : 'right']);
  }

  delete(key) {
    const n = this.find(key);
    const leftOrRight = n.getLeftOrRight();
    switch (n.getChildrenNumber()) {
    case 0:
      n.parent[leftOrRight] = null;
      break;
    case 1:
      n.parent[leftOrRight] = n.left || n.right;
      n.parent[leftOrRight].parent = n.parent;
      break;
    default:
      const skey = n.getSuccessor().key;
      this.delete(skey);
      n.key = skey;
    }
  }

  printByIneorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      innerFunc(n.left);
      str += ` ${n.key}`;
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  printByPreorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      str += ` ${n.key}`;
      innerFunc(n.left);
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  print() {
    this.printByIneorder();
    this.printByPreorder();
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  const tree = new BinaryTree();
  lines.forEach(function(cmd) {
    switch (cmd.charAt(0)) {
    case 'i': tree.insert(Number(cmd.split(' ')[1])); break;
    case 'f': console.log(tree.find(Number(cmd.split(' ')[1])) ? 'yes' : 'no'); break;
    case 'd': tree.delete(Number(cmd.split(' ')[1])); break;
    default: tree.print();
    }
  });
})();



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

int main(){
    ll n,d,x;cin >> n >> d >> x;
    vector<ll> v(n);
    rep(i,n)cin >> v[i];
    ll ans=x;
    rep(i,n){
        ans++;
        ans+=(d-1)/v[i];
    }
    cout << ans << endl;
}

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

#define S 64

int a[S], b[S], c[S], d[S];
int N, M;

void input(){
	std::cin >> N >> M;
	for( int i = 1; i <= N; i++ ){
		std::cin >> a[i] >> b[i];
	}
	for( int i = 1; i <= M; i++ ){
		std::cin >> c[i] >> d[i];
	}
}

void run(){
	int mj = -1;
	int mindist = INT_MAX;
	int temp;
	for( int i = 1; i <= N; i++ ){
		mj = -1;
		mindist = INT_MAX;
		for( int j = 1; j <= M; j++ ){
			temp = abs(a[i]-c[j]) + abs(b[i]-d[j]);
			if( temp < mindist ){
				mindist = temp;
				mj = j;
			}
		}
		std::cout << mj << std::endl;
	}
	return;
}

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


Measured memory_bytes: 256
s = list(input())
t = list(input())
dp = [[0 for _ in range(len(t)+1)] for _ in range(len(s)+1)]
for j in range(1,len(t)+1):
    for i in range(1,len(s)+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1

        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])
ans = []
p = len(s)
q = len(t)
len = dp[p][q]
while len > 0:
    if s[p-1] == t[q-1]:
        ans.append(s[p-1])
        len -= 1
        p -= 1
        q -= 1
    elif dp[p][q] == dp[p-1][q]:
        p -= 1
    else:
        q -= 1
an = ''.join(ans[::-1])
print(an)


Measured memory_bytes: 119900
n,k,q = map(lambda x: int(x), input().split())
a = []
score = [k-q]*n
for i in range(q):
    a.append(int(input()))

for i in a:
    score[i-1] += 1

for i in score :
    if i > 0:
        print('Yes')
    else:
        print('No')


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

using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<tuple<int, int, int>> y_p_n;
    for (int i = 0; i < M; i++)
    {
        int P, Y;
        cin >> P >> Y;
        y_p_n.push_back(make_tuple(Y, P, i+1));
    }
    sort(y_p_n.begin(), y_p_n.end());
    int c[N+1] = {0};
    vector<pair<int, string>> ans;
    for (int i = 0; i < M; i++)
    {
        int second = get<1>(y_p_n[i]);
        int city_num = get<2>(y_p_n[i]);
        c[second]++;
        string s_num = to_string(c[second]);
        string s_city = to_string(second);
        string tmp = string(6 - s_city.size(), '0').append(s_city) + string(6 - s_num.size(), '0').append(s_num);
        ans.push_back(make_pair(city_num, tmp));
    }
    sort(ans.begin(), ans.end());
    for (int i = 0; i < M; i++)
    {
        cout << ans[i].second << endl;
    }
    
}

Measured memory_bytes: 10480
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

#define mem(Arr,x) memset(Arr,x,sizeof(Arr))

const int maxN=202000*8;
const int Mod=924844033;
const int inf=2147483647;

int n,N,L,G,Fac[maxN],InvF[maxN];
int edgecnt=0,Head[maxN],Next[maxN],V[maxN],Sz[maxN],Cnt[maxN];
int A[maxN],B[maxN],Rader[maxN];

void Add_Edge(int u,int v);
void dfs(int u,int fa);
int QPow(int x,int cnt,int M);
int GetG(int x);
void NTT(int *P,int opt);

int main(){
	Fac[0]=InvF[0]=1;for (int i=1;i<maxN;i++) Fac[i]=1ll*Fac[i-1]*i%Mod;
	InvF[maxN-1]=QPow(Fac[maxN-1],Mod-2,Mod);for (int i=maxN-2;i>=1;i--) InvF[i]=1ll*InvF[i+1]*(i+1)%Mod;
	G=GetG(Mod);mem(Head,-1);
	scanf("%d",&n);for (N=1;N<=(n+n);N<<=1) ++L;for (int i=0;i<N;i++) Rader[i]=(Rader[i>>1]>>1)|((i&1)<<(L-1));
	for (int i=1;i<n;i++){
		int u,v;scanf("%d%d",&u,&v);
		Add_Edge(u,v);Add_Edge(v,u);
	}
	dfs(1,1);
	for (int i=1;i<=n;i++) A[i]=1ll*Cnt[i]*Fac[i]%Mod;
	for (int i=0;i<=n;i++) B[i]=InvF[i];
    /*
	for (int i=1;i<=n;i++) cout<<Cnt[i]<<" ";cout<<endl;
	for (int i=0;i<N;i++) cout<<A[i]<<" ";cout<<endl;
	for (int i=0;i<N;i++) cout<<B[i]<<" ";cout<<endl;
	//*/
	reverse(&B[0],&B[n+1]);
	NTT(A,1);NTT(B,1);for (int i=0;i<N;i++) A[i]=1ll*A[i]*B[i]%Mod;NTT(A,-1);
	for (int i=1,mul=1;i<=n;i++) printf("%lld\n",(1ll*Fac[n]*InvF[n-i]%Mod*InvF[i]%Mod*n%Mod-1ll*InvF[i]*A[i+n]%Mod+Mod)%Mod);
	return 0;
}

void Add_Edge(int u,int v){
	Next[++edgecnt]=Head[u];Head[u]=edgecnt;V[edgecnt]=v;
	return;
}

void dfs(int u,int fa){
	Sz[u]=1;
	for (int i=Head[u];i!=-1;i=Next[i])
		if (V[i]!=fa){
			dfs(V[i],u);Sz[u]+=Sz[V[i]];++Cnt[Sz[V[i]]];
		}
	if (Sz[u]!=n) ++Cnt[n-Sz[u]];return;
}

int QPow(int x,int cnt,int M){
	int ret=1;
	while (cnt){
		if (cnt&1) ret=1ll*ret*x%M;
		x=1ll*x*x%M;cnt>>=1;
	}
	return ret;
}

int GetG(int x){
	int pcnt=0,P[50],k=x-1;
	for (int i=2;1ll*i*i<=k;i++)
		if (k%i==0){
			P[++pcnt]=i;while (k%i==0) k/=i;
		}
	for (int i=2;i;i++){
		bool flag=1;
		for (int j=1;(j<=pcnt)&&(flag);j++) if (QPow(i,(x-1)/P[j],x)==1) flag=0;
		if (flag) return i;
	}
}

void NTT(int *P,int opt){
	for (int i=0;i<N;i++) if (i<Rader[i]) swap(P[i],P[Rader[i]]);
	for (int i=1;i<N;i<<=1){
		int dw=QPow(G,(Mod-1)/(i<<1),Mod);
		if (opt==-1) dw=QPow(dw,Mod-2,Mod);
		for (int j=0;j<N;j+=(i<<1))
			for (int k=0,w=1;k<i;k++,w=1ll*w*dw%Mod){
				int X=P[j+k],Y=1ll*P[j+k+i]*w%Mod;
				P[j+k]=(X+Y)%Mod;P[j+k+i]=(X-Y+Mod)%Mod;
			}
	}
	if (opt==-1){
		int inv=QPow(N,Mod-2,Mod);
		for (int i=0;i<N;i++) P[i]=1ll*P[i]*inv%Mod;
	}
	return;
}


Measured memory_bytes: 54784
object Main {
  def main(args: Array[String]): Unit = {
    val in = io.Source.stdin.getLines().next.split(" ").map(_.toInt)
    if(in(0) < in(1)) println("a < b")
    if(in(0) == in(1)) println("a == b")
    if(in(0) > in(1)) println("a > b")
  }
}


Measured memory_bytes: 43832
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AtCoder solver = new AtCoder();
        solver.solve(1, in, out);
        out.close();
    }

    static class AtCoder {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
            int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
            char[][] board = new char[50][50];

            int X = in.nextInt();
            int Y = in.nextInt();

            String s = in.nextLine();

            for (int i = 0; i < X; i++) {
                s = in.nextLine();
                for (int j = 0; j < Y; j++) {
                    board[i][j] = s.charAt(j);
                }
            }

            for (int i = 0; i < X; i++) {
                for (int j = 0; j < Y; j++) {
                    if (board[i][j] == '.') {
                        int cnt = 0;
                        for (int k = 0; k < 8; k++) {
                            int x = i + dx[k];
                            int y = j + dy[k];
                            if (x >= 0 && x < X && y >= 0 && y < Y && board[x][y] == '#') cnt++;
                        }
                        board[i][j] = (char) ('0' + cnt);
                    }
                }
            }

            for (int i = 0; i < X; i++) {
                for (int j = 0; j < Y; j++) {
                    out.print(board[i][j]);
                }
                out.println();
            }
        }
    }
}


Measured memory_bytes: 23124
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int n,big,flag=0,sum=0;
	cin >> n;
	vector<int>p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	big = p[0];
	for (int i = 0; i < n; i++) {
		big = max(big, p[i]);
	}
	for (int i = 0; i < n; i++) {
		if (big == p[i] && flag == 0) {
			flag++;
			sum += big / 2;
		}
		else {
			sum += p[i];
		}
	}
	cout << sum << endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
int main ()
{
	int N;
	int sum = 0;
 
	scanf("%d", &N);
	int tmp = N;
	while (tmp > 0) {
		sum += tmp % 10;
		tmp /= 10;
	}
	if (N % sum == 0) {
		puts("Yes");
	} else {
		puts("No");
	}
  
  
  
  return 0;
}


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

const ll MOD = 1e9+7;
ll n, m, ans = 1, cnt=0, tot=0, sum[100050];

void getprime(){
	for(ll i = 2; i <= m; i++){
		if(m % i == 0){
			m /= i;
			sum[++cnt]++;
			while(m % i == 0)  
				m /= i, sum[cnt]++;
			tot += sum[cnt];
		}
	}
	if(m != 1) sum[++cnt] = 1, tot++;
}

ll inv(ll x){
    return x==1 ? 1 : (MOD-MOD/x)*inv(MOD%x)%MOD;
}
ll C(ll n,ll m){
    if(m<0 || n<m) return 0;
    if(m > n-m)  m = n-m;
    ll zi = 1, mu = 1;
    for(ll i = 0; i < m; i++){
        zi = zi *(n-i) %MOD;
        mu = mu *(i+1) %MOD;
    }
    return zi*inv(mu)%MOD;
}

int main(){
	scanf("%lld%lld",&n, &m);
	getprime();
	for(ll i = 1; i <= cnt; i++){
		ans *= C(sum[i]+n-1, n-1);
		ans %= MOD;
	}
	printf("%lld", ans);
	return 0;
} 

Measured memory_bytes: 256