akhauriyash/Code-Regression huggingface dataset:
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

struct edge {
    int to, a, b;
};

using elem = tuple<ll, pil>; // cost, vertex (= vertex, count)
const int MAX_N = 50, MAX_A = 50;
int n, m, s;
vec<edge> g[MAX_N];
int c[MAX_N], d[MAX_N];
ll ans[MAX_N][MAX_N * MAX_A + 1];

pil vertex(int i, ll k) {
    return mp(i, min(k, 1LL * MAX_N * MAX_A));
}

int main() {
    fastio();

    cin >> n >> m >> s;
    forn(i, m) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--, v--;
        g[u].push_back((edge) { v, a, b });
        g[v].push_back((edge) { u, a, b });
    }
    forn(i, n) {
        cin >> c[i] >> d[i];
    }

    forn(i, MAX_N) forn(j, MAX_N * MAX_A + 1) {
        ans[i][j] = LLONG_MAX;
    }

    priority_queue<elem, vec<elem>, greater<elem>> q;
    auto u = vertex(0, s);
    q.emplace(0, u);
    ans[0][u.snd] = 0;

    while (!q.empty()) {
        auto [cost, v] = q.top();
        auto [x, k] = v;
        q.pop();

        if (cost > ans[x][k]) continue;

        auto u = vertex(x, k + c[x]);
        if (cost + d[x] < ans[x][u.snd]) {
            ans[x][u.snd] = cost + d[x];
            q.emplace(cost + d[x], u);
        }

        for (auto [y, a, b] : g[x]) {
            if (a <= k) {
                auto u = vertex(y, k - a);

                if (cost + b < ans[y][u.snd]) {
                    ans[y][u.snd] = cost + b;
                    q.emplace(cost + b, u);
                }
            }
        }
    }

    forn1(i, n - 1) {
        cout << *min_element(ans[i], ans[i] + MAX_N * MAX_A + 1) << "\n";
    }

    return 0;
}

Measured memory_bytes: 7376
X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
AB=[]
for i in range(len(A)):
    for j in range(len(B)):
        AB.append(A[i]+B[j])
AB.sort(reverse=True)

AB=AB[:min(3000,len(A)*len(B))]
ABC=[]
for i in range(len(AB)):
    for j in range(len(C)):
        ABC.append(AB[i]+C[j])

ABC.sort(reverse=True)

for i in range(K):
    print(ABC[i])

Measured memory_bytes: 147776
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>
#include <array>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main()
{
    string S;
    cin >> S;

    int Q;
    cin >> Q;

    int rev = 0;

    array<string, 2> str;

    for (int i = 0; i < Q; ++i) {
        int T;
        cin >> T;

        if (T == 1) {
            rev = 1 - rev;
        } else if (T == 2) {
            int F;
            char C;
            cin >> F >> C;
            --F;

            if (rev == 0) {
                str[F] += C;
            } else {
                str[1-F] += C;
            }
        }
    }

    string ans;

    if (rev == 0) {
        reverse(begin(str[0]), end(str[0]));

        ans += str[0];
        ans += S;
        ans += str[1];
    } else {
        reverse(begin(S), end(S));
        reverse(begin(str[1]), end(str[1]));

        ans += str[1];
        ans += S;
        ans += str[0];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1292
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

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

  std::unordered_set<int64_t> ds;
  for (auto _ : irange(0L, n)) {
    int64_t d;
    cin >> d;

    ds.insert(d);
  }

  cout << ds.size() << endl;
}


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

int	main()
{
	int	N;
	cin >> N;
	int64_t	sum = 0;
	for (int i = 1; i <= N; ++i) {
		if (i % 5 && i % 3)
			sum += i;
	}
	cout << sum << endl;
}


Measured memory_bytes: 3624
package main

import "fmt"

func main() {
	var s, t string
	fmt.Scanln(&s)
	fmt.Scanln(&t)

	fmt.Println(logic(s, t))
}

func logic(s, t string) int {
	count := 0
	for i, s := range s {
		if []rune(t)[i] == s {
			count++
		}
	}
	return count
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL)
    x=x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right!=NIL)
    x=x->right;
  return x;
}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key)
    return u;
  if(k<u->key)
    return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL)
    return treeMinimum(x->right);
  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL || z->right==NIL)
    y=z;
  else y=treeSuccessor(z);

  if(y->left!=NIL)
    x=y->left;
  else x=y->right;

  if(x!=NIL)
    x->parent=y->parent;

  if(y->parent==NIL)
    root=x;
  else if(y==y->parent->left)
    y->parent->left=x;
  else y->parent->right=x;

  if(y!=z)
    z->key=y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key)
      x=x->left;
    else x=x->right;
  }
  z->parent=y;

  if(y==NIL)root=z;
  else if(z->key<y->key)
    y->left=z;
  else y->right=z;
}

void inorder(Node u){
  if(u==NIL)
    return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)
    return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20452
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.nextLine();
        int n = scan.nextInt();
        for(int i = 0; i < n; i++){
            String cmd = scan.next();
            if(cmd.equals("print")){
                int l = scan.nextInt();
                int r = scan.nextInt();
                System.out.println(s.substring(l, r + 1));
            }
            if(cmd.equals("reverse")){
                int l = scan.nextInt();
                int r = scan.nextInt();
                String t = s;
                s = "";
                for(int j = 0; j < t.length(); j++){
                    if(l <= j && r >= j){
                        s += t.charAt(r - (j - l));
                    }
                    else s += t.charAt(j);
                }
            }
            if(cmd.equals("replace")){
                int l = scan.nextInt();
                int r = scan.nextInt();
                String p = scan.next();
                String t = s;
                s = "";
                for(int j = 0; j < t.length(); j++){
                    if(l <= j && r >= j){
                        s += p.charAt(j - l);
                    }
                    else s += t.charAt(j);
                }
            }
        }
    }
}



Measured memory_bytes: 93748
N = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors

ans = len(make_divisors(N-1)) - 1
#print(ans)

divisors = make_divisors(N)
def dfs(x,N):
    while N % x == 0:
        N //= x
#        print(N)
    N %= x
#    print(N)
    return N == 1

counta = 0
for i in range(1,len(divisors)):
    if dfs(divisors[i],N):
        counta += 1
#print(counta)
ans += counta

print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <stdint.h>

using namespace std;

int main()
{
  int64_t N, M;
  cin >> N >> M;

  for (int min=M/N; min>0; --min) {
    if (M%min==0) {
      cout << min << endl;
      break;
    }
  }
  
  return 0;
}


Measured memory_bytes: 384
import sys
N = int(input())
pyramids = [tuple(map(int,input().split())) for _ in range(N)]
for i in range(101):
  for j in range(101):
    H_set = set()
    keep = []
    for k in range(len(pyramids)):
      x,y,h = pyramids[k]
      if h == 0:
        keep.append((x,y))
        continue
      H_set.add(h + abs(x - j) + abs(y - i))
    if len(H_set) == 1:
      if len(keep) != 0:
        is_suitable = True
        for x,y in keep:
          if list(H_set)[0] - abs(j - x) - abs(i - y) > 0:
            is_suitable = False
            break
        if is_suitable:
          print(j,i,list(H_set)[0])
          sys.exit()
        else:
          continue
      else:
        print(j,i,list(H_set)[0])
        sys.exit()

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'

def main():
    N,K=mis()
    N %= K
    print(min(N, abs(K-N)))

main()







Measured memory_bytes: 5164
using System;

namespace APC001_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var xy = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            var x = xy[0];
            var y = xy[1];
            if (x % y == 0)
            {
                Console.WriteLine(-1);
            }
            else
            {
                for (var i = 2; i < int.MaxValue; i++)
                {
                    if (x * i % y != 0)
                    {
                        Console.WriteLine(x * i);
                        return;
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 13140
N,K=map(int,input().split())
listX=list()

while K>0:
    dk=int(input())
    listk=input().split()
    listX.extend(listk)
    K=K-1

listX=[int(s) for s in listX]
listN=list(range(N))
listN.append(N)
listN.remove(0)
listZ=list(set(listN)-set(listX))

L=str(len(listZ))
print(L)


Measured memory_bytes: 9516
package main

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

//•*¨*•.¸¸♪I/O•*¨*•.¸¸♪

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(a)
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer(make([]byte, 10000), 100000000)

	n := scanInt()
	k := scanInt()
	hs := scanInts(n)

	sort.Ints(hs)

	ans := int64(0)
	for i := 0; i < n; i++ {
		if k > 0 {
			k--
		} else {
			ans += int64(hs[n-1-i])
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 5120
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef pair<int,int> P;
typedef long long int lnt;
lnt n,x[100000],l,q,a[100000],b[100000];
lnt lca[20][100000];
const lnt INF=0xffffffffffff;
lnt aaa,bbb;
int main()
{
	cin>>n;
	for(lnt i=0;i<n;i++){
		cin>>x[i];
	}
	cin>>l>>q;
	for(lnt i=0;i<q;i++){
		cin>>aaa>>bbb;
		a[i]=min(aaa-1,bbb-1);
		b[i]=max(aaa-1,bbb-1);
	}
	for(lnt i=0;i<20;i++){
		for(lnt j=0;j<100000;j++) lca[i][j]=INF;
	}
	for(lnt i=0;i<n-1;i++){
		if(x[i]+l>=x[n-1]){
			lca[0][i]=n-1;
			continue;
		}
		lca[0][i]=upper_bound(x,x+n,x[i]+l)-x-1;
	}
	for(lnt i=1;i<20;i++){
		for(lnt j=0;j<n-1;j++){
			if(lca[i-1][j]!=INF) lca[i][j]=lca[i-1][lca[i-1][j]];
		}
	}
	lnt now,ans=0;
	for(lnt i=0;i<q;i++){
		ans=0;
		now=a[i];
		for(lnt soe=19;soe>=1;soe--){
			if(lca[soe][now]!=INF&&lca[soe][now]<b[i]){
				now=lca[soe][now];
				ans+=(1<<soe);
			}
		}
		while(now<b[i]){
			now=lca[0][now];
			ans++;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 18816
#include<stdio.h>
int main(void){
	int x,y,tmp=0;
	
	while(1){
		scanf("%d %d",&x,&y);
		if(x==0&&y==0){
			break;
		}
		if(x>y){
			tmp=x;
			x=y;
			y=tmp;
		}
		printf("%d %d\n",x,y);
	}
	return 0;
}

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

ll t, a, b, c, d;

void pr(int x) {
	if (x == 0)
		cout << "No\n";
	else
		cout << "Yes\n";
}

void doit() {
	cin >> a >> b >> c >> d;
	if (a < b) {
		pr(0);
		return;
	}
	if (d < b) {
		pr(0);
		return;
	}
	if (c >= b) {
		pr(1);
		return;
	}
	ll g = __gcd(b, d);
	//from a subtract g til less than b
	ll k = (a-b)/g+1;
	ll res = a-k*g;
	assert(res < b);
	if (res > c)
		pr(0);
	else
		pr(1);
	return;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> t;
	for (int i = 0; i < t; ++i)
		doit();
}

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

long long a[2 * 100000 + 5];

int main ()
{
    long long n, min_sum = 0; 
    cin >> n; 
    for(int i = 0; i < n; ++i)cin >> a[i];
    for (int i = 0; i < n - 1; ++i)
    {
        if (a[i] > a[i + 1])
        {
            min_sum += a[i] - a[i + 1];
            a[i + 1] += a[i] - a[i + 1];
        }
    }
    cout << min_sum << endl; 
}

Measured memory_bytes: 5188
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

int main() {
	int n;
	cin >> n;
	vector<bool> expo(n+1);
	expo[1] = true;
	for(int b=2; b*b<=n; b++){
		int v = b*b;
		while(v<=n){
			expo[v] = true;
			v*=b;
		}
	}
	for(int i=n; i>=1; i--){
		if(expo[i]){
			cout << i << endl;
			break;
		}
	}
 	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int W, H, N;
	int p = 0;
	int q = 0;
	cin >> W >> H >> N;

	for (int i = 0; i < N; i++) {
		int x, y, a;
		cin >> x >> y >> a;

		switch (a) {
		case 1:
			p = max(p, x);
			break;

		case 2:
			W = min(W, x);
			break;

		case 3:
			q = max(q, y);
			break;

		case 4:
			H = min(H, y);
			break;
		}
	}

	int S = 0;
	if (W > p&& H > q) {
		S = (W - p) * (H - q);
	}

	cout << S << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct edge{
    int to;
    ll cap;
    int rev; //逆辺のindex
};

const int MAX_V = 1e3;
vector<edge> es[MAX_V];
vector<bool> used(MAX_V, false);

//fromからtoに容量capの辺を張る
void add_edge(int from, int to, ll cap){
    edge e1 = {to, cap, sz(es[to])}, e2 = {from, 0, sz(es[from])};
    es[from].eb(e1), es[to].eb(e2);
}

//増加パスをdfsで探す
ll dfs(int now, int goal, ll flow){
    if(now == goal) return flow;
    used[now] = true;
    for(auto &e: es[now]){
        if(!used[e.to] && e.cap > 0){
            ll f = dfs(e.to, goal, min(flow, e.cap));
            if(f > 0){
                e.cap -= f;
                es[e.to][e.rev].cap += f;
                return f;
            }
        }
    }
    return 0;
}

ll max_flow(int s, int t){
    ll flow = 0;
    while(true){
        fill(all(used), false);
        ll f = dfs(s, t, INF);
        if(f == 0) break;
        flow += f;
    }
    return flow;
}

int main(){
    int N;
    cin >> N;
    int MAX = 1e7;
    vector<int> a(MAX+2, 0);
    rep(i, N){
        int x; cin >> x;
        a[x] = 1;
    }
    vector<int> od, ev;
    rep(i, MAX+1){
        if(a[i]^a[i+1]){
            if(i&1) od.pb(i);
            else ev.pb(i);
        } 
    }
    int n = sz(od), m = sz(ev), s = n+m, t = n+m+1;
    rep(i, n) add_edge(s, i, 1);
    rep(i, m) add_edge(n+i, t, 1);
    rep(i, n) rep(j, m){
        int d = abs(od[i]-ev[j]);
        bool p = (d != 1);
        for(int k = 2; k*k <= d; k++){
            if(d%k == 0) p = false;
        }
        if(p) add_edge(i, n+j, 1);
    }
    int f = max_flow(s, t);
    cout << n+m-f+(n-f)%2 << endl;
}

Measured memory_bytes: 39680
#include <stdio.h>
#include <string.h>
#define LEN 100005
 
typedef struct pp {
  char name[100];
  int t;
} P;
 
P Q[LEN];
int head, tail, n;
 
void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}
 
P dequeue() {
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}
 
int min(int a,int b) {
  return a < b ? a : b; 
}
 
int main() {
  int elaps = 0, c;
  int i, q;
  P u;
  char str[64];
  
  scanf("%d %d",&n ,&q);
  for(i=1; i<=n; i++) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1; tail = n + 1;
 
  while(head != tail) {
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0) enqueue(u);
    else {
      printf("%s %d\n",u.name,elaps);
    }
  }
  return 0;
}

Measured memory_bytes: 10756
#include <bits/stdc++.h>
#define ll long long
#define ld long double 
#define For(i, a, n) for(long long i = a; (a < n) ? (i < n) : (i > n); (a < n) ? (i++) : (i--))
#define ee 1000000007
#define pb push_back
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
using namespace std;


void solve() {
    string s, d;
    cin >> s >> d;
    ll ans = 100000000, c = 0;
    For(i, 0, s.size() - d.size() + 1) {
        For(j, 0, d.size()) {
            if(s[i + j] != d[j])
                c++;
        }
        ans = min(ans, c);
        c = 0;
    }
    cout << ans << "\n";
}

int main() {
    fio;
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
}

Measured memory_bytes: 3644
/*
author: Apoorv Singh
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;

typedef vector <int> vi;
typedef vector <long long> vl;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define ll long long
#define pb push_back   
#define all(c) c.begin(), c.end()
#define watch(x) cout << (#x) << " " << (x) << endl;
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second

ll modulo = 1e9 + 7;

template <class X>

void printarr(X arr[], int n)
{
    for (int i = 0; i < n; ++i)
        cout << arr[i] << " ";
    cout << endl;
}

ll fpow(ll a, ll n)
{
    ll ans = 1;
    while (n)
    {
        if (n&1)
            ans = (ans * a)%modulo;
        a = (a*a)%modulo;
        n = n >> 1;
    }
    return ans;
}

/*
const int M = 1e6 + 10;
int composite[M] = {0};

void sieve()
{
    FOR(i,2,M)
    {
        if (!composite[i])
        {
            for (int j = 2*i; j < M; j += i)
                composite[j] = max(composite[j], i);
        }
    }
}
*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b;
    int k;
    cin >> a >> b >> k;
    int turn = 0;
    FOR(i,0,k)
    {
    	if (turn == 0)
    	{
    		b += a/2;
    		a /= 2;
    		turn = 1;
    	}
    	else
    	{
    		a += b/2;
    		b /= 2;
    		turn = 0;
    	}
    }
    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N,D;
    cin >> N >> D;
    int ans=N/(2*D+1);
  	if (N%(2*D+1)) ans++;
  	cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
from scipy.sparse.csgraph import floyd_warshall
import numpy as np

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

D = np.ones([N, N]) * np.inf
D[np.eye(N, dtype=bool)] = 0

for _ in range(M):
  A, B, C = map(int, input().split())
  D[A-1, B-1] = C
  D[B-1, A-1] = C

D = floyd_warshall(D)
D2 = (D<=L)*1.0 # boolean -> float
D2[D2==0] = np.inf
# D2 = (D <= L) + (D > L)*np.inf

D2 = floyd_warshall(D2) - 1

Q = int(input())
for _ in range(Q):
  s, t = map(int, input().split())
  r = D2[s-1, t-1]
  if r < np.inf:
    print(int(r))
  else:
    print(-1)

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

using LL = long long;

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

    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<int>> m(h, vector<int>(w, 0));
    int x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--, x2--, y1--, y2--;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            char x;
            cin >> x;
            if (x == '@') {
                m[i][j] = -1;
            }
        }
    }

    queue<pair<int, int>> que;
    int dx[]{-1, 1, 0, 0};
    int dy[]{0, 0, 1, -1};
    m[x1][y1] = 1;
    que.emplace(x1, y1);
    while (!que.empty()) {
        auto [x, y] = que.front();
        que.pop();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= k; j++) {
                int xx = dx[i] * j + x, yy = dy[i] * j + y;
                if (xx < 0 || yy < 0 || xx >= h || yy >= w) break;
                if (m[xx][yy]) {
                    if (m[x][y] + 1 != m[xx][yy]) break;  else continue;
                }
                m[xx][yy] = m[x][y] + 1;
                que.emplace(xx, yy);
                // cerr << "(" << xx << ", " << yy << ") " << m[xx][yy] << ' ' << m[x][y] << endl;
            }
        }
    }
    int ans = m[x2][y2];
    if (~m[x2][y2]) {
        ans--;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int zz=1 ; zz<=t ; zz++)
#define PRINT_CASE printf("Case %d: ",zz)
#define Debug(x)            cout<<#x " = "<<(x)<<endl

const int maxn = (int)3e5+5;
typedef long long ll;


void solve(){
   int n, k, tot=0;
   cin >> n >> k;
   vector < int > v(n);
   for(int i=0 ; i<n ; i++) cin >> v[i];
   sort(v.begin(), v.end());
   for(int i=0; i<k; i++){
      tot+=v[i];
   }
   cout << tot << endl;
}

int main()
{
    CIN
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    //cout << "Fi Amanillah" << endl;


    int t=1;
    // cin >> t;

    while(t--){
      solve();
    }
    return 0;
}



Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define endl '\n'
#include <math.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin>>N;
    set<string> _set;
    for(int i = 0; i < N; i++) {
        string s;
        cin>>s;
        _set.insert(s);

    }
    cout<<_set.size()<<endl;
    return 0;
}




Measured memory_bytes: 19200
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();

    switch (s) {
    case "Sunny":
      System.out.println("Cloudy");
      break;

    case "Cloudy":
      System.out.println("Rainy");
      break;

    case "Rainy":
      System.out.println("Sunny");
      break;
    }

  }
}

Measured memory_bytes: 35728
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	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;
	}
}

// 二項係数計算
long long 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;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	long long int n;
	cin >> n;
	int s[1002] = {};
	long long int sum[1002] = {};
	for (int i = 2; i <= 1000; i++) {
		if (s[i] == 0) {
			for (int j = i; j <= 1000; j = j + i) {
				s[j] = 1;
			}
		}
	}

	for (int i = 2; i <= n; i++) {
		long long int t = i;
		for (int j = 2; j <= n; j++) {
			if (s[j] == 1) {
				while (t % j == 0) {
					t = t / j;
					sum[j] = sum[j] + 1;
				}
			}
		}
	}
	long long int ans = 1;
	for (int i = 2; i <= 1000; i++) {
		if (sum[i] != 0) {
			ans = ans * (sum[i] + 1);
			ans = ans % MOD;
		}
	}
	cout << ans;
}

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

using namespace std;

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

  int N, K;

  cin >> N >> K;
  int count = 0;
  for (int i = 1; i <= N; ++i) {
    int hi;
    cin >> hi;
    if (hi >= K) {
      ++count;
    }
  }

  cout << count << endl;
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int a[100][100],b[100][100];
bitset<30000>dp[82][82];

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

int main(){
	int h,w;cin>>h>>w;
	rep(i,h)rep(j,w)scanf("%d",&a[i][j]);
	rep(i,h)rep(j,w)scanf("%d",&b[i][j]),a[i][j]-=b[i][j],a[i][j]=abs(a[i][j]);
	int K=15000;
	dp[0][0][K+a[0][0]]=1;
	dp[0][0][K-a[0][0]]=1;
	rep(i,h)rep(j,w){
		if(i+1<h){
			dp[i+1][j]|=dp[i][j]<<a[i+1][j];
			dp[i+1][j]|=dp[i][j]>>a[i+1][j];
		}
		if(j+1<w){
			dp[i][j+1]|=dp[i][j]<<a[i][j+1];
			dp[i][j+1]|=dp[i][j]>>a[i][j+1];
		}
	}
	int Min=INT_MAX;
	rep(i,30000){
		if(dp[h-1][w-1][i]==1)Min=min(Min,abs(i-K));
	}
	cout<<Min<<endl;
}

Measured memory_bytes: 24832
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include<algorithm>
#include <set>
#include <stack>
#include <stdlib.h>

using namespace std;

int main()
{
    int long long a,z,p=0;
    char arr[27];
    char arr1[30];
    cin>>a;
    for(int i=1;i<26;i++)
    {
        arr[i]=char(i+96);
    }
    arr[0]='z';
    while(a!=0)
    {
        arr1[p++]=arr[a%26];
        z=a%26;
        if(z==0)
            z=26;
        a-=z;
        a/=26;
    }

    for(int i=p-1;i>=0;i--)
        cout<<arr1[i];
    return 0;
}

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

class BitArrayEntry {
public:
    BitArrayEntry(uint8_t *value, const uint8_t offset):
    value(value),
    offset(offset) {}

    BitArrayEntry & operator = (const uint8_t bit) {
        const uint8_t mask = 1 << offset;
        if(bit) {
            *value |= mask;
        } else {
            *value &= ~mask;
        }
        return *this;
    }

    operator uint8_t () {
        return (*value >> offset) & 1;
    }

private:
    uint8_t *value;
    uint8_t offset;
};

class BitArray {
public:
    BitArray(const uint64_t size, const uint8_t value):
    bits((size + 7) / 8, value),
    length(size) {

    }

    BitArrayEntry operator [] (const uint64_t x) {
        return BitArrayEntry(&bits[x / 8], x % 8);
    }

    uint64_t size() const {
        return length;
    }

private:
    std::vector<uint8_t> bits;
    uint64_t length;
};

int main() {
    uint64_t x;
    std::cin >> x;

    if(x == 2) {
        std::cout << 2 << std::endl;
        return 0;
    }

    auto bits = BitArray(2 * x, static_cast<uint8_t>(0xff));

    const auto max = std::sqrt(2 * x);

    for(int i = 2; i <= max; ++i) {
        for(uint64_t j = i; j < 2 * x; j += i) {
            bits[j] = 0;
        }
    }

    for(uint64_t i = x; i < 2 * x; ++i) {
        if(bits[i]) {
            std::cout << i << std::endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{

      int a,b,c;
      cin>>a>>b>>c;
      if(a*c<=b)
        cout<<c<<endl;
      else if(b<a)
        cout<<'0'<<endl;
      else
        cout<<b/a<<endl;
        return 0;
}


Measured memory_bytes: 256
def permutation(n, k, mod):
    if n < k or k < 0:
        return 0
    s = 1
    for _ in range(k):
        s *= n
        s %= mod
        n -= 1
    return s

n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mod = pow(10, 9) + 7
a.sort(reverse = True)
b.sort(reverse = True)
a.append(0)
b.append(0)
now = n * m
ok, unknown = 0, 0
i, j = 0, 0
ans = 1 if a[0] == b[0] == now else 0
while not (i == n and j == m):
    unknown = now - max(a[i], b[j])
    now = max(a[i], b[j]) - 1
    ans *= permutation(i * j - ok, unknown, mod)
    ans %= mod
    ok += 1
    if a[i] == b[j]:
        i += 1
        j += 1
    elif a[i] > b[j]:
        i += 1
        ans *= j
        ans %= mod
    else:
        j += 1
        ans *= i
        ans %= mod
    ok += unknown
    unknown = 0
ans *= permutation(now, now, mod)
ans %= mod
print(ans)

Measured memory_bytes: 9324
using System;

public class Test
{
	static public void Main( )
	{
		int n = int.Parse( Console.ReadLine() );
		string[] strs = Console.ReadLine().Split( ' ' );
		string[] nstrs = new string[n];
		for( int i=0; i<n; i++ ) {
			nstrs[i] = strs[n-i-1];
		}
		//Array.Reverse( strs );
		Console.WriteLine( String.Join( " ", nstrs ) );
	}
}

Measured memory_bytes: 5328
#include<iostream> 
#include<string>
using namespace std; 
 
int main ()
{
  int x,y;
  cin>>x>>y;
  if(((x==1)||(x==3)||(x==5)||(x==7)||(x==8)||(x==10)||(x==12))&&((y==1)||(y==3)||(y==5)||(y==7)||(y==8)||(y==10)||(y==12)))
  {
      cout<<"Yes\n";
  }
  else if (((x==4)||(x==6)||(x==9)||(x==11))&&((y==4)||(y==6)||(y==9)||(y==11)))
  {
      cout<<"Yes\n";
  }
  else if ((x==2)&&(y==2))
  {
            cout<<"Yes\n";
 
  }
  else
  {
      cout<<"No\n";
  }
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N; cin >> N;
    vector<int> P(N, 0);
    for (int i = 0; i < N; ++i) cin >> P[i];
    vector<int> copy(N, 0);
    for (int i = 0; i < N; ++i) copy[i] = P[i];
    sort(copy.begin(), copy.end());
    int cnt = 0;
    for (int i = 0; i < N; ++i) {
        if (cnt > 2) {
            printf("%s\n", "NO");
            return 0;
        }
        if (copy[i] != P[i]) cnt++;
    }
    printf("%s\n", "YES");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  int N; cin >> N;
  string s;
  map<char,int> c;
  rep(i,N){
    cin >> s;
    if (s[0]=='M' || s[0]=='A' || s[0]=='R'|| s[0]=='C' || s[0]=='H') c[s[0]]++;
  }
  ll retval = 0;
  string march = "MARCH";

  for (int tmp=0;tmp<(1<<5);tmp++){
    bitset<5> s(tmp);
    if (s.count()!=3) continue;
    
    ll cnt = 1;
    rep(i,5){
      if (s.test(i)) cnt *= c[march[i]]; 
    }
    retval += cnt;
  }

  cout << retval << endl;




  // cout << fixed << setprecision(10);
  
  return 0;
}



Measured memory_bytes: 3576
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] num = new int[45];
		num[0] = 1;
		num[1] = 1;
		for(int i = 2; i <= n ; i++) {
				num[i] = num[i -1] + num[i -2];
		}
		int a = num[n];
		System.out.println(a);
	}
}


Measured memory_bytes: 26196
#include <vector>
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<vector<int>> abc(N, vector<int>(3));  // 多次元配列 
    for (int i = 0; i < N; i++) cin >> abc[i][0] >> abc[i][1] >> abc[i][2];
    vector<vector<int>> dp(N, vector<int>(3)); 
    dp[0] = {abc[0][0], abc[0][1], abc[0][2]};
    for (int i = 1; i < N; i++) {
        dp[i] = {abc[i][0]+max(dp[i-1][1], dp[i-1][2]), abc[i][1]+max(dp[i-1][0], dp[i-1][2]), abc[i][2]+max(dp[i-1][0], dp[i-1][1])};
    }
    cout << *max_element(dp[N-1].begin(), dp[N-1].end()) << endl;
    return 0; 
}

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

int main()
{
    long long s, c;
    scanf("%lld%lld", &s, &c);
    if(2*s>=c)
    {
        printf("%lld\n", c/2);
    }
    else
    {
        printf("%lld", (c-2*s)/4+s);
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

char muki[300100];
int hidari[300100]; // i番目をリーダーにしたとき、それより左で並び替えないといけないひと
int migi[300100];

#define FOR(var,start,end) for(int var=start; var<end; var++)
#define REP(var,cnt) FOR(var,0,cnt)

int main(void) {
	int N;
	cin >> N;
	
	REP(i, N) {
		char c;
		cin >> c;
		if ( c != 'E' && c != 'W' ) {
			i--;
			continue;
		}
		muki[i] = c;
	}
	
	hidari[0] = 0;
	for(int i=1; i<N; i++) {
		hidari[i] = hidari[i-1];
		if ( muki[i-1] == 'W' ) {
			hidari[i]++;
		}
	}
	
	migi[N-1] = 0;
	for(int i=(N-2); i>=0; i--) {
		migi[i] = migi[i+1];
		if ( muki[i+1] == 'E' ) {
			migi[i]++;
		}
	}
	
	int maxret = N;
	REP(i, N) {
		maxret = min(maxret, hidari[i]+migi[i]);
	}
	
	cout << maxret << endl;
}


Measured memory_bytes: 2944
# vim: set fileencoding=utf-8:


def main():
    n = raw_input()
    ans = ""
    for i, alp in enumerate(n):
        if alp == "1":
            ans += "9"
        elif alp == "9":
            ans += "1"
        else:
            ans += alp

    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

int main(){
    long long int N,M,R,ans=0;
    cin >> N >> M >> R;
    vector<int> r(R);

    for(int i=0;i<R;i++){
        cin >> r[i];
        r[i]--;
    }

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

    long long int d[N][N];

    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(i==j){
                d[i][j] = 0;
            }else{
                d[i][j] = 1e9;
            }
        }
    }

    for(int i=0;i<M;i++){
        int a,b,t;
        cin >> a >> b >> t;
        a--;
        b--;
        d[a][b] = t;
        d[b][a] = t;
    }

    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            for(int k=0;k<N;k++){
                d[j][k] = min(d[j][k],d[j][i]+d[i][k]);
            }
        }
    }

    do{
        long long int tmp = 0;
        for(int i=1;i<R;i++){
            tmp += d[r[i-1]][r[i]];
        }
        
        if(ans==0){
            ans = tmp;
        }else{
            ans = min(ans,tmp);
        }
    }while(next_permutation(r.begin(),r.end()));

    cout << ans << endl;
}

Measured memory_bytes: 512
using System;

public class Program
{
    static string s;

    static string output;

    public static void Main(string[] args)
    {
        Input();
        Proc();
        Output();
    }

    static void Input()
    {
        string[] input = null;

        // スペース区切りの整数の入力
        input = Console.ReadLine().Split(' ');
        s = input[0];
    }

    static void Proc()
    {
        string[] weather = { "Sunny", "Cloudy", "Rainy" };

        for (long idx = 0; idx < weather.Length; idx++)
        {
            if (s.Equals(weather[idx]))
            {
                output = weather[(idx + 1) % 3];
                break;
            }
        }
        
    }

    static void Output()
    {
        //出力
        Console.WriteLine(output);
    }
}

Measured memory_bytes: 11092
#include<cstdio>
#include<cstring>
#define N 105
using namespace std;
int n,o_t[N];
int ans;
bool line[N][N],f[N];
struct node
{
	int x;int y;
}red[N];

struct node blue[N]; 

void read()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d %d",&red[i].x,&red[i].y);
	for(int i=1;i<=n;i++)
		scanf("%d %d",&blue[i].x,&blue[i].y);
}
int PD(int x)
{
	for(int j=1;j<=n;j++)
	{
		if(line[x][j]&&!f[j])
		{
			f[j]=1;
			if(o_t[j]==0||PD(o_t[j]))
			{
				o_t[j]=x;
				return 1;
			}
		}
	}
	return 0;
}
int main()
{
	read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			if(red[i].x<blue[j].x&&red[i].y<blue[j].y)
			line[i][j]=1;
		}
	for(int i=1;i<=n;i++)
	{
		memset(f,0,sizeof f);
		if(PD(i)) ans++;
	}
	printf("%d",ans);
 } 

Measured memory_bytes: 504
n=int(input())
h=list(map(int,input().split()))

ans=min(h)
for i in range(n):
    h[i] -= ans

while sum(h)!=0:
    i=0
    crnt = h[i]
    while crnt==0:
        i+=1
        crnt=h[i]
    s=i
    while i<(n-1) and h[i]!=0:
        crnt = min(crnt, h[i])
        i+=1
    for ii in range(s, i+1):
        h[ii] = max(0, h[ii]-crnt)
    ans+=crnt

print(ans)

Measured memory_bytes: 3064
// Problem : A - We Love Golf
// Contest : AtCoder - AtCoder Beginner Contest 165
// URL : https://atcoder.jp/contests/abc165/tasks/abc165_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;

signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int k;
		cin>>k;
		int a,b;
		cin>>a>>b;
		for(int i=a;i<=b;++i)
		{
			if(i%k==0)
			{
				cout<<"OK";
				return 0;
			}
		}
		cout<<"NG";    	
    }
    return 0;
}



Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>

using namespace std;

int main() {
    double h, w, x, y;
    cin >> h >> w >> x >> y;
   int p = 0 ;
    if (x == h / 2.0 && y == w / 2.0) p=1;
    cout << h * w / 2.0 << " " << p << endl;
    return 0;

 }
    
        

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

int cnt[N],n;

int main(){
	cin>>n;
	for(int i=1;i<=100;i++)
		for(int j=1;j<=100;j++)
			for(int k=1;k<=100;k++)
				cnt[i*i+j*j+k*k+i*j+j*k+k*i]++;
	for(int i=1;i<=n;i++)cout<<cnt[i]<<'\n';
}

Measured memory_bytes: 3852
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		scanner.useDelimiter("[\\n,]");
		
		int input1, input2, ansSita = 0;
		double ansX = 0, ansY = 0;
		while(true){
			input1 = scanner.nextInt();
			input2 = scanner.nextInt();
			if(input1 == 0 && input2 == 0){
				break;
			}
			ansX = ansX + ((double)input1*Math.sin((ansSita*Math.PI)/180));
			ansY = ansY + ((double)input1*Math.cos((ansSita*Math.PI)/180));
			ansSita = (ansSita + input2);
		}
		System.out.println((int)ansX);
		System.out.println((int)ansY);
	}
}

Measured memory_bytes: 15348
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L
const int mxN = 2e2;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (c * b >= a) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    return 0;
}

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

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	

	REP(i, n) {
		cin >> v[i];
	}
	vector<int> copy(v);
	SORT(v);
	int b = v[n / 2];
	int a = v[n / 2 - 1];

	REP(i, n) {
		if (copy[i] <= a) {
			cout << b << endl;
		}
		else if (copy[i] >= b) {
			cout << a << endl;
		}

	}
	

	return 0;
}



Measured memory_bytes: 3712
n = int(input())
hs = list(map(int, input().split(' ')))


dp = [0] * (n + 1)

for i in range(1, n):
    if hs[i] <= hs[i - 1]:
        dp[i] = dp[i - 1] + 1
    else:
        dp[i] = 0
        
print(max(dp))



Measured memory_bytes: 63708
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define vec vector
#define pb push_back
#define s(x) scanf("%d",&x)
#define all(x)	x.begin(),x.end()
#define pii pair<int,int>
#define fi first
#define se second
#define mod 1000000007
#define SZ 200005
#define endl "\n"
#define trc(x) cerr << #x << ": " << x << endl
#define trcc(x,y) cerr << #x << ": " << x << endl << #y << ": " << y << endl << endl
#define boost ios::sync_with_stdio(0);cin.tie(0)

int n, m, k, x,d;



void purple18()
{
	cin >> x >> k >> d;
	x = abs(x);

	int steps = x/d;
	// trc(steps);
	if(steps >= k) { 
		cout << abs(x - k*d) << endl;
	}
	else {
		k-=steps;
		if(k%2==0)
		cout << abs(x-steps*d);
		else
		{
			cout << abs(x-(steps+1)*d) <<endl;
		}
		
		// cout << min(abs(x-steps*d), abs()) << endl;
	}
	



}




signed main() {
	boost;
	int t=1;
	// cin>>t;
	while(t--) purple18();
}

Measured memory_bytes: 3640
import fractions
from functools import reduce
def main():
    n,x = map(int, input().split())
    X = list(map(int,input().split()))

    array = []
    for i in range(len(X)):
        array.append(abs(X[i]-x))
    gcd1 = reduce(lambda a,b: fractions.gcd(a,b), array)
    print(gcd1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 88852
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll x,k;
  cin >> k >> x;
  if(k*500>=x) pr("Yes");
  else pr("No");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

int main()
{
  string A;
  cin >> A;
  long long ans = 1;
  vector<long long> count(30);
  rep(i, A.size())
  {
    ans += (i - count[A[i] - 'a']);
    count[A[i] - 'a']++;
  }
  cout << ans << endl;
  return 0;
}

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

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

    int a,b,c;
    cin>>a>>b>>c;
    int e=0;
    if(a%2==0) e++;
    if(b%2==0) e++;
    if(c%2==0) e++;
    bool hom=true;
    if(e>=2) hom=false;
    if(hom){
        cout<<"Hom"<<endl;
    }
    else cout<<"Tem"<<endl;
}



Measured memory_bytes: 3236