akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, k, q, a; cin >> n >> k >> q;
	int test[123456] = { 0 };
	for (int i = 0; i < q; i++) {
		cin >> a;
		test[a]++;
	}
	for (int h = 1; h <= n; h++) {
		test[h] = test[h] - q + k;
	}
	for (int h = 1; h <= n; h++) {
		if (test[h] > 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	cin >> n;
}

Measured memory_bytes: 1152
#include "bits/stdc++.h"

using namespace std;
#define rep(i, n) for(int i = 0; i < signed(n); i++)
#define rrep(i, n) for(int i = signed(n) - 1; i >= 0; i--)
#define all(co) co.begin(), co.end()
#define int long long
//using LL = long long;
//using P = pair < int, int > ;
//using PI = pair < P, int > ;
typedef pair<int, int> P;
typedef long long LL;
typedef pair<P, int> PI;
typedef pair<int, P> IP;
const int INF = 1 << 29;
const LL LINF = 1ll << 62ll;

struct edge{ int from, to, cost; };

int dr[] = { -1, 0, 1, 0 };
int dc[] = { 0, 1, 0, -1 };

template<typename T = int>
vector<vector<T>> vvector(int h, int w, T def = T()){ return move(vector<vector<T>>(h, vector<T>(w, def))); }
class range {
private: struct I{ int x; int operator*(){ return x; }bool operator!=(I& lhs){ return x < lhs.x; }void operator++(){ ++x; } }; I i, n;
public:range(int n) :i({ 0 }), n({ n }){}range(int i, int n) :i({ i }), n({ n }){}I& begin(){ return i; }I& end(){ return n; }
};

signed main()
{
	int n;
	while (cin >> n && n)
	{
		int m, h, k; cin >> m >> h >> k;
		vector<int> points(n);
		rep(i, n) cin >> points[i];
		auto stage = vvector<bool>(h + 1, n + 1);
		vector<P> bars(m);
		rep(i, m)
		{
			int a, b; cin >> a >> b;
			stage[b][a] = true;
			bars[i] = P(b, a);
		}
		vector<vector<vector<int>>> dp(h + 1, vector<vector<int>>(n + 1, vector<int>(2, -1)));
		rep(i, n + 1) dp[h][i][1] = dp[0][i][0] = i;
		rep(i, h) rep(_j, n)
		{
			int j = _j + 1;
			if (stage[i + 1][j])
				dp[i + 1][j + 1][0] = dp[i][j][0];
			else if (stage[i + 1][j - 1])
				dp[i + 1][j - 1][0] = dp[i][j][0];
			else dp[i + 1][j][0] = dp[i][j][0];

			if (stage[h - i - 1][j])
				dp[h - i - 1][j + 1][1] = dp[h - i][j][1];
			else if (stage[h - i - 1][j - 1])
				dp[h - i - 1][j - 1][1] = dp[h - i][j][1];
			else dp[h - i - 1][j][1] = dp[h - i][j][1];
		}

		int base = 0;
		rep(_i, k)
		{
			int i = _i + 1;
			base += points[dp[0][i][1] - 1];
		}
		int ans = base;
		rep(l, m)
		{
			P p = bars[l];
			int i = p.first, j = p.second;
			bool b1 = dp[p.first][p.second][0] <= k, b2 = dp[p.first][p.second + 1][0] <= k;

			if (b1 == b2) continue;

			int now = dp[i][j + b1][1], next = dp[i][j + b2][1];
			ans = min(ans, base - points[now - 1] + points[next - 1]);
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 57568
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ld long double
#define ll long long
//#define int ll
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
vv vec;
int val[100005];
bool comp(int a,int b){
	if(val[a]!=val[b])
		return val[a]>val[b];
	return a<b;
}
int32_t main(){
	boost;
	//freopen(".in","r",stdin);
	int n,m,a,b;
	cin>>n>>m;
	for (int i = 0; i < n; ++i)
		cin>>val[i];
	vec.resize(n);
	while(m--){
		cin>>a>>b;
		a--,b--;
		vec[a].pb(b);
		vec[b].pb(a);
	}
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		sort(all(vec[i]),comp);
		if(sz(vec[i]))ans+=(val[vec[i][0]]<val[i]);
		else ans++;
	}
	cout<<ans<<"\n";
	return 0;
}
//long long
//array bounds
//special cases
//binary search

Measured memory_bytes: 8716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
using iii = pair<ii, ll>;
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define __lcm(a, b) a * b / __gcd(a, b)
const ll MOD = 1e9 + 7;
const ll INF = 2e9;
// const ll N = ;

ll n;

void solve() {
    cin >> n;
    cout << n * (n - 1) / 2 << "\n";
}

int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    solve();
    
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};

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

  sort(task.begin(),task.end());
  int now=0;
  for(int i=0;i<N;i++){
    if(now+task[i].second>task[i].first){
      cout<<"No"<<endl;
      return 0;
    }
    now+=task[i].second;
  }
  cout<<"Yes"<<endl;
  return 0;
}



Measured memory_bytes: 3328
n,k = map(int,input().split())
m = 10**9+7
b = 1
r = n-k+1
print(b*r%m)
for i in range(2,k+1):
  b *= k-i+1
  b //= i-1
  r *= n-k-i+2
  r //= i
  print(b*r%m)

Measured memory_bytes: 41968
(let* ((N (read-line))
       (target (aref N (- (length N) 1)))
       (hon-l '(#\2 #\4 #\5 #\7 #\9))
       (pon-l '(#\0 #\1 #\6 #\8))
       (specific nil))
  (when (find target hon-l)
    (setq specific 'hon))
  (when (find target pon-l)
    (setq specific 'pon))
  (princ (cond ((eq target #\3)
                "bon")
               ((eq specific 'hon)
                "hon")
               ((eq specific 'pon)
                "pon"))))


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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  vector<int> s = p;

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

  int count = 0;
  rep(i, n) {
    if (p[i] != s[i]) {
      count++;
    }
  }

  if (count == 0 || count == 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <climits>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

  map<int,int> dict; // key,coumt  key == coumt => good seq
  int N; cin>>N;
  for(int i = 0; i < N; i++) {
    int a; cin>>a;
    if(dict.find(a) != dict.end()) {
      dict[a]++;
    } else {
      dict.insert(make_pair(a,1));
    }
  }

  int cnt = 0;
  for(auto p: dict) {
    if(p.first < p.second) {
      cnt += p.second - p.first;
    } else if(p.first > p.second) {
      cnt += p.second;
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 4736
use std::io;
fn main() {
    let mut l1 = String::new();
    let stdin = io::stdin();
    stdin.read_line(&mut l1).unwrap();
    let trimed = l1.trim_end();
    let mut itr = trimed.split_ascii_whitespace();
    let s = itr.next().unwrap().parse::<i64>().unwrap();
    let w = itr.next().unwrap().parse::<i64>().unwrap();
    if s <= w {
        println!("unsafe");
    } else {
        println!("safe");
    }
}


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

typedef pair<int, int> Pair;

const int MAXH = 33;
const int MAXW = 33;
int h, w, s, t, all;
int u[MAXH][MAXW];
Pair mem[MAXW][MAXH][MAXW][MAXH];
int S[MAXH][MAXW];

int sum(int x1, int y1, int x2, int y2) {
  return S[y2][x2] - S[y2][x1] - S[y1][x2] + S[y1][x1];
}

Pair rec(int x1, int y1, int x2, int y2) {
  Pair &res = mem[x1][y1][x2][y2];
  if (res.first != -1) return res;
  res = Pair(1, sum(x1, y1, x2, y2));
  for (int i = x1+1; i < x2; ++i) {
    if (all - sum(x1, y1, i, y2) <= s &&
        all - sum(i, y1, x2, y2) <= s) {
      Pair p = rec(x1, y1, i, y2);
      Pair q = rec(i, y1, x2, y2);
      Pair v(p.first + q.first, min(p.second, q.second));
      if (res < v) res = v;
    }
  }
  for (int i = y1+1; i < y2; ++i) {
    if (all - sum(x1, y1, x2, i) <= s &&
        all - sum(x1, i, x2, y2) <= s) {
      Pair p = rec(x1, y1, x2, i);
      Pair q = rec(x1, i, x2, y2);
      Pair v(p.first + q.first, min(p.second, q.second));
      if (res < v) res = v;
    }
  }
  return res;
}

int main() {
  while (cin >> h >> w >> s && (h|w|s)) {
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        cin >> u[i][j];
      }
    }

    memset(S, 0, sizeof(S));
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        S[i+1][j+1] += S[i+1][j] + u[i][j];
      }
    }
    for (int j = 0; j < w; ++j) {
      for (int i = 0; i < h; ++i) {
        S[i+1][j+1] += S[i][j+1];
      }
    }

    all = sum(0, 0, w, h);
    fill(mem[0][0][0], mem[MAXW][0][0], Pair(-1, -1));
    Pair res = rec(0, 0, w, h);
    cout << res.first << " " << s - all + res.second << endl;
  }
  return 0;
}

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

int main() {
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<ll> a(x), b(y), c(z);
  for (int i = 0; i < x; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < y; i++) {
    cin >> b.at(i);
  }
  for (int i = 0; i < z; i++) {
    cin >> c.at(i);
  }

  sort(a.begin(), a.end(), greater<ll>());
  sort(b.begin(), b.end(), greater<ll>());
  sort(c.begin(), c.end(), greater<ll>());

  vector<ll> ab(x * y);
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) {
      ab.push_back(a.at(i) + b.at(j));
    }
  }
  sort(ab.begin(), ab.end(), greater<ll>());
  ab.resize(k);

  vector<ll> abc(ab.size() * z);
  for (int i = 0; i < ab.size(); i++) {
    for (int j = 0; j < z; j++) {
      abc.push_back(ab.at(i) + c.at(j));
    }
  }
  sort(abc.begin(), abc.end(), greater<ll>());
  abc.resize(k);

  for (ll ans : abc) {
    cout << ans << endl;
  }
}


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

int main()
{
	string s = "";
	cin >> s;
	int ans = 0;
	char before = '4';
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == before)
		{
			ans++;
			before = s[i] == '0' ? '1' : '0';
		}
		else
		{
			before = s[i];
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 512
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

MAX_PRIME = 10**4
def prime_list():
    sqrt_max = int(MAX_PRIME ** 0.5)
    primes = [True for i in range(MAX_PRIME+1)]
    primes[0] = primes[1] = False

    for p in range(sqrt_max):
        if primes[p]:
            for px in range(p*2, MAX_PRIME, p):
                primes[px] = False

    p_list = [i for i in range(MAX_PRIME) if primes[i]]
    return p_list


def is_prime(n, prime_list):
    sqrt_n = int(n ** 0.5)
    for i in prime_list:
        if i > sqrt_n:
            break
        if n % i == 0:
            return False
    return True

p_list = prime_list()

n = int(sys.stdin.readline())
num_p = 0

for i in range(n):
    x = int(sys.stdin.readline())
    if is_prime(x, p_list):
        num_p += 1
print(num_p)



Measured memory_bytes: 5780
import java.io.*;
import java.util.*;
import java.util.Stack;
import java.util.regex.Pattern;


public class Main {

	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
		//it reads the data about the specified point and divide the data about it ,it is quite fast
		//than using direct 

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static long mod = (long)(1e9+7);
	public static void main(String[] args) {
		 FastReader sc = new FastReader();
		 long a = sc.nextLong();
		 long b = sc.nextLong();
		 long c = sc.nextLong();
		 long d = sc.nextLong();
		 long ans = b-a+1-range(a,b,c,d);
         out.println(ans);
		 out.close();
		 
	}
	
	static long FindLCM(long c, long d) 
    { 
        return (c * d) / gcd(c,d);
    } 
	private static long gcd(long c, long d) {
		
		// TIME COMPLEXITY: O(Log(max(a,b)))
		if(c<d) return gcd(d,c);
		if(d==0) return c;
		else return gcd(d,c%d);
	}
	static long range(long a, long b, long c, long d) 
    { 
       
        long lcm = FindLCM(c, d); 
       
        long a_divisor = b / c - (a - 1) / c; 
        long b_divisor = b / d - (a - 1) / d; 
       
       
        long common_divisor = b / lcm - (a - 1) / lcm; 
       
        long ans = a_divisor + b_divisor - common_divisor; 
        return ans; 
    } 

}		 





Measured memory_bytes: 23124
N = int(input())
ans = 0

def dfs(s):
    global ans
    if int(s) > N:
        return

    if all(s.count(c) for c in '753'):
        ans += 1
    
    dfs(s + '7')
    dfs(s + '5')
    dfs(s + '3')

dfs('0')

print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;



public class Main {   
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        Tower[] tower = new Tower[4];
        for(int i=0; i < tower.length; i++) tower[i] = new Tower();
        
        int n;
        n = sc.nextInt();
        
        for(int i=0; i < n; i++){
            //System.out.println(tower[0]);
            tower[sc.nextInt()-1].index(sc.nextInt(), sc.nextInt(), sc.nextInt());
        }
        String result = "";
        for(int i=0; i < tower.length; i++){
            result += tower[i].print();
            if(i != tower.length -1) result += "####################\n";
        }
        //result = result.substring(0, result.length() - 2);
        
        System.out.print(result);
    }
}

class Tower{
    
    Floor[] floor = new Floor[3];
    
    Tower(){
        for(int i=0; i < floor.length; i++) floor[i] = new Floor();        
    }
    
    void index(int f ,int r ,int v){
        floor[f-1].addPeople(r, v);
    }
    
    String print(){
        String result = "";
        for(Floor a : floor){
            for(int b : a.room){
                result += " " + b;
            }
            result += "\n";
        }
        return result;
    }
}

class Floor{    
    int[] room = new int[10];
    
    Floor(){
        for(int i=0; i < room.length; i++) room[i] = 0;
    }
    
    void addPeople(int r ,int v){
        this.room[r-1] += v;
    }
}

       


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

int main()
{
  ll N,M;
  cin >> N >> M;
  vector<int> A(N);
  priority_queue<ll> pq;
  REP(i, N){
    cin >> A[i];
    pq.push(A[i]);
  }

  REP(i,M){
    ll x = pq.top();
    pq.pop();
    x/=2;
    pq.push(x);
  }

  ll sum = 0;
  while(!pq.empty()){
    sum+=pq.top();
    pq.pop();
  }

  cout << sum << endl;
}

Measured memory_bytes: 1784
A1 = map(int, input().split())
A2 = map(int, input().split())
A3 = map(int, input().split())
N = int(input())
b = [int(input()) for x in range(N)]
A1_check = []
A2_check = []
A3_check = []

for i, item in enumerate(A1):
    if item in b:
        A1_check.append(i+1)

for i, item in enumerate(A2):
    if item in b:
        A2_check.append(i+1)

for i, item in enumerate(A3):
    if item in b:
        A3_check.append(i+1)

if (len(A1_check) == 3 or \
len(A2_check) == 3 or \
len(A3_check) == 3 or \
(1 in A1_check and 1 in A2_check and 1 in A3_check) or \
(2 in A1_check and 2 in A2_check and 2 in A3_check) or \
(3 in A1_check and 3 in A2_check and 3 in A3_check) or \
(1 in A1_check and 2 in A2_check and 3 in A3_check) or \
(3 in A1_check and 2 in A2_check and 1 in A3_check)):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
 		Scanner scanner = new Scanner(System.in);
 		int sum = 1;
 		int N = scanner.nextInt();
 		String S = scanner.next();
 		String[] splitArray = S.split("");
 		
 		for (int i = 1; i < splitArray.length; i++) {
 			if (splitArray[i - 1].equals(splitArray[i])) {
 			} else {
 				sum += 1;
 			}
 		}
 		System.out.println(sum);
	}

}


Measured memory_bytes: 32368
#include<iostream>
#include<random> // random_device mt19937
#include<map>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long int li;

int main(){
  int a[9];
  rep(i,9){
    int n; cin >>n; a[i]=n;
  }
  int n; cin >>n;
  rep(_,n){
    int c; cin >>c;
    rep(i,9) if(a[i]==c) a[i]*=-1;
  }
  int b[9];
  rep(i,9) b[i]=(a[i]<0);
  int flag=0;
  if(b[0] and b[3] and b[6]) flag=1;
  if(b[1] and b[4] and b[7]) flag=1;
  if(b[2] and b[5] and b[8]) flag=1;
  if(b[0] and b[1] and b[2]) flag=1;
  if(b[3] and b[4] and b[5]) flag=1;
  if(b[6] and b[7] and b[8]) flag=1;
  if(b[0] and b[4] and b[8]) flag=1;
  if(b[2] and b[4] and b[6]) flag=1;
  printf("%s",flag?"Yes":"No");
}


Measured memory_bytes: 256
import unittest


class TestB(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think('sardine'), 'xxxxxxx')

    def test_2(self):
        self.assertEqual(think('xxxx'), 'xxxx')

    def test_3(self):
        self.assertEqual(think('gone'), 'xxxx')


def solve():
    s = read()
    result = think(s)
    write(result)


def read():
    return read_line()


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(s):
    return 'x' * len(s)


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()


Measured memory_bytes: 51184
H, W = map(int, input().split())

wlist = []

flagc = [0 for i in range(W)]
for i in range(H):
    rtmp = str(input())
    rtmp_s = list(rtmp)

    flag = 0
    for j in range(len(rtmp_s)):
        if rtmp_s[j] == '#':
            flag += 1
            flagc[j] += 1

    if flag == 0:
        pass
    else:
        wlist.append(rtmp_s)


count = 0
for i in range(W):
    if flagc[i] == 0:
        count += 1

ans = []
for i in range(len(wlist)):
    ansr = []
    k = 0
    for j in range(W):
        if flagc[j] == 0:
            pass
        else:
            ansr.append(wlist[i][k])
        k += 1

    ans.append(ansr)


for i in range(len(ans)):
    for j in range(len(ans[0])):
        print(ans[i][j], end='')
    print('')


Measured memory_bytes: 4596
package main

import (
	"bufio"
	"flag"
	"fmt"
	"io"
	"math/big"
	"os"
)

var reader *bufio.Reader
var writer *bufio.Writer

var inputFile = flag.String("input", "", "")

func init() {
	flag.Parse()
	var i io.Reader
	if *inputFile != "" {
		i, _ = os.Open(*inputFile)
	} else {
		i = os.Stdin
	}
	reader = bufio.NewReaderSize(i, 1<<20)
	writer = bufio.NewWriterSize(os.Stdout, 1<<20)
}

func println(a ...interface{}) {
	_, _ = fmt.Fprintln(writer, a...)
}

func printf(format string, a ...interface{}) {
	_, _ = fmt.Fprintf(writer, format, a...)
}

func scanf(format string, a ...interface{}) {
	_, _ = fmt.Fscanf(reader, format, a...)
}

func scan(a interface{}) {
	_, _ = fmt.Fscan(reader, a)
}

func NextInt64() int64 {
	var res int64
	scan(&res)
	return res
}

func NextInt() int {
	var res int
	scan(&res)
	return res
}

func NextIntArray(n int) []int {
	res := make([]int, n)
	for i := range res {
		scan(&res[i])
	}
	return res
}

func NextInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		scan(&res[i])
	}
	return res
}

func NextString() string {
	var res string
	scan(&res)
	return res
}

func NextBigInt() *big.Int {
	n := new(big.Int)
	n, _ = n.SetString(NextString(), 10)
	return n
}

func AbsInt64(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func MinInt64(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func MaxInt64(x, y int64) int64 {
	if x > y {
		return x
	}
	return y
}

func main() {
	defer writer.Flush()

	n := NextInt()
	W := NextInt()

	dp := make([]int64, W + 1)

	for i := 0; i < n; i++ {
		w := NextInt()
		v := NextInt64()
		
		for j := W; j >= w; j-- {
			dp[j] = MaxInt64(dp[j], dp[j - w] + v)
		}
	}
	
	answer := int64(0)
	for i := 0; i <= W; i++ {
		answer = MaxInt64(answer, dp[i])
	}
	println(answer)
}


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

int main(){
    long long i,k=0,n,h;
    cin >> n >> h;
    long long a[n],b[n],mx=0,sum=0;
    vector <long long> c(100010);
    for(i=0;i<n;i++){
        cin >> a[i] >> b[i];
        mx = max(mx,a[i]);
    }
    for(i=0;i<n;i++){
        if(b[i]>mx){
            sum += b[i];
            c[i] = b[i];
            k++;
        }
    }

    if(h<=sum){
        sort(c.begin(),c.end());
        for(i=0;i<n;i++){
            h -= c[100009-i];
            if(h<=0){
                cout << i+1 << endl;
                return 0;
            }
        }
    }else{
        if((h-sum)%mx){
           cout << (h-sum)/mx + k + 1 <<endl;
        }else{
            cout << (h-sum)/mx + k << endl;
        }
    }
}    

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>

#define MAX_ELEMENTS 3000

using namespace std;

long long dp[MAX_ELEMENTS][MAX_ELEMENTS]; // I thought dp could be X - Y after N turns have passed, but then (After the editorial) I noticed it could be X - Y based on the current positions of L and R; 
long long elementValues[MAX_ELEMENTS];

int main()
{
    int nElements;
    unsigned long long eValue;
    cin >> nElements;
    for(int i = 0; i < nElements; i++)
    {
        cin >> eValue;
        elementValues[i] = eValue;
    } 
    for(int i = nElements - 1; i >= 0; i--)
    {
        for(int j = i; j < nElements; j++)
        {
            if (i == j)
                dp[i][j] = elementValues[i];  // Basically when they have only one option
            else
                dp[i][j] = max(elementValues[i] - dp[i+1][j], elementValues[j] - dp[i][j-1]);
        }
    }
    cout << dp[0][nElements-1];
}

Measured memory_bytes: 70016
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int x;cin >> x;
    vector<int> kouho = {1};
    for(int i = 2;i <= x;i++){
        for(int j = i*i;j <= x;j*= i)kouho.push_back(j);
    }
    sort(kouho.begin(),kouho.end());
    cout << kouho.back() << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <cstdlib>

using namespace std;

struct Panel {
	int x1, y1, x2, y2;
	int level;
	string name;
	vector<Panel*> children;
};

void skip(const string &str, int &pos, char c) {
	//assert(str[pos] == c);
	if(str[pos] != c) {
		cerr << pos << ": " << "expected " << c << " but " << (char)str[pos] << endl;
	}
	++pos;
}


string inittag(const string &str, int &pos) {
	skip(str, pos, '<');
	int end = str.find_first_of('>', pos);
	string name = str.substr(pos, end-pos);
	pos = end;
	skip(str, pos, '>');
	return name;
}

void endtag(const string &str, int &pos, const string &name) {
	pos = str.find_first_of('>', pos);
	skip(str, pos, '>');
}


int readInt(const string &str, int &pos) {
	int n = 0;
	while(isdigit(str[pos])) n = n*10+str[pos++]-'0';
	return n;
}

vector<Panel*> allpanel;

Panel* panel(const string &str, int &pos, int level) {
	string name = inittag(str, pos);

	Panel *p = new Panel;
	p->name = name;
	p->level = level;
	p->x1 = readInt(str, pos);
	skip(str, pos, ',');
	p->y1 = readInt(str, pos);
	skip(str, pos, ',');
	p->x2 = readInt(str, pos);
	skip(str, pos, ',');
	p->y2 = readInt(str, pos);
	while(str[pos+1] != '/') {
		Panel *c = panel(str, pos, level+1);
		p->children.push_back(c);
	}
	allpanel.push_back(p);
	endtag(str, pos, name);

	return p;
}

int main() {
	while(true) {
		int n;
		cin >> n;
		if(n == 0) break;

		string tag;
		cin.ignore();
		getline(cin, tag);
		//cout << tag << endl;

		allpanel.clear();
		int pos = 0;
		Panel *parent = panel(tag, pos, 0);

		for(int i = 0; i < n; ++i) {
			int x, y;
			cin >> x >> y;
			Panel *ans=  NULL;
			int level = -1;
			for(int j = 0; j < allpanel.size(); ++j) {
				Panel *p = allpanel[j];
				if(p->x1 <= x && x <= p->x2 && p->y1 <= y && y <= p->y2) {
					if(p->level > level) {
						ans = p;
						level = p->level;
					}
				}
			}
			if(ans) {
				cout << ans->name << " " << ans->children.size() << endl;
			}
			else {
				cout << "OUT OF MAIN PANEL 1" << endl;
			}
		}
	}
	return 0;
}

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

int main(void)
{
  int i;
  char str[21];
  cin >> str;
  
  for(i = 0; str[i] != '\0'; i++){
  }

  int j;
  char ans[21];

  for(j = 0; j < i; j++){
    ans[j] = str[i-j-1];
  }
  ans[j] = '\0';

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2968
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;


// Bipartite_Matching 
// Verify AOJ
// O(EV)

class Bipartite_Matching{
	public :
		void init(int _n){
			n=_n;
			G.resize(n);
			match.resize(n);
			used.resize(n);
		}

		void add_edge(int from,int to){
			G[from].push_back(to);
			G[to].push_back(from);
		}
	
		void add_edge_both(int from,int to){
			add_edge(from,to);
			add_edge(to,from);
		}
	
		
		int bipartite_matching(void){
			int res=0;
			match.assign(n,-1);
			rep(v,n){
				if(match[v] <0){
					used.assign(n,false);
					if(dfs(v))
						res++;
				}
			}
			return res;
		}	

	private:
	
		int n;
		static const int DINIC_INF = inf;
		vvi G;
		vi match;
		vector<bool> used;

		bool dfs(int v){
			used[v]=true;
			rep(i,G[v].size()){
				int u=G[v][i],w=match[u];
				if(w<0|| !used[w]&& dfs(w)){
					match[u]=v;
					match[v]=u;
					return true;
				}
			}
			return false;
		}
};


int m,n;
int blue[510];
int red[510];

int main(void){
	while(cin >> m >> n,m|n){
		Bipartite_Matching b;
		rep(i,m) cin >> blue[i];
		rep(i,n) cin >> red[i];
		b.init(m+n);
		rep(i,m)rep(j,n){
			if(__gcd(blue[i],red[j])==1)
				continue;
			else
				b.add_edge(i,m+j);
		}
		cout << b.bipartite_matching() << endl;
	}
	return 0;
}

Measured memory_bytes: 2712
import numpy as np
N, K = map(int, input().split())
P = np.array(input().split(), dtype=int)
# 期待値に変換
Q = P/2 + 0.5
# 累積和をとる
S = Q.cumsum()
# K範囲での最大値
if N == K:
    print(S[-1])
else:
	T = S[K:] - S[:-K]
	print(max(T))

Measured memory_bytes: 32660
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>
using namespace std;

typedef long long ll;
typedef string S;
typedef pair<int,int> P;

const int mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> a(4);
    cin >> a[0] >> a[1] >> a[2] >> a[3];
    sort(a.begin(),a.end());
    if(a[0]==1&&a[1]==4&&a[2]==7&&a[3]==9){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;

const int N = 2e5 + 5;
const ll mod = 1e9 + 7;

ll fact[N];

ll binpow(ll x, ll y) { 
    ll ans = 1; 
    x = x % mod;
    while (y > 0) { 
        if (y & 1) {
            ans = (ans * x) % mod;
        } 
        y >>= 1;
        x = (x * x) % mod; 
    } 
    return ans; 
} 

void init() {
    fact[0] = 1; 
    for (int i = 1; i <= N; i++) {
        fact[i] = fact[i - 1] * i % mod;
    } 
}

ll modInverse(ll n) { 
    return binpow(n, mod - 2); 
} 

ll C(ll n, ll r) { 
    if (r == 0) { 
        return 1; 
    }
    return (fact[n]* modInverse(fact[r]) % mod * modInverse(fact[n - r]) % mod) % mod; 
} 

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll h, w, a, b;
	cin >> h >> w >> a >> b;
    init();
    ll ans = 0;
    for (ll i = 1; i <= h - a; i++) {
        ans = (ans + (C(i + b - 2, min(i - 1, b - 1)) * C(h - i + w - b - 1, min(w - b - 1, h - i))) % mod) % mod;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 1e5+5;
const double pi = acos(-1.0);
int main()
{
	int n;cin>>n;
	double s=2*pi*n;
	cout<<s;
	return 0;
}

Measured memory_bytes: 3780
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9

ull comb_x_and_two(ull x) {
	return x * (x - 1) / 2;
}

int main() {
	ull n, m, x, a, dp[100001];
	ull ans = 0;
	map<ull, ull> T;
	dp[0] = 0;
	T[0] = 1;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> x; 
		dp[i + 1] = (dp[i] + x) % m;
			T[dp[i+1]]++;
	}

	map<ull, ull>::iterator it;
	for (it = T.begin(); it != T.end(); it++)
	{
		pair<ull, ull> item = *it;
		ans += comb_x_and_two(item.second);
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
const int INF = 1e9;
const int MOD = 1000000007;

int main(){
    int n,p;
    cin >> n >> p;
    string s;
    cin >> s;
    if(10%p==0){
        ll ans = 0;
        rep(i,n){
            int d = s[i] - '0';
            if(d%p ==0){
                ans += i+1;
            }
        }
        cout << ans << endl;
    }else{
        ll ans = 0;
        vector<int> res(p,0);
        res[0] ++;
        int now = 0;
        int t = 1;
        for(int i=n-1;i>=0;i--){
            now = (now + (s[i] - '0') * t)%p;
            ans += res[now];
            ++res[now];
            t = (t * 10)%p;
        }
        cout << ans << endl; 
    }
    return 0;
}

Measured memory_bytes: 640
// 2012/07/09 Tazoe

#include <iostream>
using namespace std;

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

		if(n==0)
			break;

		double g_max = 0.0;
		int b_max = 0;

		int y;
		cin >> y;

		for(int i=0; i<n; i++){
			int b, r, t;
			cin >> b >> r >> t;

			double g;
			if(t==1){
				g = 1.0+(double)y*(double)r/100.0;
			}
			else{
				g = 1.0;
				for(int j=0; j<y; j++){
					g *= (1.0+(double)r/100.0);
				}
			}

			if(g>g_max){
				g_max = g;
				b_max = b;
			}
		}

		cout << b_max << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B;
  cin >> A >> B;
  if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
    cout << "Possible" << endl;
  }
  else {
    cout << "Impossible" << endl;
  }
}

Measured memory_bytes: 256
fn main() {
    let nd = read_vec::<usize>();
    let n = nd[0];
    let d = nd[1];

    if n % (2 * d + 1) == 0 {
        println!("{}", n / (2 * d + 1));
    } else {
        println!("{}", n / (2 * d + 1) + 1);
    }
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
using namespace std;

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int winner;
  while(1){
    c-=b;
    if(c<=0){
      winner=1;
      break;
    }
    a-=d;
    if(a<=0){
      winner=0;
      break;
    }
  }
  if(winner==1){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
}

Measured memory_bytes: 3636
// ABC 142 D
#include <bits/stdc++.h>
using namespace std;

long long gcd(long long a, long long b) {
  if (b == 0) return a;
  else return gcd(b, a % b);
}

// 素因数分解
vector<pair<long long, long long>> prime_factorize(long long n) {
  vector<pair<long long, long long>> res;
  for (long long p = 2; p*p <= n; p++) {
    if (n % p != 0) continue;
    int num = 0;
    while (n % p == 0) { num++; n /= p; }
    res.push_back(make_pair(p, num));
  }
  if (n != 1) res.push_back(make_pair(n, 1));
  return res;
}

int main() {
  long long A, B; cin >> A >> B;
  long long x = gcd(A, B);
  vector<pair<long long, long long>> pf = prime_factorize(x);
  cout << pf.size() + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <vector>
typedef long long ll;
using namespace std;

const int N=1005;

int a[N];
int ans[N];

void solve(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
	}
	for(int i=n;i>=1;i--){
		int id=0;
		for(int j=i;j>=1;j--){
			if(a[j]==j){
				id=j;
				break;
			}
		}
		if(id==0){
			printf("-1\n");
			return ;
		}
		ans[i]=id;
		for(int j=id+1;j<=i;j++){
			a[j-1]=a[j];
		}
	}
	for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
}

int main(){

	solve();

    return 0;
}

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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)          \
  sort(x.begin(), x.end()); \
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << "(" << #x << ", " << #y << ") = " \
                          << "(" << x << ", " << y << ")" << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

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

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

  ll n;
  cin >> n;

  vector<ll> v(n);

  ll fsum = 0;
  ll tsum = 0;
  ll esum = 0;
  rep(i, n) {
    cin >> v[i];
    if (v[i] % 4 == 0) {
      fsum++;
    } else if (v[i] % 2 == 0) {
      tsum++;
    } else {
      esum++;
    }
  }

  ll kumi = tsum / 2;
  ll sore = tsum - kumi;

  if (fsum + kumi >= esum + sore - 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 1024
def root(n)
    ret = Math.sqrt(n).floor
    ret -= 1 while ret**2 > n
    ret += 1 while(ret+1)**2 <= n
    ret
end

MOD = 10**9+7
N, K = gets.split.map(&:to_i)
Q = root(N)

num = Array.new(Q+1)
(1...Q).each do |i|
    num[i] = N/i - N/(i+1)
end
num[Q] = N/Q - Q

dp1 = Array.new(K+1){Array.new(Q+1, 0)}
dp2 = Array.new(K+1){Array.new(Q+1, 0)}
dp1[0][1] = 1
K.times do |i|
    sum0 = dp1[i].inject(:+) % MOD

    sum = 0
    Q.downto(1) do |j|
        sum += dp2[i][j]
        dp1[i+1][j] = (sum0 + sum) % MOD
    end

    sum = 0
    (1..Q).each do |j|
        sum += dp1[i][j]
        dp2[i+1][j] = sum * num[j] % MOD
    end
end

ans = (dp1[K] + dp2[K]).inject(:+) % MOD
puts ans

Measured memory_bytes: 52604
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    int a,b;cin>>a>>b;
    int A,B;
    vector<int>power={2,3,4,5,6,7,8,9,10,11,12,13,1};
    rep(i,power.size()){
        if(a==power.at(i)){
            A=i;
        }
        if(b==power.at(i)){
            B=i;
        }
    }
    if(A>B)cout<<"Alice"<<endl;
    else if(A==B) cout<<"Draw"<<endl;
    else cout<<"Bob"<<endl;
}


Measured memory_bytes: 3592
N,K = map(int, input().split())
list_input = []
food_type = []
food = []
for n in range(N):
    list_input.append(list(map(int,input().split())))
    num = list_input[n][0]+1
    #print('num:'+str(num))
    each_food = []
    for i in range(1,num):
        #print(list_input[n][i])
        each_food.append(list_input[n][i])
        if list_input[n][i] in food_type:
            continue
        else:
            #print(i, list_input[n][i])
            food_type.append(list_input[n][i])
    food.append(each_food)
ans = 0
for t in food_type:
    all_like = True
    for f in food:
        if t not in f:
            all_like = False
    if all_like:
        ans += 1
print(ans)

Measured memory_bytes: 38256
class union_find():
    def __init__(self, n):
        self.par = [i for i in range(n + 1)]
        self.rank = [1 for i in range(n + 1)]
        self.size = [1 for i in range(n + 1)]

    def find(self, c):
        if self.par[c] == c:
            return c

        ret = self.find(self.par[c])
        self.par[c] = ret
        return ret

    def union(self, x, y):

        xr = self.find(x)
        yr = self.find(y)
        if xr == yr:
            return

        if self.rank[yr] > self.rank[xr]:
            self.par[xr] = yr
            self.size[xr] += self.size[yr]
            self.size[yr] = self.size[xr]
        else:
            self.par[yr] = xr
            self.size[yr] += self.size[xr]
            self.size[xr] = self.size[yr]
            if self.rank[xr] == self.rank[yr]:
                self.rank[xr] += 1

    def mass_size(self):
        return [i == v for i, v in enumerate(self.par)].count(True) - 1

    def show(self):
        print('parent', self.par[1:])
        print('rank', self.rank[1:])

def main():
    from collections import defaultdict

    dicf = defaultdict(lambda :[])
    dicb = defaultdict(lambda :[])

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

    uf = union_find(N)
    for i in range(M):
        a, b = map(int, input().split())
        dicf[a].append(b)
        dicf[b].append(a)
        if a > b:
            a, b = b, a
        uf.union(a, b)

    for i in range(K):
        c, d = map(int, input().split())
        dicb[c].append(d)
        dicb[d].append(c)

    ans = []
    for i in range(1, N + 1):
        x = uf.size[uf.find(i)] - len(dicf[i]) - 1
        m = 0
        for b in dicb[i]:
            if uf.find(b) == uf.find(i):
                m += 1

        ans.append(x - m)


    print(' '.join(map(str, ans)))




if __name__ == '__main__':
    main()

Measured memory_bytes: 68656
#include<bits/stdc++.h>
#define ll long long 
#define OJ \
        freopen("input.txt","r",stdin); \
        freopen("output.txt","w",stdout);
using namespace std;
int gcd(int a,int b)
{
  int ans;
    if(b==0)
    {
      return a;
    }
  ans=gcd(b,a%b);
  return ans;
      
}

int main()
{
 // OJ;
 int h1,m1,h2,m2,k;
 cin>>h1>>m1>>h2>>m2>>k;
 int total=(h2-h1)*60+m2-m1;
 cout<<total-k;

 }


Measured memory_bytes: 3600
#include <iostream>

void call(int n);

int main()
{
	int n;
	std::cin >> n;
	call(n);
	return 0;
}

void call(int n)
{
	int i = 1;
	while (i <= n) 
	{
		int x = i;
		if (x % 3 == 0 || x % 10 == 3)
		{
			std::cout << " " << i;
		}
		else
		{
			do {
				if (x % 10 == 3)
				{
					std::cout << " " << i;
					break;
				}
				x /= 10;
			} while (x != 0);
		}
		i++;
	}
	std::cout << '\n';
}

Measured memory_bytes: 3084
if True:
    n,m=map(int,input().split())
    a=[[0 for i in range(n)] for j in range(8)]
    for i in range(n):
        x,y,z=map(int,input().split())
        t=0
        for p in range(2):
            for q in range(2):
                for r in range(2):
                    a[t][i]=x*(1-2*p)+y*(1-2*q)+z*(1-2*r)
                    t+=1
ans=0
for i in range(8):
    b=a[i]
    b.sort(reverse=True)
    ans=max(ans,sum(b[:m]))
print(ans)

Measured memory_bytes: 44396
import math
n, p = map(int, input().split())

sqrtp = int(math.sqrt(p))

b = []

for i in range(2, sqrtp+1):
    count = 0
    while p % i == 0:
        count += 1
        p = p // i
    b.append((i, count))
if p > 1:
    b.append((p, 1))

num = 1
for i, c in b:
    c = c // n
    if c > 0:
        num *= (i ** c)

print(num)



Measured memory_bytes: 106136
#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

typedef long long ll;

double xx(double r) {
  return r*r;
}

ll gcd(ll a, ll b) {
  if (a == 0) return b;
  return gcd(b%a, a);
}

int main() {
  ll a, b;
  while ( scanf("%lld%lld", &a, &b) != EOF ) {
    ll g = gcd(a, b);
    ll l = a / g * b;
    cout << g << " " << l << endl;
  }
}

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

typedef long long int ll;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (auto& i : A) cin >> i;

    sort(A.begin(), A.end());
    int x = 0;
    for (int i = 1; i < N; i++) {
        if (A[i] > 2 * A[i-1]) x = i;
        A[i] += A[i-1];
    }

    cout << N - x << endl;

    return 0;
}

Measured memory_bytes: 1024
A, B, K = map(int, input().split())
i = 0

if A <= K:
  K = K - A 
  A = 0
if A > K:
  A = A - K
  K = 0
if B <= K and A == 0:
  K = K - B
  B = 0
if B >= K and A == 0:
  B = B - K
  K = 0

print(A)
print(B)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
    
#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)
#define risi (0.05)

using namespace std;


int main(void)
{
    int a,b,c,d;
    int i,j,k,l;
    int number;
    int answercounter = 0;
    int answerarray[1000] = {0};
    int temp = 0;
    while(cin >> number)
    {
        for(i = 0;i <= 9;i++)
            if(i <= number)
                for(j = 0;j<=9;j++)
                    if(i+j<= number)
                        for(k = 0;k<=9;k++)
                            if(i+j+k <= number)
                                for(l = 0;l<=9;l++)
                                    if((i+j+k+l) == number)
                                        temp++;
        answerarray[answercounter] = temp;
        temp = 0;
        answercounter++;
        
                                        
    }
    REP(i,answercounter)
    cout << answerarray[i] << endl;
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

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

	int N;
	ll A, B; cin >> N >> A >> B;

	vector<ll> V; // 2点の距離
	ll befo; cin >> befo;
	ll tmp;
	for (int i = 0; i < N - 1; i++) {
		cin >> tmp;
		V.push_back(tmp - befo);
		befo = tmp;
	}
	sort(V.begin(), V.end());

	// Vを累積和にする
	for (int i = 1; i < N - 1; i++) {
		V[i] += V[i - 1];
	}

	ll ans = LLINF;
	// i回ワープするときの最小コスト
	for (int i = 0; i <= N - 1; i++) {
		int walk = N - 1 - i;
		ll tmpans = B * i;
		if (walk != 0) tmpans += (A * V[walk - 1]);
		ans = min(ans, tmpans);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1400
a,b = map(int, input().split())
ans=0
for bit in range(40):
  if bit==0:
    if a%2==1 and b%2==1:
      ans+=((b-a+2)//2%2)
    elif a%2==0 and b%2==0:
      ans+=(b-a)//2%2
    else:
      ans+=((b-a+1)//2%2)
    continue
  cnt=0
  d=2**bit
  if a&d:
    cnt+=d-a%d
  if b&d:
    cnt+=b%d-d+1
  if cnt%2==1:
    ans+=d

print(ans)

Measured memory_bytes: 3064