akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdint>
#include <cmath>
#include <vector>
#include <map>
#include <climits>
#include <numeric>
#include <algorithm>

using namespace std;

struct Cerulean {
    int64_t pos = 0;
    int64_t hp = 0;
};

constexpr int64_t attack_count(int64_t hp, int64_t atk)
{
    return hp <= 0 ? 0 : (hp / atk + (hp % atk ? 1 : 0));
}

constexpr int64_t enough_damage(int64_t hp, int64_t atk)
{
    return hp <= 0 ? 0 : (hp + (hp % atk == 0 ? 0 : atk - hp % atk));
}

int main()
{
    int64_t N,D,A;
    cin >> N >> D >> A;
    vector<Cerulean> ceruleans(N);
    for(auto& c : ceruleans) cin >> c.pos >> c.hp;
    sort(begin(ceruleans), end(ceruleans), [](const auto& x, const auto& y){ return x.pos < y.pos; });
    if(D > 0){
        size_t i = 0;
        size_t j = 1;
        int64_t damage = enough_damage(ceruleans[0].hp, A);
        for(; j < ceruleans.size(); ){
            while(ceruleans[j].pos - ceruleans[i].pos > 2 * D){
                damage -= enough_damage(ceruleans[i].hp, A);
                ++i;
            }
            ceruleans[j].hp = max(0L, ceruleans[j].hp - damage);
            damage += enough_damage(ceruleans[j].hp, A);
            ++j;
        }
    }
    
    int64_t count = 0;
    for(size_t i = 0; i < ceruleans.size(); ++i){
        count += attack_count(ceruleans[i].hp, A);
    }
    cout << count << '\n';
}

Measured memory_bytes: 3328
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <set>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
const ll mod = 1000000007;
const ll INF = 1000000000000000;
ll bit[100010], num;
ll par[100010], sz[100010];
ll n, a, b, ans, dp[100010], leaf[100010], res[2];
vector<ll> road[200010];
bool flg[200010];

struct edge { ll to, cost; };
ll V;
vector<edge> G[300010];
ll d[300010];

ll root(int x) { // �f�[�^x��������؂̍����ċA�œ���Froot(x) = {x�̖؂̍�}
	if (par[x] == x) return x;
	return par[x] = root(par[x]);
}

void unite(int x, int y) { // x��y�̖؂𕹍�
	int rx = root(x); //x�̍���rx
	int ry = root(y); //y�̍���ry
	if (rx == ry) return; //x��y�̍�������(=�����؂ɂ���)���͂��̂܂�
	par[rx] = ry; //x��y�̍��������łȂ�(=�����؂ɂȂ�)���Fx�̍�rx��y�̍�ry�ɂ���
}

bool same(int x, int y) { // 2�̃f�[�^x, y��������؂������Ȃ�true��Ԃ�
	int rx = root(x);
	int ry = root(y);
	return rx == ry;
}

ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x)
{
	while (i <= num)
	{
		bit[i] += x;
		i += i & -i;
	}
}

ll po(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return po(x, y - 1) * x % mod;
	}
	else
	{
		ll yyy = po(x, y / 2);
		return yyy * yyy % mod;
	}
}

ll pow_mod(ll x, ll y)
{
	ll res = 1;
	while (y > 0)
	{
		if (y % 2 == 1)
		{
			(res *= x) %= mod;
		}
		(x *= x) %= mod;
		y /= 2;
	}
	return res;
}

ll div(ll x)
{
	return po(x, mod - 2);
}


ll dfs(ll x)
{
	flg[x] = true;

	vector<ll> vec;
	vec.push_back(0);
	for (int i = 0; i < road[x].size(); i++)
	{
		if (flg[road[x][i]]) continue;
		vec.push_back(dfs(road[x][i]));
	}

	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());

	if (vec.size() != 1)
	{
		ans = max(ans, vec[0] + vec[1] + 1);
	}
	
	return vec[0] + 1;
}

int main(void)
{
	cin >> n;
	for (int i = 1; i < n; i++)
	{
		cin >> a >> b;
		road[a].push_back(b);
		road[b].push_back(a);
	}

	if (n == 1)
	{
		cout << "First" << endl;
		return 0;
	}
	if (n == 2)
	{
		cout << "Second" << endl;
		return 0;
	}

	dfs(1);

	if (ans % 3 == 2)
	{
		cout << "Second" << endl;
	}
	else
	{
		cout << "First" << endl;
	}
	
	int www;
	cin >> www;
}


Measured memory_bytes: 41856
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<ll,ll>
#define vi(x) vector<x>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
   
    string s;
    cin>>s;
    if(s[0]=='7' or s[1]=='7' or s[2]=='7') cout<<"Yes";
    else cout<<"No";
}

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

bool kaibun(string s){
  ll n = s.length();
  ll i = 0;
 for(i = 0; i < n/2; i++){
    if(s[i] != s[n-1-i]) return false;
  }
  return true;
}

  
int main(){
    string s;
    cin >> s;
  string s1,s2;
  ll n = s.length();
  s1 = s.substr(0,(n-1)/2);
  s2 = s.substr((n-1)/2+1,(n-1)/2);
  if(kaibun(s1) && kaibun(s2) && kaibun(s)) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
        int[] v = new int[n];
        for(int i=0;i<n;i++) v[i]=sc.nextInt();
        int[] c = new int[n];
        for(int i=0;i<n;i++) c[i]=sc.nextInt();
        int ans=0;
        for(int i=0;i<(1<<n);i++){
            int x=0;
            int y=0;
            for(int j=0;j<n;j++){
                if((i>>j)%2==1){
                    x+=v[j];
                    y+=c[j];
                }
            }
            ans=Math.max(ans,x-y);
        }
        out.println(ans);
	}
}

// int n = sc.nextInt();
// int[] array = new int[n];
// String s = sc.next();
// s.charAt(i)
// out.println();
// Math.min()


Measured memory_bytes: 22224
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
#include<cmath>
using namespace std;

int main() {
	int n,ans=0,ma=0;
	cin>>n;
	vector<int>a(1000);
	for(int i=0;i<n;i++){
		cin>>a[i];
		ma=max(ma,a[i]);
	}
	a[n]=0;
	for(int i=0;i<=ma;i++){
		for(int j=0;j<=n;j++){
			if(i!=0&&a[j]!=0){
				a[j]--;
			}
			if(j!=0&&a[j-1]!=0&&a[j]==0){
				ans++;
			}
		}
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
G_MAX = 40*10
N_MAX = 40
INF = float('inf')

dp = [[[INF]*(G_MAX+1) for _ in range(G_MAX+1)] 
      for _ in range(N_MAX+1)]
N,Ma,Mb = map(int, input().split())
a,b,c = [],[],[]
for _ in range(N):
    ai,bi,ci = map(int, input().split())
    a.append(ai)
    b.append(bi)
    c.append(ci)

dp[0][0][0] = 0
from math import isinf
for i in range(N):
    for ca in range(G_MAX+1):
        for cb in range(G_MAX+1):
            if isinf(dp[i][ca][cb]): continue
            dp[i+1][ca][cb] = min(dp[i+1][ca][cb],
                                 dp[i][ca][cb])
            dp[i+1][ca+a[i]][cb+b[i]] = min(dp[i+1][ca+a[i]][cb+b[i]],
                                           dp[i][ca][cb]+c[i])
            
    
ans = INF
for ca in range(1,G_MAX+1):
    for cb in range(1,G_MAX+1):
        if ca*Mb==cb*Ma:
            ans = min(ans, dp[N][ca][cb])
            
if isinf(ans): ans = -1
print(ans)

Measured memory_bytes: 59496
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;

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

const int inf = 1e9 + 1;
const double eps = 1e-9;
const int MAXN = 3001;

int n;
int a[MAXN];
ll dp[MAXN][MAXN]; //dp[j][i] je (x-y) za interval od j do j+i

int main(){

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

    for (int i = 1; i <= n; i++){
        for (int j = 0; j <= n-i; j++){
            if (i%2 == n%2) dp[j][i] = max(dp[j][i-1] + a[j+i-1], dp[j+1][i-1] + a[j]);
            else dp[j][i] = min(dp[j][i-1] - a[j+i-1], dp[j+1][i-1] - a[j]);
        }
    }

    cout << dp[0][n];

    return 0;

}

Measured memory_bytes: 70016
fn lcm(a: i64, b: i64) -> i64 {
    let mut x = a;
    let mut y = b;
    if x < y {
        std::mem::swap(&mut x, &mut y);
    }
    while y != 0 {
        let tmp = y;
        y = x % y;
        x = tmp;
    }
    a * b / x
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    let v: Vec<i64> = buf.split_whitespace().map(|x| x.parse().unwrap()).collect();
    let (a, b) = (v[0], v[1]);

    println!("{}", lcm(a, b));
}


Measured memory_bytes: 4352
#include<map>
#include<iostream>
#include<iomanip>
//#include<conio.h>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<stdio.h>
#include<fstream>
#include<assert.h>
#include<time.h>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<sstream>
#include<string.h>
#define mp make_pair
#define ll long long
#define all(v) v.begin(),v.end()
#define memset(a,b) memset(a,b,sizeof(a))
using namespace std;
const int INF=1e9;
inline void write(ll x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
inline void rd(long long &val){
    long long x=0;
    int f=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-'){
		f=-1;
		ch=getchar();
	}
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    val=x*f;
}
inline void rd(int &val){
    int x=0;
    int f=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-'){
		f=-1;
		ch=getchar();
	}
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    val=x*f;
}
inline void print(int x){
	write(x);
	putchar('\n');
}
vector<pair<int,int> >g[1000005];
vector<int> newg[1000005],all[1000005];
int use[1000005];
int dist[1000005];
int x[1000005],n,m,b,e;
int ptr[1000005];
int main(){
	ios_base::sync_with_stdio(false);
	int i,j;
	int p,q,z,mx=0,u,v,c,col,it;
	rd(n);
	rd(m);
	for(i=0;i<m;i++){
		rd(p),rd(q),rd(z);
		p--,q--;
		g[p].push_back(mp(z,q));
		g[q].push_back(mp(z,p));
		all[z].push_back(p);
		all[z].push_back(q);
		mx=max(mx,z);
	}
	for(i=0;i<n;i++) sort(g[i].begin(),g[i].end());
	int newn=n;
	for(col=0;col<=mx;col++){
		if(!all[col].size()) continue;
		for(it=0;it<all[col].size();it++){
//			cout<<col<<" "<<it<<" : ";
			v=all[col][it];
			if(use[v]==col){
//				cout<<endl;
				continue;
			}
			queue<int> q;
			q.push(v);
			use[v]=col;
			vector<int> vec;
			vec.push_back(v);
			while(!q.empty()){
				int t=q.front();
				q.pop();
				while(ptr[t]<g[t].size()){
					c=g[t][ptr[t]].first;
					if(c!=col) break;
					u=g[t][ptr[t]].second;
					if(use[u]!=col){
						use[u]=col;
						q.push(u);
						vec.push_back(u);
					}
					ptr[t]++;
				}
			}
			for(i=0;i<vec.size();i++){
//				cout<<vec[i]<<" ";
				newg[vec[i]].push_back(newn);
				newg[newn].push_back(vec[i]);
			}
//			cout<<endl;
			newn++;
		}
	}
	for(i=0;i<newn;i++) dist[i]=-2;
	queue<int> qu;
	dist[0]=0;
	qu.push(0);
	while(!qu.empty()){
		int t=qu.front();
		qu.pop();
		for(i=0;i<newg[t].size();i++){
			u=newg[t][i];
			if(dist[u]==-2){
				dist[u]=dist[t]+1;
				qu.push(u);
			}
		}
	}
//	cout<<endl;
	cout<<dist[n-1]/2<<endl;
	return 0;
}


Measured memory_bytes: 102016
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    int N,M;
    int[] L, R;
    private void solve() {
        N = nextInt();
        M = nextInt();
        L = new int[M];
        R = new int[M];
        for(int i = 0;i < M;i++) {
            L[i] = nextInt();
            R[i] = nextInt();
        }

        int[] sum = new int[N + 1];
        for(int i = 0;i < M;i++) {
            sum[L[i]-1]++;
            sum[R[i]]--;
        }
        for(int i = 0;i < N;i++) {
            sum[i + 1] += sum[i];
        }

        int ans = 0;
        for(int i = 0;i < N;i++) {
            if (sum[i] == M) {
                ans++;
            }
        }

        out.println(ans);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

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

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

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 41216
ARRAY = gets.split.map(&:to_i)
N = ARRAY[0]
M = ARRAY[1]
Q = ARRAY[2]
$a = 0
B = []
Q.times do
    B.push(gets.split.map(&:to_i))
end
# puts B
qq = Array.new(N, 1)

def df(n, qq)
    if (n == N) then
        tmp = ans(qq)
        $a = tmp if tmp > $a
    else
        q = n == 0 ? 1 : qq[n - 1]
        for i in q..M do
            qq[n] = i
            df(n + 1, qq)
        end
    end
end

def ans(qq)
    ai = 0
    # p qq
    B.each do |ar|
        if qq[ar[1] - 1] - qq[ar[0] - 1] == ar[2]
            ai += ar[3]
        end
    end
    ai
end

df(0, qq)
puts $a


Measured memory_bytes: 14324
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define es cout<<" "
#define dump(x) cout<<" "<<#x<<"="<<x
#define pdump(p) cout<<" "<<#p<<"=("<<p.fst<<","<<p.snd<<")"
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std; using lint = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<lint, lint>;
template<class T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<class T, class... Ts> 
auto make_vec(size_t a, Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));}

int main(void) {
    lint x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<lint> a(x), b(y), c(z);
    repeat (i, x) cin >> a[i];
    repeat (i, y) cin >> b[i];
    repeat (i, z) cin >> c[i];
    
    vector<lint> v;
    repeat (i, x) repeat (j, y) v.push_back(a[i] + b[j]);
    sort(v.begin(), v.end(), greater<lint>());
    
    if (v.size() > 3001) v.erase(v.begin() + 3000, v.end());
    
    vector<lint> w;
    repeat (i, v.size()) repeat (j, z) w.push_back(v[i] + c[j]);
    sort(w.begin(), w.end(), greater<lint>());
    repeat (i, k) cout << w[i] << endl;
}

Measured memory_bytes: 42472
#include <cstdio>

using namespace std;

int m = 1000000007;
long long inv[4000001];
long long fact[4000001];
long long invfact[4000001];
long long dp[2001][2001];

void calc_inv(int n, int mod) {
    inv[1] = 1;
    for (int i = 2; i <= n; i++) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
    
    fact[0] = invfact[0] = 1;
    for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    for (int i = 1; i <= n; i++) invfact[i] = invfact[i - 1] * inv[i] % mod;
}

long long comb(int x, int y, int m) {
    return fact[x] * invfact[y] % m * invfact[x - y] % m;
}

int main() {
    int n, k, i, j;
    
    scanf("%d %d", &n, &k);
    
    if (k == 1) {
        puts("1");
        
        return 0;
    }
    
    calc_inv(n * k, m);
    
    dp[0][0] = 1;
    
    for (i = 0; i <= n; i++) {
        for (j = 0; j <= i; j++) {
            if (i < n) {
                dp[i + 1][j] += dp[i][j];
                if (dp[i + 1][j] >= m) dp[i + 1][j] -= m;
            }
            
            if (j < n && j < i) {
                int c = (n - j - 1) * (k - 1) + n - i;
                dp[i][j + 1] += dp[i][j] * comb(c + k - 2, k - 2, m) % m;
                if (dp[i][j + 1] >= m) dp[i][j + 1] -= m;
            }
        }
    }
    
    printf("%lld\n", dp[n][n] * fact[n] % m);
    
    return 0;
}


Measured memory_bytes: 116480
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()
 
#define cMOD 1000000007ULL
#define cINF ((1ull<<62)-1)
#define cINFINT ((1<<30)-1)
 
 
int main()
{
	ull n = 0;
	cin >> n;
	vector<pair<ll,bool>> a( n, pair<ll,bool>() );
	pair<ll,ll> min_ = { 100000, -1 };
	REP(i, n) {
		cin >> a[i].first;
		a[i].second = a[i].first >= 0;
		if( min_.first > abs(a[i].first) )
		{
			min_ = { abs(a[i].first), i };
		}
	}
 
	int isAll = 0;
	REP(i,n)
	{
		if( a[i].second )
		{
			if( isAll == -1 ) { isAll = 0; break; }
			isAll = 1;
		}
		else
		{
			if( isAll == 1 ) { isAll = 0; break; }
			isAll = -1;
		}
	}
	if( isAll != 0 )
		a[min_.second].second = !a[min_.second].second;
 
	ll sum = 0;
	REP( i, n )
	{
		sum += a[i].first * ( a[i].second ? 1 : -1 );
	}
	cout << sum << endl;
 
	ll plusIdx = -1;
	ll minusIdx = -1;
	REP( i, n )
	{
		if( plusIdx == -1 ) if( a[i].second )
			plusIdx = i;
		if( minusIdx == -1 ) if( !a[i].second )
			minusIdx = i;
	}
	ll now = a[minusIdx].first;
	REP( i, n ) if( i != plusIdx && i != minusIdx )
	if( a[i].second )
	{
		cout << now << " " << a[i].first << endl;
		now -= a[i].first;
	}
	cout << a[plusIdx].first << " " << now << endl;
	now = a[plusIdx].first - now;
	REP( i, n ) if( i != plusIdx && i != minusIdx )
	if( !a[i].second )
	{
		cout << now << " " << a[i].first << endl;
		now -= a[i].first;
	}
 
	return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define inf       ((ll)1e18)
#define mod       1000000007
#define double    long double
#define ull       unsigned long long
#define vi        vector<ll>
#define ppi       pair<int,int>
#define pii       pair<pair<int,int>,int>
#define pb        push_back
#define pi        2*acos(0.0)
#define rev       greater<int>()
#define pr(a,x,y) for(int i=x;i<y;i++){cout<<a[i]<<" ";}
#define ps(s)     for(auto i:s){cout<<i<<" ";}
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define rall(v)   v.rbegin(), v.rend()
#define test      cout<<"This is test"<<endl;
#define str       string
#define endl      '\n'
#define e         cout<<'\n';
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
bool p[1000005];
void init(){
	memset(p,true,sizeof(p));
	p[0]=p[1]=false;
	for(int i=2;i*i<=1000000;i++){
		if(p[i]){
			for(int j=i*i;j<=1000000;j+=i){
				p[j]=false;
			}
		}
	}
}
void solve(){
	init();
	ll n;cin>>n;
	for(int i=n;;i++){
		if(p[i]){cout<<i;return;}
	}
}
int32_t main(){
	kehsihba();
	//init();
	ll t=1;
	//cin>>t;
	for(int k=1;k<=t;k++){
		//cout<<"Case "<<k<<": ";
		solve();
		//e;
	}
}

Measured memory_bytes: 4588
n = int(input())
s = []
for i in range(n):
    s.append(input())

s_sorted = sorted(s)

current = ''
cnt = 0
max_cnt = 0
ans = []
for i in range(n):
    if s_sorted[i] != current:
        if cnt > max_cnt:
            ans = []
            ans.append(current)
            max_cnt = cnt
        elif cnt == max_cnt:
            ans.append(current)
        cnt = 1
        current = s_sorted[i]
    else:
        cnt += 1

if cnt > max_cnt:
    ans = []
    ans.append(current)
    max_cnt = cnt
elif cnt == max_cnt:
    ans.append(current)

for i in ans:
    print(i)

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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);


  ll a,b,c,k;cin>>a>>b>>c>>k;
  ll ans=0;
  ans = min(k,a);
  k -= min(k,a);
  k -= min(k,b);
  ans -= min(k,c);
  cout<<ans<<endl;


  return 0;
}


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

int main() {
 string a,b;
 bool ok =false;
 int A;
 cin >> a >> b;
 A=stoi(a+b);

  for(int i=1;i<1000;i++){
    if(i*i==A){
      ok=true;
    }
  }

  if(ok){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;

bool is_int32(double x){
  return static_cast<std::int32_t>(x) == x;
}

int main(){
  int n, d;
  int ans = 0;
  cin >> n >> d;
  vector<vector<int>> a(n, vector<int>(d));
  REP(i, n){
    REP(j, d){
      cin >> a[i][j];
    }
  }

  for(int i = 0; i < n; i++){
    for(int j = i + 1; j < n; j++){
      int dist2 = 0;
      REP(k, d){
        dist2 += pow(a[i][k] - a[j][k], 2);
      }
      double dist = sqrt(dist2);
      if (is_int32(dist)){
        ans++;
      }
    }
  }
  
  cout << ans << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string s,t;
    cin>>s>>t;
    int i,j,n=s.size(),m=t.size(),ans=INT_MAX;
    for(i=0;i<=n-m;i++)
    {
        int c=0;
        for(j=i;j<i+m;j++)
        {
            if(s[j]!=t[j-i])
            c++;
        }
        ans=min(ans,c);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3652
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int[] a = new int[3];
		a[0]=nextInt();a[1]=nextInt();a[2]=nextInt();
		Arrays.sort(a);
		out.println(a[0]+a[1]);
	}

	private static int nextInt() {
		return Integer.parseInt(next());
	}
	private static long nextLong() {
		return Long.parseLong(next());
	}
	private static String next() {
		return sc.next();
	}

}


Measured memory_bytes: 21716
from sys import stdin
il = lambda func=int: list(map(func, stdin.readline().rstrip().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]

n = int(input())
t, a = il()
h = il()
mint = 10000000
for cnt, i in enumerate(h):
    if abs(a- (t - i * 0.006)) < mint:
        mint = abs(a- (t - i * 0.006))
        ans = cnt+1
print(ans)

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

int main() {
  long q;
  cin >> q;
  vector<long> l(q);
  vector<long> r(q);
  vector<long> aaa(100001);
  for(int i=0;i<q;i++) cin >> l[i] >> r[i];

  for(int i=3;i<100001;i++) {
    aaa[i]=aaa[i-1];
    if(i%2==0) continue;
    bool a=false;
    for(int j=2;j*j<=i;j++) {
      if(i%j==0) {
        a=true;
        break;
      }
    }
    if(a) continue;
    for(int j=2;j*j<=(i+1)/2;j++) {
      if((i+1)/2%j==0) {
        a=true;
        break;
      }
    }
    if(a) continue;
    aaa[i]++;
  }

  for(int i=0;i<q;i++) {
    cout << aaa[r[i]]-aaa[l[i]-1] << endl;
  }
}

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

int main() {
  string s, ans;
  cin >> s;
  for (char c : s) {
    switch(c) {
      case '0':
        ans += '0';
        break;
      case '1':
        ans += '1';
        break;
      case 'B':
        if (ans.size() != 0) ans = ans.substr(0, ans.size()-1);
        break;
    }
  }
  cout << ans << endl;
}

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

constexpr long long mod = 998244353;

// zero-based numbering
template<class T> struct Fenwick {
    vector<T> bit; int N;
    Fenwick(int n) : N(n) { bit.assign(n+1, 0); }
    // add w to a
    void add(int a, T w) {
        for (int x = ++a; x <= N; x += x & -x) bit[x] = (bit[x] + w + mod) % mod;
    }
    // sum [0, a)
    T sum(int a) {
        T ret = 0;
        for (int x = a; x > 0; x -= x & -x) ret = (ret + bit[x] + mod) % mod;
        return ret;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, K; cin >> N >> K;
    vector<pair<int, int>> V;
    for (int i = 0; i < K; i++) {
        int L, R; cin >> L >> R;
        V.emplace_back(L, R+1);   
    }

    Fenwick<long long> DP(N+2);
    DP.add(1, 1);
    DP.add(2, mod - 1);
    for (int i = 1; i < N; i++) {
        long long Cur = DP.sum(i+1);
        for (auto &[l, r]: V) {
            if (i+l > N) continue;
            DP.add(i+l, Cur);
            DP.add(min(N+1, i+r), mod-Cur);
        }
    }
    long long Ans = DP.sum(N+1);
    cout << (Ans % mod + mod) % mod << "\n";
    return 0;
}

Measured memory_bytes: 4780
def S(k):
    return k * (k + 1) // 2

N = int(input())
M = int((N+1)**.5)
ans = 0
# 前半
for i in range(1, N // (M+1) + 1):
    ans += i * S(N // i)
# 後半
for k in range(1, M+1):
    ans += S(k) * (S(N//k) - S(N//(k+1)))
print(ans)

Measured memory_bytes: 9412
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)//階乗
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

template<typename T>
T keta(T a) {  
	ll kazu=1;
	while(1) {
		if (a / 10 != 0) { a /= 10;kazu++; }
		else break;
	}
	return kazu;
}//桁


/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/
int main() {
	ll N, M; cin >> N >> M;
	ll a,b,r=0;
	vector<ll> A(1000000),B(10000000);
	vector<ll> C[1000000];
	for (int i = 0;i < M;i++) {
		cin >> A[i] >> B[i];
		C[A[i]].push_back(B[i]);
	}
	for (int i = 0;i < N;i++) {
		sort(C[i+1].begin(), C[i+1].end());
	}
	for (ll i = 0;i < M;i++) {
				r = keta(A[i]);
				for (ll e = 6-r;e > 0;e--)cout << 0;
				cout << A[i];
				auto itr = lower_bound(C[A[i]].begin(), C[A[i]].end(), B[i]);
				ll k = itr - C[A[i]].begin();
				r = keta(k+1);
				for (ll e = 6 - r;e > 0;e--)cout << 0;
				cout << k+1 << endl;
			}
}


Measured memory_bytes: 114048
from sys import stdin

class Node:
    def __init__(self, value: int):
        self.value = value
        self.previous_node = None
        self.next_node = None


class LinkedList():
    def __init__(self):
        self.first = None
        self.last = None
    
    def delete_node(self, node: Node):
        if node.next_node != None:
            node.next_node.previous_node = node.previous_node
        if node.previous_node != None:
            node.previous_node.next_node = node.next_node
        if node == self.first:
            self.first = node.next_node
        if node == self.last:
            self.last = node.previous_node

    def value_generator(self):
        node = self.first
        while node != None:
            yield node.value
            node = node.next_node

    def insert(self, x: int):
        node = Node(x)
        node.next_node = self.first
        if self.first != None:
            self.first.previous_node = node
        self.first = node
        if self.last == None:
            self.last = node

    def delete(self, x: int):
        target_node = self.first
        while target_node != None and target_node.value != x:
            target_node = target_node.next_node
        if target_node != None:
            self.delete_node(target_node)


def main():
    linked_list = LinkedList()
    insert,delete,delete_node = linked_list.insert,linked_list.delete,linked_list.delete_node
    _ = int(stdin.readline())
    for line in (line.split() for line in stdin.readlines()):
        command = line[0]
        if command == "insert":
            insert(int(line[1]))
        elif command == "delete":
            delete(int(line[1]))
        elif command == "deleteFirst":
            delete_node(linked_list.first)
        elif command == "deleteLast":
            delete_node(linked_list.last)
    print(*linked_list.value_generator())


main()


Measured memory_bytes: 346544
def main():
    N = int(input())
    X = input()
    XINT = int(X,2)
    ANS = [0]*N
    TEMP = [0]*N
    CHAIND = [0]*N

    cnt = count_ones_by_bitmask(XINT)
    
    if cnt == 0:
        for i in range(N):
            print(1)
            return
    if cnt ==1:
        for i in  range(N):
            if X[i] == '1':
                print(0) #全てが0になる
            else:
                if i==N-1:
                    print((int(X[N-1])+1)%2+1) # 2の剰余の反転
                else:
                    print((int(X[N-1]))%2+1) # 2の剰余
        return

    p = XINT % (cnt+1)
    m = XINT % (cnt-1)
    pmod = 1
    mmod = 1
    for i in range(N):
        ANS[i] = 1
        if (X[N-i-1] == '0'):
            TEMP[i] = (p + pmod) % (cnt+1)
        else:
            TEMP[i] = (m - mmod) % (cnt-1)
        pmod = (pmod*2) % (cnt+1)
        mmod = (mmod*2) % (cnt-1)


    CHA = list(set(TEMP))

    for i in range(len(CHA)):
        an = 0
        cha = CHA[i]
        cnt = count_ones_by_bitmask(CHA[i])
        while cnt>0:
            an += 1
            cha = cha%cnt
            cnt = count_ones_by_bitmask(cha)
        CHAIND[CHA[i]] = an

    for i in reversed(range(N)):
        print(ANS[i]+CHAIND[TEMP[i]])


def count_ones_by_bitmask(num):
    count = 0
    while num:
        count += num & 1
        num >>= 1
    return count

if __name__ == '__main__':
    main()


Measured memory_bytes: 22208
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <string.h>

using namespace std;

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

const int MAX = 100100;

int n, m;
int v[MAX];
int par[MAX];	
priority_queue<int> all[MAX];
int best[MAX];

int find(int x) {
	return x == par[x] ? x : (par[x] = find(par[x]));
}

void merge(int x, int y) {
	par[find(x)] = find(y);
}

int main() {
	std::ios::sync_with_stdio(false);

	int x, y;

	cin >> n >> m;
	for(int i = 0; i < n; i ++) {
		cin >> v[i];
	}

	for(int i = 0; i < n; i ++) {
		par[i] = i;
		best[i] = -1;
	}

	for(int i = 0; i < m; i ++) {
		cin >> x >> y;
		if(find(x) != find(y)) {
			merge(x, y);
		}
	}

	int thisParent;
	for(int i = 0; i < n; i ++) {
		thisParent = find(i);

		all[thisParent].push(-v[i]);

		if(best[thisParent] == -1) {
			best[thisParent] = v[i];
		} else {
			best[thisParent] = min(best[thisParent], v[i]);
		}
	}

	ll result = 0;
	int degreeOneCount = 0;
	int compCount = 0;

	priority_queue<pii> candid;
	for(int i = 0; i < n; i ++) {
		if(i == find(i)) {
			if(all[i].size() == 1) {
				result += best[i];
				degreeOneCount ++;
			} else {
				candid.push(make_pair(-best[i], i));	
				compCount ++;
			}
		}
	}

	if(compCount + degreeOneCount == 1) {
		cout << 0 << endl;
		return 0;
	}

	if(compCount == 0 && degreeOneCount == 2) {
		cout << v[0] + v[1] << endl;
		return 0;
	}

	if(compCount == 0 && degreeOneCount > 2) {
		cout << "Impossible" << endl;
		return 0;
	}
	
	vector<int> remain;
	int totalNeed = max(0 , (compCount-1) * 2 - compCount);

	if(candid.size() > 1) {
		while(candid.size()) {
			result -= candid.top().first;
			x = candid.top().second;
			candid.pop();

			all[x].pop();
			while(all[x].size()) {
				remain.push_back(all[x].top()*(-1));
				all[x].pop();
			}
		}	
	} else {
		while(candid.size()) {
			x = candid.top().second;
			candid.pop();

			while(all[x].size()) {
				remain.push_back(all[x].top()*(-1));
				all[x].pop();
			}
		}	
	}

	// cout << " " << totalNeed << " " << remain.size() << " -- " << degreeOneCount << endl;
	// cout << result << endl;

	sort(remain.begin(), remain.end());
	int i = 0;
	for(; i < remain.size() && i < totalNeed; i ++) {
		result += remain[i];
	}
	
	for(; i < remain.size() && degreeOneCount > 0; i ++) {
		result += remain[i];
		degreeOneCount --;
	}

	if(degreeOneCount != 0) {
		cout << "Impossible" << endl;
	} else {
		cout << result << endl;
	}

	return 0;
}

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

int main() {
  int n,x,min = 10000,sum = 0;
  cin >> n >> x;
  vector<int>m(n);
  for(int i = 0;i < n;i++){
    cin >> m.at(i);
    if(m.at(i) < min){
      min = m.at(i);
    }
    sum += m.at(i);
  }
  cout << n+(x-sum)/min << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
ship = [list(map(int, input().split())) for i in range(M)]


goal_ship = []
transit = []

for i in ship:
    if i[1] == N:
        goal_ship.append(i[0])
for i in ship:
    if i[0] == 1:
        transit.append(i[1])

goal_ship = set(goal_ship)
transit = set(transit)

ans = goal_ship & transit

if len(ans):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 60276
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    int n;
    cin >> n;
    ll sum = 0;
    for(int i = 1;i<n;i++) {
        sum += i;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll h,w,k;cin >> h >> w >> k;
    vector<string> g(h);rep(i,h)cin >> g[i];
    vvl d(h,vl(w,-1));
    ll num=1;
    rep(i,h){
        ll ok=0;
        rep(j,w)if(g[i][j]=='#')ok++;
        if(ok){
            ll use=1;
            rep(j,w){
                if(use&&g[i][j]=='#')use--;
                else if(g[i][j]=='#')num++;
                d[i][j]=num;
            }
            num++;
        }
    }
    repl(i,1,h){
        rep(j,w){
            if(d[i][j]==-1){
                d[i][j]=d[i-1][j];
            }
        }
    }
    perl(i,h-1,0){
        rep(j,w){
            if(d[i][j]==-1){
                d[i][j]=d[i+1][j];
            }
        }
    }
    rep(i,h){
        rep(j,w){
            cout << d[i][j] <<" ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 4516
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll sum = 0;
  ll xors = 0;
  int right = 0;
  ll ans = 0;
  for (int left = 0; left < n; left++) {
    while (right < n && (sum + a[right]) == (xors xor a[right])) {
      sum += a[right];
      xors = xors xor a[right];
      right++;
    }
    ans += (right - left);
    sum -= a[left];
    xors = xors xor a[left];
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include<cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include<iostream>
#include<queue>
#include<set>
#include<string>
#include <vector>

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

using namespace std;

int main(){
	int n, q, S[10000], T[500], ans = 0;
	scanf("%d", &n);
	REP(i, n){
		scanf(" %d", &S[i]);
	}
	scanf("%d", &q);
	REP(i, q){
		scanf(" %d", &T[i]);
	}

	REP(i, q){
		REP(j, n){
			if (T[i] == S[j]){
				ans++;
				break;
			}
		}
	}

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

	return 0;
}


Measured memory_bytes: 3216
import java.util.*;

public class Main{
	public static void main(String[] artgs){
		Scanner sc = new Scanner(System.in);
		String[] arr = sc.nextLine().split(" ");
		int N = Integer.parseInt(arr[0]);
		int K = Integer.parseInt(arr[1]);
		arr = sc.nextLine().split(" ");
		int[] A = new int[N];
		for (int i = 0; i < A.length; i++){
			A[i] = Integer.parseInt(arr[i]);
		}
		sc.close();

		int res = 1+(int)Math.ceil((double)(N-K)/(K-1));
		System.out.println(res);
	}
}


Measured memory_bytes: 49080
#include <iostream>
#include <vector>
#include <iomanip>
#include <stack>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstring>
//#include <fstream>
#include <complex>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n;i>0;i--)
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define SORT(v) sort((v).begin(),(v).end())
const ll INF = (1LL << 50);
typedef pair<int, int> P;

int main() {

	int N;
	cin >> N;
	if (N % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}


	string s;
	cin >> s;

	bool ok = true;
	for (int i = 0; i < N / 2; i++) {
		if (s[i] != s[i + N / 2]) {
			ok = false;
		}
	}

	if (ok) cout << "Yes" << endl;
	else cout << "No" << endl;



	return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
void comb_sort(int* array, int size) {
    int h = size;
    bool is_swapped = false;

    while (h > 1 || is_swapped) {
        if (h > 1) {
            h = (h * 10) / 13;
        }

        is_swapped = false;
        for (int i = 0; i < size - h; ++i) {
            if (array[i] < array[i + h]) {
                // swap
                int temp = array[i];
                array[i] = array[i + h];
                array[i + h] = temp;
                is_swapped = true;
            }
        }
    }
}

int main(){
    int a,b[200000],flag,c;
   long long int ans=0;
    scanf("%d",&a);
  for(int i=0;i<a;i++){
   scanf("%d",&b[i]);
  }
   
  comb_sort(b,a);
  
   ans+=b[0];
  for(int i=1;i<a-1;i++){
   ans+=b[(i+1)/2];
   }
  
  printf("%lld",ans);
  return 0;
}

Measured memory_bytes: 2512
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int h;
    int w;
    int k;
    char s[999][999];
    int a[300][300]={};
    int tmp=0;
    // int zero=0;
    int count=999;
    
    cin >> h >> w >> k;
    
    for(int i=0; i<=h-1; i++){
        
        cin >> s[i];
        
        for(int j=0; j<=w-1; j++){
            
            if(s[i][j]=='#'){
                
                tmp += 1;
                a[i][j] = tmp;
                count = min(i, count);
                
            }
            
        }
        
    }
    
    tmp = 0;
    
    for(int i=0; i<=h-1; i++){
        
        tmp = 0;
        // zero = 0;
        
        for(int j=0; j<=w-1; j++){
            
            /*
            
            if(j==0&&a[i][j]==0){ // sento=0
                
                zero = 1;
                continue;
                
            }
            
            */
            
            if(a[i][j]==0){
                
                a[i][j] = tmp;
                
            } else {
                
                if(tmp==0){
                    
                    for(int p=0; p<=j-1; p++){
                        
                        a[i][p] = a[i][j];
                        
                    }
                    
                }
                
                tmp = a[i][j];
                
            }
            
        }
        
    }
    
    if(a[0][0]==0){
        
        for(int i=0; i<=count-1; i++){
            
            for(int j=0; j<=w-1; j++){
                
                a[i][j] = a[count][j];
                
            }
            
        }
        
    }
    
    for(int i=0; i<=h-1; i++){
        
        if(a[i][0]==0){
            
            for(int j=0; j<=w-1; j++){
                
                a[i][j] = a[i-1][j];
                
            }
            
        }
        
    }
    
    // cout << "debug : " << count << endl; // debug
    
    for(int i=0; i<=h-1; i++){
        
        for(int j=0; j<=w-1; j++){
            
            cout << a[i][j];
            
            if(j<=w-2){
                
                cout << " ";
                
            }
            
        }
        
        cout << endl;
        
    }

    return 0;
    
}

Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main()
{
    char q,w;
    int a,b;
    cin>>q>>w;
    if(q=='A')
        a=10;
    else if(q=='B')
        a=11;
    else if(q=='C')
        a=12;
    else if(q=='D')
        a=13;
    else if(q=='E')
        a=14;
    else
        a=15;
    if(w=='A')
        b=10;
    else if(w=='B')
        b=11;
    else if(w=='C')
        b=12;
    else if(w=='D')
        b=13;
    else if(w=='E')
        b=14;
    else
        b=15;
    if(a>b)
        cout<<">";
    else if(a<b)
        cout<<"<";
    else
        cout<<"=";
}


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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
int dx[4] = { 0,  0, 1, -1 };
int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

int main() {
	int a, b; cin >> a >> b;
	if (a + b >= 10) {
		ANS("error");
	}
	else {
		ANS(a + b);
	}
}


Measured memory_bytes: 256
/*---------------Go Code GO---------------*/

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

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using Order_Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//(order) Set.order_of_key(); (pointer) Set.find_by_order();

#define PI acos(-1.0)
#define O_O                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define precision(a) fixed << setprecision(a)
#define endl '\n'
#define Flush cout << flush
#define LLMX 0x3fffffffffffffff

long long N;

int main()
{
    O_O;
    long long N, K;
    long long gcd, k, mx = 0;
    cin >> N;
    long long A[N + 4], B[N + 4], per[N + 4];

    for (int i = 1; i <= N; i++)
    {
        cin >> per[i];
    }
    for (long long i = 1; i <= N; i++)
    {
        A[i] = N * i;
    }
    for (long long i = N + 1; i <= 2 * N; i++)
    {
        B[i - N] = i * N;
    }
    reverse(B + 1, B + N + 1);
    long long base = A[1] + B[1];
    for (int i = 2; i <= N; i++)
    {
        A[per[i]] += i - 1;
    }
    for (int i = 1; i <= N; i++)
        cout << A[i] << ' ';
    cout << endl;
    for (int i = 1; i <= N; i++)
        cout << B[i] << ' ';
    cout << endl;
    return 0;
}

Measured memory_bytes: 4076
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;

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

int main(){
	ll k,n;
    cin >> k >> n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++){
    	cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    ll wid = k+a[0]-a[n-1];
    for(ll i=1;i<n;i++){
    	ll tmp = a[i]-a[i-1];
        if(tmp>wid) wid =tmp;
    }
    cout << k-wid << endl;
}

Measured memory_bytes: 1920
from math import cos, sin, pi
def plot(x,y):
    print(f'{x:.8f} {y:.8f}')

def koch (n, x1, y1, x2, y2):
    if n == 0:
        plot(x1,y1)
        return
    sx = (2*x1+x2)/3
    sy = (2*y1+y2)/3
    tx = (x1+2*x2)/3
    ty = (y1+2*y2)/3
    ux = (tx-sx)*cos(pi/3)-(ty-sy)*sin(pi/3)+sx
    uy = (tx-sx)*sin(pi/3)+(ty-sy)*cos(pi/3)+sy
    koch(n-1, x1, y1, sx, sy)
    koch(n-1, sx, sy, ux, uy)
    koch(n-1, ux, uy, tx, ty)
    koch(n-1, tx, ty, x2, y2)
    
n = int(input())    
koch(n, 0,0, 100,0)
plot(100,0)


Measured memory_bytes: 5772
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 7;
int n, a[maxn];
ll k;
set<int> sp;
int p[maxn], tot;
int main()
{
    scanf("%d%lld", &n, &k);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    sp.insert(1);
    int cur = 1, last = -1;
    p[++tot] = 1;
    while (true) {
        cur = a[cur];
        if(sp.count(cur)) {
            last = cur;
            break;
        }
        else {
            p[++tot] = cur;
            sp.insert(cur);
        }
    }
    int N = sp.size(), tmp;
    for (int i = 1; i <= tot; i++) {
        if(last == p[i]) {
            N = N - i + 1;
            tmp = i - 1;
            break;
        }
    }
    if(k + 1<= tot) {
        printf("%d\n", p[k + 1]);
        return 0;
    }
    k -= tmp;
    int x = (k + 1) % N;
    if(x == 0) x = N;
    printf("%d\n", p[tmp + x]);
}


Measured memory_bytes: 14392