akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  
  vector<vector<int>> g(n);
  for(int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  
  // BFS
  vector<int> ans(n, -1);
  queue<int> q;
  
  ans[0] = 0;
  q.push(0);
  
  while(!q.empty()) {
    int v = q.front();
    q.pop();
    
    for(int near: g[v]) {
      if(ans[near] != -1) continue;
      
      ans[near] = v;
      q.push(near);
    }
  }
  
  cout << "Yes" << endl;
  for(int i = 1; i < n; i++) {
    cout << ans[i]+1 << endl;
  }
  
  return 0;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

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

    rep(i,n/7+1){
        rep(j,n/4+1){
            if(i*7+j*4==n){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }

    cout<<"No"<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9+5;
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    vector<int> h(n);
    vector<int> dp(n,INF);
    for(int& i : h)
        scanf("%d",&i);
    dp[0]=0;
    for(int i=0; i<n; i++){
        for(int j = i+1; j<=i+k; ++j){
            if(j<n)
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
        }
    }
    printf("%d\n",dp[n-1]);
    //while(1);
    return 0;
}

Measured memory_bytes: 1024
import std.stdio, std.conv, std.string, std.algorithm, std.math, std.array, std.container;

int n, k, c;

bool[] solve() {
  scanf("%d %d %d\n", &n, &k, &c);
  string s = readln.chomp;
  bool[] banned = s.map!(c => c=='x').array;
  int[] l = new int[k];
  int k_cnt = 0;
  for(int i=0; i<n; i++) {
    if(!banned[i]) {
      l[k_cnt] = i;
      i += c;
      if(++k_cnt == k) break;
    }
  }
  if(k_cnt < k) return new bool[n];
  int[] r = new int[k];
  k_cnt = k;
  for(int i=n-1; i>=0; i--) {
    if(!banned[i]) {
      r[--k_cnt] = i;
      i -= c;
      if(k_cnt == 0) break;
    }
  }
  bool[] result = new bool[n];
  for(int i=0; i<l.length; i++) {
    result[l[i]] = l[i]==r[i];
  }
  return result;
}

void main() {
  auto res = solve();
  for(int i=0; i<res.length; i++) {
    if(res[i]) writeln(i+1);
  }
}



Measured memory_bytes: 5500
//#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <numeric>
//#include <omp.h>
#include<memory>
#include <cstdio>

using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,s,e) for (int i = s; i > (e); --i)
typedef long long int ll;
const int MOD=1000000007;
int main(){
    int N, K;
  	int P[1001];
    int res = 0;
	cin >> N >> K;
  	rep(i, N){
    	cin >> P[i];
      	//cout << P[i] << endl;
    }
  	sort(P, P+N);
    //cout << P[0] << P[1] << endl; 
    rep(i, K){
    	res += P[i];
    }
  	cout << res << endl;
  	
	
    return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1001001001;

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n) {
		if (n & 1) {
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y) swap(x, y);

	while (0 < y) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x * y / gcd(x, y);
}

template<class Type>
bool is_prime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2) {
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++) {
		if (isPrime[i]) {
			Type j = i + i;
			while (j <= n) {
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binary_search_judge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binary_search(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok)) {
		int mid = (ng + ok) / 2;
		if (binary_search_judge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{	
	string s;
	cin >> s;
	vector<int> A_pos = { 8,6,4,0 };

	for (int bit = 0; bit < (1 << 4); bit++) {
		string t = "AKIHABARA";
		for (int i = 0; i < 4; i++) {
			if ((bit >> i) & 1) t.erase(t.begin() + A_pos[i]);
		}
		if (s == t) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
}

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

#define ll long long
#define vi vector<long long>
#define r(i, a) for(int i=0; i<a; i++)
#define re(i, a, b) for(int i=a; i<b; i++)
#define inp(a,b) cin>>a>>b
#define in(a) cin>>t
#define pb push_back
#define mod 1000000007
#define ma unordered_map<long long>
//
//class node{
//    public:
//    ll data;
//    node *left;
//    node *right;
//    node (ll val){
//        data=val;
//        left = right = NULL;
//    }
//    
//};
//
//node *insert(ll val, node *root){
//    if(root==NULL){
//        return new node(val);
//    }
//    else if(val>root->data){
//        root->right = insert(val, root->right); 
//    }
//    else if(val<=root->data){
//        root->left = insert(val, root->left);
//    }
//}
//
//void inorder(node *root){
//    if(root!=NULL){
//        inorder(root->left);
//        cout<<root->data<<" ";
//        inorder(root->right);
//    }
//}
//
//
//ll findheight(node *root){
//    if(root==NULL)
//        return 0;
//    ll l=0,r=0;
//    if(root->left!=NULL) l=findheight(root->left);
//    if(root->right!=NULL) r=findheight(root->right);
//    return max(l,r)+1;
//}

//ll n;








void func(){ 
    string s, t;
    cin>>s;
    cin>>t;
    ll count=0;
    for(int i=0; i<s.length(); i++){
        if(s[i]!=t[i])
            count++;
    }
    cout<<count<<endl;

}

int main(){

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

//sieve();

//int t;
//cin >> t;
//for(ll i=1; i<=t; i++)
//{
    
    func();
//    cout<<endl;
//cout<<func()<<endl;

//if(func())
//    cout<<"Yes"<< endl;
//else
//    cout <<"No"<<endl; 
//cout<<"Case:"<<i<<" "<<     <<endl;
//}
return 0;
}


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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int N = (int)1e5;
void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int n;
int f[N + 1], h[N + 1];
int dp(int n)
{
    if(n == 1) return 0;
    if(n < 1) return INF;
    if(f[n] != INF) return f[n];
    int val = 0;
    if(n > 1)
    val = dp(n - 1) + abs(h[n] - h[n - 1]);
    if(n > 2)
    val = min(val, dp(n - 2) + abs(h[n] - h[n - 2]));
    return f[n] = val;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    FOR(i, 1, N) f[i] = INF;
    cin >> n;
    FOR(i, 1, n) cin >> h[i];
    cout << dp(n);
    return 0;
}


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

int main(){
    int i;
    string x;
    cin >> x;
    
    for(i=0; i<3; i++) {
        if(x[i] == '1') x[i] = '9';
        else x[i] = '1';
    }
    cout << x << endl;
    return 0;
}



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

const ll maxs = 2e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){

}

void solve(){

    ll k,q;
    cin >> k >> q;
    ll d[k];
    for(ll i=0;i<k;i++)
        cin >> d[i];
    
    while(q--){
        ll n,x,m;
        cin >> n >> x >> m;
        x%=m;
        ll zero = 0;
        ll sum = x;
        for(ll i=0;i<k;i++){
            ll val = d[i]%m;
            ll timer = (n-1)/k;
            if((n-1)%k > i)
                timer++;
            if(val == 0){
                zero += timer;
            }
            else{
                sum += timer*val;
            }
        }

        ll out = (sum/m) - (x/m);
        ll ans = (n-1) - (out + zero);

        cout << ans << endl;
    }
}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;   
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 384
n, m = map(int, input().split())
pss = [list(input().split()) for _ in range(m)]
ac = [0] * n
wa = [0] * n
ans1 = 0
ans2 = 0
for i in range(m):
    if ac[int(pss[i][0]) - 1] == 0:
        if pss[i][1] == 'AC':
            ans1 += 1
            ans2 += wa[int(pss[i][0]) - 1]
            ac[int(pss[i][0]) - 1] = 1
        else:
            wa[int(pss[i][0]) - 1] += 1
    else:
        continue
print(str(ans1) + ' ' + str(ans2))


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

int main()
{
	string s;
  	cin >> s;
  	string t;
  	cin >> t;
  	int cnt=0;
  	for(int i=0;i<3;i++)
    {
    	if(s[i]==t[i])	cnt++;
    }
  	cout << cnt;
  	return 0;
}


Measured memory_bytes: 256
while gets
  xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2 = $_.split.map(&:to_f)

  if (xa2 < xb1) || (ya2 < yb1) || (xa1 > xb2) || (ya1 > yb2)
    puts "NO"
  else
    puts "YES"
  end
end

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int a;
	string s;
	cin >> a;
	map<string,int> m;
	vector<string>v;
	while(a--){
		cin >> s;
		m[s]++; 
		v.push_back(s);
	}
	for(auto i : m){
		if(i.second == 2){
			cout << "No" << endl;
			return 0;
		}
	}
	for(int i=1;i<v.size();i++){
//		cout  << v[i][0] << ' ' << v[i-1][v[i-1].size() - 1] << endl;
		if(v[i][0] != v[i-1][v[i-1].size() - 1]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  cin >> n;
  if(n % 1000==0){
    cout << 0 << endl;
    return 0;
  }
  for(int i = 0;i < 100000;i++){
    if(i * 1000 > n){
      cout << i * 1000 - n << endl;
      return 0;
    }
  }
}

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

using namespace std;

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef long long ll; typedef vector<int> VI; typedef pair<ll, ll> pii;
const ll mod = 1e16+7;

int n, m;
vector<vector<pii>> r;


vector<ll> bfs(int sy) {
	vector<ll>  dd(n, -mod);
	queue< pii > que;
	que.push(pii(0,0));
	dd[sy]=0;
	int ct=0; ll mxx=-1;
	while(!que.empty()){
		if(ct++ == 1000000 ){ mxx = dd[n-1];}
		if(ct++ >2000000){
			if( dd[n-1] > mxx ) dd[0] = -1;
			break;
		}
		ll cy,cc; tie(cy,cc) = que.front();
		que.pop();
		for(auto x: r[(int)cy]){
			if(cc + x.second > dd[x.first]){
			  que.push( pii(x.first, cc + x.second) );
				dd[x.first]= cc + x.second;
			}
		}
	}
	return dd;
}


int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> n >> m;
	
	r.resize(n);
	
	rep(i,m){
		int a,b,c;
		cin >>a >>b >>c;
		r[a-1].emplace_back(b-1,c);
	}
	
	auto rc = bfs(0);
	//for(auto x :rc) cout<<x <<" "; puts("");
	if(rc[0]==-1) puts("inf");
	else cout << rc[n-1] << endl;
	return 0;
}



Measured memory_bytes: 384
// 基本型の受け取り
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

// 1次元ベクタでの受け取り
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

// 2次元ベクタの受け取り
type Vec2<T> = Vec<Vec<T>>;

fn read_vec2<T: std::str::FromStr>(n: i64) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

// println の省略
fn print<T: std::fmt::Display>(x: T) -> () {
    println!("{}", x);
}

fn main() {
    let mut ab: Vec<i64> = read_vec();
    
    ab.sort();
    let a = ab[0];
    let b = ab[1];
    let diff = b - a;

    if diff < 1 {
        print(a + b);
    } else {
        print(b * 2 - 1);
    }

}


Measured memory_bytes: 4352
#include <stdio.h>

int main(){
  int d[50];
  int C=0;
  long long int N;
  scanf("%lld",&N);
  d[0]=0;
  while(N>0){
    d[C]=(int)((N-1)%26LL);
    N=(N-1)/26LL;
    C++;
  }
  for(int i=C-1;i>=0;i--){
    printf("%c",'a'+d[i]);
  }
  printf("\n");
  return 0;
}
  

Measured memory_bytes: 1600
//       In the name of         ****                      God                     ****

/*

Copyright (C)          JadedBeast

                                   Morocco

created : 8/3/2019

*/

#include <bits/stdc++.h>
using namespace std;
#define time cout << "\ntime: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
#define W 100001
inline void Boost() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}
static	int n,w;
long long DP[101][W],knap[101][2];

long long dp(int i,int weight){
	if(weight<0)
		return -6969696969;
	if (weight==0 || i==n)
		return 0;
	if(DP[i][weight]!=-1)
		return DP[i][weight];

	return DP[i][weight]=max(knap[i][1]+dp(i+1,weight-knap[i][0]),dp(i+1,weight));


}



int main(void){
	Boost();
	cin >>n >> w;
	
	for(int i=0 ;i<n ;i++)
		for(int j=0 ; j<2 ;j++)
			cin >>knap[i][j];

	memset(DP,-1,sizeof(DP));

	cout <<dp(0,w)<<endl;

   return 0;
}


Measured memory_bytes: 79232
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        String s = sc.next();

        if (s.charAt(s.length()-1) == 's')
            s += "es";
        else
            s += "s";

        System.out.println(s);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 36496
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    private static class Pair implements Comparable<Pair> {
        int first, second;
        private Pair(int first, int second) {
            this.first = first;
            this.second = second;
        }

        @Override
        public int compareTo(Pair p) {
            if (first == p.first) {
                return second - p.second;
            } else {
                return first - p.first;
            }
        }
    }

    private final static int MAXN = 100000;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Pair> pairs = new ArrayList<>();
        boolean[] flag = new boolean[n + 2];

        flag[0] = flag[n + 1] = false;
        for (int i = 1; i <= n; ++i) {
            flag[i] = true;
        }

        boolean zero = true;
        for (int i = 0; i < n; ++i) {
            int a = scanner.nextInt();
            pairs.add(new Pair(a, i + 1));
            if (a != 0) {
                zero = false;
            }
        }

        if (zero) {
            System.out.println(0);
            return;
        }

        Collections.sort(pairs);

        int max = 1, count = 1, iter = 0;
        for (Pair p: pairs) {
            if (p.first != iter) {
                max = Math.max(max, count);
                iter = p.first;
            }

            flag[p.second] = false;
            if (flag[p.second - 1] && flag[p.second + 1]) {
                ++count;
            } else if (!flag[p.second - 1] && !flag[p.second + 1]) {
                --count;
            }
        }
        max = Math.max(max, count);

        System.out.println(max);
    }
}



Measured memory_bytes: 74080
x,n=map(int,input().split())
if n==0:
	print(x)
	exit()
p=list(map(int,input().split()))
s=x-1
b=x+1
if x not in p:
	print(x)
else:
	while True:
		if s not in p:
			print(s)
			exit()
		s-=1
		if b not in p:
			print(b)
			exit()
		b+=1


Measured memory_bytes: 9192
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    else return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll ret=a*b;
    ll u=gcd(a,b);
    return ret/u;
}
ll f(ll a,ll b,ll n){
    ll ret=b/n-a/n;
    if(a%n==0)ret++;
    return ret;
}
int main(){
    ll a,b,c,d;cin>>a>>b>>c>>d;
    ll ans=f(a,b,c)+f(a,b,d)-f(a,b,lcm(c,d));
    cout<<b-a+1-ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;

int N, s[100010];
signed main() {
	cin >> N;
	REP(i, N) {
		cin >> s[i];
	}
	int ans = 0;
	for (int C = 1; C < N; C++) {
		int res = 0;
		int score = 0;
		set<int>st;
		for (int x = 0; x*C < N-1; x++) {
			//pe(C)pe(x); pe("->");
			int A = N - 1 - x * C;
			int B = A - C;
			if (B <= 0)goto END;
			if (st.find(x*C) != st.end() || st.find(A) != st.end())goto END;
			st.insert(x*C);
			if (st.find(A) != st.end())goto END; 
			st.insert(A);
			score += s[x*C] + s[A];
			res = max(res, score);
			//print(res);
			ans = max(ans, res);
		}
		ans = max(ans, res);
	END:;
		//cout << endl;
	}
	print(ans);
}


Measured memory_bytes: 7808
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  [h, a] <- getIntList
  let n = 0
  print $ solve h a n

solve :: Int -> Int -> Int -> Int
solve h a n = if a*n >= h then n else solve h a (n+1)

Measured memory_bytes: 380
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  vector<int> d(3);
  cin >> d[0] >> d[1] >> d[2];
  sort(all(d),greater<int>());
  cout << d[0] * 10 + d[1] + d[2] << endl;
  return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(0,a+1):
    for j in range(0,b+1):
        for k in range(0,c+1):
            if i * 500 + j * 100 + k * 50 == x:
                ans += 1
print(ans)


Measured memory_bytes: 3060
while True:
	m, f, r = map(int, input().split())
	if m == f == r == -1:
		break
	elif m == -1 or f == -1 or m + f < 30:
		print("F")
	elif m + f >= 80:
		print("A")
	elif 65 <= m + f:
		print("B")
	elif 50 <= m + f:
		print("C")
	else:
		if r >= 50:
			print("C")
		else:
			print("D")


Measured memory_bytes: 5596
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define N 200005
#define F first
#define S second
using namespace std;

typedef long long ll;
ll U = 2e8;
double M = acos(-1.0);
ll n, m, x1, x2, yy1, y2, sz, mn, mx, b[N];
pair<ll, ll> a[N];
ll g(ll p) {return p > 0 ? p: -p;}
int main()
{
	ll i, t;
	cin >> x1 >> yy1 >> x2 >> y2 >> n;
	if (x1 > x2) {
		swap(x1, x2);
		swap(y2, yy1);
	}
	for (i = 0; i < n; i++) {
		scanf ("%lld %lld", &a[i].F, &a[i].S);
	}
	if (yy1 > y2) {
		yy1 = U - yy1;
		y2 = U - y2;
		for (i = 0; i < n; i++) a[i].S = U - a[i].S;
	}
	sort(a, a + n);
	for (i = 0; i < n; i++) {
		if (x1 <= a[i].F && a[i].F <= x2 && yy1 <= a[i].S && a[i].S <= y2) {
			if (sz == 0) {
				b[0] = a[i].S;
				sz = 1;
				continue;
			}
			t = lower_bound(b, b + sz, a[i].S) - b;
			if (t == sz) sz++;
			b[t] = a[i].S;
		}
	}
	if (sz != min(x2-x1, y2-yy1)+1) printf("%.15f", (g(x2 - x1) + g(y2 - yy1)) * 100 - sz * 20 + M * 5 * sz);
	else printf("%.15f", (g(x2 - x1) + g(y2 - yy1)) * 100 - sz * 20 + M * 5 * (sz - 1) + 10 * M);
	cout << sz;
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

ll f(ll n) {
  ll res = 1;
  rep(i, n) {
    res *= i+1;
  }
  return res;
}

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

  cerr << f(4) << endl;
  ll n;
  cin >> n;
  vl p(n), q(n);
  rep(i, n) {
    cin >> p[i];
  }
  rep(i, n) {
    cin >> q[i];
  }

  ll a, b;
  ll cnt = 0;
  while (next_permutation(all(p))) {
    cnt++;
  }
  a = f(n) - cnt;
  cnt = 0;
  while (next_permutation(all(q))) {
    cnt++;
  }
  b = f(n) - cnt;
  cout << abs(a-b) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<algorithm>

using namespace std;

map< int, set<int> > Init(int);
set<int> FindFriends(map< int, set<int> >);

int main(){
  int i, n, m, a, b;
  set<int> friends;
  map< int, set<int> > data;

  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;
    data = Init(n);

    for(i=0; i<m; ++i){
      cin >> a >> b;
      data[a].insert(b);
      data[b].insert(a);
    }
    friends = FindFriends(data);
    cout << friends.size() << endl;
  }
  return 0;
}

map< int, set<int> > Init(int n){
  int i;
  set<int> _data;
  map< int, set<int> > data;
  for(i=1; i<=n; ++i) data.insert(make_pair(i, _data));
  return data;
}

set<int> FindFriends(map< int, set<int> > data){
  set<int> _data, friends;
  set<int>::iterator i, j;
  map< int, set<int> >::iterator k;
  _data = data[1];
  for(i=_data.begin(); i!=_data.end(); ++i){
    if(friends.find(*i) == friends.end())
      friends.insert(*i);
    k = data.find(*i);
    for(j=k->second.begin(); j!=k->second.end(); ++j){
      if(*j != 1 && friends.find(*j) == friends.end())
	friends.insert(*j);
    }
  }
  return friends;
}

Measured memory_bytes: 3208
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>


#define REP(i,N) for(auto i = 0; i <N; i++)
using namespace std;
typedef long long ll;


int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}

ll lin(){
    ll temp;
    scanf("%lld",&temp);
    return temp;
}



int main() {
    
    ll A = lin();
    ll B = lin();
    ll C = lin();
    ll X = lin();
    ll Y = lin();

    
    ll ans = LONG_MAX;
    
    for(auto i = 0; i<= max(X,Y); i++){
        
        if (ans > 2*C*i + max(0LL,(X-i)*A)  + max(0LL,(Y-i)*B)){
            ans = 2*C*i + max(0LL,(X-i)*A) + max(0LL,(Y-i)*B);
        }
        
    }
    
    cout << ans << endl;
    
    return 0;
}


                          





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

const int nm = 1e5;

int r = 0;

//union-find
int par[nm], des[nm];
int root(int v) {
	if (par[v] == v)
		return v;
	return root(par[v]);
}
void unite(int x, int y) {
	int rx = root(x);
	int ry = root(y);
	if (rx == ry)
		return;
	++r;
	if (des[ry] > des[rx])
		swap(rx, ry);
	par[ry] = rx;
	des[rx] += des[ry] + 1;
}
void initUF() {
	for (int i = 0; i < nm; i++)
		par[i] = i;
}

int n, m;

int main() {
	initUF();
	cin >> n >> m;
	for (int i = 0, a, b; i < m; ++i) {
		cin >> a >> b;
		--a;
		--b;
		unite(a, b);
	}
	cout << n - 1 - r << endl;

}


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

const int TLE = 10000;
int main(void){
  int n,tmax, ans;
  
  cin >> n >> tmax;
  ans = TLE;
  for (int i=0; i<n; i++){
    int c,t;
    cin >> c >> t;
    if (t<=tmax) ans = min(ans, c);
  }
  if (ans==TLE) cout << "TLE" << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>

#define ALL(a)  (a).begin(),(a).end()

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main() {
    string s;
    int n, ans = 0;


    cin >> n >> s;

    for (int i = 0; i < s.length(); i++) {
        s[i] += n;
        if (s[i] > 'Z') s[i] -= 26;
    }

    cout << s << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
using namespace std;

#define ll long long int
#define ld long long double
#define reps(i,f,n) for(int i=f;i<n;i++)
#define rep(i,n) reps(i,0,n)
#define m1 cout<<"move1"<<endl
#define m2 cout<<"move2"<<endl
#define m3 cout<<"move3"<<endl
#define m4 cout<<"move4"<<endl

int main(){
  ll sum=0;
  int N=0;
  int max_v= -1;
  int min_v= 10000;
  int a;
  int b;
  // m2;
  while(cin>>a,a != 0){
    N = a;
    // cout<<a<<endl;
    // m1;
    for(int i=0;i<N;i++){
      cin>>b;
      max_v=max(max_v,b);
      min_v=min(min_v,b);
      sum += b;
      // cout<<sum<<endl;
    }
    sum = sum - max_v - min_v;
    cout<<sum / ( N -2)<<endl;
    max_v=-1;
    min_v=1000;
    sum =0;
  }
  return 0;

}
    

    
    

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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

const long long INF = 1LL<<60;
const int mod = 1000000007;

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

int N;
vector<int> a(100010);
vector<int> b(100010);
vector<int> c(100010);

vector<vector<ll>> dp(3, vector<ll>(100010, -1));

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

    cin >> N;
    REP(i, N) {
        cin >> a.at(i) >> b.at(i) >> c.at(i);
    }

    dp.at(0).at(0) = dp.at(1).at(0) = dp.at(2).at(0) = 0;

    for (int i = 0; i < N; i++){
        chmax(dp.at(0).at(i + 1), dp.at(1).at(i) + b.at(i));
        chmax(dp.at(0).at(i + 1), dp.at(2).at(i) + c.at(i));
        chmax(dp.at(1).at(i + 1), dp.at(0).at(i) + a.at(i));
        chmax(dp.at(1).at(i + 1), dp.at(2).at(i) + c.at(i));
        chmax(dp.at(2).at(i + 1), dp.at(0).at(i) + a.at(i));
        chmax(dp.at(2).at(i + 1), dp.at(1).at(i) + b.at(i));
    }

    ll ans = 0;

    for (int i = 0; i < 3; i++) {
        chmax(ans, dp.at(i).at(N));
    }

    cout << ans << endl;
    
    return 0;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  int n, k;
  cin >> n >> k;
  vl h(n);
  rep (i, n) {
    cin >> h[i];
  }
  sort(all(h));
  int i = 0, j = k - 1;
  ll ans = INF;
  while (j < n) {
    ans = min(ans, h[j] - h[i]);
    i++; j++;
  }
  cout << ans << endl;
    
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1e9
typedef long long ll;
typedef vector<ll> Vec;
  
struct State{
    Vec v;
    int sp,cost;
    State(Vec v,int sp,int cost)
	: v(v),sp(sp),cost(cost) {}
    bool operator < (const State &s)const{
	return cost > s.cost;
    }
};
 
int ch,cv;
const int d[4] = {-1,1,-3,3};
 
ll getVal(Vec &v){
    ll res = 0LL;
    for(auto &x : v){
	res *= 9;
	res += x;
    }
    return res;
}
 
int dijkstra(Vec &st,ll target,int sp){
    priority_queue<State> Q;
    Q.push(State(st,sp,0));
    unordered_map<ll,int> mp;
    mp[getVal(st)] = 0;
 
    while(!Q.empty()){
	State s = Q.top(); Q.pop();
	ll val = getVal(s.v);
	if(mp.find(val) != mp.end() && mp[val] < s.cost){
	    continue;
	}
	if(val == target) return mp[val];
	for(int i = 0 ; i < 4 ; i++){
	    int nsp = (s.sp + d[i] + 9) % 9;
	    int cost = (i < 2 ? ch : cv);
	    swap(s.v[nsp],s.v[s.sp]);
	    ll nval = getVal(s.v);
	    if(mp.find(nval) == mp.end() ||
	       mp[val] + cost < mp[nval]){
		mp[nval] = mp[val] + cost;
		Q.push(State(s.v,nsp,mp[nval]));
	    }
	    swap(s.v[nsp],s.v[s.sp]);
	}
    }
    return INF;
}
 
int main(){
    while(cin >> ch >> cv, (ch|cv)){
	int sp;
	Vec s(9),t(9);
	for(int i = 0 ; i < 9 ; i++){
	    cin >> s[i];
	    if(s[i] == 0) sp = i;
	}
	for(int i = 0 ; i < 9 ; i++){
	    cin >> t[i];
	}
	cout << dijkstra(s,getVal(t),sp) << endl;
    }
    return 0;
}

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

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

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

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

ll X[100005];

int main()
{
    int N, M;
    cin >> N >> M;
    REP(i, M)
    {
        cin >> X[i];
    }
    sort(X, X + M);
    if (N >= M)
    {
        cout << 0 << endl;
        return 0;
    }

    vector<int> v;
    FOR(i, M, 1)
    {
        v.push_back(abs(X[i] - X[i - 1]));
    }
    sort(v.begin(), v.end());
    ll sum = 0;
    REP(i, M - N)
    {
        sum += v[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
typedef long long ll;
typedef long double ld;

int main(){
    ll N ,M;
    cin >> N >> M;
    ll G[51][51] = {0};
    ll ans = 0;
    for(int i = 0; i < M; i++){
        ll tmp1, tmp2;
        ll ans = 0;
        cin >> tmp1 >> tmp2;
        tmp1--;
        tmp2--;
        G[tmp1][tmp2] = 1;
        G[tmp2][tmp1] = 1;
    }

    while(1){
        bool flag = false;
        for(int i = 0; i < N; i++){
            ll cnt = 0;
            ll tmp_i = -1;
            ll tmp_j = -1;
            for(int j = 0; j < N; j++){
                if(G[i][j] == 1){
                    cnt++;
                    tmp_i = i;
                    tmp_j = j;
                }
            }
            if(cnt == 1){
                ans++;
                flag = true;
                G[tmp_i][tmp_j] = 0;
                G[tmp_j][tmp_i] = 0;
            }
        }
        if(!flag) break;
    }

    cout << ans << endl;

}

Measured memory_bytes: 3632
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

#define REP(i,n) for(int i=0;(i)<(n);(i)++)
#define ll long long

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

	int Mzero = 0;//ペアがいない(の数を保存
	int Mone = 0;//ペアがいない)の数を保存
	REP(i, S.length()) {
		if (S[i] == '(') Mzero++;
		else if (S[i] == ')') {
			if (Mzero > 0) Mzero--;
			else Mone++;
		}
	}

	//cout << Mzero << Mone << endl;

	
	
	REP(i, Mone) {
			cout << '(';
	}

	cout << S;
	REP(i, Mzero) {
			cout << ')';
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
n=int(input())
m=[{}for i in range(n+1)]
w=10**9+7
def f(s):
    for i in range(4):
        t=list(s)
        if i>=1:
            t[i-1],t[i]=t[i],t[i-1]
        if "".join(t).count("AGC")>0:
            return False
    return True
def a(p,q):
    if q in m[p]:
        return m[p][q]
    if p==n:
        return 1
    r=0
    for i in "AGCT":
        if f(q+i):
            r=(r+a(p+1,q[1:]+i))%w
    m[p][q]=r
    return r
print(a(0,"WHY"))



Measured memory_bytes: 47836
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
using namespace std;



const long long int mod=1000000007;
const long long int INF=99999999999999999;

long long int n,m,res=0,a[200005],sum=0,now=0;



int main() {
	cout << fixed << setprecision(10);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    res=INF;
    for(int i=1;i<=n;i++){
        now+=a[i];
        res=min(res,abs(2*now-sum));
    }
    cout<<res;
} 


Measured memory_bytes: 1792
#define R(i,n) for(i=0;i<=n;i++)
t,l,b,a,I,J,s;main(n){while(scanf("%d%d%d%d",&n,&t,&l,&b),n){float d[101][101]={{}},o=0;int f[101]={};R(s,l-1)scanf("%d",&a),f[a]=1;R(s,b-1)scanf("%d",&a),f[a]=2;d[0][0]=1;R(l,t){o+=d[l][n];d[l][n]=0;R(b,n){I=l+(f[b]-1?1:2);if(I<=t)R(s,5){J=b+s+1;if(J>n)J=2*n-J;J=f[J]-2?J:0;d[I][J]+=d[l][b]/6;}}}printf("%f\n",o);}}

Measured memory_bytes: 1808
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
  string a;
  cin>>a;
  int ans=0;
  if(a=="RRR")ans=3;
  else if(a.at(0)=='R'||a.at(1)=='R'||a.at(2)=='R')
  {
    ans++;
    if(a.at(0)=='R'&&a.at(1)=='R')
    {
      ans++;
    }
    else if(a.at(1)=='R'&&a.at(2)=='R')
    {
      ans++;
    }
  }
  cout<<ans<<endl;
}

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

int main() {
  int x, y;
  cin >> x >> y;

  int diff = 4*x - y;
  int minnmum = 2*x;

  if(minnmum > y){
    cout << "No" << endl;
    return 0;
  }


  if (diff ==0){
    cout << "Yes" << endl;
  } else if (diff > 0){

    if( diff % 2 ==0){

      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }

  }else{
    cout <<"No"<<endl;
  }

  return 0;
}


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

map<long long, int> primes(long long n){
    map<long long, int> r;
    for(long long i=2;i*i<=n;i++){
        while(n%i==0){
            r[i]++;
            n/=i;
        }
    }
    if(n!=1) r[n]=1;
    return r;
}

int main(void){
    long long n;
    cin >> n;
    map<long long, int> p=primes(n);
    int counter=0;
    for(auto itr=p.begin(); itr!=p.end(); itr++){
        int p=itr->first;
        int c=itr->second;
        int take=1;
        while(c>=take){
            c-=take;
            take++;counter++;
        }
    }
    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 3636
#-*- coding:utf-8 -*-
import math

if __name__ == "__main__":
	H, W, D = list(map(int, input().split()))
	masu = {}
	for i in range(H):
		inputs = list(map(int, input().split()))
		for j in range(W):
			masu[inputs[j]] = [i, j]

	Q = int(input())
	L = []
	R = []
	for i in range(Q):
		l, r = list(map(int, input().split()))
		L.append(l)
		R.append(r)
	# i=D+1 ~ H*W の累積和Sを求める
	S = [0] * (H*W+1)
	for i in range(D+1, H*W+1):
		S[i] = S[i-D] + abs(masu[i][0]-masu[i-D][0]) + abs(masu[i][1]-masu[i-D][1])
	# 回答する
	for i in range(Q):
		print(S[R[i]] - S[L[i]])


Measured memory_bytes: 33640
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,T;
    cin>>N>>T;
    int ans=1e9;
    for(int i=0;i<N;i++){
        int c,t;
        cin>>c>>t;
        if(t<=T)
            ans = min(c,ans);
    }
    if(ans<1e9)
        cout << ans << endl;
    else
        cout << "TLE" << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int k, t;
	cin >> k >> t;
	
	vector<int> a(t);
	for(int i = 0; i < t; ++i) {
		cin >> a[i];
	}

	sort(a.begin(), a.end(), greater<int>());
	
	for(int i = 1; i < t; i++) {
		if( a[i] == 0 ) continue;
		
		a[i - 1] -= a[i];
		a[i] = 0;
	}
	
	int ans = 0;
	for(int i = 0; i < t; ++i) {
		ans += a[i];
	}

	if( ans > 0 ) ans--;
	if( ans < 0 ) ans = 0;
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <queue>

typedef long long ll;

using namespace std;

int main() {
	ll k;
	cin >> k;
	
	queue<ll> q;
	for(ll i = 1; i < 10; i++) q.push(i);
	
	for(ll i = 0; i < k - 1; i++) {
		ll x = q.front();
		q.pop();
		if(x % 10 != 0) q.push(10 * x + (x % 10) - 1);
		q.push(10 * x + (x % 10));
		if(x % 10 != 9) q.push(10 * x + (x % 10) + 1);
	}
	
	cout << q.front() << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll;

long long n, p; 
long long a;
long long ans = 0;

int main() {
	cin >> n >> p;
	bool flag = true;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a % 2 == 1) {
			flag = false;
		}
	}
	if (flag == true) {
		if (p == 0) {
			cout << (long long)pow(2, n) << endl;
		}
		else {
			cout << 0 << endl;
		}
	}
	else {
		cout << (long long)pow(2, n - 1) << endl;
	}
	return 0;
}

Measured memory_bytes: 384
import sys
from functools import lru_cache

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, X = map(int, readline().split())

    A = [0] * (N + 1)
    B = [0] * (N + 1)
    A[0] = B[0] = 1
    for i in range(N):
        A[i + 1] = 2 * A[i] + 3
        B[i + 1] = 2 * B[i] + 1

    def rec(i, x):
        if i == 0:
            return 1 if x > 0 else 0
        elif x <= 1 + A[i - 1]:
            return rec(i - 1, x - 1)
        else:
            return B[i - 1] + 1 + rec(i - 1, x - 2 - A[i - 1])

    print(rec(N, X))
    return


if __name__ == '__main__':
    main()


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

int main() {
  string S, T; cin >> S >> T;
  int head = -1;
  for (int i = 0; i < S.size(); i++) { //i番目がTの先頭の場合
    bool key = true;
    for (int j = 0; j < T.size(); j++) {
      if (S[i+j] == T[j] || S[i+j] == '?') continue;
      else {
        key = false;
        break;
      }
    }
    if (key) head = i;
  }
  
  if (head == -1) cout << "UNRESTORABLE" << endl;
  else {
    for (int i = 0; i < T.size(); i++) {
      S[head + i] = T[i];
    }
    for (int i = 0; i < S.size(); i++) {
      if (S[i] == '?') {
        S[i] = 'a';
      }
    }
    cout << S << endl;
  }      
}

Measured memory_bytes: 256
x, n = [int(_) for _ in input().split(' ')]

if n == 0:
    print(x)
else:
    p = {int(_) for _ in input().split(' ')}

    answer = 0
    m = 102
    for i in range(102):
        if not(i in p) and abs(x - i) < m:
            answer = i
            m = abs(x - i)
    print(answer)

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


int main() {
   int N;
   cin >> N;
   vector<int> a(N);
    int ans = 0;
   for(int i = 0; i < N; i++) cin >> a[i];
    int t = 1;
    int i = 0;
   while(1) {
       if(t == a[i]) t++;
       else ans++;

       if(i < N - 1) { i++; }
       else if(i == N - 1) { break; }
   }
    if(ans == N) { ans = -1; }
   cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

template<typename T>
struct BIT {
    int n;
    vector<T> d;
    BIT(int n=0):n(n),d(n+1) {}
    void add(int i,T x=1){
        for(i++;i<=n;i += i&-i){
            d[i] += x;
        }
    }
    T sum(int i){
        T x = 0;
        for(i++;i;i-= i&-i) {
            x += d[i];
        }
        return x;
    }
};

int i,l,r,pos;
char c;

vector<BIT<int>> bit(26,BIT<int>(500005));
vector<BIT<int>> data(26,BIT<int>(500005));

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    string s;
    int q;
    cin >> n >> s >> q;
    // 1-indexedでbitをしたい

    rep(i,n){
        int x = s[i] - 'a';
        bit[x].add(i+1);
    }

    rep(_,q){
        int type;cin >> type;
        if(type==1){
            cin >> pos;
            cin >> c;
            int y = s[pos-1] - 'a'; // y は現在のアルファベット
            int x = c - 'a';    // x は次に追加するアルファベット
            data[y].add(pos);
            s[pos-1] = c;
            bit[x].add(pos);
        }else{
            cin >> l >> r;
            int ans = 0;
            rep(i,26){
                int t = bit[i].sum(r)-bit[i].sum(l-1);
                t -= data[i].sum(r)-data[i].sum(l-1);
                if(t)ans++;
            }
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 105948
#include<cstdio>

const int MAX_N = 1e6, MOD = 1e9 + 7;
int r1, c1, r2, c2;
int fac[2 * MAX_N + 2], inv[2 * MAX_N + 2];

int po(int x, int y) {
    int ans = 1;
    while (y > 0) {
        if (y & 1) ans = static_cast<long>(ans) * x % MOD;
        x = static_cast<long>(x) * x % MOD;
        y >>= 1;
    }
    return ans;
}

int gcalc(int x, int y) {
    if (x == 0 || y == 0) return 0;
    int res = ((((static_cast<long>(fac[x + y + 2])
            * inv[x + 1] % MOD * inv[y + 1] % MOD
            + MOD - static_cast<long>(fac[x + 1])
            * inv[x] % MOD * inv[1] % MOD) % MOD
            + MOD - static_cast<long>(fac[x])
            * inv[x] % MOD * inv[0] % MOD) % MOD
            + MOD - static_cast<long>(fac[x + 1])
            * inv[x] % MOD * inv[1] % MOD) % MOD
            + 1) % MOD;
    return res;
}

int main() {
    scanf("%d %d %d %d", &r1, &c1, &r2, &c2);

    int n = r2 + c2 + 2;
    fac[0] = 1;
    for (int i = 1; i <= n; i++) {
        fac[i] = static_cast<long>(fac[i - 1]) * i % MOD;
    }
    inv[n] = po(fac[n], MOD - 2);
    for (int i = n - 1; i >= 0; i--) {
        inv[i] = static_cast<long>(inv[i + 1]) * (i + 1) % MOD;
    }   
    
    int ans = ((gcalc(r2, c2) - gcalc(r2, c1 - 1)
            - gcalc(r1 - 1, c2) + MOD) % MOD + gcalc(r1 - 1, c1 - 1)) % MOD;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 15744