akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define INS(x) x.begin(),x.end()
    
long long a[200005];
set<int> str;
vector<int> check;
map<int,long long> p;
    
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;

    for (int i=0;i<n;i++)
    {
        cin>>a[i];
        int l=str.size();
        str.insert(a[i]);
        if (str.size()>l)
            check.push_back(a[i]);
        p[a[i]]++;
    }

    long long ans=0;
    for (auto i:check)
    {
        ans+=p[i]*(p[i]-1)/2;
    }

    for (int i=0;i<n;i++)
        cout<<ans-(p[a[i]]-1)<<'\n';
    return 0;
}

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

int main(){
  int N;
  long long K;
  cin >> N >> K;
  vector<long long> A(N), F(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  for(int i = 0; i < N; ++i) cin >> F[i];
  long long ok = 1e18, ng = -1;
  sort(A.begin(), A.end());
  sort(F.rbegin(), F.rend());
  while(ok-ng > 1){
    long long m = (ok+ng)/2;
    long long t = 0;
    for(int i = 0; i < N; ++i){
      t += max(0LL,A[i]-m/F[i]);
    }
    if(t <= K) ok = m;
    else ng = m;
  }
  cout << ok << endl;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mp make_pair
ll power(ll x,ll y,ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
int main(){
  ll n,m;
  cin >> n >> m;
  if(n%m==0)  cout << n/m << endl;
  else cout << n/m +1 << endl;

}


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

const int INF = 1e9;

const int MAXN = 3e5;
int N;
char A[MAXN];

int nxt[MAXN][26]; // current # done, next index
int dp[MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> A;
	N = int(strlen(A));

	for (int c = 0; c < 26; c++) {
		nxt[N][c] = N;
	}
	for (int i = N-1; i >= 0; i--) {
		for (int c = 0; c < 26; c++) {
			nxt[i][c] = nxt[i+1][c];
		}
		nxt[i][int(A[i] - 'a')] = i;
	}

	// reach N+1
	dp[N+1] = 0;
	for (int i = N; i >= 0; i--) {
		dp[i] = INF;
		for (int c = 0; c < 26; c++) {
			dp[i] = min(dp[i], dp[nxt[i][c] + 1] + 1);
		}
	}

	int cur = 0;
	string ans;
	while (cur != N+1) {
		int c = 0;
		while (dp[cur] != dp[nxt[cur][c] + 1] + 1) {
			c++;
		}
		ans += char(c + 'a');
		cur = nxt[cur][c] + 1;
	}
	cout << ans << '\n';

	return 0;
}

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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int a[n], b[n], c[m], d[m];
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> c[i] >> d[i];
  }
  for (int i = 0; i < n; i++) {
    int min = 200000000;
    int tn = 0;
    for (int j = 0; j < m; j++) {
      int di = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (di < min) {
        min = di;
        tn = j;
      }
    }
    cout << ++tn << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;
int n;
int a[102];
void plot() {
    rep(i,n) cout<<(i==0?"":" ")<<a[i];
    cout<<endl;
}
void insert_sort() {
    for(int i=1;i<n;i++) {
        plot();
        int v=a[i];
        int j=i-1;
        while(j>=0 && a[j] > v) {
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=v;
    }
    plot();

}

int main() {
    cin>>n;
    rep(i,n) cin>>a[i];
    insert_sort();
    return 0;
}

Measured memory_bytes: 1164
import sys
input = sys.stdin.readline
def calc(x):
    if x == 0:
        return 0
    r = x % 4
    if r == 0:
        return x
    elif r == 1:
        return 1
    elif r == 2:
        return 1 ^ x
    else:
        return 0
def print_ans(A, B):
    """Test Case
    >>> print_ans(2, 4)
    5
    >>> print_ans(123, 456)
    435
    >>> print_ans(123456789012, 123456789012)
    123456789012
    """
    tmp = calc(A -1)
    tmp2 = calc(B)
    print(tmp ^ tmp2)

    

if __name__ == '__main__':
    A, B = map(int, input().rstrip().split())
    print_ans(A, B)


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
 
int N;
int A[101];
 
void print() {
  for(int i = 1; i <= N; ++i)
    cout << (i!=1?" ":"") << A[i];
  cout << endl;
}
 
int main() {
  cin >> N;
  for(int i = 1; i <= N; ++i) cin >> A[i];
 
  print();
  for(int j = 2; j <= N; ++j) {
    int key = A[j];
    /* insert A[j] into the sorted sequence A[1,....,j-1] */
    int i = j - 1;
    while(i > 0 && A[i] > key) {
      A[i+1] = A[i];
      i = i - 1;
    }
    A[i+1] = key;
    print();
  }
  return 0;
}

Measured memory_bytes: 3092
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<queue>
#define int long long
using namespace std;
signed main() {
	int n, a = 0, b = 0, ans = 0; cin >> n;
	vector<vector<int>>aa(n, vector<int>(2));
	for (int h = 0; h < n; h++) {
		cin >> aa[h][0] >> aa[h][1];
	}
	sort(aa.begin(), aa.end());
	a = aa[0][0]; b = aa[0][1];
	for (int h = 1; h < n; h++) {
		if (a + b > aa[h][0] - aa[h][1]) {
			if (a + b > aa[h][0] + aa[h][1]) {
				a = aa[h][0]; b = aa[h][1];
			}
			ans++;
		}
		else {
			a = aa[h][0]; b = aa[h][1];
		}
	}
	cout << n - ans << endl;
}

Measured memory_bytes: 5760
x3, y3, x4, y4 = map(int, input().split())
changeX = x4 - x3
changeY = y4 - y3
x = x4
y = y4
for _ in range(2):
    temp = changeX
    changeX = changeY * -1
    changeY = temp
    x = x + changeX
    y = y + changeY
    print(x, y, end = ' ')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
using namespace std;
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#define LL long long
#define INF (LL)1e10
using namespace std;

LL bfs(LL start, LL goal, LL N, vector<vector<LL>> edges){
    deque<pair<LL, LL>> q;
    vector<vector<LL>> visited(N, vector<LL>(3, INF));
    q.emplace_back(make_pair(0, start));
    while(!q.empty()){
        auto l0=q.front().first,src=q.front().second;
        q.pop_front();
        if(l0 >= visited[src][l0%3])continue;
        visited[src][l0%3]=l0;
        if(src==goal && l0%3==0)break;
        for(auto dst: edges[src]){
            q.emplace_back(make_pair(l0+1, dst));
        }
    }
    return visited[goal][0];
}

void solve(long long N, long long M, std::vector<long long> u, std::vector<long long> v, long long S, long long T){
    vector<vector<LL>> edges(N);
    for(LL i=0; i<M; i++){
        edges[u[i]-1].emplace_back(v[i]-1);
    }
    auto ans = bfs(S-1, T-1, N, edges);
    cout << (ans < INF ? ans/3 : -1) << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> u(M);
    std::vector<long long> v(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&u[i]);
        scanf("%lld",&v[i]);
    }
    long long S;
    scanf("%lld",&S);
    long long T;
    scanf("%lld",&T);
    solve(N, M, std::move(u), std::move(v), S, T);
    return 0;
}


Measured memory_bytes: 18176
n,k=map(int,input().split())
s=[0]*n
count=0
for i in range(k*2):
  if i%2==0:
    d=int(input())
  else:
    *a,=map(int,input().split())
    for j in range(d):
      tmp=a[j]
      s[tmp-1]+=1
for i in range(n):
  if s[i]==0:
    count+=1
print(count)

Measured memory_bytes: 9204
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).ok();
    let mut it = buf.split_whitespace();
    let a = it.next().unwrap().parse::<u64>().unwrap();
    let b = it.next().unwrap().parse::<u64>().unwrap();
    let mut div : Vec<u64> = Vec::new();
    for i in 2..a {
        if i * i > a { break; }
        if a % i == 0 {
            if b % i == 0 { div.push(i) }
            if b % (a/i) == 0 { div.push(a/i) }
        }
    }
    if a > 1 && b % a == 0 { div.push(a); }
    div.sort();
    let mut res : Vec<u64> = Vec::new();
    for d in div {
        if res.iter().all(|x| d % x != 0) { res.push(d); }
    }
    println!("{}", res.len() + 1);
}


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

int main() {
  int N;
  cin >> N;
  vector<int> data(N);
  for (int i = 0; i < N-1; i++) {
    cin >> data.at(i);
  }
  data.at(N-1) = 30000000;
  sort(data.begin(), data.end());
  
  vector<int> ans(N);
  for (int i = 0; i < N-1; i++) {
    if (data.at(i) < data.at(i+1)) {
      ans.at(data.at(i)-1) = i+1;
    }
    else {
      continue;
    }
  }
  cout << ans.at(0) << endl;
  for (int i = 1; i < N; i++) {
    if (ans.at(i) == 0) {
      ans.at(i) = ans.at(i-1);
      cout << ans.at(i)-ans.at(i-1) << endl;
    }
    else {
      cout << ans.at(i)-ans.at(i-1) << endl;
    }
  }
  
}

Measured memory_bytes: 4768
//#define _GLIBCXX_DEBUG
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<string>
#include<bitset>
#include<random>
#include<ctime>
using namespace std;
typedef long long ll;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n;
	cin >> n;
	vector<ll> a(n);
	cin >> a[0];
	bool fl = true;
	ll mint = a[0]-1;
	for (int i = 1; i < n; ++i) {
		cin >> a[i];
		if (a[i] < mint) {
			fl = false;
		}
		mint = max(mint, a[i]-1);
	}
	if (fl) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}


Measured memory_bytes: 1024
#include<stdio.h>
 
int main(void){
   int X,Y;
   int i;
   int count=0;
    scanf("%d %d",&X,&Y);
 
    for(i=0;i<=X;i++){
       int sum=(X-i)*4+i*2;
        if(sum==Y){
            printf("Yes\n");
            count++;;
        }
    }
    if(count==0){
       printf("No\n");
    }
    return 0;
}



Measured memory_bytes: 1640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
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...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111
	

	void solve(){
		

		ini(x,x1,x2);
		if(x1*x2>=x){
			return out("Yes");
		}
		else{
			return out("No");
		}
		
			
			
			


				
		


		
		
		
		

		


		
		
	}



	



















int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int N = 2555;
int n, m, d;
int a[N][N];

void printC(int x) {
	char c = 'B';;
	if (x == 0)
		c = 'R';
	if (x == 1)
		c = 'Y';
	if (x == 2)
		c = 'G';
	if (x == 3)
		c = 'B';
	printf("%c", c);
}
void printAns() {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++)
			printC(a[i][j]);
		printf("\n");
	}
}

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

	scanf("%d%d%d", &n, &m, &d);
	if (d & 1) {
		for (int i = 0; i < n; i++)
			for (int j = 0; j < m; j++)
				a[i][j] = (i + j) & 1;
		printAns();
		return 0;
	}
	d /= 2;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) {
			int x = i + j, y = 2 * (n + m) + i - j;
			x /= 2;
			y /= 2;
			x %= 2 * d;
			y %= 2 * d;
			x /= d;
			y /= d;
			a[i][j] = x * 2 + y;
		}
	printAns();

	return 0;
}


Measured memory_bytes: 5760
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        string s = ReadLine();
        int N = s.Length;

        int pscore = 0;
        foreach (var i in s)
        {
            if (i == 'g')
                pscore++;
            else
                pscore--;
        }
        WriteLine(pscore/2);
    }
}


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

typedef long long inti;
int main()
{
	int n,m;
	cin>>n>>m;
	vector<string> v(n);
	for(inti i=0;i<n;i++)
	cin>>v[i];
	vector<vector<inti> > ans(n, vector<inti> (m,0));
	inti mod=1e9+7;
	for(inti i=n-1;i>=0;i--)
	{
		if(v[i][m-1]=='.')
		ans[i][m-1]=1;
		else break;
	}
	for(inti i=m-1;i>=0;i--)
	{
		if(v[n-1][i]=='.')
		ans[n-1][i]=1;
		else break;
	}
	for(inti i=n-2;i>=0;i--)
	{
		for(int j=m-2;j>=0;j--)
		{
		
		if(v[i][j]=='.')
		ans[i][j]=(ans[i][j+1] + ans[i+1][j])%mod;
	}}
	cout<<ans[0][0];
	return 0;
}


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

namespace AOJ_GPL_6_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var VE = ReadInt();
            int V = VE[0];
            int E = VE[1];

            FordFulkerson fd = new FordFulkerson(V);
            for (int i = 0; i < E; i++)
            {
                var input = ReadInt();
                fd.AddEdge(input[0], input[1], input[2]);
            }

            var ans = fd.MaxFlow(0, V - 1);

            Console.WriteLine(ans);
            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }

    class FordFulkerson//最大流
    {
        public struct Edge
        {
            public int to, cap, rev;
        }

        public List<Edge>[] G;
        bool[] used;
        int INF = 1000000009;

        public FordFulkerson(int V) //頂点数
        {
            G = new List<Edge>[V].Select(x => new List<Edge>()).ToArray();
            used = new bool[V];
        }

        public void AddEdge(int from, int to, int cap)
        {
            G[from].Add(new Edge() { to = to, cap = cap, rev = G[to].Count });
            G[to].Add(new Edge() { to = from, cap = 0, rev = G[from].Count - 1 });
        }

        int Dfs(int v, int t, int f)
        {
            if (v == t) 
                return f;
            used[v] = true;

            for (int i = 0; i < G[v].Count; i++)
            {
                var e = G[v][i];
                if (!used[e.to] && e.cap > 0)
                {
                    int d = Dfs(e.to, t, Math.Min(f, e.cap));
                    if (d > 0)
                    {
                        e.cap -= d;
                        G[v][i] = e;

                        var temp = G[e.to][e.rev];
                        temp.cap += d;
                        G[e.to][e.rev] = temp;

                        return d;
                    }
                }
            }
            return 0;
        }

        public int MaxFlow(int s, int t)
        {
            int flow = 0;
            while (true)
            {
                used = new bool[used.Length];
                int f = Dfs(s, t, INF);
                if (f == 0) return flow;
                flow += f;
            }
        }
    }
}



Measured memory_bytes: 20508
import math
N = 100001
pr = [True]*(N+1)
pr[0] = pr[1] = False
for i in range(2,int(math.sqrt(N))) :
    if pr[i]:
        for j in range(i+i,N,i):pr[j] = False

c = [0]*(N+1)

for i in range(3,N,2):
    if pr[i] and pr[(i+1)//2]:
        c[i]+=1
for i in range(3,N):
    c[i]+=c[i-1]
Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split())
    print(c[r]-c[l-1])

Measured memory_bytes: 7156
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
using ll = long long;

ll as[100010], bs[100010];

int main() {
	ll A, B, M, am = LLONG_MAX, bm = LLONG_MAX;
	cin >> A >> B >> M;
	for (int i = 0;i < A;i++) {
		cin >> as[i];
		am = min(am, as[i]);
	}
	for (int i = 0;i < B;i++) {
		cin >> bs[i];
		bm = min(bm, bs[i]);
	}
	ll ans = am + bm, x, y, c;
	for (int i = 0;i < M;i++) {
		cin >> x >> y >> c;
		ans = min(as[x - 1] + bs[y - 1] - c, ans);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
import java.awt.*;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int h=sc.nextInt(),w=sc.nextInt();
        int arr[][]=new int[h][w];
        for (int i=0;i<h;i++){
            String s=sc.next();
            for (int j=0;j<w;j++){
                arr[i][j]=s.charAt(j);
            }
        }
        int mod=(int)1e9+7;
        int dp[][]=new int[h][w];
        dp[0][0]=1;
        for (int i=0;i<h;i++){
            for (int j=0;j<w;j++){
                if (i-1>=0 && arr[i][j]=='.') {
                    dp[i][j] += dp[i-1][j];
                }
                if (j-1>=0 && arr[i][j]=='.'){
                    dp[i][j]+=dp[i][j-1];
                }
                if (dp[i][j]>=mod)dp[i][j]-=mod;
            }
        }
        System.out.println(dp[h-1][w-1]);
    }
}

Measured memory_bytes: 37328
from itertools import product
n,*B=map(int,input().split())
A=[int(input()) for i in range(n)]
s=10**9
for P in product([0,1,2,3],repeat=n):
  if {0,1,2}<=set(P):
    m=[0,0,0]
    for x,y in zip(P,A):
      if x!=3:
        m[x]+=y
    t=sum(abs(m-y) for m,y in zip(m,B))
    l=sum(1 for j in P if j!=3)-3
    s=min(s,t+l*10)
print(s)

Measured memory_bytes: 3064
use std::io::stdin;

#[derive(Default)]
struct Scanner {
	buffer: Vec<String>
}

impl Scanner {
	fn next<T: std::str::FromStr> (&mut self) -> T {
		loop {
			if let Some(token) = self.buffer.pop() {
				return token.parse().ok().expect("Failed parse");
			}
			let mut input = String::new();
			stdin().read_line(&mut input).expect("Failed read");
			self.buffer = input.split_whitespace().rev().map(String::from).collect();
		}
	}
}

fn main() {
	let mut scan = Scanner::default();
	let n: usize = scan.next();
	let mut a: [usize; 100005] = [0; 100005];
	let mut ans: usize = 0;
	let mut x: usize;
	let mut y: usize;
	for _ in 0..n {
		x = scan.next();
		a[x] += 1;
		ans += x;
	}
	let q: u32 = scan.next();
	for _ in 0..q {
		x = scan.next();
		ans -= x * a[x];
		y = a[x];
		a[x] = 0;
		x = scan.next();
		ans += x * y;
		a[x] += y;
		println!("{}", ans);
	}
}


Measured memory_bytes: 8872
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define ET cout << "\n"
#define DB(a,s,e) {for(int i=s;i<e;i++) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll dp[100005];
const ll INF=1e18;

int main()
{jizz
	ll n,w,a,b,sv=0;
	cin >> n >> w;
	fill(dp+1,dp+100005,INF);
	while(n--)
	{
		cin >> a >> b,sv+=b;
		for(int i=sv;i>=b;--i)
			dp[i]=min(dp[i],dp[i-b]+a);
	}
	for(int i=sv;i>=0;--i)
		if(dp[i]<=w) 
			return cout << i << "\n",0;
}

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

#define rep(i, n) FOR(i, 0, n)
#define FOR(i, x, n) for (int i = (x); i < (n); ++i)
#define all(v) (v).begin(), (v).end()

using ll = long long;

template<class T> void chmax(T& a, T b){ if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b){ if (a > b) { a = b; } }

int main() {
    int s, w;
    cin >> s >> w;
    if (s <= w) {
        cout << "unsafe" << endl;
    }
    else {
        cout << "safe" << endl;
    }

    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl

using Graf_char=vector<vector<char>>;
using Graf_int=vector<vector<int>>;
#define MAX 10000000

int main()
{
    int n;
    ll m;
    cin >> n >> m;
    vector<ll> fact;
    vector<ll> fact_;
    int count=0;
    for(int i=1;i*i<=m;++i){
        if(m%i==0){
            fact.push_back(i);
        }
    }
    count=fact.size();
    fact_=fact;
    ll max=0;
    for(int i=0;i<count;++i){
        fact_.push_back(m/fact[i]);
        
    }
    rep(i,fact_.size()){
        if(fact_[i]>max&&m/fact_[i]>=n){
            max=fact_[i];
        }
    }
    cout << max << endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <functional>
#include <cmath>
#include <cstdint>
#include <mutex>
#include <thread>
#include <bitset>

using namespace std;


int main(void)
{
	unsigned long long int x;
	cin >> x;

	unsigned long long int m = 100;

	int i;
	for (i = 0;m < x ; i++)
	{
		m += m / 100;
	}
	cout << i;
	return 0;
}

Measured memory_bytes: 3636
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<60);
const ld pi=acosl(1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};


void solve(){
	ll n,k;cin>>n>>k;
  vector<ll>A(n);
  vector<ll>F(n);
  rep(i,n)cin>>A[i];
  rep(i,n)cin>>F[i];
  sort(all(A));
  sort(all(F),greater<ll>());
  ll right=INF;
  ll left=-1;
  ll num,mid;
  while(right-left>1){
    mid=left+(right-left)/2;
    num=0;
    rep(i,n){
      num+=max((ll)0,A[i]-mid/F[i]);
    }
    if(!(num<=k))left=mid;
    else right=mid;
  }
  cout<<right<<endl;
}

signed main(){
	/*ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
	cout<<setprecision(30);*/
	solve();
}


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

using namespace std;

#define foru(i, l, r) for (register int i = l; i <= r; i++)
#define ford(i, r, l) for (register int i = r; i >= l; i--)

typedef long long ll;
const int maxn = 1e6 + 5;
int A[maxn], N, Add;
ll Ans;

int main() {
  //  freopen("b.in", "r", stdin);
  //  freopen("b.out", "w", stdout);
  scanf("%d", &N);
  foru(i, 1, N) scanf("%d", &A[i]);
  foru(i, 1, N) {
    Ans += A[i] >> 1, A[i] &= 1;
    if (A[i] && A[i + 1]) Ans++, A[i]--, A[i + 1]--;
  }
  printf("%lld\n", Ans);
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    vector<int> C(n);
    int count = 0;
    int max = 0;
    for(int i = 0; i < n; i++){
        cin >> A.at(i);
        if(A.at(i) > max){
            max = A.at(i);
        }
    }
    for(int i = 0; i < n; i++){
        if(A.at(i) == max){
            C.at(i) = 1;
            count += 1;
        }
    }    
    int second_max = 0;
    if(count == 1){
        for(int i = 0; i < n; i++){
            if(C.at(i) == 0){
                if(second_max < A.at(i)) second_max = A.at(i);
            }
        }
        for(int i = 0; i < n; i++){
            if(C.at(i) == 0){
                cout << max << endl;
            }else{
                cout << second_max << endl;
            }
        }
    }else{
        for(int i = 0; i < n; i++){
            cout << max << endl;
        }
    }
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N,M; cin>>N>>M;
  vector<bool> F(N);
  F[0]=1;
  vi A(N,1);
  rep(i,0,M){
    int X,Y; cin>>X>>Y;
    if(F[X-1]){
      F[Y-1]=1;
      if(A[X-1]==1)
        F[X-1]=0;
    }
    A[X-1]--;
    A[Y-1]++;
  }
  int ans=0;
  rep(i,0,N){
    if(F[i])
      ans++;
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define mset(x) memset(x, 0, sizeof(x))
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, i;
    cin >> n;
    int ac(0), wa(0), tle(0), re(0);
    rep(i, n) {
        string s;
        cin >> s;
        if (s.compare("AC") == 0) {
            ac++;
        } else if (s.compare("WA") == 0) {
            wa++;
        } else if (s.compare("TLE") == 0) {
            tle++;
        } else if (s.compare("RE") == 0) {
            re++;
        }
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}


Measured memory_bytes: 3620
main :: IO ()
main = do
  n <- (read :: String -> Int) <$> getLine
  vs <- map (read :: String -> Int) . words <$> getLine
  cs <- map (read :: String -> Int) . words <$> getLine
  print $ ans vs cs

ans :: [Int] -> [Int] -> Int
ans vs cs = sum $ zipWith (\x y -> if x > y then x-y else 0) vs cs

Measured memory_bytes: 636
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int		Cnt;
	int		Taro = 0;
	int		Hana = 0;

	auto ToLower = [](string &str)
	{
		for (auto &it : str)
			it = tolower(it);
	};

	cin >> Cnt;

	string	strTaro;
	string	strHana;

	for (int i = 0; i < Cnt; i++)
	{
		cin >> strTaro >> strHana;
		ToLower(strTaro);
		ToLower(strHana);

		if (strTaro > strHana)
		{
			Taro += 3;
		}
		else if (strTaro < strHana)
		{
			Hana += 3;
		}
		else
		{
			Taro += 1;
			Hana += 1;
		}
	}

	cout << Taro << " " << Hana << "\n";

	return 0;
}

Measured memory_bytes: 3156
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <sstream>
#include <cmath>
#include <numeric>
#include <array>

using namespace std;

typedef long long ll;


int main(int argc, const char * argv[]) {
    string S; cin >> S;
    vector<int> a(S.size(), 0);
    
    char cur = S[0]; // R
    int cnt = 0;
    int index = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] != cur) {
            if (cnt == 0) {
                for (int j = index; j < i; j++) {
                    if ((i - 1 - j) % 2 == 0) {
                        a[i-1] += 1;
                    } else {
                        a[i] += 1;
                    }
                }
                index = i;
                cur = 'L';
            } else if (cnt == 1) {
                for (int j = index; j < i; j++) {
                    if ((j - index) % 2 == 0) {
                        a[index] += 1;
                    } else {
                        a[index-1] += 1;
                    }
                }
                index = i;
                cur = 'R';
            }
            cnt = (cnt + 1) % 2;
        }
    }
    
    if (cnt == 1) {
        for (int j = index; j < S.size(); j++) {
            if ((j - index) % 2 == 0) {
                a[index] += 1;
            } else {
                a[index-1] += 1;
            }
        }
    }
    
    for (int i = 0; i < S.size(); i++) cout << a[i] << " ";
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 1088
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

char maze[1005][1005];
int num[1005][1005];
bool vis[1000005];

int h, w;

bool dfs(int r, int c, int n) {
    if (r < 0 || r >= h || c < 0 || c >= w) { return false; }
    if (maze[r][c] == '#') { return false; }
    if (num[r][c] > 0) { return false; }
    num[r][c] = n;
    vector<vector<int>> ds = {
        {0, 1},
        {1, 0},
        {0, -1},
        {-1, 0}
    };
    for (auto d : ds) {
        dfs(r + d[0], c + d[1], n);
    }
    return true;
}

int getn(int r, int c) {
    if (r < 0 || r >= h || c < 0 || c >= w) { return 0; }
    return num[r][c];
}

int main() {
    int ch, cw;
    int dh, dw;
    cin >> h >> w >> ch >> cw >> dh >> dw;
    for (int i = 0; i < h; i++) {
        scanf("%s", maze[i]);
    }
    int count = 1;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (dfs(i, j, count)) {
                count++;
            }
        }
    }
    // for (int i = 0; i < h; i++) {
    //     for (int j = 0; j < w; j++) {
    //         printf("%d", num[i][j]);
    //     }
    //     puts("");
    // }
    vector<set<int>> edges;
    for (int i = 0; i <= count; i++) {
        edges.push_back({});
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int from = num[i][j];
            if (from == 0) { continue; }
            for (int di = -2; di <= 2; di++) {
                for (int dj = -2; dj <= 2; dj++) {
                    int to = getn(i + di, j + dj);
                    if (to == 0 || from == to) { continue; }
                    edges[from].insert(to);
                }
            }
        }
    }
    // for (int i = 1; i < count; i++) {
    //     for (auto to : edges[i]) {
    //         printf("%d -> %d\n", i, to);
    //     }
    // }

    // bfs
    queue<int> q;
    int start = num[ch - 1][cw - 1];
    int end = num[dh - 1][dw - 1];
    // printf("try %d -> %d\n", start, end);
    int ans = -1;
    bool ok = false;
    q.push(start);
    vis[start] = true;
    while (!ok && !q.empty()) {
        int len = q.size();
        for (int i = 0; i < len; i++) {
            int nxt = q.front(); q.pop();
            if (nxt == end) {
                ok = true;
                break;
            } else {
                for (auto to: edges[nxt]) {
                    if (!vis[to]) {
                        q.push(to);
                        vis[to] = true;
                    }
                }
            }
        }
        ans++;
    }
    if (ok) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }
}


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

using namespace std;

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
	
	long N,K; cin>>N>>K;
	if (N == 1) {
        cout << K << endl;
        return 0;
	}
	vector<int> tree[N];
	for (int i = 0; i < N-1; i++) {
	    int a,b;
	    cin>>a>>b;
	    a--,b--;
	    tree[a].push_back(b);
        tree[b].push_back(a);
	}

    const long MOD = 1e9+7;
    auto mod = [&](long x) {return x%MOD;};
	vector<long> fact(100001);
	fact[0] = 1;
	for (long i = 1; i < fact.size(); i++)
	    fact[i] = mod(fact[i-1]*i);
	auto mod_pow = [&](long x, long y) {
	    long t = 1;
	    long u = x;
	    while (y) {
	        if (y&1)
	            t = mod(t*u);
	        u=mod(u*u);
	        y>>=1;
	    }
	    return t;
	};
	auto mod_inv = [&](long x, long y) {
	    return mod(x * mod_pow(y, MOD-2));
	};
	auto mod_perm = [&](long x, long y) {
	    return mod_inv(fact[x], fact[x-y]);
	};
	function<long(int, int)> coloring = [&](int f, int c) -> long {
	    long patsup = K-(f==-1?1:2);
	    int cnt = tree[c].size()-(f==-1?0:1);
	    if (patsup < cnt)
	        return 0;
	    long p = 1;
	    for (auto t : tree[c]) {
	        if (t == f)
                continue;
	        p = mod(p * coloring(c, t));
	    }
        p = mod(p * mod_perm(K-(f==-1?1:2), cnt));
	    return p;
	};
	auto ans = mod(coloring(-1, 0)*K);
	cout << ans << endl;
	
    return 0;
}


Measured memory_bytes: 13568
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#include <deque>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl
#define isort(a) sort(a.begin(),a.end())

using namespace std;

#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

typedef pair<ll,ll> Pair;
const ll inf =1000000007;


 ll solve(){
    string s,t;
    map<char,vector<ll>> mp;
    cin >> s >>t;

    //map make
    for(ll i=0;i<s.size();i++){
        if(mp.find(s[i])!=mp.end()){
            mp[s[i]].pb(i);
        }
        else{
            mp[s[i]]={i};
        }
    }

    ll round=0;
    ll ima=-1;

    for(ll i=0;i<t.size();i++){
        if(mp[t[i]].empty()){
            cout << -1 << endl;
            return 0;
        }
        else if(upper_bound(mp[t[i]].begin(),mp[t[i]].end(),ima)!=mp[t[i]].end()){
            ima=*upper_bound(mp[t[i]].begin(),mp[t[i]].end(),ima);
        }
        else{
            round++;
            ima=mp[t[i]][0];
        }
    }
    ll ans=s.size()*round+ima+1;
    cout <<  ans << endl;
    return 0;
}

int main(){
    solve();
}

Measured memory_bytes: 1728
#include<iostream>
#include<cstring>
#include<stack>
using namespace std;

int M[101][101], sta[101], en[101], n;
stack<int>S;

void dfs()
{
	int id, op;
	bool have;
	id = op = 1;

	while (true)
	{ 
		if (sta[id] == 0)          
		{
			S.push(id);
			sta[id] = op++;
		}

		have = false;
		
		for (int pid = 1; pid <= n; pid++)
		{
			if (M[id][pid] == 1 && sta[pid] == 0)     
			{
				id = pid;
				have = true;
				break;
			}
		}

		if (!have)
		{
			S.pop();
			en[id] = op++;

			if (!S.empty())
				id = S.top();
			else
			{
				for (int i = 1; i <= n; i++)
				{
					if (sta[i] == 0)
					{
						id = i;
						break;
					}		
				}			
			}
		}

		if (op > 2 * n)
			break;
	}
}

int main()
{
	int id, pid, k;

	memset(M, 0, sizeof(M));
	memset(sta, 0, sizeof(sta));
	memset(en, 0, sizeof(en));

	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> id >> k;

		for (int j = 1; j <= k; j++)
		{
			cin >> pid;
			M[id][pid] = 1;
		}
	}

	dfs();

	for (int i = 1; i <= n; i++)
		cout << i << " " << sta[i] << " " << en[i] << endl;

	return 0;
}


Measured memory_bytes: 3156
import java.util.Scanner;
import java.util.Arrays;

class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	int N = scan.nextInt();
        int[] array = new int[N];
	int cost=0;
	int lowCost = 1000000;
        for(int i=0;i<N;i++){
            array[i] = scan.nextInt();
        }
	Arrays.sort(array);
        for(int i=-100;i<=100;i++){
            for(int j=0;j<array.length;j++){
                cost += Math.pow((array[j]-i),2);
	    }
            if(lowCost > cost){
                lowCost = cost;
	    }   
            cost = 0;
        }
        System.out.println(lowCost);
    }
}


Measured memory_bytes: 9680
// author: Saman Mahdanian
#include <iostream>
#include <cassert>

using namespace std;
const int N = 1e6 + 10;

int n, a[N];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];

	long long int ans = 0;
	int head = n - 1;
	for (int i = n - 1; ~i; i--) {
		if (i < n - 1 && a[i] + 1 == a[i + 1])
			continue;
		int start = i - a[i];
		if (start < 0 || start > head) {
			cout << -1 << endl;
			return 0;
		}
		head = start;
		ans += a[i];
	}
	cout << ans << endl;
}

// SamMHD :: Mar5-2019 :: Another Homework for Shayan (the Great!)...


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define lint long long
using namespace std;
lint readint() {
	char c = getchar_unlocked();
	lint ans = 0;
	while ('0' <= c && c <= '9') {
		ans = ans * 10 + c - '0';
		c = getchar_unlocked();
	}
	return ans;
}
char ch[1024];
void writeint(lint x) {
	int ptr = 0;
	while (x) {
		ch[ptr++] = (x % 10) + '0';
		x /= 10;
	}
	while (ptr) {
		putchar_unlocked(ch[--ptr]);
	}
	putchar_unlocked(' ');
}
int q;
constexpr int mod=1000000007;
lint x,y,a,n,m;
constexpr lint f[]={0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,75025,121393,196418,317811,514229,832040,1346269,2178309,3524578,5702887,9227465,14930352,24157817,39088169,63245986,102334155,165580141,267914296,433494437,701408733,1134903170,1836311903,2971215073,4807526976,7778742049,12586269025,20365011074,32951280099,53316291173,86267571272,139583862445,225851433717,365435296162,591286729879,956722026041,1548008755920,2504730781961,4052739537881,6557470319842,10610209857723,17167680177565,27777890035288,44945570212853,72723460248141,117669030460994,190392490709135,308061521170129,498454011879264,806515533049393,1304969544928657,2111485077978050,3416454622906707,5527939700884757,8944394323791464,14472334024676221,23416728348467685,37889062373143906,61305790721611591,99194853094755497,160500643816367088,259695496911122585,420196140727489673,679891637638612258,1100087778366101931};
int main(){
	q=readint();
	rep(i,q){
		x=readint();y=readint();
		if(x>y)swap(x,y);
		if(y<=2){
			writeint(1);writeint(y==1?1:x==1?2:4);
			continue;
		}
		rep(j,99){
			if(x<f[j]||y<f[j+1]){
				a=(x==1?2:1);
				rep(k,j-2){
					n=f[j-1]+f[j-3-k]*f[k+2],m=f[j]+f[j-2-k]*f[k+2];
					if(n<=x&&m<=y)a+=(y-m)/n+1;
				}
				if(f[j]<=x){
					a++;
					rep(k,j-2)a+=(x-f[j])/(f[j-2-k]*f[k+2]);
				}
				writeint(j-2);writeint(a%mod);
				break;
			}
		}
	}
}

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

K = int(input())

l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
     1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[K - 1])


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

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define vi vector< int > 
#define pii pair< int, int >
#define mii map< int , int > 
#define F(start,stop) for(int i=start; i<stop; i++)
#define FRev(start,stop) for(int i=start; i>=stop; i--)
#define MOD1 1000000007
#define MOD2 998244353

int main()
{

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	IOS

	int x,y;
	cin >> x >> y;

	bool isPos = false;

	for(int i=0; i<=x; i++){
		if(2*i + 4*(x-i) == y){
			isPos = true;
			break;
		}
	}

	if(isPos)
		cout << "Yes" << endl;
	else
		cout << "No\n";

}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();

		long[] array = new long[N];

		long sum = 0;
		long num = 0;
		for(int i = 0; i < N; i++) {
			array[i] = scan.nextLong();
			if(i != 0) {
				num = array[i] - array[i-1];
				if(num < 0) {
					array[i] = array[i] + Math.abs(num);
					sum = sum + Math.abs(num);
				}
			}
		}
		System.out.println(sum);
	}

}

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

int main(){
    long long int N;
    cin >> N;
    long long int orig = N;
    long long int a=0;
    while(N!=0){
        a += N%10;
        N /= 10;
    }
    if(orig%a==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
maxindex = maxvalue = 0
a = []
for i in range(n):
    _a = int(input())
    if maxvalue <= _a:
        maxvalue = _a
        maxindex = i
    a.append(_a)

for i in range(n):
    if i != maxindex:
        print(maxvalue)
        continue
    t = a[:]
    t.pop(i)
    print(max(t))


Measured memory_bytes: 14080
#include<iostream>
using namespace std;
 
int main(){
  int n,t;
  int s,f;
  while(cin >> t , t){
    cin >> n;
    int sum = 0;
    for(int i=0;i<n;i++){
      cin >> s >> f;
      sum += f-s;
    }
    if(t<=sum)cout << "OK\n";
    else cout << t-sum << endl;
  }
}

Measured memory_bytes: 0
n, m = map(int, input().split())
if n <= 1 and m <= 1:
    print(0)
elif n <= 1:
    print(m * (m - 1) // 2)
elif m <= 1:
    print(n * (n - 1) // 2)
else:
    print(n * (n - 1) // 2 + m * (m - 1) // 2)



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

int main() {
    int n, m; cin >> n >> m;
    int ans = m;
    for(int i = 0; i < n; ++i) {
        int a, b; cin >> a >> b;
        m += a - b;
        if(m < 0) {
            cout << 0 << endl;
            return 0;
        }
        ans = max(ans, m);
    }
    cout << ans << endl;
}



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

int main() {
    int N ;
    cin >> N;
    int c;
    vector<int> A(N);
    for(int i=1; i<N ;i++){
        cin >> A.at(i);
    }
    vector<int> ans(N);
    for(int i=0; i<N; i++){
        int c = A.at(i);
        int d = 0;
        for(int j=0;j<100000;j++){
          if(c%2 == 1){
            ans.at(i)=d;
            break;
          }
          if(c%2 ==0){
            c /= 2;
            d++;
          }
        }
    }
    sort(ans.begin(),ans.end());
    cout << ans.at(1) << endl;
}


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

const ll m=1000000007;

int n,ans=0;

void dfs(string s){
    
    if(s.size()==10||stoi(s)>n) return;
    if(s.find('3')!=std::string::npos&&s.find('5')!=std::string::npos&&s.find('7')!=std::string::npos) {
        ans++;
        
    }
    dfs(s+'3');
    dfs(s+'5');
    dfs(s+'7');
}


int main(){
    
    cin>>n;
    dfs("3");
    dfs("5");
    dfs("7");
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
const ll MAX = 30000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    ll cnt = 0;
    while (a >= b){
        b *= 2;
        cnt++;
    }
    while (b >= c){
        c *= 2;
        cnt++;
    }
    Yes(cnt <= k);
}


Measured memory_bytes: 3636