akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, k int
	fmt.Fscan(r, &n)
	fmt.Fscan(r, &k)

	ans := min(n%k, abs(n%k-k))
	fmt.Println(ans)

}

// Union-Find
type unionFind struct {
	d []int
}

func newUnionFind(n int) *unionFind {
	uf := new(unionFind)
	uf.d = make([]int, n)
	for i := 0; i < n; i++ {
		uf.d[i] = -1
	}
	return uf
}

func (uf *unionFind) find(x int) int {
	if uf.d[x] < 0 {
		return x
	}
	uf.d[x] = uf.find(uf.d[x])
	return uf.d[x]
}

func (uf *unionFind) unite(x, y int) bool {
	rootX := uf.find(x)
	rootY := uf.find(y)
	if rootX == rootY {
		return false
	}

	if uf.d[rootX] < uf.d[rootY] {
		uf.d[rootX] += uf.d[rootY]
		uf.d[rootY] = rootX
	} else {
		uf.d[rootY] += uf.d[rootX]
		uf.d[rootX] = rootY
	}

	return true
}

func (uf *unionFind) same(x, y int) bool {
	return uf.find(x) == uf.find(y)
}

func (uf *unionFind) size(x int) int {
	return -uf.d[uf.find(x)]
}

// mod combination
func modpow(a, n, mod int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % mod
		}
		a = a * a % mod
		n = n / 2
	}
	return res
}

func modcomb(n, a, mod int) int {
	x := 1
	y := 1
	for i := 0; i < a; i++ {
		x = x * (n - i)
		x %= mod
		y = y * (i + 1)
		y %= mod
	}
	return x * modpow(y, mod-2, mod) % mod
}

func modfactorial(n, mod int) int {
	result := 1
	for i := 1; i <= n; i++ {
		result = (result * i) % mod
	}
	return result
}

// Utility

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func primeFactor(x int) map[int]int {
	res := make(map[int]int)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			res[i]++
			x = x / i
		}
	}
	if x != 1 {
		res[x] = 1
	}
	return res
}

func divisor(x int) []int {
	res := make([]int, 0)
	for i := 1; i*i <= x; i++ {
		if x%i == 0 {
			res = append(res, i)
			if i != x/i {
				res = append(res, x/i)
			}
		}
	}
	return res
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
	return x / gcd(x, y) * y
}

func reverseString(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

// Queue ...
type Queue []int

// pop ...
func (q *Queue) empty() bool {
	return len(*q) == 0
}

// push ...
func (q *Queue) push(i int) {
	*q = append(*q, i)
}

// pop ...
func (q *Queue) pop() (int, bool) {
	if q.empty() {
		return 0, false
	} else {
		res := (*q)[0]
		*q = (*q)[1:]
		return res, true
	}
}

// Stack ...
type Stack []int

// pop ...
func (s *Stack) empty() bool {
	return len(*s) == 0
}

// push ...
func (s *Stack) push(i int) {
	*s = append(*s, i)
}

// pop ...
func (s *Stack) pop() (int, bool) {
	if s.empty() {
		return 0, false
	} else {
		index := len(*s) - 1
		res := (*s)[index]
		*s = (*s)[:index]
		return res, true
	}
}


Measured memory_bytes: 640
# DPL_1_A - コイン問題　

import sys

N, M = map(int, sys.stdin.readline().strip().split())  # N払う　コイン種類M 枚
c = list(map(int, sys.stdin.readline().strip().split()))

# dp 初期化
dp = [[float('inf')] * (N + 1) for _ in range(M + 1)]
for i in range(len(dp)):
    dp[i][0] = 0


for m in range(M):
    for n in range(N + 1):
        dp[m + 1][n] = min(dp[m + 1][n], dp[m][n])
        next_n = n + c[m]
        if next_n <= N:
            dp[m + 1][next_n] = min(dp[m + 1][n] + 1, dp[m][next_n])


# for i in range(len(dp)):
#     print(dp[i])

print(dp[-1][-1])



Measured memory_bytes: 43732
/*
    author : Divyansh Gupta
*/

#include <iostream>
#include <iomanip>
#include <cstring>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <climits>

using namespace std;

void print_err() {
	cerr<<"\n";
}

template <class T,class... Arg>
void print_err(T x,Arg&&... args) {
	cerr<<x<<" ";
	print_err(args...);
}

#ifdef local
#define debug(...) print_err(__VA_ARGS__)
#else
#define debug(...)
#endif

#define test_case int test_cases;\
                cin>>test_cases;\
                while(test_cases--)
#define lu(var,l,r) for(var=l;var<r;var++)
#define ld(var,r,l) for(var=r;var>=l;var--)
#define ll long long
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int> >
#define vll vector<ll>
#define vvll vector<vector<ll> >;               	
#define pii pair<int,int>                	
#define br cout<<"\n"
#define sp cout<<" "
#define pr cout<<
#define in cin>>
#define f first
#define s second                    
#define mod 1000000007

ll match(vvi &dp,int A[][22],int mask,int n,int flag,int N) {
	if(n == 0 && mask == flag)
		return 1;
	if(n == 0 || mask == flag)
		return 0;
	if(dp[n][mask] != -1)
		return dp[n][mask];
	ll ans = 0;
	int i;
	lu(i , 1 , N + 1) {
		if(A[n][i] == 1 && (1 << (i - 1) & mask) == 0){
			ans = (ans + match(dp,A,mask | 1 << (i - 1),n - 1 , flag,N)) % mod;
		}
	}
	return dp[n][mask] = ans;
}
            
void solve(){
	int n,i,j,A[22][22];
	vvi dp(22,vi(1<<22,-1));
	in n;
	lu(i , 1 , n + 1) {
		lu(j , 1 , n + 1) {
			in A[i][j];
		}
	}
	pr match(dp,A,0,n,(1 << n) - 1,n) % mod;
	br;
}

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

Measured memory_bytes: 377216
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=100005;
inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
int n;
vector<int>adj[N];
int fa[N],dis[N];
int dfs(int u)
{
	dis[u]=dis[fa[u]]+1;
	int mxd=u,nmxd;
	for(int i=0;i<adj[u].size();i++)
	{
		int v=adj[u][i];
		if(v==fa[u])continue;
		fa[v]=u;
		nmxd=dfs(v);
		if(dis[mxd]<dis[nmxd])mxd=nmxd;
	}
	return mxd;
}
int vis[N],d[N],num,deg[N];
int q[N],p,now,ans[N];
int main()
{
	n=read();
	int u,v;
	for(int i=1;i<n;i++)
	{
		u=read();v=read();
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	int s,t;
	fa[1]=0;dis[1]=0;s=dfs(1);
	fa[s]=0;dis[s]=0;t=dfs(s);
	for(;t;t=fa[t]){
		vis[t]=1;d[++num]=t;
	}
	for(int i=1;i<=n;i++)
	{
		if(vis[i])continue;
		int pas=0;
		for(int k=0;k<adj[i].size();k++)
		{
			int v=adj[i][k];
			if(vis[v]){
				pas=1;deg[v]++;
			}
		}
		if(!pas){
			puts("-1");
			return 0;
		}
	}
	
	p=0,now=1;
	for(int i=1;i<=num;i++)
	{
		for(int j=1;j<=deg[d[i]];j++)
			q[++p]=now+j;
		q[++p]=now;
		now=now+deg[d[i]]+1;
	}
	
	for(int i=1;i<=n;i++)ans[i]=q[i];
	
	p=0,now=1;
	for(int i=num;i>=1;i--)
	{
		for(int j=1;j<=deg[d[i]];j++)
			q[++p]=now+j;
		q[++p]=now;
		now=now+deg[d[i]]+1;
	}
	int ok=0;
	for(int i=1;i<=n;i++){
		if(q[i]<ans[i]){
			ok=1;
			break;
		}
		if(q[i]>ans[i])break;
	}
	if(!ok)for(int i=1;i<=n;i++)printf("%d ",ans[i]);
	else for(int i=1;i<=n;i++)printf("%d ",q[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 19272
n = int(input())
array = [input().split() for i in range(n)]
S = []
H = []
C = []
D = []
for i in range(1,14):
    S.append(i)
    H.append(i)
    C.append(i)
    D.append(i)
for i in range(n):
    if array[i][0] == "S":
        S[int(array[i][1])-1]=" "
    elif array[i][0] == "H":
        H[int(array[i][1])-1]=" "
    elif array[i][0] == "C":
        C[int(array[i][1])-1]=" "
    else:
        D[int(array[i][1])-1]=" "
for i in range(13):
    if S[i] != " ":
        print("S "+str(S[i]))
for i in range(13):
    if H[i] != " ":
        print("H "+str(H[i]))
for i in range(13):
    if C[i] != " ":
        print("C "+str(C[i]))
for i in range(13):
    if D[i] != " ":
        print("D "+str(D[i]))

Measured memory_bytes: 7736
/***
 *          _           _       _ _                             _
 *      ___| |__   ___ | | ___ (_) |__  _   _  __ _ _ __   ___ | |__   ___   __ _
 *     / __| '_ \ / _ \| |/ _ \| | '_ \| | | |/ _` | '_ \ / _ \| '_ \ / _ \ / _` |
 *    | (__| | | | (_) | | (_) | | | | | |_| | (_| | | | | (_) | | | | (_) | (_| |
 *     \___|_| |_|\___/|_|\___/|_|_| |_|\__,_|\__,_|_| |_|\___/|_| |_|\___/ \__,_|
 *
 *                _       ____            _____     _
 *      /\/\     /_\     /___ \  /\ /\    \_   \   /_\
 *     /    \   //_\\   //  / / / / \ \    / /\/  //_\\
 *    / /\/\ \ /  _  \ / \_/ /  \ \_/ / /\/ /_   /  _  \
 *    \/    \/ \_/ \_/ \___,_\   \___/  \____/   \_/ \_/
 *
 */
#include<bits/stdc++.h>
using namespace std;
#define g(a,b,c) for(int a=b;a<c;a++)
#define ff(a,b,c) for(int a=c;a>b;a--)
#define ffk(a,b,c) for(int a=b;a<=c;a++)
#define fff(a,b,c) for(int a=c;a>=b;a--)
int main (){
	int luutrai=-1,luuphai=-1;
string s;
cin>>s;
for(int i=0;i<s.length()-1;i++){
	if(s[i]==s[i+1]){
		cout<<i+1<<" "<<i+2;
		return 0;
	}
}
for(int i=0;i<s.length()-2;i++){
	if(s[i]!=s[i+1]&&s[i+1]!=s[i+2]&&s[i]==s[i+2]){
		cout<<i+1<<" "<<i+3;
		return 0;
	}
}
cout<<"-1 -1";
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>
#include<queue>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define dump(a) cout << a << endl; 

template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0; true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

void ansYes(bool a) {
	if (a == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void ansYES(bool a) {
	if (a == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Int euclidean_gcd(Int a, Int b) {
	while (true) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

typedef pair<int, int> pai;


//ここまでライブラリ
//ここから本文

int main() {
	int a;
	cin >> a;
	if (1200 > a) {
		dump("ABC");
	}
	else if (2800 > a) {
		dump("ARC");
	}
	else {
		dump("AGC");
	}
}


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

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

for(int i=1;i<n;i++)
{
    int key=arr[i];
    int j=i-1;
    while(j>=0 && arr[j]>key)
    {
        arr[j+1]=arr[j];
        j--;
    }
    arr[j+1]=key;
    for(int k=0;k<n-1;k++)
        cout << arr[k] << " ";
    cout << arr[n-1] << endl;
}
return 0;
}

Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int x = sc.nextInt();
        sc.close();

        if (a + b >= x && a <= x) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 23764
#include <stdio.h>
using namespace std;
int main()
{
    int a,b,c,i,ans=0;
    scanf("%d%d%d",&a,&b,&c);
    int s[a];
    for(i=0;i<a;i++)
    {
        scanf("%d",&s[i]);
        if(s[i]<b||s[i]>=c)
            ans++;
    }
    printf("%d\n",ans);
    return 0;
}

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

using namespace std;

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

#define all(x) (x).begin(), (x).end()
#define fap(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

const int inf = 0x3f3f3f3f;
const ll INF = 2e18;

int main() {
	FastIO;

	int n;
	cin >> n;

	vector<ll> a(n), b(n);
	for(int i=0; i<n; ++i) cin >> a[i] >> b[i];

	ll res = 0;
	for(int i=n-1; i>=0; --i) {
		a[i] += res;
		if(a[i] % b[i]) {
			ll rem = b[i] - a[i] % b[i];
			res += rem;
		}
	}

	cout << res << "\n";
	
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main(void){
    int n, k, x, y;
    int m = 0, i;

    scanf("%d", &n);
    scanf("%d", &k);
    scanf("%d", &x);
    scanf("%d", &y);

    for(i=1;i<=n;i++){
        if(i<=k){
            m += x;
        }else{
            m += y;
        }
    }

    printf("%d\n", m);

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vt<int>>;

int main(){
  long double a,b,h,m;
  cin >> a >> b >> h >> m;

  long double rad = M_PI*2*(
                    h/12.0+(m/60.0)/12.0 - m/60.0);

  long double ans = a*a + b*b - 2.0*a*b*cosl(rad);
  cout << fixed << setprecision(10) << sqrtl(ans) << '\n';
  return 0;
}


Measured memory_bytes: 4168
#include <stdio.h>
long long a [100010];
int main (){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%lld",&a[i]);
int zero =0;
for(int i=0;i<n;i++)if(a[i]==0) zero ++;
if(zero >0){
// a[i] contains 0
printf("0\n");
return 0;
}
long long prod =1;
for(int i=0;i<n;i++){
if(a[i ] <=1000000000000000000/ prod ){
// This condition is equivalent to prod*a[i] <=10ˆ18
prod *=a[i];
}else{
printf("-1\n");
return 0;
}
}
printf("%lld\n",prod );
}


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

void printDivisors(ll n) 
{ 
    // Note that this loop runs till square root 
    ll ans = LLONG_MAX;
    for (ll i=1; i<=sqrt(n); i++) 
    { 
        if (n%i == 0) 
        { 
            // If divisors are equal, print only one 
            if (n/i == i) 
            {
            	ll d = n / i;
            	
            	ll temp = d + i - 2;
            	
            	ans = min(ans, temp);
			}
  
            else // Otherwise print both 
            {
            	ll d = n / i;
            	ll temp = d + i - 2;
            	ans = min(ans, temp);
            	
            	ll e = n / d;
            	temp = e + d - 2;
            	ans = min(ans, temp);
            	
			}
        } 
    } 
    
    cout << ans << endl;
} 
 
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	ll n;
	
	cin >> n;
	
	printDivisors(n);
	
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <ctime>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
using namespace std;

int h, w;
char f[105][105];
int a = 0;

const int dh[] = {-1, 0, 0, 1};
const int dw[] = {0, -1, 1, 0};

void del(int i, int j, char c){
	f[i][j] = '.';
	for(int d = 0; d < 4; d++){
		int ni = i + dh[d];
		int nj = j + dw[d];
		if(ni >= 0 && ni < h && 0 <= nj && nj < w && f[ni][nj] == c){
			del(ni, nj, f[ni][nj]);
		}
	}
	return;
}

int main(){
	while(1){
		cin >> h >> w;
		if(h == 0 && w == 0){
			break;
		}
		for(int i = 0; i < h; i++){
			scanf("%s", f[i]);
		}
		int ans = 0;
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if(f[i][j] != '.'){
					ans++;
					del(i, j, f[i][j]);
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3804
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');
        int M = int.Parse(input[0]);
        int D = int.Parse(input[1]);
        int count = 0;
        for(int i = 2; i <= M; i++)
        {
            for(int j = 2; j <= D; j++)
            {
                if ((j % 10) * (j / 10) == i&&(j/10!=1)&&(j%10!=1)) { count++; }
            }
        }
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 11092
#include <algorithm>
#include <iostream>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;

struct Edge {
  ll cost;
  int to;
  Edge() {}
  Edge(int c, int t) : cost(c), to(t) {}
  friend bool operator < (const Edge& lhs, const Edge& rhs) { return lhs.cost < rhs.cost; };
  friend bool operator > (const Edge& lhs, const Edge& rhs) { return rhs < lhs; };
  friend bool operator <= (const Edge& lhs, const Edge& rhs) { return !(lhs > rhs); };
  friend bool operator >= (const Edge& lhs, const Edge& rhs) { return !(lhs < rhs); };
};

typedef vector<vector<Edge>> Graph;
Graph graph(1000);
Graph rgraph(1000);

bool ok1[1000]; // 頂点1からたどりつける
bool okN[1000]; // 頂点nにたどりつける

void dfs1(int from) { 
  ok1[from] = true;
  for (auto& e: graph[from]) { 
    if (ok1[e.to]) continue;
    dfs1(e.to);
  }
}

void dfsN(int from) { 
  okN[from] = true;
  for (auto& e: rgraph[from]) { 
    if (okN[e.to]) continue;
    dfsN(e.to);
  }
}

const ll INF = 1001001001001;

// 負の閉路があればtrueを返す
bool bellman_ford(int V) {
  vector<ll> dist(V, INF);
  dist[0] = 0;
  for (int i = 0; i <= V; ++i) {
    for (int v = 0; v < V; ++v) {
      if (!ok1[v] || !okN[v]) continue;
      for (auto &e : graph[v]) {
        if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) {
          if (!ok1[e.to] || !okN[e.to]) continue;
          dist[e.to] = dist[v] + e.cost;
          if (i == V) return true;
        }
      }
    }
  }
  cout << -dist[V-1] << endl;
  return false;
}

int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    --a; --b;
    graph[a].emplace_back(-c, b); // 最大化したいのでコストを反転する
    rgraph[b].emplace_back(-c, a); // Nにたどり着けるかを調べるためのもの
  }
  dfs1(0);
  dfsN(N-1);
  bool has_loop = bellman_ford(N);
  if (has_loop) cout << "inf" << endl;
}

Measured memory_bytes: 384
import collections
n=int(input())
lis=[]
lim=int(100000**(0.5))*int(6**(0.5))//3
for x in range(1,lim+1):
    for y in range(1,lim+1):
        for z in range(1,lim+1):
            lis.append(x**2+y**2+z**2+x*y+y*z+z*x)

c=collections.Counter(lis)
for i in range(1,n+1):
    print(c[i])

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

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define FILE_IO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define trav(e, x) for (auto &e : x)
#define pb(x) push_back(x)
#define eb(x...) emplace_back(x)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
//#define int long long
using namespace std;
typedef pair<int, int> ii;

signed main() {
    FAST_IO;
    //FILE_IO;

    string s;
    cin >> s;
    int ans = 0;
    int i = 0, j = s.length() - 1;
    while (i < j) if (s[i++] != s[j--]) ans++;
    cout << ans;
}


Measured memory_bytes: 3628
/*
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B&lang=ja
*/

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

int main(){
    while(1){
        int n,x;
        cin >> n >> x;
        if(n==0) break;

        int count = 0;
        for(int i=1; i<=n; ++i){
            for(int j=i+1; j<=n;++j){
                for(int k=j+1; k<=n;++k){
                    if(i+j+k==x) count++;
                }
            }
        }
        cout << count << endl;
    }
}


Measured memory_bytes: 3100
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = 0;
		if(b == 1) {
			ans = 0;
		} else if(b <= a) {
			ans = 1;
		} else {
			b -= a;
			a--;
			ans++;
			b += a - 1;
			ans += (b / a);
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 23124
N,A,B = map(int, input().split())
S = input()

def ans(b):
  print('Yes' if b else 'No')

passed = 0 # 現在までに予選通過した人数のカウント
overseas = 0 # 海外の学生のカウント

# 条件式の効率はよくないが明瞭さを重視
for s in S:
  if s == 'a':
    if passed < A + B:
      passed += 1
      ans(1)
    else:
      ans(0)
  elif s == 'b':
    overseas += 1
    if passed < A + B and overseas <= B:
      passed += 1
      ans(1)
    else:
      ans(0)
  else:
    ans(0)

Measured memory_bytes: 4016
#include<stdio.h>
int main(void) {
	int w, a, b, c, i, z;
	while (1) {
		scanf("%d", &w);
		if (w == -1)break;
		a = 1150;
		for (i = 11;i <= w;i++) {
			if (i <= 20) {
				a += 125;
			}
			else if (i >= 31) {
				a += 160;
			}
			else {
				a += 140;
			}
		}
		b = (4280 - a) ;
		printf("%d\n", b);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll i=0,i##_len=(n);i<i##_len;i++)
#define brep(i,a,b) for(ll i=(a),i##_len=(b);i<=i##_len;i++)
#define rrep(i,n) ll i=(n);ll now=-1;while(i--&&(now++||1))
#define Yes(n) cout<<((n)?Yes:No)
#define pb push_back
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vbl = vector<bool>;
using vint = vector<int>;
using vstr = vector<string>;
static inline void ignore_ret(int x) {x++;}
template<class T> inline bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline map<T,T> factorize(T n){map<T,T>r;for(T i=2;i*i<=n;i++){while(n%i== 0){r[i]++;n/=i;}}if(n!=1)r[n]=1;return r;}
template<class T> inline T gcd_vec(vector<T>v){T r=v[0];for(T i=1;i<v.size();i++)r=gcd(r,v[i]);return r;}
template<class T> inline T lcm_vec(vector<T>v){T r=v[0];for(T i=1;i<v.size();i++)r=lcm(r,v[i]);return r;}
template<class T> inline T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> inline T nCr(T n,T k){if(n<k||n<0||k<0)return 0;T r=1;k=min(k,n-k);for(T i=n-k+1;i<=n;i++)r*=i;return r/factorial(k);}
template<class T> inline T dot_product(vector<T>u,vector<T>v){if(u.size()<v.size())return 0;T r=0;for(T i=0;i<u.size();i++)r+=u[i]*v[i];return r;}
template<class T> inline T sum(vector<T>v){return reduce(all(v),0LL);}

void solve(ll N, ll K, vector<ll> h) {
  sort(all(h));
  ll ans = LLONG_MAX;
  rep(i, N - K + 1) chmin(ans, h[i + K - 1] - h[i]);
  cout << ans << endl;
}

int main() {
  ll N;
  ignore_ret(scanf("%lld",&N));
  ll K;
  ignore_ret(scanf("%lld",&K));
  vector<ll> h(N);
  for(int i = 0 ; i < N ; i++){
    ignore_ret(scanf("%lld",&h[i]));
  }
  solve(N, K, move(h));
  return 0;
}


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

ll gcd(ll a,ll b) {
  return (b? gcd(b,a%b):a);
}

int main() {
  ll a,b;
  cin>>a>>b;
  ll g=gcd(a,b);
  cout<<a*b/g<<endl;
  return 0;
}

Measured memory_bytes: 256
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def s_list(): return list(input())
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def num__grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]#NumberGrid
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def grid(n): return [s_list() for _ in range(n)]

a, b, c = wi()

if c <= a - b:
    print(0)
else:
    print(c - (a - b))

Measured memory_bytes: 6480
#include <bits/stdc++.h>
using namespace std;
int n, a[101];
long long ans;
void dfs(int x) {
	if (x == n + 1) {
		long long s = 0;
		for (int i = 1; i <= n; i++) {
			s += a[i];
		}
		ans = max(ans, s);
		return;
	}
	if (a[x] < 0) {
		int b[101] = {0};
		for (int i = 1; i <= n; i++) {
			b[i] = a[i];
		}
		for (int i = x; i <= n; i += x) {
			a[i] = 0;
		}
		dfs(x + 1);
		for (int i = 1; i <= n; i++) {
			a[i] = b[i];
		}
	}
	dfs(x + 1);
}
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = n; i > n / 6; i--) {
		long long s = 0;
		for (int j = i; j <= n; j += i) {
			s += a[j];
		}
		if (s > 0) {
			continue;
		}
		for (int j = i; j <= n; j += i) {
			a[j] = 0;
		}
	}
	dfs(1);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List
import Data.Ratio
import Data.Maybe

listToTuple2 [a,b] = (a,b)

main = do
  (d,g) <- listToTuple2 . map read . words <$> getLine :: IO (Int,Int)

  dat <- forM [1..d] $ \i -> do
    (p,c) <- listToTuple2 . map read . words  <$> getLine :: IO (Int,Int)

    return $ (i, p, c, 100*i*p+c)

  print $ minimum . catMaybes $ (flip map) (pset dat) $
    \(a,b) ->
      let
        psum = sum $ map (\(_,p,_,_) -> p) a
        score = sum $ map (\(_,_,_,s) -> s) a
      in
        case b of
          [] -> if score >= g then Just psum else Nothing
          _ ->
            let
              (i,p,c,_) = last b
              n = ceiling $ (g-score) % (i*100)
            in
              if score >= g then
                Just psum
              else
                if n < p then
                  Just (psum + n)
                else
                  Nothing

  where
    pset :: [a] -> [([a],[a])]
    pset [] = [([],[])]
    pset (x:xs) = concat [map (second (x:)) (pset xs), map (first (x:)) (pset xs)]

    first f (a,b) = (f a, b)
    second f (a,b) = (a, f b)

Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
#define mods 1000000007
#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef long long int lint;
typedef unsigned long long int ulint;
 
lint n,dizi[3020],dp[3020][3020];
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lint i,j,k,l,il;
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>dizi[i];
        }
        il=0;
    for(j=n;j>0;j--,il++){
        for(i=1;i<=j;i++){
            
            if(j%2==0){
                if(j==n){
                    dp[j][i]=-dizi[i];
                    }else{
                    dp[j][i]=fmin(dp[j+1][i+1]-dizi[i],dp[j+1][i]-dizi[i+il]);
                    }
                
                }else{
                if(j==n){
                    dp[j][i]=dizi[i];
                    }else{
                    dp[j][i]=fmax(dp[j+1][i+1]+dizi[i],dp[j+1][i]+dizi[i+il]);

                    }
                
                }
            }
        }
   /* for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            cout<<dp[i][j]<<" ";
            }
            cout<<endl;
        }*/
    cout<<dp[1][1];
    return 0;
}

Measured memory_bytes: 69376
#include <bits/stdc++.h>
#define sanyes ios_base::sync_with_stdio(0), cout.tie(0); cin.tie(0);
#define llong long long int
#define pb push_back
#define bpc __builtin_popcount
#define f first
#define s second

const llong mxn = 1e5 + 7;
const llong mod = 1e9 + 7;
const llong inf = 1e18 + 9;

using namespace std;

llong n, dp[1001][1001], pref[mxn], a[mxn], sum = 0;

int main(){
    cin >> n;
    for (int i = 1; i <= n * 2; i ++){
        cin >> a[i];
    }sort(a + 1, a + (n * 2) + 1);
    reverse(a + 1, a + (n * 2) + 1);
    for (int i = 1; i <= 2 * n; i ++){
        if(i % 2 == 0){
            sum += a[i];
        }
    }cout << endl << sum;
    return 0;
}


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

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in = new Scanner(System.in);
		String s1=in.next();
		String s2=in.next();
		int n=s1.length();
		int m=s2.length();
		int [][] ans=new int [n+1][m+1];
		for(int i=0;i<=n;i++)
		{
			for(int j=0;j<=m;j++)
			{
				if(i==0||j==0)
				{
					ans[i][j]=0;
				}
				else if(s1.charAt(i-1)==s2.charAt(j-1))
				{
					ans[i][j]=ans[i-1][j-1]+1;
				}
				else
				{
					ans[i][j]=Math.max(ans[i][j-1],ans[i-1][j]);
				}
			}
		}
		String s=new String();
		int i=n;
		int j=m;
		while((i>0)&&(j>0))
		{
			if(s1.charAt(i-1)==s2.charAt(j-1))
			{
				s=s+s1.charAt(i-1);
				i--;
				j--;
			}
			else if(ans[i-1][j]>ans[i][j-1])
				i--;
			else
				j--;
		}
		String ret=reverse(s);
		System.out.println(ret);
			
	}
	public static String reverse(String s)
	{
		int n=s.length();
		String ans=new String();
		for(int i=0;i<n;i++)
		{
			ans=ans+s.charAt(n-1-i);
		}
		return ans;
	}
}
	

Measured memory_bytes: 101964
import sys

N = int(sys.stdin.readline())

red = []
for _ in range(N):
    a, b = map(int, sys.stdin.readline().split())
    red.append((a, b))
red.sort(reverse=True, key=lambda x: x[1])

blue = []
for _ in range(N):
    c, d = map(int, sys.stdin.readline().split())
    blue.append((c, d))
blue.sort()

used = set()
for c, d in blue:
    for a, b in red:
        if a < c and b < d and (a, b) not in used:
            used.add((a, b))
            break

print(len(used))

Measured memory_bytes: 9020
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll a, b;
  cin >> a >> b;
  ll curr = 1; 
  ll xx = 0;
  while(curr < b) {
   curr-=1;
   curr+= a;
   xx++;
  }
  cout << xx << endl;
  return 0;
} //good night.s

Measured memory_bytes: 256
import numpy as np
N,M,Q=map(int, input().split())
a=np.array([[0]*(N+1) for i in range(N+1)])
for i in range(M):
  l,r=map(int, input().split())
  a[l][r]+=1
a=a.cumsum(axis=0).cumsum(axis=1)
for i in range(Q):
  p,q=map(int, input().split())
  print(a[q][q]-a[p-1][q])

Measured memory_bytes: 33124
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
int grid[5][5];
array<int, 7> dy = {1, 1, 0, 0, 0, -1, -1}, dx = {-1, 0, -1, 0, 1, 0, 1};
array<int, 19> ys = {0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4};
array<int, 19> xs = {2, 3, 4, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 0, 1, 2};
array <tuple<int, int, int>, 7> op;
bool solve(string &s){
    for (int i = 0; i < 5; ++i) {
        for (int j = 0; j < 5; ++j) {
            grid[i][j] = 0;
        }
    }
    for (int i = 0; i < (1<<20); ++i) {
        for (int j = 0; j < 20; ++j) {
            grid[ys[j]][xs[j]] = (i>>j)&1;
        }

        for (int k = 0; k < 7; ++k) {
            int p = 0;
            for (int l = 0; l < 7; ++l) {
                if(grid[2+dy[k]+dy[l]][2+dx[k]+dx[l]]) p += (1<<l);
            }
            op[k] = make_tuple(2+dy[k], 2+dx[k], s[p]-'0');
        }
        for (auto &&m : op) {
            int y, x, p;
            tie(y, x, p) = m;
            grid[y][x] = p;
        }
        int d = grid[2][2];
        int p = 0;
        for (int l = 0; l < 7; ++l) {
            if(grid[2+dy[l]][2+dx[l]]) p += (1<<l);
        }
        grid[2][2] = s[p]-'0';
        if(grid[2][2] != d) return false;
    }
    return true;
}

int main() {
    string s;
    while(cin >> s, s != "#") {
        puts(solve(s) ? "yes" : "no");
    }
    return 0;
}


Measured memory_bytes: 3136
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int K;
  cin>>K;
  int A,B;
  cin>>A>>B;
  
  for(int i=A;i<=B;i++){
    if(i%K==0){
      cout<<"OK"<<endl;
      return 0;
    }
  }
  cout<<"NG"<<endl;

  return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0;i<n;i++)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { 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; }
const long long INF = 2LL << 60;
using ll = long long;
using P = pair<ll, ll>;
int main(int argc, char const *argv[]){
    int x, n;
    ll ansi=INF;
    int ans;
    cin >> x >> n;
    vector<ll> p(n+10,INF);
    rep(i,n) cin >> p[i];
    sort(p.begin(),p.end());
    int idx=0;
    for(int i=-100;i<201;i++){
        if(p[idx]==i){
            idx++;
            continue;
        }
        if(chmin(ansi,(ll)abs(x-i))){
            ans=i;
        }
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3580
/*input
5
2 3 1 1 4
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

vector<int> edge[maxn];
int vis[maxn];

vector<int> ring;
vector<int> path;
bool onring[maxn];
void dfs(int u){
	// cout<<u<<'\n';
	path.pb(u);
	// for(int i:path) cout<<i<<' ';
		// cout<<'\n';
	vis[u]=-1;
	for(int v:edge[u]){
		if(!vis[v]) dfs(v);
		else if(vis[v]==-1){
			// cout<<"meet:"<<u<<' '<<v<<'\n';
			for(int j=SZ(path)-1;j>=0;j--){
				ring.pb(path[j]);
				onring[path[j]]=1;
				if(path[j]==v) break;
			}
		}
	}
	vis[u]=1;
	path.pop_back();
}
vector<pii> ans;

int dfs2(int u){
	vector<int> nxt;
	for(int v:edge[u]) if(!onring[v]){
		nxt.pb(dfs2(v));
	}
	SORT_UNIQUE(nxt);
	int grundy=-1;
	REP(i,SZ(nxt)) if(nxt[i]!=i){
		grundy=i;
		break;
	}
	if(grundy==-1) grundy=SZ(nxt);
	if(onring[u]){
		nxt.pb(grundy);
		sort(ALL(nxt));
		int grundy2=-1;
		REP(i,SZ(nxt)) if(nxt[i]!=i){
			grundy2=i;
			break;
		}
		if(grundy2==-1) grundy2=SZ(nxt);
		ans.pb(MP(grundy,grundy2));
	}
	return grundy;
}

int main(){
	IOS;
	// freopen("loop0.in","r",stdin);

	int n;
	cin>>n;
	REP(i,n){
		int tmp;
		cin>>tmp;
		tmp--;
		edge[tmp].pb(i);
	}
	REP(i,n) if(!vis[i]){
		dfs(i);
	}
	REP(i,n) vis[i]=0;
	for(int i:ring) dfs2(i);
	// REP(i,SZ(ans)) cout<<ans[i]<<'\n';
	{
		int pre=ans[0].F;
		for(int i=1;i<SZ(ans);i++){
			if(pre==ans[i].F) pre=ans[i].S;
			else pre=ans[i].F;
		}
		if(pre!=ans[0].F){
			cout<<"POSSIBLE\n";
			return 0;
		}
	}
	{
		int pre=ans[0].S;
		for(int i=1;i<SZ(ans);i++){
			if(pre==ans[i].F) pre=ans[i].S;
			else pre=ans[i].F;
		}
		if(pre==ans[0].F){
			cout<<"POSSIBLE\n";
			return 0;
		}
	}
	cout<<"IMPOSSIBLE\n";
	return 0;
}


Measured memory_bytes: 30068
#include<bits/stdc++.h>
using namespace std;
/*-----------------------*/
#define FAST        ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
#define endl        "\n"
#define ff          first
#define ss          second
#define cc(x)       cout<<#x<<"="<<x<<" ";
#define CC(x)       for(auto xx: x) cout<<xx<<" ";
#define ee          cout<<"\n";
#define ll          long long
#define ull         unsigned long long
#define pii         pair<int,int>
#define mp          make_pair
#define all(x)      x.begin(),x.end()
#define ps(x)       push(x)
#define psb(x)      push_back(x)
#define psf(x)      push_front(x)
#define pp          pop()
#define ppb         pop_back()
#define ppf         pop_front()
#define OK          cout<<"Ok"<<"\n";
#define TESTS       ll test;cin>>test;for(ll   tcase=1;tcase<=test;tcase++)
/*------------------------*/
#define MAX int(2e6+9)



int main()
{
    FAST
    int n;
    cin>>n;
    string x;
    map <string,int> MP;
    for(int i=0; i<n; i++)
    {
        cin>>x;
        if(MP.find(x)==MP.end()) MP[x]=1;
        else
            MP[x]++;

    }
    int mx=-1;
    for(auto it=MP.begin();it!=MP.end();it++)
    {
      mx=max(mx,it->ss);
    }
    for(auto it=MP.begin();it!=MP.end();it++)
    {
      if(it->ss==mx) cout<<it->ff<<endl;
    }






    return 0;
}


Measured memory_bytes: 23808
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=100000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}
ll gcd(ll x,ll y){
    if(x<y) return gcd(y,x);
    if(y==0) return x;
    return gcd(y,x%y);
}

int main(){
    ll n,X;cin>>n>>X;
    vector<ll> x;
    ll xx[n];
    x.push_back(X);
    for(ll i=0;i<n;i++){
        cin>>xx[i];
        x.push_back(xx[i]);
    }
    sort(x.begin(),x.end());
    ll g;
    g=x[1]-x[0];
    for(ll i=1;i<n;i++){
        g=gcd(g,x[i+1]-x[i]);
    }
    cout<<g<<endl;
    return 0;
}



Measured memory_bytes: 1912
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
int N,Q;
string S;
int x[100000];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N>>Q;
    cin>>S;
    if(S[0]=='A'&&S[1]=='C') x[1]=1;
    rep(i,2,N){
        if(S[i-1]=='A'&&S[i]=='C') x[i]=x[i-2]+1;
        else x[i]=x[i-1];
    }
    rep(i,0,Q){
        int l,r;
        cin>>l>>r;
        l--;
        r--;
        cout <<x[r]-x[l]<<"\n";
    }
}

Measured memory_bytes: 1488
l = list(range(-100,205))
num1 = [int(s) for s in input().split()]
in_tmp = input()
flag = False
if in_tmp == '':
    flag = True
if flag == False:
    num2 = [int(s) for s in in_tmp.split()]

    for n in num2:
        l.remove(n)
        l_list = [int(s) for s in l]
    abs_min = 500
    num_min = 500
    for n in l_list:
        tmp = abs(num1[0] - n)
        if abs_min > tmp:
            abs_min = tmp
            num_min = n
        if abs_min == tmp:
            if num_min > n:
                num_min = n
    print(num_min)
if flag == True:
    print(num1[0])


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

using namespace std;

typedef long long ll;

int main(){
        ll N, K;
        cin>>N>>K;
        ll res=0;
        if(K==0){
                cout<<N*N<<endl;
                return 0;
        }
        for(ll i=0;i<=N;i++){
                if(i>K){
                        res+=max(0LL, i-K)*(N/i);
                        res+=max(0LL, N%i-K+1);
                }
        }
        cout<<res<<endl;
        return 0;
}


Measured memory_bytes: 256
import numpy

N = int(input())
A = list(map(int, input().split()))
res = numpy.cumsum(A)

if res[-1] % 2 == 0:
  L = res[-1]//2
  ans = [abs(r - L) for r in res]
  print(2*min(ans))
else:
  L1 = res[-1]//2
  L2 = L1 + 1
  ans = [min(abs(r - L1),abs(r-L2)) for r in res]
  print(2*min(ans)+1)

Measured memory_bytes: 34180
#include <iostream>

#define Nmax int(1e5 + 5)
using namespace std;

long long sum;
int N;
int a[Nmax],b[Nmax];

void cit()
{
    cin >> N;
    for(int i = 1; i <= N + 1; ++i)
        cin >> a[i];
    for(int i = 1; i <= N; ++i)
        cin >> b[i];
}

int main()
{
    cit();
    for(int i = N; i >= 1; --i)
    {
        int Min_1 = min(b[i],a[i + 1]);
        sum += Min_1;
        b[i] -= Min_1;
        sum += min(b[i],a[i]);
        int Min_0 = min(a[i],b[i]);
        a[i] -= Min_0;
        b[i] -= Min_0;
    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 1024
L,R=map(int,input().split())
d=R-L
ans=2019

L=L%2019
R=L+d
if d>=2019:
  print(0)
  
else:
  for i in range(L,R+1):
    for j in range(i+1,R+1):
      ans=min(ans,(i*j)%2019)
  print(ans)


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

int main() {
  
  string s;
  cin >> s;
  vector<string> vec(7);
  vec = {"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};
  for(int i = 0; i < 7; i++){
    if(vec.at(i) == s) cout << i + 1 << endl;
  }
  
  
}



Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
int main(){
  int S, a, b, c, d;
  cin >> S;
  d = S % 10; c = (S - d) / 10 % 10; b = (S - 10 * c - d) / 100 % 10; a = (S - 100 * b - 10 * c - d) / 1000 % 10;
  if (a == b || b == c || c == d)
    cout << "Bad" << endl;
  else cout << "Good" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main(){
	int h, w; cin >> h >> w; std::vector<std::vector<int>> a(h, std::vector<int>(w));
	for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) cin >> a[i][j];
	
	typedef std::pair<std::pair<int, int>, std::pair<int, int>> P;
	std::vector<P> vec;
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			if(a[i][j] % 2) {
				if(j + 1 < w and a[i][j + 1] % 2) {
					vec.push_back({{i + 1, j + 1}, {i + 1, j + 2}});
					a[i][j + 1] += 1;
					a[i][j] -= 1;
				} else if(i + 1 < h and a[i + 1][j] % 2) {
					vec.push_back({{i + 1, j + 1}, {i + 2, j + 1}});
					a[i + 1][j] += 1;
					a[i][j] -= 1;
				} else if(j + 1 < w) {
					vec.push_back({{i + 1, j + 1}, {i + 1, j + 2}});
					a[i][j + 1] += 1;
					a[i][j] -= 1;
				} else if(i + 1 < h) {
					vec.push_back({{i + 1, j + 1}, {i + 2, j + 1}});
					a[i + 1][j] += 1;
					a[i][j] -= 1;
				}
			}
		}
	}
	
	cout << vec.size() << endl;
	for(auto v : vec) cout << v.first.first << " " << v.first.second << " "
						   << v.second.first << " " << v.second.second << endl;
	return 0;
}


Measured memory_bytes: 5232
//If we can go to any losing state by using any element of array,
//it will be termed be wining state then. 
// 2 4
// 2 3
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int main()
{
	ll n,k;
	cin>>n>>k;
	ll a[n];
	bool dp[k+1];
	for(ll e=0;e<=k;e++)
	{
		dp[e]=0;
	}
	for(ll p=0;p<n;p++)
	{
		cin>>a[p];
	}
	sort(a,a+n);
	for(ll p=0;p<=k;p++)
	{
		for(ll p_a=0;p_a<n&&p>=a[p_a];p_a++)
		{
			if(dp[p-a[p_a]]==0)
			{
				dp[p]=1;
			}
		}
	}
	if(dp[k]==1)
	{
		cout<<"First";
	}
	else
	{
		cout<<"Second";
	}
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define rrep(i,n) for (int i = (n - 1);i >= 0;i--)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;

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

    int a,b,c;
    cin >> a >> b >> c;
    if(a == b && a != c) cout << "Yes" << endl;
    else if(a == c && a != b) cout << "Yes" << endl;
    else if(b == c && a != b) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

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

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = ll(1e5) + 5;
const double EPS = 10e-8;
const double PI = 3.14159265359;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

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

int main() {
    int h, w, n, px = 0, py = 0, dir = 1;
    vector<vector<int>> ans;
    cin >> h >> w >> n;
    ans = vector<vector<int>>(h, vector<int>(w, 0));
    REP(i, n) {
        int a;
        cin >> a;
        REP(j, a) {
            ans[py][px] = i + 1;
            if (px + dir == w || px + dir == -1) {
                py++;
                dir *= -1;
                continue;
            }
            px += dir;
        }
    }
    REP(i, h) {
        cout << ans[i][0];
        FOR(j, 1, w) { cout << " " << ans[i][j]; }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 384