akhauriyash/Code-Regression huggingface dataset:
import numpy as np

n, m = map(int, input().split())
is_ac = np.zeros(n, dtype=bool)
wc_count = np.zeros(n, dtype=int)

for _ in range(m):
    p, s = input().split()
    p = int(p)
    if not is_ac[p - 1]:
        if s == "WA":
            wc_count[p - 1] += 1
        else:
            is_ac[p - 1] = True
print(is_ac.sum(), wc_count[is_ac].sum())


Measured memory_bytes: 14644
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0532

"""
import sys
from sys import stdin
input = stdin.readline
from datetime import datetime, timedelta

def main(args):
    for _ in range(3):
        hh1, mm1, ss1, hh2, mm2, ss2 = map(int, input().split())
        enter = datetime(2000, 1, 1, hour=hh1, minute=mm1, second=ss1)
        exit = datetime(2000, 1, 1, hour=hh2, minute=mm2, second=ss2)
        diff = exit - enter
        print(diff.seconds//3600, diff.seconds%3600//60, diff.seconds%60)


if __name__ == '__main__':
    main(sys.argv[1:])

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

ll c, d;

ll calc(ll n) {
    return n - n / c - n / d + n / (c * d / __gcd(c, d));
}

int main() {
    ll a, b;
    cin >> a >> b >> c >> d;
    cout << calc(b) - calc(a-1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1000000000;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n;
	cin >> n;
	VI l(n);
	REP(i, n)
		cin >> l[i];
	sort(ALL(l),greater<int>());
	int ans = 0;
	REP(i, n - 2) {
		for (int j = i + 1; j < n - 1; j++) {
			for (int k = j + 1; k < n; k++) {
				if (l[i] < l[j] + l[k] && l[j] < l[i] + l[k] && l[k] < l[i] + l[j])
					ans ++;
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
using namespace std;

int main(){
  int n,m;
  map<string,int> val;
  set<string> keys;
  cin >> n;
  for(int i = 0;i < n;i++) {
    string s;
    cin >> s;
    if(val.count(s) == 0) {
      val[s] = 1;
    } else {
      val[s]++;
    }
    keys.insert(s);
  }
  cin >> m;
  for(int i = 0;i < m;i++) 
  {
    string s;
    cin >> s;
    if(val.count(s) == 0) {
      val[s] = -1;
    } else {
      val[s]--;
    }
    keys.insert(s);
  }
  string kk;
  int max = -1000000;
  for(auto kk:keys) {
    if(max < val[kk])
    {
      max = val[kk];
    }
  }
  cout << max*(max > 0) << endl;
}

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

using namespace std;

#define all(x) begin(x), end(x)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

constexpr int MOD = 1e9 + 7;

int sum(int a, int b, int mod=MOD) {
    int c = a + b;
    if (c >= mod) {
        c -= mod;
    }

    return c;
}

inline int prod(int a, int b, int mod=MOD) {
    return (1LL * a * b) % mod;
}

int modpow(int base, int exp, int mod=MOD) {
    int res = 1;
    int cur = base;
    for (int p = 1; p <= exp; p <<= 1) {
        if (p & exp) {
            res = prod(res, cur, mod);
        }

        cur = prod(cur, cur, mod);
    }

    return res;
}

inline int inv(int x, int mod=MOD) {
    return modpow(x, mod - 2, mod);
}

constexpr int MAXN = 5003;
int m;
// how many ways are there to write j characters in exactly i steps?
int dp[2][MAXN];

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    m = s.size();

    int row = 0;
    dp[row][0] = 1;

    for (int i = 1; i <= n; ++i) {
        row ^= 1;
        memset(dp[row], 0, sizeof(dp[row]));

        dp[row][0] = sum(dp[row][0], sum(dp[row ^ 1][0], dp[row ^ 1][1]));
        for (int j = 1; j <= n; ++j) {
            // add a character
            dp[row][j] = sum(dp[row][j], prod(2, dp[row ^ 1][j - 1]));

            // delete a character
            dp[row][j] = sum(dp[row][j], dp[row ^ 1][j + 1]);
        }
    }

    int res = prod(dp[row][m], inv(modpow(2, m)));
    cout << res << '\n';

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)

bool prime[1000000];
int main(){
	memset(prime, true, sizeof(prime));
	prime[0] = prime[1] = false;
	for(int i = 2; i * i < 1000000; i++){
		if(prime[i]){
			for(int j = i * 2; j < 1000000; j += i){
				prime[j] = false;
			}
		}
	}
	int n;
	while(cin >> n && n){
		int cnt = 0;
		rep2(i, 2, n / 2 + 1){
			if(prime[i] && prime[n-i]) cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  
  if ( (S.at(5) == '0') && (S.at(6) <= '4') )
    cout << "Heisei" << endl;
  else
    cout << "TBD" << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

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

	cout << (a % 500 <= b ? "Yes" : "No") << endl;
}

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

using namespace std;

#define LL long long
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{
    FAST();
    int i,n;
    LL xr=0,sum,rem;
    cin >> n;
    vector<LL>a(n);
    for(i=0;i<n;i++)cin >> a[i];
    sum=a[0]+a[1];
    for(i=2;i<n;i++)xr ^= a[i];
    if(sum%2 != xr%2)cout << "-1";
    else
    {
        rem=(sum-xr)/2LL;
        if(rem > a[0]  ||  (rem & xr))cout << "-1";
        else
        {
            for(i=40;i>-1;i--)
            {
                if(!((xr >> i) & 1))continue;
                if((rem | (1LL << i)) > a[0])continue;
                rem |= (1LL << i);
            }
            if(rem == 0)cout << "-1";
            else cout << a[0]-rem;
        }
    }
    return 0;
}


Measured memory_bytes: 3656
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <numeric>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll MOD = 1000000007;
const int mod = 1000000007;
ll INF = 1LL << 60;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
   for (auto &v : vec)
      is >> v;
   return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec)
{
   os << "[";
   for (auto v : vec)
      os << v << ",";
   os << "]";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const deque<T> &vec)
{
   os << "deq[";
   for (auto v : vec)
      os << v << ",";
   os << "]";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &vec)
{
   os << "{";
   for (auto v : vec)
      os << v << ",";
   os << "}";
   return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{
   os << "(" << pa.first << "," << pa.second << ")";
   return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &mp)
{
   os << "{";
   for (auto v : mp)
      os << v.first << "=>" << v.second << ",";
   os << "}";
   return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp)
{
   os << "{";
   for (auto v : mp)
      os << v.first << "=>" << v.second << ",";
   os << "}";
   return os;
};
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
   fill((T *)array, (T *)(array + N), val);
}


ll a[202020];
int solve()
{
   ll n;
   cin >> n;
   ll y = 0;
   for(int i=0; i < n; i++){
      cin >> a[i];
      y += a[i];
   }
   // ll y = accumulate(a, a + n, 0);
   ll ans = (1LL << 61) , x = 0;
   for(int i=0; i < n-1; i++){
      y -= a[i];
      x += a[i];
      ans = min(ans, abs(x - y));
   }
   cout << ans << endl;
   return 0;
}

int main()
{
   //cout.precision(10)
   ios::sync_with_stdio(false);
   cin.tie(0);

   solve();
}

Measured memory_bytes: 1792
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int h = scanner.nextInt();
			int w = scanner.nextInt();
			if ((h | w) == 0)
				break;
			StringBuilder b = new StringBuilder();
			for (int i = 0; i < h; i++)
				b.append(scanner.next());
			Deque<Point> deque = new ArrayDeque<Main.Point>();
			int k = b.indexOf("@");
			deque.push(new Point(k / w, k % w, b.toString(), 1));
			int ans = -1;
			Set<String> set = new HashSet<String>();
			loop: while (!deque.isEmpty()) {
				Point p = deque.poll();
				String g = p.g;
				int d = p.d;
				int y = p.y;
				int x = p.x;
				int a = y * w + x;
				if (set.contains(g))
					continue;
				set.add(g);
				for (int i = 0; i < 4; i++) {
					int sy = y + dy[i];
					int sx = x + dx[i];
					int aa = sy * w + sx;
					char c = g.charAt(aa);
					if (c == '#' || c == 'w')
						continue;
					if (c == 'E') {
						ans = d;
						break loop;
					}
					if (c == '.') {
						char[] tmp = g.toCharArray();
						tmp[a] = '.';
						tmp[aa] = '@';
						deque.offer(new Point(sy, sx, String.valueOf(tmp),
								d + 1));
					}
					if (c == 'c') {
						char[] tmp = g.toCharArray();
						tmp[aa] = '.';
						while (true) {
							int ny = sy + dy[i];
							int nx = sx + dx[i];
							char nc = tmp[ny * w + nx];
							if (nc == '#' || nc == 'c') {
								tmp[sy * w + sx] = 'c';
								break;
							}
							if (nc == 'w') {
								tmp[ny * w + nx] = '.';
								break;
							}
							sy = ny;
							sx = nx;
						}
						deque.offer(new Point(y, x, String.valueOf(tmp), d));
					}
				}

			}
			System.out.println(ans);
		}
	}

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

	class Point {
		int y, x;
		String g;
		int d;

		public Point(int y, int x, String g, int d) {
			super();
			this.y = y;
			this.x = x;
			this.g = g;
			this.d = d;
		}

		@Override
		public String toString() {
			return "Point [y=" + y + ", x=" + x + ", g=" + g + ", d=" + d + "]";
		}

	}
}

Measured memory_bytes: 114928
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[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 ) * } } ; }
#[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" ) } ; }
#[allow(dead_code)]
pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
    let out = stdout();
    let writer = BufWriter::new(out.lock());
    f(writer)
}
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) } ; }
#[allow(dead_code)]
fn main() {
    input!{
        x: chars,
    }
    let mut stack = Vec::new();
    let length = x.len();
    //debug!(length);
    let mut ans = 0;
    for v in x {
        if stack.is_empty() && v == 'T' {
            continue;
        }
        if v == 'T' {
            stack.pop();
            ans += 1;
        } else {
            stack.push(v);
        }
    }
    println!("{}", length - ans * 2);
}

Measured memory_bytes: 6396
p=10**9+7
n, k = map(int, input().split())
def f(k):
  a = k*(2*n-k+1)/2 
  b = k*(k-1)/2 
  return int(a-b+1)
x = 0
for i in range(k,n+2):
  x += f(i)
print(x%p)

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

using namespace std;


void solve(){
    int a, b, c;
    cin >> a >> b >> c;
    int first = max(max(a,b),c);
    int second =0;
    if(a== first){
         second = max(b,c);
    }
    else if(b == first){
         second = max(a,c);
    }
    else{
         second = max(b,a);
    }
    int last = min(min(a, b), c);
    first *= 10;
    first += second;
    first += last;
    cout << first << endl;

}

int main()
{
    solve();
    return 0;
}


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

using namespace std;

#define cerr if(false)cerr
#define what(x) cerr<<#x<<" = "<<x<<endl
 
typedef long long ll;
typedef pair<ll, ll> ii;

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 322;
const ll inf = 1e18;
int main(){

	ios_base::sync_with_stdio(false); 
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	vector<ll> arr(n);

	bool flag = false;
	for(int i = 0; i < n; i++){
		cin >> arr[i];
		if(arr[i] == 0)flag = true;
	}
	if(flag){
		cout << 0 << endl;
		return 0;
	}

	ll ans = 1;
	for(int i = 0; i < n; i++){
		if(ans > inf / arr[i]){
			cout << -1 << endl;
			return 0;
		}
		ans *= arr[i];
	}

	if(ans > inf){
		cout << -1 << endl;
	}else{
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3992
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

int main(){
    while(1){
        string s;
        cin >> s;
        if(s=="-") break;
        int m;
        cin >> m;
        string tmp;
        FOR(i, 0, m){
            int h;
            cin >> h;
            tmp = s.substr(0, h);
            s.erase(0, h);
            s = s + tmp;
        }
        cout << s << endl;
    }
}

Measured memory_bytes: 3208
while True:
    n, a, b = map(int, input().split())
    if not n:
        break
    if a > b:
        a, b = b, a
    dp = [False] * (n + b - a + 1)
    dp[1:n + 1] = [True] * n
    for i in range(n - a + 1):
        if not dp[i]:
            dp[i + a] = False
            dp[i + b] = False
    print(dp.count(True))

Measured memory_bytes: 30788
import sys
 
input = sys.stdin.readline

a=input()
b=a.split(" ")
N=int(b[0])
M=int(b[1])
in2=[]
out2=[]
for i in range(M):
    c=input()
    d=c.split(" ")
    in1=int(d[0])
    out=int(d[1])
    if in1==1:
        in2.append(str(out))
    elif out==N:
        out2.append(str(in1))
        
in2_set=set(in2)
out2_set=set(out2)
matched_list=list(in2_set & out2_set)
#print(matched_list)
if len(matched_list)==0:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Measured memory_bytes: 26600
// Aizu Vol-1 0113: Period
// 2017.8.2

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char *gets(char *);
char buf[100], *p;

int getInt(void)
{
	int n = 0;
	while (isspace(*p)) p++;
	while (isdigit(*p)) n = 10 * n + (*p++ - '0');
	return n;
}

#define MAX 1000000
int rr[MAX + 1];

int main()
{
	int a, b, r, k;
	int i, w;

	while (gets(p = buf) != NULL) {
		for (i = 0; i < MAX; i++) rr[i] = -1;
		a = getInt(), b = getInt();
		for (rr[a] = 0, k = 1; ; k++) {
			a *= 10;
			putchar('0' + a / b);
			if ((r = a % b) == 0) { putchar('\n'); break; }
			if (rr[r] >= 0) {
				putchar('\n');
				w = rr[r];
				for (i = 0; i < w; i++) putchar(' ');
				while (w++ < k) putchar('^');
				putchar('\n');
				break;
			}
			rr[r] = k, a = r;
		}
	}
	return 0;
}

Measured memory_bytes: 4388
import std.stdio, std.algorithm;

void main() {
  for(int n, s; readf("%d %d\n", &n, &s), n != 0;) {
    int[] arr = new int[](n);
    int ans;
    foreach(i; 0..n) readf("%d\n", &arr[i]);
    sort(arr);
    for(int i = 0; i < arr.length; i++) {
      int lb = i, ub = n;
      while(ub - lb > 1) {
        int mid = (lb + ub) / 2;
        if (arr[mid] + arr[i] > s) ub = mid;
        else lb = mid;
      }
      ans += (n - ub);
    }
    writeln(ans);
  }
}

Measured memory_bytes: 2036
int main()
{
    int n,i,a;
    int amax=0,bmax=0;
    int b[100001]={0};
    
    scanf("%d",&n);
    
    for(i=0;i<n;i++)
    {
        scanf("%d",&a);
        if(amax<a)
        {
            amax=a;
        }
        
        b[a]+=1;
        
        if(a!=0)
        {
            b[a-1]+=1;
        }
        if(a<100000)
        {
            b[a+1]+=1;
        }
    }
    
    for(i=0; i < amax+1; i++)
    {
        if(bmax<b[i])
        {
            bmax=b[i];
        }
    }
    
    printf("%d\n",bmax);
    
    return 0;
}


Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
ans = 1
cnt = [0, 0, 0]

for i in a:
    ans *= cnt.count(i)
    ans %= mod
    if i not in cnt:
        print(0)
        exit()
    ind = cnt.index(i)
    cnt[ind] += 1

print(ans)

Measured memory_bytes: 14092
fun main(args: Array<String>) {
    val s = readLine()!!

    var d = Int.MAX_VALUE
    for ((i, c) in s.withIndex()) {
        if (s.length - 3 < i) {
            break
        }
        val a = s.substring(i, i+3).toInt()
        d = Math.min(d, Math.abs(753 - a))
    }

    println(d)
}

Measured memory_bytes: 33752
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int):

    for i in range(0,N//4+1):
        for j in range(0,N//7+1):
            if (4*i + 7*j) ==  N:
                print(YES)
                return

    print(NO)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


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

using namespace std;

main() {
#ifdef HOME
    //freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int h, n, x, sum = 0;
    cin >> h >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> x;
        sum += x;
    }
    if (sum >= h) cout << "Yes";
    else cout << "No";
    return 0;
}



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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}

vector<pair<int,ll>> vec[100000];
ll cost[100000];
void dfs(int now,ll COST){
    cost[now]=COST;
    int next;
    REP(i,vec[now].size()){
        next=vec[now][i].first;
        if(cost[next]<0){
            dfs(next,COST+vec[now][i].second);
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S;
    cin>>S;
    int ans;ans=0;
    if(S=="SUN"){
        ans=7;
    }else if(S=="SAT"){
        ans=1;
    }else if(S=="FRI"){
        ans=2;
    }else if(S=="THU"){
        ans=3;
    }else if(S=="WED"){
        ans=4;
    }else if(S=="TUE"){
        ans=5;
    }else if(S=="MON"){
        ans=6;
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[105];
ll B[105];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }
    REP(i, N) {
        cin >> B[i];
    }

    ll ans = 0;
    ll s = 0;
    REP(i, N) {
        s += A[i];
        ll t = s;
        FOR(j, N, i) {
            t += B[j];
        }
        ans = std::max(ans, t);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math") 
//#pragma GCC target("avx2")
#define _CRT_SECURE_NO_WARNINGS // - for VisualStudio: do not disturb about warnings
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <functional>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <climits>

using namespace std;
#define open_streams ifstream fin("output.txt");ofstream fout("output.txt")
#define close_streams fin.close();fout.close()
#define speed cout.tie(0);cin.tie(0);ios_base::sync_with_stdio(0)
#define pus system("pause");
#define ll long long
#define ull unsigned long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define UNIQ(a) a.resize(unique(all(a)) - a.begin())
#define eps 1e-6
//const double PI = M_PI;
const int INF = INT_MAX;
const ll limit = 1LL * 1e18;
const int MOD = 1e9 + 711;
const int MOD2 = 1e9 + 933;
const int MOD3 = 1e9 + 993;
//---------------------------------------------------------------------------
const int mod = 1e9 + 7;
const int maxn = 5e5 + 100;





signed main() {
	speed;
	int n, t;
	cin >> n >> t;
	vector<pair<int, int>> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i].first >> a[i].second;
	}
	sort(all(a));
	vector<int> dp(t + 1,-1);
	dp[0] = 0;
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int time = a[i].first, val = a[i].second;
		for (int j = t - 1; j >= 0; --j) {
			if (dp[j] == -1) {
				continue;
			}
			ans = max(ans, dp[j] + val);
			if (j + time < t) {
				dp[j + time] = max(dp[j + time], dp[j] + val);
			}
		}
	}
	cout << ans;
	cerr << "\n\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 384
use std::io::*; //Not mine.
use std::str::FromStr;
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn main() {
    let n: usize = read();
    let mut ab: Vec<i64> = vec![0; n];
    let mut div: i64 = 0;
    for i in 0..n {
        let a: i64 = read();
        let b: i64 = read();
        ab[i] = a + b;

        div -= b;
    }
    ab.sort();
    ab.reverse();
    let k = n / 2;
    let mut sum_a: i64 = 0;
    for i in 0..n {
        if i % 2 == 0 {
            sum_a += ab[i];
        }
    }
    println!("{}", sum_a + div);
}


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

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: i64,
        k: i64,
        x: [i64; n],
    }
    let mut sum = 0;
    for i in 0..x.len() {
        if (x[i] as f64) < (k as f64) / 2.0_f64 {
            sum += x[i] * 2;
        } else {
            sum += (k - x[i]) * 2
        }
    }
    println!("{}", sum);
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main()
{
    string s, ans;
    int N;
    cin >> N >> s;
    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] + N > 'Z')
        {
            s[i] += N - 26;
        }
        else
        {
            s[i] = s[i] + N;
        }
    }

    cout << s << endl;
    return 0;
}

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

int main(void)
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    int ONA, ONB;
    int count = 0;

    //1秒~100秒の状態を見る
    for( int i = 0; i < 100; i++){
        if( A <= i && i < B){
            ONA = 1;
        }else{
            ONA = -1;
        }
        if( C <= i && i < D){
            ONB = 1;
        }else{
            ONB = -1;
        }

        //両方とも押していたらカウント
        if( ONA == 1 && ONB == 1){
            count++;
        }
    }

    //出力
    cout << count;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

using Graph = vector<vector<int> >;

int main() {
    // 頂点数と辺数
    int N, M; cin >> N >> M;

    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(2 * N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    // BFS のためのデータ構造
    vector<int> ans(N , -1);
    vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.push(0); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            ans[nv] = v;
            que.push(nv);
        }
    }
    /*
    rep(v,N){
      if(dist[v] == -1){
        cout << "No" << endl;
        return 0;
      }
    }
    */
    // 結果出力 (各頂点の頂点 0 からの距離を見る)
    // for (int v = 0; v < N; ++v) cout << v << ": " << dist[v] << endl;
    cout << "Yes" << endl;
    for(ll v = 1; v < N ; v ++) cout << ans[v] + 1 << endl;
}


Measured memory_bytes: 13000
/**
 * 二分探索
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_B&lang=ja
 */

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector <int>S(n);
  for (int i = 0; i < n; i++) {
    cin >> S.at(i);
  }

  int q;
  cin >> q;
  vector <int>T(q);
  for (int i = 0; i < q; i++) {
    cin >> T.at(i);
  }

  // 二分探索
  int cnt = 0;
  // Tに含まれる整数で、Sに含まれているものの個数をカウントする
  for (int i = 0; i < q; i++) {
    int minJ = 0;
    int maxJ = n;
    // minJとmaxJが反転してしまったら、探索をしたが見つからなかったということになる
    while (minJ <= maxJ) {
      // Sの中央の値で比較することで、配列の前半と後半のどちらに求める値があるのかを探索する
      int j = (minJ + maxJ) / 2;

      if (S.at(j) < T.at(i)) {
        // 前半に探索する値は存在しない
        minJ = j + 1;
      } else if (S.at(j) > T.at(i)) {
        // 後半に探索する値は存在しない
        maxJ = j - 1;
      } else {
        // 要素が一致した
        cnt++;
        break;
      }
    }
  }
  
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 3284
#include <stdio.h>
int main(){
  int m[100][100];
  int n,u,k,v;
  scanf("%d",&n);
  int i,j;
  for(i=0;i<n;i++){
   for(j=0;j<n;j++){
      m[i][j] = 0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
     for(j=0;j<k;j++){
     scanf("%d",&v);
      v--;
     m[u][v] = 1;
    }
   }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
     if(j!=0)printf(" ");
      printf("%d",m[i][j]);
    }
      printf("\n");
   }
  return 0;
}

Measured memory_bytes: 1836
#include<string>
#include<iostream>
#include<cstdio>

using namespace std;

int main(void){
	string str,ans;
	int n,cnt;
	char c,sp[100];
	while(1){
		cin >> n;
		if(n==0)break;
		cin >> str;
		while(n-->0){
			c=str[0];
			cnt=0;
			ans="";
			for(int i=0;i<str.size();i++){
				if(c==str[i])cnt++;
				else{
					sprintf(sp,"%d",cnt);
					ans+=sp;
					ans+=c;
					c=str[i];
					cnt=1;
				}
			}
			sprintf(sp,"%d",cnt);
			ans+=sp;
			ans+=c;
			str=ans;
		}
		cout << str << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define all int i=0; i<n; i++
#define INF 9999999999999999
using namespace std;
typedef long long int ll; 
#define int ll    

int32_t main(){
	int h,ans=0,k=0;
	cin>>h;
	while(true){
		ans+= pow(2,k);
		if(h==1){
			break;
		}
		h/=2;
		k++;
	}
	
	cout<<ans<<endl;
	
}

Measured memory_bytes: 256
import java.util.Scanner;

 class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s=in.next();
        StringBuilder str=new StringBuilder();
        for(int i=0;i<s.length();i++){

            str.append('x');
        }
        System.out.println(str);
    }
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  string s, t; cin >> s >> t;
  int sn = s.size(), tn = t.size();
  VI sa(sn + 1), sb(sn + 1), ta(tn + 1), tb(tn + 1);
  for (int i = 0; i < sn; i++) {
    sa[i + 1] = sa[i] + (s[i] == 'A');
    sb[i + 1] = sb[i] + (s[i] == 'B');
  }
  for (int i = 0; i < tn; i++) {
    ta[i + 1] = ta[i] + (t[i] == 'A');
    tb[i + 1] = tb[i] + (t[i] == 'B');
  }
  int q; cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b, c, d; cin >> a >> b >> c >> d;
    a--; c--;
    int sd = (sa[b] - sa[a]) - (sb[b] - sb[a]);
    int td = (ta[d] - ta[c]) - (tb[d] - tb[c]);
    bool f = (sd - td) % 3 == 0;
    cout << (f ? "YES" : "NO") << '\n';
  }
  return 0;
}

Measured memory_bytes: 2512
package main

import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
"strings"
)


var err error
var inputReader *bufio.Reader
func main() {
	inputReader = bufio.NewReader(os.Stdin)
	var counterA, counterB int
	var input string
	input, err = inputReader.ReadString('\n')
	input = strings.Replace(input, "\n", "", -1)
	counterA, err = strconv.Atoi(input)
	//fmt.Scanf("%d",&temp)
	A := make([]int, counterA, 100000)
	for i := 0; i < counterA; i++ {
		if i == counterA-1 {
			input, err = inputReader.ReadString('\n')
			input = strings.Replace(input, "\n", "", -1)
			A[i], err = strconv.Atoi(input)
		} else {
			input, err = inputReader.ReadString(' ')
			input = strings.Replace(input, " ", "", -1)
			A[i], err = strconv.Atoi(input)
			//fmt.Scanf("%d",&A[i])
		}
	}
	if !sort.IsSorted(sort.IntSlice(A)){
		sort.Sort(sort.IntSlice(A))
	}
	input, err = inputReader.ReadString('\n')
	input = strings.Replace(input, "\n", "", -1)
	counterB, err = strconv.Atoi(input)
	//fmt.Scanf("%d",&temp)
	B := make([]int, counterB, 100000)
	for i := 0; i < counterB; i++ {
		if i == counterB-1 {
			input, err = inputReader.ReadString('\n')
			input = strings.Replace(input, "\n", "", -1)
			B[i], err = strconv.Atoi(input)
		} else {
			input, err = inputReader.ReadString(' ')
			input = strings.Replace(input, " ", "", -1)
			B[i], err = strconv.Atoi(input)
			//fmt.Scanf("%d",&A[i])
		}
	}
	if !sort.IsSorted(sort.IntSlice(B)){
		sort.Sort(sort.IntSlice(B))
	}
	binarysearch(A, counterA, B, counterB)

}
/*
type IntSlice []int
func (c IntSlice) Len() int{
	return len(c)
}
func (c IntSlice) Swap(i,j int) {
	c[i],c[j]=c[j],c[i]
}
func (c IntSlice) Less(i,j int) bool{
	return c[i]<c[j]
}*/
func binarysearch(A []int, cA int, B []int, cB int) {
	flag := 0
	for i := 0; i < cB; i++ {
			if findbybinary(A,0,cA-1,B[i])==1 {
				flag++
			}
	}
	fmt.Println(flag)
}
func findbybinary(arr []int,low,high,tar int) int{
	if low > high {
		return 0
	}
	mid := low + (high-low)/2

	if arr[mid] > tar {
		return findbybinary(arr, low, mid-1, tar)
	} else if arr[mid] < tar {
		return findbybinary(arr, mid+1, high, tar)
	}
	return 1
}


Measured memory_bytes: 5516
#include<stdio.h>

void calcNumberOfDigit(int num) {
	int count = 1;
	while(num/10 != 0) {
		count++;
		num /= 10;
	}
	printf("%d\n", count);
}

int main(void) {
	int i, a[200], b[200];
	while(scanf("%d %d",&a,&b)!=EOF) {
		calcNumberOfDigit(a[i] + b[i]);	
	}
	return 0;
} 

Measured memory_bytes: 600
N = int(input())
txylist = [[0,0,0]]
for i in range(N):
    txylist.append(list(map(int,input().split())))
can = True
for i in range(1,N+1):
    t = txylist[i][0]-txylist[i-1][0]
    x = txylist[i][1]-txylist[i-1][1]
    y = txylist[i][2]-txylist[i-1][2]
    if (x + y) % 2 == t % 2 and abs(x) + abs(y) <= t:
        continue
    else:
        can = False
        break
if can:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 27300
import java.io.*;

public class Main {
    public static void main(String[] args) {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        try {
            for(int i = 1; ; i++) {
                int x = Integer.parseInt(br.readLine());
                if(x == 0) {
                    break;
                }
                System.out.println("Case " + i + ": " + x);
            }
        } catch(IOException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 27160
#include<cstdint>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<iterator>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>
#include<utility>
#include<initializer_list>


#define repi(i,start,end)for(int64_t (i)=(start);(i)<(end);++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x, v) for(auto& (x) : (v))
#define iterate(itr, v) for(auto (itr)=(v).begin();(itr)!=(v).end();++(itr))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vin(v) rep(i,(v).size()) cin >> (v)[i];
#define vpin(v) rep(i,(v).size()) cin >> (v)[i].first >> (v)[i].second

using namespace std;
using Int = int64_t;
using pint = pair<Int, Int>;
using vint = vector<Int>;
using vvint = vector<vint>;
using vpint = vector<pint>;
using vstr = vector<string>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;  } return 0;  }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;  } return 0;  }
template<class T>void put_double(T a){cout<<setprecision(12);cout<<a<<"\n";}
template<class T>void println(T a){cout << a << "\n";}
template<class T>void put_line(T &v){iterate(itr,v){cout<<*itr<<((itr==--v.end())?"\n":" ");}}
// auto [x, y] = make_tuple(3, 4); => let (x, y) = (3, 4);
#define INF 1e+9
#define MAX_V 10

struct edge {
    int to;
    int cost;
};

// <最短距離, 頂点の番号>
using P = pair<int, int>;

int V;
vector<vector<edge>> G;
vint d;

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;

        for (int i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main(void) {
    int n, m;
    cin >> n >> m;
    V = n;
    d.resize(n);
    rep(i, n) d[i] = LLONG_MAX;
    G.resize(n);
    vector<P> ab(m); vpin(ab);
    vvint connect(n);
    rfor(p, ab) {
        auto [x, y] = p;
        x--; y--;
        G[x].push_back({y, 1});
        G[y].push_back({x, 1});
    }
    dijkstra(0);
    vint ans(n, -1);
    repi(i, 1, n) {
        int cost = d[i];
        cost--;
        rfor(c, G[i]) {
            //cout << c.to + 1 << " ";
            if(d[c.to] == cost) ans[i] = c.to + 1;
        }
        //println("");
    }
    //put_line(ans);
    int flag = 1;
    repi(i, 1, n) flag &= ans[i] != -1;
    if(flag) {
        println("Yes");
        repi(i, 1, n) println(ans[i]);
    } else {
        println("No");
    }

    return 0;
}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n, c;
	cin >> n >> c;
	vector<vector<int>> t(c, vector<int>(100001));
	for(int i = 0; i < n; i++) {
		int x, y, z;
		cin >> x >> y >> z;
		z--;
		t[z][x - 1]++;
		t[z][y]--;
	}
	for(int i = 0; i < c; i++) {
		for(int j = 1; j < 100001; j++) {
			t[i][j] = t[i][j - 1] + t[i][j];
		}
	}
	int ans = 0;
	for(int i = 0; i < 100001; i++) {
		int sum = 0;
		for(int j = 0; j < c; j++) {
			if(t[j][i] >= 1) {
				sum++;
			}
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
	return 0;	
}


Measured memory_bytes: 12416
import collections
import sys
sys.setrecursionlimit(2000000)
# import math
# import itertools
# import statistics
# import numpy as np
#n = int(input())
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a_count = collections.Counter(a)
a_list = list(a_count.items())
a_sorted = sorted(a_list, key=lambda x: x[1])
# print(a_sorted)
count = 0
for i in range(len(a_sorted)-k):
    count += a_sorted[i][1]

print(count)


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

int main(){
	while (1){
		int sum = 0;
		int n;
		int a_sum = 0;
		cin >> n;
		if (!n) return 0;
		for (int i = 0; i < n; i++){
			int a_num, b_num;
			cin >> a_num;
			cin >> b_num;

			if (a_num > b_num){
				a_sum += (a_num + b_num);
			}
			else if (a_num == b_num){
				a_sum += a_num;
			}
			sum += a_num + b_num;
		}

		cout << a_sum << " " << sum - a_sum << "\n";
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

struct UnionFind{
    vector<int> branch;
    UnionFind(int N = 0) : branch(N,-1){}

    int find(int x){
        if(branch[x] < 0) return x;
        else return branch[x] = find(branch[x]);//メモ化、要素を入れて根が返ってくる
    }

    bool unite(int x, int y){
        int rx,ry;
        rx = find(x);
        ry = find(y);
        if(rx == ry) return false;//連結できたかどうか
        if(-branch[rx] < -branch[ry]) swap(rx,ry);
        branch[rx] += branch[ry];//木のサイズを負の値で管理
        branch[ry] = rx;
        return true;
    }

    bool same(int x, int y){
        if(find(x) == find(y)) return true;
        else return false;
    }

    int size(int x){
        return -branch[find(x)];
    }
};

int main(){
    int n,m,k;
    cin >> n >> m >> k;
    UnionFind tree(n);
    map<int,int> fri,bro;
    for(int i = 0; i < m; i++){
        int a,b;
        cin >> a >> b;
        a--;b--;
        fri[a]++;
        fri[b]++;
        tree.unite(a,b);
    }
    for(int i = 0; i < k; i++){
        int c,d;
        cin >> c >> d;
        c--;d--;
        if(tree.same(c,d)){
            bro[c]++;bro[d]++;
        }
    }
    for(int i = 0; i < n; i++){
        cout << tree.size(i)-1-bro[i]-fri[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 13000
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;

public class Main {

	public static void main(String[] args) throws IOException {
      	long s = System.currentTimeMillis();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] inputs = br.readLine().split(" ");
		int N = Integer.parseInt(inputs[0]);

		int tb[][] = new int[N + 1][N]; // pのn番目の対戦相手 r = tb[p][n]  (1-origin 
		int pIdx[] = new int[N + 1];	// pの試合消化数 = pIdx[p]       同上

		// p:player  r:rival
		for ( int p = 1; p <= N; p++ ) {
			pIdx[p] = 1;

			inputs = br.readLine().split(" ");
			for ( int n = 1; n <= N - 1; n++ ) {
				int r = Integer.parseInt(inputs[n - 1]);
				tb[p][n] = r;
			}
		}

		int match = N * (N - 1) / 2;
		int days = 0;

		HashSet<Integer> todayDone = new HashSet<>(); // その日の試合が成立して除外された選手をここに入れる
		do {
          	// 嘘解法：時間がかかるケースは日数＝試合数と推測
			long e = System.currentTimeMillis();
			if(e - s > 600) {
				System.out.print(N * (N - 1) / 2);
				br.close();
				return;
			}
          
			days++;
			todayDone.clear();

			for ( int p = 1; p <= N; p++ ) {
				if ( todayDone.contains(p) || pIdx[p] >= N ) continue;

				int r = tb[p][pIdx[p]];
				if ( todayDone.contains(r) || pIdx[r] >= N ) continue;
				
				// pの「相手の相手」がpだったら試合成立
				int r_r = tb[r][pIdx[r]];				
				if ( p == r_r ) {
					todayDone.add(p);
					todayDone.add(r);
					pIdx[p]++;
					pIdx[r]++;
					match--;
				}
			}

		} while ( todayDone.size() > 0 );

		System.out.println(match == 0 ? days - 1 : -1);
		br.close();
	}
}


Measured memory_bytes: 97676
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

class UnionFind_weight:
    # 初期化
    def __init__(self, n):
        # 根なら-size, 子なら親の頂点
        self.par = [-1] * n
        # 木の高さ
        self.rank = [0] * n
        # 親との差分
        self.weight = [0] * n

    # 検索
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            p = self.par[x]  # 根につなぎ直す前の親をメモ
            self.par[x] = self.find(self.par[x])
            self.weight[x] += self.weight[p]
            return self.par[x]

    # 併合
    # x → y の重みを w とする。
    def unite(self, x, y, w):
        w += self.weight[x] - self.weight[y]
        x = self.find(x)
        y = self.find(y)
        if x != y:  # 異なる集合に属する場合のみ併合
            if self.rank[x] < self.rank[y]:  # 高い方をxとする。
                x,y = y,x
                w = -w
            if self.rank[x] == self.rank[y]:  # 同じ高さの時は高さ+1
                self.rank[x] += 1
            # yの親をxとし、xのサイズにyのサイズを加える。重みも更新。
            self.par[x] += self.par[y]
            self.par[y] = x
            self.weight[y] = w

    # 同集合判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # 集合の大きさ
    def size(self, x):
        return -self.par[self.find(x)]
    
    # x → y の重み
    def diff(self, x, y):
        return self.weight[y] - self.weight[x]

n,m = readints()

u = UnionFind_weight(n)

ans = 1
for i in range(m):
    l,r,d = readints()
    l-=1;r-=1
    if u.same(l,r):
        if u.diff(l,r) != d:
            ans = 0
            break
    else:
        u.unite(l,r,d)

print('Yes' if ans else 'No')






Measured memory_bytes: 84736