akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int l = s.size();
    for(int i=0;i<l-1-i;++i){
        if(s[i]!=s[l-1-i]){
            cout << "No" << endl;
            return 0;
        }
    }
    int x = (l-1)/2;
    for(int i=0;i<x-1-i;++i){
        if(s[i]!=s[x-1-i]){
            cout << "No" << endl;
            return 0;
        }
    }
    int y = (l+3)/2-1;
    for(int i=y;i<l-1-i;++i){
        if(s[i]!=s[l-1-i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	std::string S;
	std::cin >> S;
	S[3] = '8';
	std::cout << S << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#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() {
int N,A,x;
cin>>N>>A;
x=N*N-A;
cout<<x<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>

using namespace std;
 
int main(){
    int n, m;
 
    cin >> n >> m;
    int a[n],b[m],c[n];
 
    memset(c,0,sizeof(c));
 
    for(int i = 0 ; i < n ; i++) cin >> a[i];
    for(int i = 0 ; i < m ; i++) cin >> b[i];
 
    for(int i = 0 ; i < m ; i++){
	for(int j = 0 ; j < n ; j++){
	    if(a[j] <= b[i]){
		c[j]++;
		break;
	    }
	}
    }
 
    int ans,maxi = 0;
    for(int i = 0 ; i < n ; i++){
	if(maxi < c[i]){
	    maxi = c[i];
	    ans = i + 1;
	}
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 1e9 + 7;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
const int inf = 1000000000; // 10^9 Ten to the power of nine.
/**** Type Define ****/
 
   int main(){
       ll x,y; cin>>x>>y;
       int flag =0;
       for (int i = 0; i <= x; i++)
       {
          if(2*i+4*(x-i)==y){
            flag++;
       }
       }
         if(flag==0){cout<<"No";}
         else{cout<<"Yes";}
         return 0;  
   }

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

    int M, D;
    cin >> M >> D;

    int ans = 0;
    for(int i = 0; i <= M; i++) {
        for(int j = 0; j <= D; j++) {
            if(j < 22) {
                continue;
            }

            int x = j / 10;
            int y = (j % 10) % 10;

            if(x < 2 || y < 2){
                continue;
            }

            if(i == (x * y)){
                ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    string s;
    cin >> s;
    int n = s.size();
    int cnt = 0;
    rep(i,n){
        rep(j,alpha.size()){
            if(s[i] == alpha[j]){
                cnt++;
                break;
            }
        }
    }
    int cntt = 0;
    for(int i = 2;i<=n-2;i++){
        if(s[i] == 'C'){
            cntt++;
        }
    }
    if(cnt == n-2 && s[0] == 'A' && cntt == 1){
        cout << "AC" << endl;
    }
    else{
        cout << "WA" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=100010,mod=998244353;
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline int read(){
	int x=0,f=0;char ch=getchar();
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int n,K,v[55],dp[111][55][55],ans;
int main(){
	n=read();K=read();
	FOR(i,1,n) v[i]=read();
	MEM(dp,~0x3f);
	FOR(i,0,K){
		dp[i][1][n]=0;
		FOR(j,1,n) FOR(k,j,n){
			if(i>=1){
				if(j!=1) dp[i][j][k]=max(dp[i][j][k],dp[i-1][j-1][k]+v[j-1]);
				if(k!=n) dp[i][j][k]=max(dp[i][j][k],dp[i-1][j][k+1]+v[k+1]);
			}
			if(i>=2){
				if(j!=1) dp[i][j][k]=max(dp[i][j][k],dp[i-2][j-1][k]);
				if(k!=n) dp[i][j][k]=max(dp[i][j][k],dp[i-2][j][k+1]);
			}
			ans=max(ans,dp[i][j][k]);
		}
		FOR(j,1,n) ans=max(ans,dp[i][j][j]+v[j]);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1536
def slove():
    import sys
    input = sys.stdin.readline
    n, y = list(map(int, input().rstrip('\n').split()))
    for a in range(n + 1):
        for b in range(n + 1):
            if 10000 * a + 5000 * b > y:
                break
            elif (n - a - b) * 1000 == y - (10000 * a + 5000 * b):
                print(a, b, n - a - b)
                exit()
    print(-1, -1, -1)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 39280
n,h=map(int,input().split())
li=[tuple(map(int,input().split())) for i in range(n)]

zenbu=[]

for i in range(n):
  a=[li[i][0],"a"]
  b=[li[i][1],"b"]
  zenbu.append(a)
  zenbu.append(b)

zenbu.sort(reverse=True)

life=h
ans=0

import math
for i in range(n):
  if zenbu[i][1]=="b":
    life-=zenbu[i][0]
    ans+=1
    if life<=0:
      print(ans)
      exit()
  elif zenbu[i][1]=="a":
    print(ans+math.ceil(life/zenbu[i][0]))
    exit()
#以下、bを全部投げて足りない場合。この場合は残りを最大のaで割る
ali=[]
for i in range(n):
  ali.append(li[i][0])
ali.sort()

print(ans+math.ceil(life/ali[-1]))

Measured memory_bytes: 37788
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] S = new String[n];
		for (int i = 0; i < n; i++) {
			S[i] = sc.next();
		}

		String az = "abcdefghijklmnopqrstuvwxyz";
		int[] cnt_az = new int[26];
		for (int i = 0; i < cnt_az.length; i++) {
			cnt_az[i] = Integer.MAX_VALUE;
		}

		for (int i = 0; i < S.length; i++) {
			for (int j = 0; j < az.length(); j++) {
				int cnt = 0;
				for(char c : S[i].toCharArray()){
					if (c == az.charAt(j)) {
						cnt++;
					}
				}
				cnt_az[j] = Math.min(cnt_az[j], cnt);
			}
		}

		for (int i = 0; i < cnt_az.length; i++) {
			if (cnt_az[i] == Integer.MAX_VALUE) {
				cnt_az[i] = 0;
			}
		}

		for (int i = 0; i < cnt_az.length; i++) {
			for (int j = 0; j < cnt_az[i]; j++) {
				System.out.print(az.charAt(i));
			}
		}
		System.out.println("");
	}
}


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

int main()
{
  int n, k, x, sum = 0;
  cin >> n >> k;
  
  for (int i = 0; i < n; i++) {
    cin >> x;
    sum += (x < k-x) ? 2*x : 2*(k-x);
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
//using Graph = vector<vector<int>>;


const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
ll gcd(ll a,ll b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
ll lcm(ll a,ll b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

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

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}









int main() {
  string s;
  cin >> s;
  if (s[s.size()-1] == 's') cout << s + "es" << endl;
  else cout << s + 's' << endl;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
using P = pair<int,int>; using vp = vector<P>;
constexpr int MOD = /** 1000000007; //*/ 998244353;
//////////

void solve(){
  ini(N); ins(S);

  vvi idx(10);
  rep(i , N){
    idx[S[i] - '0'].pb(i);
  }
  int ans = 0;
  rep(l,10) rep(m,10) rep(r,10){
    if(idx[l].empty()) continue;
    if(idx[m].empty()) continue;
    if(idx[r].empty()) continue;
    int li = idx[l][0] , ri = idx[r].back();
    trc(l,m,r,li,ri);
    auto it = upper_bound(all(idx[m]) , li);
    if( it!=idx[m].end() && *it < ri) ans++;
  }
  out(ans);

}

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

#define ll long long
#define ii pair<int, int>

const int N = 2e5 + 10;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    if (s[0] != 'A')
    {
        cout << "WA" << endl;
        return 0;
    }
    int cnt = 0;
    for (int i = 2; i < n - 1; i ++ )
        cnt += (s[i] == 'C');
    if (cnt != 1)
    {
        cout << "WA" << endl;
        return 0;
    }
    cnt = 0;
    for (int i = 1; i < n; i ++)
    {
        cnt += (s[i] >= 'A' && s[i] <= 'Z');
    }
    if (cnt != 1)
    {
        cout << "WA" << endl;
        return 0;
    }
    cout << "AC" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[110];
int minn=1000000;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	
	for(int i=1;i<=100;i++)
	{
		int ans=0;
		for(int j=1;j<=n;j++)
		{
			ans+=(a[j]-i)*(a[j]-i);
		}
		if(ans<minn) minn=ans;
	}
	cout<<minn;
	return 0;
} 

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

int main() {
    string S;
    cin >> S;
    
    int size = S.size();
    bitset<10> b;
    long long sum = 0;
    int pos;
    string former;
    for (int tmp = 0; tmp < (1 << size - 1); tmp++) {
        b = tmp;
        former = S;
        for (int i = 0; i < size - 1; i++) {
            if (b.test(i)) {
                pos = size - i - 1;
                sum += stoll(former.substr(pos, former.size() - pos));
                former = former.substr(0, pos);
            }
        }
        if (former.size() != 0) {
            sum += stoll(former);
        }
    }
    cout << sum << endl;
}


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

#define int long long
#define EB emplace_back

using namespace std;

int32_t main()
{


	int tt=1;
	// cin>>tt
	 while(tt--)
	 {
	 	int n; cin>>n;
	 	int flag =0;
	 	for (int i = 0; i < n; ++i)
	 	{
	 		int temp; cin>>temp;
			{
				if(temp%2==0)
				{
					if(temp%3==0 or temp%5==0) {}
					else flag=1;
					
				}

			}
	 	}
	 	if(flag) cout<<"DENIED";
	 	else cout<<"APPROVED";

	 }
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int gcd(long long a, long long b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}
int main(){
  long long A, B, C, D;
  cin >> A >> B >> C >> D;
  //CとDのgcd求めんとな...
  long long J = gcd(C, D);
  long long E = C*D/J;
  long long I = B - A + 1 ;
  long long F = B / C - A / C;
  long long G = B / D - A / D;
  long long H = B / E - A / E;
  if(A % C == 0) F++;
  if(A % D == 0) G++;
  if(A % E == 0) H++;
  cout << I - F - G + H << endl;
}


Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

k,n = inpm()
a = inpl()

d = 0
for i in range(n):
    if i == n-1:
        d = max(d,k + a[0] - a[i])
    else:
        d = max(d,a[i+1] - a[i])

print(k - d)


Measured memory_bytes: 55368
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	if n == 1 {
		fmt.Fprintln(writer, "First")
		return
	}
	ee := make([][]edge, n)
	for i := 0; i < n-1; i++ {
		a := getNextInt(scanner) - 1
		b := getNextInt(scanner) - 1
		appendEdge(a, b, i, ee)
		appendEdge(b, a, i, ee)
	}
	dd := make([]int, n)
	dfs(0, -1, 0, dd, ee)
	win := make([]bool, n+1)
	win[0] = true
	for i := 2; i < n+1; i++ {
		win[i] = !(win[i-1] && win[i-2])
	}
	mx := -1
	for i := 0; i < n; i++ {
		mx = maxint(mx, dd[i])
	}
	if win[mx] {
		fmt.Fprintln(writer, "First")
		return
	}
	fmt.Fprintln(writer, "Second")
}

func dfs(c, p, d int, dd []int, ee [][]edge) int {
	dd[c] = d
	hh := make([]int, 2)
	hh[0] = d
	hh[1] = d
	for _, e := range ee[c] {
		if e.to == p {
			continue
		}
		h := dfs(e.to, c, d+1, dd, ee)
		hh = append(hh, h)
		sort.Ints(hh)
		hh = hh[1:]
	}
	dd[c] = hh[0] + hh[1] - d<<1
	return hh[1]
}

func maxint(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func appendEdge(from, to, id int, ee [][]edge) {
	ee[from] = append(ee[from], edge{
		to: to,
		id: id,
	})
}

type edge struct {
	to, id int
}


Measured memory_bytes: 120704
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  string S, T;
  int ans=0;
  cin >> S;
  T="CODEFESTIVAL2016";
  for (int i=0; i<16; i++) {
    if (S.at(i)!=T.at(i)) {
      ans=ans+1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3596
#include <algorithm>
#include <cstdint>
#include <limits>
#include <queue>
#include <vector>

///////////////////
#include <iostream>
using namespace std;
///////////////////

template <typename T>
struct Edge {
  int64_t to;
  T cost;
  Edge(int64_t to_, T cost_) : to(to_), cost(cost_) {}

  T To(void) const { return to; }
  T Cost(void) const { return cost; }
};

template <typename T>
using WeightedGraph = vector<vector<Edge<T>>>;

template <typename T>
void Dijkstra(const WeightedGraph<T>& graph, int64_t s, vector<T>* dst) {
  const T kInf = numeric_limits<T>::max();
  dst->clear();
  dst->resize(graph.size());
  fill(dst->begin(), dst->end(), kInf);

  using P = pair<T, int64_t>;

  priority_queue<P, vector<P>, greater<P>> que;

  (*dst)[s] = 0;
  que.push(P(T(0), s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    const int64_t v_id = p.second;

    const T d = (*dst)[v_id];

    if (d < p.first) continue;

    for (const auto& e : graph[v_id]) {
      const auto& nv_id = e.To();
      const T n_cost    = d + e.Cost();
      if ((*dst)[nv_id] <= n_cost) continue;
      (*dst)[nv_id] = n_cost;
      que.push(P((*dst)[nv_id], nv_id));
    }
  }
}

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

#ifdef USE_STACK_TRACE_LOGGER
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#include <glog/logging.h>
#pragma clang diagnostic pop
#endif  //__clang__
#endif  // USE_STACK_TRACE_LOGGER

using ll = long long;
signed main(int argc, char* argv[]) {
  (void)argc;
#ifdef USE_STACK_TRACE_LOGGER
  google::InitGoogleLogging(argv[0]);
  google::InstallFailureSignalHandler();
#else
  (void)argv;
#endif  // USE_STACK_TRACE_LOGGER

  ll n, m, s;
  cin >> n >> m >> s;
  vector<ll> u(m), v(m), a(m), b(m), c(n), d(n);

  ll a_max = numeric_limits<ll>::min();
  rep(i, m) {
    cin >> u[i] >> v[i] >> a[i] >> b[i];
    u[i]--;
    v[i]--;
    a_max = max(a_max, a[i]);
  }

  rep(i, n) { cin >> c[i] >> d[i]; }

  ll p = a_max * (n - 1) + 1;

  WeightedGraph<ll> g(p * n);

  rep(i, m) {
    rep(j, p) {
      if (j < a[i]) continue;
      g[u[i] * p + j].emplace_back(v[i] * p + j - a[i], b[i]);
      g[v[i] * p + j].emplace_back(u[i] * p + j - a[i], b[i]);
    }
  }

  rep(i, n) {
    rep(j, p) { g[i * p + j].emplace_back(i * p + min(p - 1, j + c[i]), d[i]); }
  }

  vector<ll> ans;
  Dijkstra(g, std::min(p - 1, s), &ans);

  rep(i, n) {
    if (i == 0) continue;
    ll min_ = numeric_limits<ll>::max();
    rep(j, p) { min_ = min(min_, ans[i * p + j]); }
    printf("%lld\n", min_);
  }
  return 0;
}

Measured memory_bytes: 23004
#include <iostream>
#include <cmath>

using namespace std;
#define N 101000
#define inf (1 << 30)
int h[N],d[N],i,j,n,k,curr;
int main()
{
    cin >> n;
    cin >> k;
    for (i = 0; i < n; ++i){
        cin >> h[i];
        d[i] = inf;
    }
    d[0] = 0;
    for (i = 0; i < n; ++i)
        for(j = 0; j < k; ++j)
            if(i + j + 1 < n){
                curr = abs(h[i] - h[i + j + 1]);
                d[i + j + 1] = min (d[i + j + 1], d[i] + curr);
            }
    cout << d[n - 1];
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
	{
	    cin>>arr[i];
	}
	int ans[n];
	ans[0]=0;
	ans[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++)
	{
	    int temp=ans[i-2]+abs(arr[i-2]-arr[i]);
	    int temp2=ans[i-1]+abs(arr[i-1]-arr[i]);
	    temp=min(temp,temp2);
	    ans[i]=temp;
	}
	cout<<ans[n-1]<<"\n";
}
	
	

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
const int N = 2 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
int main(){/*
    freopen("in","r",stdin);
    freopen("out","w",stdout);*/
    int a,b;
    cin >> a >> b;
    a += b;
    if(a > 23)
        a = a - 24;
    cout << a << endl;
    return 0;
}   

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

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

	n %= 10;
	if (n == 3) cout << "bon";
	else if (n == 0 || n == 1 || n == 6 || n == 8) cout << "pon";
	else cout << "hon";

	return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sst stringstream
#define sz size()
#define vc vector
typedef vc<int> vi;
typedef vc<ll> vl;
typedef vc<string> vs;

int N,date[111],point[111];
int dp[111][1<<16];

int f(int cur,int mask){
	int& res=dp[cur][mask];
	if(res>-1)return res;
	if(cur==N)return res=0;
	res=f(cur+1,mask);
	if((date[cur]&mask)==date[cur]){
		res=max(res,point[cur]+f(cur+1,mask^date[cur]));
	}
	return res;
}

int main(){
	while(cin>>N && N){
		rep(i,N){
			int M;
			cin>>M>>point[i];
			date[i]=0;
			rep(j,M){
				int S,E;
				cin>>S>>E;
				rep2(k,S,E)date[i]|=1<<(k-6);
			}
		}
		memset(dp,-1,sizeof(dp));
		cout<<f(0,(1<<16)-1)<<endl;
	}
}

Measured memory_bytes: 29584
n,q = map(int,input().split())
p = [input().split() for _ in range(n)]

time = 0
while len(p) > 0:
    left = int(p[0][1]) - q
    if left <= 0:
        time = time + int(p[0][1])
        print(p[0][0],end="")
        print(" ",end="")
        print(time)
        p.pop(0)
    else:
        time = time + q
        p[0][1] = left
        p.append(p[0])
        p.pop(0)
        



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

int main() {
	// your code goes here
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	int dp[k+1]={0};
	for(int i=0;i<=k;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(a[j]<=i)
			{
				if(dp[i-a[j]]==0)dp[i]=1;
			}
		}
	}
	if(dp[k]==1)cout<<"First";
	else cout<<"Second";
	return 0;
}

Measured memory_bytes: 768
#abc169d
n=int(input())
res=0
for i in range(2,int(n**0.5)+2):
 if n%i==0:
  cnt=0
  while n%i==0:
   n//=i
   cnt+=1
  j=1
  while cnt-j>=0:
   res+=1
   cnt-=j
   j+=1
if n>1:
 res+=1
print(res)


Measured memory_bytes: 9148
#include<stdio.h>

int a[101];
int b[101];

typedef struct
{
  int dg[101];
}g;

void bfs(g g[], int n)
{
  for(int i = 1; i <= n; i++)
    {
      a[i] = -1;
    }
  int head = 0, end = 0;
  b[end++] = 1;
  a[1] = 0;

  while(head != end)
    {
      int t = b[head++];
      for(int i = 1; i <= n; i++)
	{
	  if(a[i] == -1 && g[t].dg[i] == 1)
	    {
	      a[i] = a[t]+1;
	      b[end++] = i;
	    }
	}
    }
  
}

int main()
{
  int n1, c, b, d;
  scanf("%d", &n1);
  g g[n1+1];
  for(int i = 0 ; i < n1; i++)
    {
      scanf("%d%d", &c, &b);
      for(int j = 0; j < b; j++)
	{
	  scanf("%d", &d);
	  g[c].dg[d] = 1;
	} 
    }
  bfs(g, n1);

  for(int i = 1 ;i <= n1; i++)
    {
      printf("%d %d\n", i, a[i]);
    }
  
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rd3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define rl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	ll r;
	rl(r);
	ll ar=3*r*r;
	wl(ar);
	NL;
	return 0;
}

Measured memory_bytes: 256
for(;scanf("%d",&n),n;){
    double m=999,h,w,z;
    for(;n--;){
      scanf("%d%lf%lf",&i,&h,&w);
      z=fabs(w*10000/h/h-22);
      if(m>z)m=z,I=i;
      else if(m==z&&i<I)I=i;
    }
    printf("%d\n",I);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    vector<pair<int, int>> edges;
    int mc = 0, mv = -1;
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
        edges.emplace_back(a, b);
        if (mc < sz(g[a])) {
            mc = sz(g[a]);
            mv = a;
        }
        if (mc < sz(g[b])) {
            mc = sz(g[b]);
            mv = b;
        }
    }
    priority_queue<int> pq;
    rep(i, n) {
        int c;
        cin >> c;
        pq.push(c);
    }
    vector<int> d(n, -1);
    d[mv] = pq.top(); pq.pop();
    queue<int> q;
    q.push(mv);
    while(!q.empty()) {
        int u = q.front(); q.pop();
        for (auto x : g[u]) {
            if (d[x] != -1) continue;
            d[x] = pq.top();
            pq.pop();
            q.push(x);
        }
    }
    ll total = 0;
    rep(i, n - 1) {
        total += min(d[edges[i].first], d[edges[i].second]);
    }
    printf("%lld\n", total);
    rep(i, n) {
        printf("%d%s", d[i], (i == (n - 1)) ? "\n" : " ");
    }
    return 0;
}


Measured memory_bytes: 1152
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import defaultdict

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

dic = defaultdict(int)
for num in A:
    dic[num] += 1

Q = int(input())

sum_A = sum(A)
for i in range(Q):
    b, c = map(int, input().split())
    sum_A = sum_A - b * dic[b] + c * dic[b] 
    print(sum_A)
    dic[c] += dic.pop(b)

Measured memory_bytes: 94496
#include <bits/stdc++.h>
using namespace std;
int main() {
    int64_t n,a,b;
    cin >> n >> a >> b;
    if(a > b) {
        cout << 0 << endl;
        return 0;
    }
    if(a == b) {
        cout << 1 << endl;
        return 0;
    }
    if(a != b && n == 1) {
        cout << 0 << endl;
        return 0;
    }
    if(n == 2) {
        cout << 1 << endl;
        return 0;
    }
    cout << (n - 2) * (b - a) + 1 << endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807

using namespace std;

long long GCD(long long a, long long b) {
	if (a < b)
		swap(a, b);
	if (b == 0) return a;
	else return GCD(b, a % b);
}
bool sosuu_check(int num) {
	int i;
	for (i = 2; i <= sqrt(num); ++i) {
		if (num%i == 0)
			return false;
	}
	return (num < 2) ? false : true;
}
int main() {
	vector<vector<int>> vec(10, vector<int>(10, 0));
	vector<vector<long>> need_maryoku(10, vector<long>(10, 0));
	int H, W, i, j, k;
	ll ans = 0;
	cin >> H >> W;
	REP(i, 10) {
		REP(j, 10) {
			cin >> vec[i][j];
			need_maryoku[i][j] = vec[i][j];
		}
	}
	REP(k, 10) {
		REP(i, 10) {
			REP(j, 10) {
				if (need_maryoku[i][j] > need_maryoku[i][k] + need_maryoku[k][j]) {
					need_maryoku[i][j] = need_maryoku[i][k] + need_maryoku[k][j];
				}
			}
		}
	}
	REP(i, H*W) {
		cin >> k;
		if (k >= 0) 
			ans += need_maryoku[k][1];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int n, p, r[50], d[50][50]; bool a[50][30];
int main() {
	while (true) {
		scanf("%d", &n);
		if (n == 0) break;
		for (int i = 0; i < n; i++) {
			scanf("%d", &r[i]);
			for (int j = 0; j < 30; j++) {
				a[i][j] = false;
			}
			for (int j = 0; j < r[i]; j++) {
				scanf("%d", &p); a[i][p - 1] = true;
			}
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				d[i][j] = 9999999;
			}
		}
		for (int i = 0; i < n; i++) {
			priority_queue<pair<int, int> > que; que.push(make_pair(0, i)); d[i][i] = 0;
			while (!que.empty()) {
				pair<int, int> state = que.top(); que.pop();
				int dist = -state.first;
				int node = state.second;
				for (int j = 0; j < n; j++) {
					for (int k = dist; k < 30; k++) {
						if (a[node][k] && a[j][k]) {
							if (d[i][j] > k) {
								d[i][j] = k; que.push(make_pair(-k, j));
							}
						}
					}
				}
			}
		}
		int ret = 9999999;
		for (int i = 0; i < n; i++) {
			int res = 0;
			for (int j = 0; j < n; j++) {
				res = max(res, d[j][i]);
			}
			ret = min(ret, res);
		}
		printf("%d\n", ret == 9999999 ? -1 : ret + 1);
	}
	return 0;
}

Measured memory_bytes: 3196
using System;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        string s = sc.Next();
        int ans = -1;
        switch (s)
        {
            case "SUN":
                ans = 7;
                break;
            
            case "MON":
                ans = 6;
                break;
            
            case "TUE":
                ans = 5;
                break;
            
            case "WED":
                ans = 4;
                break;
            
            case "THU":
                ans = 3;
                break;
            
            case "FRI":
                ans = 2;
                break;
            
            case "SAT":
                ans = 1;
                break;
        }
        
        Console.WriteLine(ans);
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}



class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define abdelrahman001 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define inFile(t) freopen((t),"r",stdin)
#define outFile(t) freopen((t),"w",stdout)
#define pb push_back
#define pf push_front
#define Pb pop_back
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define Pf pop_front
#define sz size
#define MP make_pair
#define Pc __builtin_popcount
#define pi 2*acos(0)
#define BiEdge(v,a,b) (v)[(a)].pb(b),(v)[(b)].pb((a))
#define mod 1000000007
#define point complex<ld>
#define X real()
#define Y imag()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define cross(a,b)(conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define rectangle pair<coordinate,coordinate>
#define line tuple<ll,ll,ll>
#define EPS 1e-7
#define polygon vector<point>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int const N = 1e5+5,M = 105;
using namespace std;
ll n,W,memo[M][N];
pll arr[M];
ll solve(ll ind,ll w)
{
    if(w > W)
        return -1e9;
    if(ind == n)
        return 0;
    ll &ans = memo[ind][w];
    if(~ans)
        return ans;
    ans = max(solve(ind+1,w+arr[ind].F) + arr[ind].S,solve(ind+1,w));
    return ans;
}
int main()
{
    abdelrahman001
    memset(memo,-1,sizeof memo);
    cin >> n >> W;
    for(int i = 0;i<n;i++)
        cin >> arr[i].F >> arr[i].S;
    cout << solve(0,0);
    return 0;
}


Measured memory_bytes: 82304
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>

using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
const double PI = 3.14159265359;

int main(void) {
	ll n, k;
	cin >> n >> k;
	ll ans = 0;
	vector<ll> v(n);
	rep(i, n) {
		cin >> v[i];
		if (v[i] >= k)ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
 
using namespace std;
using ll = long long;
constexpr int MOD = 1e9+7;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
ll gcd(ll a, ll b){ return (b == 0) ? a : gcd(b, a % b); }
ll lcm(ll a, ll b){ return a/gcd(a, b)*b; };
 
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Unique(a) a.erase(unique(Range(a)), a.end());
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

int main(void){
    Cin(int, a, b, x, y);
    x -= a, y -= b;
    Rep(x) cout << "R";
    Rep(y) cout << "U";
    Rep(x) cout << "L";
    Rep(y) cout << "D";
    cout << "LU";
    Rep(y) cout << "U";
    Rep(x) cout << "R";
    cout << "RDRD";
    Rep(y) cout << "D";
    Rep(x) cout << "L";
    cout << "LU\n";
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cta=[0]*n
ctb=[0]*n
for i in range(n):
  cta[a[i]-1]+=1
  ctb[b[i]-1]+=1

for i in range(n):
  if cta[i]+ctb[i]>n:
    print('No')
    exit()

sa=[0]
sb=[0]
for i in range(n):
  sa.append(cta[i]+sa[-1])
  sb.append(ctb[i]+sb[-1])
l=[]
for i in range(n):
  l.append(sa[i+1]-sb[i])
ans=[]
maxl=max(l)
for i in range(n):
  ans.append(str(b[(i-maxl)%n]))
print('Yes')
print(' '.join(ans))

Measured memory_bytes: 151140
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
    static int k;

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        k = in.nextInt();
        bfs();
    }

    static void bfs() {
        long cnt = 0;
        LinkedList<Long> ls = new LinkedList<Long>();
        for (int i = 1; i < 10; i++) {
            ls.addLast((long) i);
        }
        while (!ls.isEmpty()) {
            long i = ls.poll();
            cnt++;
            if (cnt == k) {
                System.out.println(i);
                return;
            }
            long x = i % 10;
            if (x >= 1)
                ls.add(i * 10 + x - 1);
            ls.add(i * 10 + x);
            if (i % 10 < 9)
                ls.add(i * 10 + x + 1);
        }
    }
}


Measured memory_bytes: 37332
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;++i){
		vector<double> a(2),b(2),c(2),d(2);
		double tmp;
		cin>>a[0]>>a[1]>>b[0]>>b[1]>>c[0]>>c[1]>>d[0]>>d[1];
		double x1=b[0]-a[0],y1=b[1]-a[1];
		double x2=d[0]-c[0],y2=d[1]-c[1];
		if(x1*y2-x2*y1==0) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
N = int(input())
S = input()

W,E = [0]*N, [0]*N

for i in range(1,N):
    if S[i-1]=='W':
        W[i] = W[i-1]+1
    else:
        W[i] = W[i-1]

S = S[::-1]
for i in range(1,N):
    if S[i-1]=='E':
        E[i] = E[i-1]+1
    else:
        E[i] = E[i-1]
E = E[::-1]

A = [0]*N
for i in range(N):
    A[i] = E[i]+W[i]

ans = min(A)
print(ans)


Measured memory_bytes: 29620
#pragma GCC target ("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma warning (disable:4996)
#include"bits/stdc++.h"
#define int long long
#define MRE assert(0);
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const long long mod = 1000000007;
const long long inf = 1e17;
typedef pair<int, int> P;
int par[200006], siz[200006];
int c[200006], w[200006];
vector<P>C[200006];
vector<int>G[200006];
int kj[200006], kji[200006];
void init(int n) {
	rep(i, n) {
		par[i] = i; siz[i] = 1;
	}
}
int find(int x) {
	if (x == par[x])return x;
	return par[x] = find(par[x]);
}
void unite(int x, int y) {
	x = find(x); y = find(y);
	if (x == y)return;
	if (siz[x] > siz[y])swap(x, y);
	par[x] = y;
	siz[y] += siz[x];
}
int modpow(int a, int x) {
	int res = 1;
	while (x) {
		if (x & 1)res = res*a%mod;
		a = a*a%mod;
		x >>= 1;
	}
	return res;
}
void setkj() {
	kj[0] = 1;
	rep(i, 200005) {
		kj[i + 1] = kj[i] * (i + 1)%mod;
		kji[i] = modpow(kj[i], mod - 2);
	}
}
signed main() {
	int n, x, y; cin >> n >> x >> y;
	rep(i, n) {
		cin >> c[i] >> w[i];
		c[i]--;
	}

	if (n == 1) {
		cout << 1 << endl; return 0;
	}

	init(n);
	setkj();

	rep(i, n) {
		C[c[i]].push_back(P(w[i],i));
	}
	rep(i, n)sort(C[i].begin(), C[i].end());
	priority_queue<P, vector<P>, greater<P>>Q;
	rep(i, n) {
		if (C[i].size()) {
			Q.push(C[i][0]);
			int t = x-C[i][0].first;
			for (int j = 1; j < C[i].size(); j++) {
				if (C[i][j].first > t)break;
				unite(C[i][0].second, C[i][j].second);
			}
		}
	}

	rep(x, 2) {
		P p = Q.top(); Q.pop();
		rep(i, n) {
			if (c[i] != c[p.second]&&w[i] + p.first <= y)unite(i, p.second);
		}
	}

	/*
	rep(i, n) {
		rep(j, n) {
			if (c[i] == c[j]) {
				if (w[i] + w[j] <= x)unite(i, j);
			}
			else {
				if (w[i] + w[j] <= y)unite(i, j);
			}
		}
	}*/

	rep(i, n) {
		G[find(i)].push_back(c[i]);
	}

	int ans = 1;
	rep(i, n) {
		int res = kj[G[i].size()];
		map<int, int>M;
		for (int e : G[i])M[e]++;
		for (auto itr = M.begin(); itr != M.end(); itr++) {
			res = res*kji[itr->second] % mod;
		}
		ans = ans*res%mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 36976
#include<stdio.h>



int main() {
	int n, m, l;
	long A[100][100];
	long B[100][100];
	long C[100][100];

	scanf("%d %d %d", &n, &m, &l);
	for (int row = 0; row < n; row++) {
		for (int col = 0; col < m; col++) {
			scanf("%ld", &A[row][col]);
		}
	}
	for (int row = 0; row < m; row++) {
		for (int col = 0; col < l; col++) {
			scanf("%ld", &B[row][col]);
		}
	}

	for (int row = 0; row < n; row++) {
		for (int col = 0; col < l; col++) {
			C[row][col] = 0;
			for (int i = 0; i < m; i++) {
				C[row][col] += A[row][i] * B[i][col];
			}
		}
	}

	for (int row = 0; row < n; row++) {
		for (int col = 0; col < l; col++) {
			printf("%ld", C[row][col]);
			if (col < l - 1)printf(" ");
		}
		printf("\n");
	}


	return 0;
}


Measured memory_bytes: 2972
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, input().rstrip('\n').split()))
    ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    ab.sort()
    cnt = 0
    for a, b in ab:
        cnt += b
        if cnt >= k:
            print(a)
            exit()


if __name__ == '__main__':
    solve()


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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

bool vis[100005];

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

    long long n, x, m;
    cin >> n >> x >> m;

    long long ret = 0;
    for (long long i=0; i<n; i++) {
        ret += x;
        vis[x] = true;
        x = x * x % m;
        if (vis[x]) {
            vector<long long> pref;
            pref.push_back(x);
            long long u = x * x % m;
            while (u != x) {
                pref.push_back(pref.back() + u);
                u = u * u % m;
            }
            ret += (n - i - 1) / (int) pref.size() * pref.back() + ((n - i - 1) % (int) pref.size() > 0 ? pref[(n - i - 1) % (int) pref.size() - 1] : 0);
            break;
        }
    }
    cout << ret << "\n";

    return 0;
}


Measured memory_bytes: 3868