akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(a)-1;i>=n;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define sn st.nd 
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
/****************************/
ll n,m,k;
ll a[100010];
string s;
unsigned long long ans=1;
int main()
{
	cin>>n;
	rep(i,n) cin>>a[i];
	sort(a,a+n);
	long double d=1;
	rep(i,n)
	{
		d*=(long double)(a[i]);
		ans*=a[i];
	}
	if(d>double(1e18))
	{
		cout<<"-1";
		return 0;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4408
// Best practice
 
#include<bits/stdc++.h>
 
#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define prec(n) 	fixed<<setprecision(n)
#define ini(a, i) 	memset(a, i, sizeof(a))
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;
 
#define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl
#define debugp(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<"("<<i.x<<","<<i.y<<")"<<" "; cout<< "]" << endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << "[" << *it << ": " << a << "]\t";
    err(++it, args...);
}
 
// const int dx[4] = { -1, 1, 0, 0};
// const int dy[4] = {0, 0, -1, 1};
// int dX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
// int dY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
 
 
// Code from Here -------------------------------------------------------------------------------

signed main() {
	tezz
 
	string s, t;
	cin >> s >> t;
	int n=s.length();
	int m=t.length();
	int ans = LLONG_MAX;
	for(int i=m; i<=n; i++){
		int c=0;
		for(int j=i-m; j<i; j++){
			if(s[j]!=t[j-(i-m)])c++;
		}
		ans = min(ans, c);
	}
	cout << ans << endl;
 
	return 0;
}  

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

public class Main{
	static void main() throws Exception{
		int maxn=1000001;
		int n=sc.nextInt();
		int[]in=new int[n];
		int[]occ=new int[maxn];
		for(int i=0;i<n;i++) {
			in[i]=sc.nextInt();
			occ[in[i]]++;
		}
		boolean[]yes=new boolean[maxn];
		Arrays.fill(yes, true);
		for(int i=1;i<maxn;i++) {
			if(occ[i]>1) {
				yes[i]=false;
			}
			if(occ[i]>=1) {
				for(int j=i+i;j<maxn;j+=i) {
					yes[j]=false;
				}
			}
		}
		int ans=0;
		for(int i=0;i<n;i++) {
			ans+=yes[in[i]]?1:0;
		}
		
		pw.println(ans);
	}
	public static void main(String[] args) throws Exception{
		pw=new PrintWriter(System.out);
		sc = new MScanner(System.in);
//		int tc=sc.nextInt();
//		while(tc-->0)
			main();
		pw.flush();
	}
	static PrintWriter pw;
	static MScanner  sc;
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}

Measured memory_bytes: 58956
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N, K;

void MAIN() {
    scanf("%d%d", &N, &K);
    if (K == 1) puts("0");
    else printf("%d\n", N-K);

}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 256
import sys

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

for j in range(N+1):
    for k in range(N+1):
        if N-j-k<0:
            continue
        Total=10**4*(N-j-k)+5000*j+10**3*k
        if Total==Y:
            print("{} {} {}".format(N-j-k,j,k))
            sys.exit()
        
print("-1 -1 -1")

Measured memory_bytes: 3060
#include <stdio.h>
#include <vector>
#include <string>

class rect {
public:
    int H;
    int W;
    rect(int H_, int W_)
        : H(H_)
        , W(W_)
    {
    }
};

void printRect(int height, int width) {
    for(int h = 0; h < height; h++){
        for(int w = 0; w < width; w++){
            if(w == 0 || w == width - 1 || h == 0 || h == height - 1){
                printf("#");
            }else{
                printf(".");
            }
        }
        printf("\n");
    }
    printf("\n");
}

int main(int argc, char* argv[]){
    std::vector<rect> list;
    int H, W;
    while(true) {
       scanf("%d %d", &H, &W);
       if(H == 0 && W == 0) break;
       list.push_back(rect(H,W));
    }

    for(auto each: list) {
        printRect(each.H, each.W);
    }
}


Measured memory_bytes: 2612
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	while (~scanf("%d", &n)) {
		int cnt = 0, now;
		for (int i = 1; i <= n; i++) {
			scanf("%d", &now);
			cnt += (now & 1);
		}
		if (cnt & 1) printf("NO\n");
			else printf("YES\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

void print_A(int n, int *A);

int main(){
   int i, j, n, v, *A;
   scanf("%d",&n);
   A=malloc(n*sizeof(int));
   for(i=0;i<n;i++) scanf("%d",A+i);
   for(i=1;i<n;i++){
      print_A(n,A);
      v=A[i];
      for(j=i-1;j>=0&&A[j]>v;j--) A[j+1]=A[j];
      A[j+1]=v;
   }
   print_A(n,A);
   return 0;
}

void print_A(int n, int *A){
   int j;
   for(j=0;j<n;j++){
      if(j!=0) printf(" ");
      printf("%d",A[j]);
   }
   printf("\n");
}

Measured memory_bytes: 604
# Single Source Shortest Path
import heapq

[vertex, edge, r] = list(map(int, input("").split()))
infty = 999999999
final_c = [infty for i in range(vertex)]
dict_c = [[] for i in range(vertex)]

for i in range(edge):
    [e1, e2, c] = list(map(int, input("").split()))
    dict_c[e1].append((e2, c))

final_c[r] = 0
root_c = [(final_c[r], r)]

def Dijkstra(root, n):
    global infty, root_c, final_c, dict_c, root_c
    while(root_c):
        (cost, v) = heapq.heappop(root_c)
        if cost > final_c[v]:
            continue
        for i in range(len(dict_c[v])):
            (e2, c) = dict_c[v][i]
            if final_c[e2] > final_c[v] + c:
                final_c[e2] = final_c[v] + c
                heapq.heappush(root_c, (final_c[e2], e2))

Dijkstra(r, vertex)
for i in range(vertex):
    if final_c[i] == infty:
        print("INF")
    else:
        print(final_c[i])



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

#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n";
#define all(c)  (c).begin(),(c).end()
#define SORT(a) sort((a).begin(),(a).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()

typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int n;
string s;

int main(){
    cin >> n >> s;
    vector<int> cl(26,n);
    vector<int> cr(26,-1);
    REP(i,n){
        int c = s[i] - 'a';
        chmin(cl[c], i);
        chmax(cr[c], i);
    }
    int res = 0;
    REP(i,n-1){
        int temp = 0;
        REP(j,26){
            if(cl[j]<=i&&i<cr[j])temp++;
        }
        chmax(res,temp);
    }
    put(res);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
	int n; cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	int cnt=0;
	int fi=-1;
	int se=-1;
	for(int i=0;i<n;i++){
		if(a[i]!=i+1){
			if(cnt>0)se=i;
			else fi=i;
			cnt++;
		}
	}
	//cout << fi << se << endl;
	if(cnt==0){
		cout << "YES" << endl;
		return 0;
	}
	if(cnt==2){
		swap(a[fi],a[se]);
		//cout << a[fi] << a[se] << endl;
		if(a[fi]==fi+1&&a[se]==se+1){
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
}

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

#l = list(map(int, input().split()))
#import numpy as np
#arr = np.array([int(i) for i in input().split()])
'''
a,b=[],[]
for i in range(n):
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''
def premf(n):
    #前処理
    #minfactor:複数の素因数分解を高速(O(Q*logA_max))に行う,indexはその整数
    #return resで素数リスト(eratosthenes),MinFactorで前処理用リスト返す
    IsPrime=[False]+[False]+[True]*(n-1)
    MinFactor=[0]+[1]+[-1]*(n-1)

    res=[]
    
    for i in range(2,n+1):
        if IsPrime[i]:
            MinFactor[i]=i
    
            res.append(i)
    
            for j in range(i*2,n+1,i):
                IsPrime[j]=False
                if MinFactor[j]==-1: MinFactor[j]=i
                
    return MinFactor
def mf(n,MinFactor):
    #minfactor:nに対し[[素因数,個数],...]を返す
    res=[]
    while n!=1:
        prime=MinFactor[n]
        exp=0
        while MinFactor[n]==prime:
            exp+=1
            n//=prime
        res.append([prime,exp])
    return res


n=int(input())
mff=premf(n)

cnt=0
for i in range(1,n):#c=i
    r=mf(i,mff)
    #print(r)
    no=1
    for jtem in r:
        no*=(jtem[1]+1)
    #print(no)
    cnt+=no
print(cnt)

Measured memory_bytes: 100156
from collections import deque

N, Q = map(int, input().split())

g = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

cnt = [0] * N
for i in range(Q):
    p, x = map(int, input().split())
    cnt[p-1] += x

que = deque([])
que.append(0)
s = [0] * N
while que:
    t = que.popleft()
    s[t] = 1
    for e in g[t]:
        if s[e] == 1: continue
        cnt[e] += cnt[t]
        que.append(e)

print(*cnt)


Measured memory_bytes: 56084
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define cans cout << ans << endl
#define cyes cout << "Yes" << endl 
#define cno cout << "No" << endl
typedef long long ll;


int main(){
    int n,k,q;
    cin >> n >> k >> q;
    vector<int> a(n);
    rep(i,q){
        int l;
        cin >> l;
        l--;
        a[l]++;
    }
    rep(i,n){
        if(k-q+a[i] <= 0) cno;
        else cyes;
    }
    return 0;
}

Measured memory_bytes: 3784
N,D,A=[int(x) for x in input().split()]
xh = [[int(x) for x in input().split()] for _ in range(N)]
xh = sorted(xh)
r=0
l=0
ans = 0
mi = 10**9
d = [0]*(N+1)
for l in range(N):
  if d[l]<xh[l][1]:
    la = (xh[l][1]-d[l]+A-1)//A
    for _ in range(N):
      if l<N and r<N and 2*D>=xh[r][0]-xh[l][0]:
        r+=1
      else:
        break
    ans += la
    d[l]+=la*A
    d[r]-=la*A
  d[l+1]+=d[l]
print(ans)


Measured memory_bytes: 83512
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <math.h>

#define MOD 1000000007
#define REP(i,n) for ((i)=0;i<(n);i++)
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define LL long long
#define ULL unsigned long long

int compare_ll(const void *a, const void *b){
	return *(ULL*)b - *(ULL*)a;
}



int main(void) {

	char S[11];
	long long ans,temp;
	int Stemp[10] = {0};


	int i,j,len;

	scanf("%s", S);
	len = strlen(S);
	ans = 0;

	Stemp[len-1]= pow(2,len-1);

	for(i = 0; i< len; i++){
		temp = 1;
		for(j = len -1 ;Stemp[j]!=0 && j>=0 ; j--){
			ans += Stemp[j] * temp * (S[len-1-i]-'0');
			temp *= 10;
		}
		Stemp[j+1] /= 2;
		Stemp[j] = Stemp[j+1];
	}

	printf("%lld", ans);

	return 0;
}

/* 最後の改行忘れるな！！ */


Measured memory_bytes: 256
#include<iostream>
using namespace std;
//Disjoint Sparse Table
#include<vector>
#include<functional>
template<typename T>
struct DST{
	function<T(T,T)>calcfn;
	int n;
	vector<vector<T> >dat;
	DST(const vector<T>&v={},
		function<T(T,T)>calcfn_=[](T a,T b){return a<b?a:b;}
	):calcfn(calcfn_)
	{
		n=v.size();
		dat.push_back(v);
		for(int i=2;i<n;i<<=1)
		{
			dat.push_back(vector<T>(n));
			for(int j=i;j<n;j+=i<<1)
			{
				dat.back()[j-1]=dat[0][j-1];
				for(int k=2;k<=i;k++)
				{
					dat.back()[j-k]=calcfn(dat[0][j-k],dat.back()[j-k+1]);
				}
				dat.back()[j]=dat[0][j];
				for(int k=2;k<=i&&j+k<=n;k++)
				{
					dat.back()[j+k-1]=calcfn(dat[0][j+k-1],dat.back()[j+k-2]);
				}
			}
		}
	}
	T query(int l,int r)//[l,r)
	{
		if(l<0)l=0;
		if(r>n)r=n;
		r--;
		if(l==r)return dat[0][l];
		int k=31-__builtin_clz(l^r);
		return calcfn(dat[k][l],dat[k][r]);
	}
};
int N,K;
bool flag[2<<17];
main()
{
	cin>>N>>K;
	vector<int>P(N);
	for(int i=0;i<N;i++)
	{
		cin>>P[i];
	}
	DST<int>X(P,[](int a,int b){return a<b?b:a;});
	DST<int>Y(P,[](int a,int b){return a>b?b:a;});
	int ans=0;
	int p=0;
	int ret=0;
	for(int i=0;i<N;i++)
	{
		if(i>0&&P[i-1]>P[i])p=i;
		if(i-p+1>=K)
		{
			flag[i]=true;
			ret=1;
		}
		if(i>=K-1&&!flag[i])
		{
			if(i==K-1||flag[i-1]||!flag[i-1]&&(P[i-K]!=Y.query(i-K,i)||P[i]!=X.query(i-K+1,i+1)))
			{
				ans++;
			}
		}
	}
	cout<<ans+ret<<endl;
}


Measured memory_bytes: 29440
#include <bits/stdc++.h>
using namespace std;
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 V, E;
struct pqdata {
    int from; int to; int cost;
    bool operator<(const pqdata &r) const { return cost > r.cost; }
};

// UnionFindの実装
struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) { }

    // 集合をマージする
    // すでに同じ集合ならfalseが返る
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if(x == y) return false;
        //要素数の少ない方を多い方に繋げる
        if(data.at(y) < data.at(x)) swap(x, y);
        data.at(x) += data.at(y);
        data.at(y) = x;
        return true;
    }

    // ある要素がどの集合に属しているかを答える
    int root(int x) {
        // 根に直接つなぎ直す
        return data.at(x) < 0 ? x : (data.at(x) = root(data.at(x)));
    }

    // ある集合の大きさを答える
    int size(int x) {
        return -data.at(root(x));
    }

    bool same(int x, int y) {
        x = root(x); y = root(y);
        return x == y;
    }
};

int main() {
    cin >> V >> E;
    priority_queue<pqdata> pque;
    UnionFind tree(V);
    for(int i = 0; i < E; ++i) {
        int s, t, w;
        cin >> s >> t >> w;
        pqdata indata;
        indata.from = s; indata.to = t; indata.cost = w;
        pque.push(indata);
    }

    int sum = 0;
    while(!pque.empty()) {
        pqdata now = pque.top();
        pque.pop();
        if(!tree.same(now.from, now.to)) {
            sum += now.cost;
            tree.merge(now.from, now.to);
        }
    }

    cout << sum << endl;
}


Measured memory_bytes: 4592
#include <cassert>
#include <algorithm>
#include <cctype>
#include <complex>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <tuple>
#include <typeinfo>
#include <unordered_set>
#include <unordered_map>
#include <vector>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REPD(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define PB(e) push_back(e)
#define FOREACH(i, c) for(auto i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define BIT(n, m) (((n) >> (m)) & 1)

typedef long long ll;

template <typename S, typename T> ostream &operator<<(ostream &out, const pair<S, T> &p) {
  out << "(" << p.first << ", " << p.second << ")";
  return out;
}

template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
  out << "[";
  REP(i, v.size()){
    if (i > 0) out << ", ";
    out << v[i];
  }
  out << "]";
  return out;
}

int main(int argc, char *argv[])
{
  int N;
  cin >> N;
  string s;
  cin >> s;

  string ns = s.substr(N);
  int dp[N + 1][N + 1];
  ll res = 0;
  REP(mask, 1 << N) {
    string red;
    string blue;
    REP(i, N) {
      if (mask & (1 << i)) {
        red.push_back(s[i]);
      } else {
        blue.push_back(s[i]);
      }
    }
    reverse(ALL(red));
    reverse(ALL(blue));
    memset(dp, 0, sizeof(int) * (N + 1) * (N + 1));
    dp[0][0] = 1;

    REP(i, N) {
      REP(r, min<int>(i, red.size()) + 1) {
        int b = i - r;
        if (b < int(blue.size())) {
          if (blue[b] == ns[i]) {
            dp[r][b + 1] += dp[r][b];
          }
        }
        if (red[r] == ns[i]) {
          dp[r + 1][b] += dp[r][b];
        }
      }
    }
    res += dp[red.size()][blue.size()];
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, cs;
  cin >> A >> B >> cs;
  int ans = 0;
  if(A <= cs) {
    ans++;
  }
  if(cs <= A + B) {
    ans++;
  }
  if(ans == 2) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define pb push_back
#define P pair<int,int>
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; }
struct edge{int to;ll cost;};  //蟻本通り構造体を設定
vector<edge> G1[100010],G2[100010];
vector<ll> d1,d2;

vector<ll> dijkstra(int s,vector<edge> g[]){//始点と行き先と料金をもらう
    vector<ll> d(100010,INFF);  //コストの値(それぞれd1とd2に返す)
    priority_queue<P,vector<P>,greater<P>> q;  //小さい順に並べる
    //priority_queue<要素の型,内部コンテナ,昇順>の指定
    d[s] = 0;  //出発点のコストは0に設定
    q.push(P(0,s));  //({0,s});? //コストと移動した先(現在地)
    while(!q.empty()){  //移動先がなくなるまでやる。負のコストが存在しないのでqは必ず空になる
        P p = q.top();q.pop();
        int v = p.second;  //現在地(ここgとqの入れてるpairの意味が違うので注意)
        REP(i,g[v].size()){
            //g[現在地][移動先の選択肢（i）]にはpair<移動先,料金>が入っている
            edge e = g[v][i];  //ここ2次元配列でpairなので複雑
            if(d[e.to] > d[v] + e.cost){  //移動先と現在地＋移動先への料金を比べる
                //設定されている値よりも小さいならそちらを採用
                d[e.to] = d[v] + e.cost;
                //採用した値をqに入れておく
                q.push(P(d[e.to],e.to));  //ここまでのコストと現在地
            }
        }
    }
    return d;  //これ一行でvectorの中身全てを返せている
}

int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    int n,m,s,t;cin >> n >> m >> s >> t;s--;t--;
    while(m--){
        int u,v;cin >> u >> v;u--;v--;
        ll a,b;cin >> a >> b;
        G1[u].pb({v,a});  //G1には円を、G2スヌークをいれる
        G2[u].pb({v,b});  //[u]からの行き先をtoに、料金をcostに入れている
        G1[v].pb({u,a});  //問題の性質上、v側からとu側からの両方を見る
        G2[v].pb({u,b});  //
    }
    d1 = dijkstra(s,G1);
    d2 = dijkstra(t,G2);
    ll mi[100010];
    fill(mi,mi+n+2,INFF);
    for(int i = n-1;i >= 0; i--){
        ll s = d1[i] + d2[i];
        mi[i] = min(mi[i+1],s);
    }
    REP(i,n){  //最後に所持金から引く
        cout << 1000000000000000-mi[i] << endl;
    }
}

Measured memory_bytes: 19476
def prime_factorize(N):
    ans = 0
    f = 1
    while f <= N:
        ans += f * (N//f) * (N//f+1) //2

        f += 1
    return ans

def main():
    N = int(input())
    ans = prime_factorize(N)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 62996
import java.util.*;
    import java.io.*;
    public class Main
    {
        public static int solve(int[][] arr, int n, int prev, int[][] dp){
            if(n < 0){
                return 0;
            }
            if(dp[n][prev+1] > 0){
                return dp[n][prev+1];
            }
            int ans = Integer.MIN_VALUE;
            if(prev != 0){
                ans = Math.max(ans, arr[n][0] + solve(arr, n-1, 0, dp));
            }
            if(prev != 1){
                ans = Math.max(ans, arr[n][1] + solve(arr, n-1, 1, dp));
            }
            if(prev != 2){
                ans = Math.max(ans, arr[n][2] + solve(arr, n-1, 2, dp));
            }
            return dp[n][prev+1] = ans;
        }
    	public static void main(String[] args) throws Exception{
            StringTokenizer str;
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            int n = Integer.parseInt(br.readLine());
            int[][] arr = new int[n][3];
            for(int i = 0; i < arr.length; i++){
                int j = 0;
                str = new StringTokenizer(br.readLine()," ");
                while(str.hasMoreTokens()){
                    arr[i][j] = Integer.parseInt(str.nextToken());
                    j++;
                }
            }
            int[][] dp = new int[n+1][4];
           System.out.println(solve(arr, n-1, -1, dp));            
        }
    }

Measured memory_bytes: 59492
using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    class Program
    {
        
        static void Main(string[] args)
        {
            

            List<int> list = new List<int>();

            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0)
                {
                    break;
                }

                int[] nendai = new int[7];

                for (int i = 0; i < n; i++)
                {
                    int dai = int.Parse(Console.ReadLine()) / 10;
                    if (dai < 6)
                    {
                        nendai[dai]++;
                    }
                    else
                    {
                        nendai[6]++;
                    }
                }

                foreach (int a in nendai)
                {
                    list.Add(a);
                }
            }


            foreach (int a in list)
            {
                Console.WriteLine(a);
            }

        }



    }
}

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

using i64 = long long;

const int N = 1e5 + 5;

int v[N];

i64 ant;
int n;

int main() {
#ifdef HOME
	freopen("arc.in", "r", stdin);
	freopen("arc.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> v[i];
		ant+= abs(v[i] - v[i - 1]); }
	ant+= abs(v[n]);

	for (int i = 1; i <= n; ++i)
		cout << ant - abs(v[i - 1] - v[i]) - abs(v[i] - v[i + 1]) + abs(v[i - 1] - v[i + 1]) << '\n';

	return 0; }


Measured memory_bytes: 1664
import java.io.*;
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[] a;
    a=new int[n];
    for(int i=0;i<n;i++){
      a[i]=sc.nextInt();
    }
    for(int i=n;i>0;i--){
      System.out.print(a[i-1]);
      if(i!=1) System.out.print(" ");
      else System.out.println();
    }
  }
}



Measured memory_bytes: 26224
#include<stdio.h>
int main()
{
    int n,i,c,f=0,a[1000];
    scanf("%d", &n);
    for(i=0;i<n;i++)
    {
        scanf("%d", &a[i]);
    }
    for(i=0;i<n;i++)
    {
        if(a[i]%2==0)
        {
            c++;
        if(a[i]%3==0||a[i]%5==0)
        {
            f++;
        }
        }
    }
    if(f==c)
    {
        printf("APPROVED\n");
    }
    else
        printf("DENIED\n");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    int res = INF;

    for (int i = 0; i + 2 < n; i++) {
        int a = s[i] - '0';
        int b = s[i+1] - '0';
        int c = s[i+2] - '0';
        int m = 100 * a + 10 * b + c;
        res = min(res, abs(m - 753));
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int N;


int main()
{


	cin >> N;

	bool ans = false;
	for (int i = 1; i <= 9 && !ans; i++) {
		if (N%i == 0 && N / i <= 9) {
			ans = true;
		}
	}

	cout << (ans ? "Yes" : "No") << endl;

	return 0;
}


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

int main(){
    int a,b,ans;
    char op;
    
    do{
        cin >> a >> op >> b;
        if(op == '?') break;
        
        if(op == '+') ans = a + b;
        else if(op == '-') ans = a - b;
        else if(op == '*') ans = a * b;
        else ans = a / b;
        
        cout << ans << endl;
    }while(1);
    
    return 0;
}


Measured memory_bytes: 3096
n,k=map(int,input().split())
p=list(map(int,input().split()))

b=[0]
for i in range(1,n+1):
  b.append(b[i-1]+p[i-1])

max_i=-1
max_v=0
for i in range(1,n+1-k):
  if b[i+k]-b[i]>max_v:
    max_i=i
    max_v=b[i+k]-b[i]
ans=0
for i in range(k):
  ans+=(p[max_i+i]+1)/2
print(ans)

Measured memory_bytes: 25060
n,k = map(int,input().split())
a = list(map(int,input().split()))

dbl_max = (len(str(bin(k-1)))) -2
dbl = [[-1] * (n) for _ in range(dbl_max) ]

for j in range(n):
    dbl[0][j] = a[j] -1

for i in range(1,dbl_max):
    for j in range(n):
        dbl[i][j] = dbl[i-1][ dbl[i-1][j] ]

ans = 0
for i in range(dbl_max):
    if( (k >> i) & 1):
        ans = dbl[i][ans]

print(ans+1)

Measured memory_bytes: 174928
def eratosthenes(n):
    is_prime = [True for i in range(n+1)]
    is_prime[0], is_prime[1] = False, False
    prime = []
    for i in range(2, n+1):
        if is_prime[i]:
            prime.append(i)
            for j in range(2*i, n+1, i):
                is_prime[j] = False
    return prime


N = int(input())

prime = eratosthenes(55555)
ans = []
for p in prime:
    if p % 5 == 1:
        ans.append(p)
    if len(ans) == N:
        break
    
print(*ans)


Measured memory_bytes: 9596
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7

n=I()
s=input().rstrip()
alphasm=[chr(i) for i in range(97, 97+26)]
num=[]
for i in range(n):
    count=0
    k=list(s[0:i])
    l=list(s[i:n])
    for char in alphasm:
        if (char in k) and (char in l):
            count+=1
    num.append(count)
print(max(num))

Measured memory_bytes: 3316
time = 0
d = 10
for _ in range(5):
    a = int(input())
    r = a%10
    if (0<r and r<d) or d==10 or (0<r and d==0):
        d,t = r,a
    time += a//10
    if r!=0: time+=1
time -= t//10
if d!=0: time-=1
time *= 10
time += t
print(time)

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

    vector <int> P(N), Q(N);

    rep(i,N){ cin >> P.at(i);}
    rep(i,N){ cin >> Q.at(i);}

    vector <int> a(N);
    rep(i,N) a.at(i) = i + 1;

    map < vector<int>, int> m_a;
    do{
        m_a[a] = m_a.size();
    }while(next_permutation(a.begin(),a.end()));
    int ans = abs(m_a.at(P)-m_a.at(Q));

    cout << ans << endl;

}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p) pom(a,p-2,p)

////////////////////////////////////////////////////////////////////////////////////////
ll n,m,k;
string s;
int main(){
    cin >> n;
    ll a[n];rep(i,0,n)cin>>a[i];

    ll s[n+1];s[0]=0;
    rep(i,0,n)s[i+1] = s[i] + a[i];

    ll res = INF;
    rep(i,0,n)res=min(res,abs(s[i]-s[n]+s[i]));
    cout << res << ednl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N, M;

    cin >> N >> M;

    int a[M], b[M];
    for (int i = 0; i < M; i++) {
        cin >> a[i] >> b[i];
    }

    int count[N] = {0};
    for (int i = 0; i < M; i++) {
        count[a[i] - 1]++;
        count[b[i] - 1]++;
    }

    for (int i = 0; i < N; i++) {
        cout << count[i] << endl;
    }

    return 0;
}




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

int main(){
  int H,W,K;
  cin>>H>>W>>K;
  vector<vector<char>> c(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>c[i][j];
    }
  }

  int ans=0;
  for(int i=0;i<(1<<H);i++){
    for(int j=0;j<(1<<W);j++){
      int count=0;
      for(int k=0;k<H;k++){
        for(int l=0;l<W;l++){
          if(c[k][l]=='.'){
            continue;
          }
          if(((i>>k)&1)==1){
            continue;
          }
          if(((j>>l)&1)==1){
            continue;
          }
          count++;
        }
      }
      if(count==K){
        ans++;
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp(a, b) make_pair(a, b)
typedef pair<int, int> pii;
inline int lowbit(int x) { return (x & (-x));}
const int maxn = 2e5 + 10;
const ll mod = 1e9 + 7;
ll fac[maxn], inv[maxn], facinv[maxn], bin[maxn];
void pre()
{
	fac[0] = 1; for(int i = 1; i < maxn; ++i) fac[i] = fac[i - 1] * i % mod;
	inv[1] = 1; for(int i = 2; i < maxn; ++i) inv[i] = (mod - mod / i) * inv[mod % i] % mod;
	facinv[0] = 1; for(int i = 1; i < maxn; ++i) facinv[i] = facinv[i - 1] * inv[i] % mod;
	bin[0] = 1; for(int i = 1; i < maxn; ++i) bin[i] = bin[i - 1] * 2 % mod;
}
ll C(int n, int m) { return n < m ? 0 : fac[n] * facinv[m] % mod * facinv[n - m] % mod;}
int main()
{
	pre();
	int n, k;
	scanf("%d%d", &n, &k);
	k = min(k, n - 1);
	ll ans = 0;
	for(int i = 0; i <= k; ++i)
		ans = (ans + C(n, i) * C(n - 1, n - i - 1) % mod) % mod;
	cout << ans << endl;
	return 0;
}
	

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

//constant
const int inf=1<<28;

//variable
int n,p;
int gor[52];

int main(){
    while(cin>>n>>p, n){
        for(int i=0; i<n; i++){
            gor[i]=0;
        }
        int p_t=p;
        for(int i=0; ; i++){
            if(p_t==0){
                p_t+=gor[i%n];
                gor[i%n]=0;
            }
            else if(p_t>0){
                gor[i%n]++;
                --p_t;
                if(gor[i%n]==p){
                    cout<<i%n<<endl;
                    break;
                }
            }
        }
    }

    return 0;
}

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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

void solve();

int main(void){
    ll vec[8][3] = {{1, 1, 1}, {1, 1, -1}, {1, -1, 1}, {1, -1, -1}, {-1, 1, 1}, {-1, 1, -1}, {-1, -1, 1}, {-1, -1, -1}};
    int N, M; cin >> N >> M;
    ll V[8][N];
    rep(i, N){
        ll x, y, z; cin >> x >> y >> z;
        rep(j, 8){
            ll tempx = x * vec[j][0];
            ll tempy = y * vec[j][1];
            ll tempz = z * vec[j][2];
            V[j][i] = tempx + tempy + tempz;
        }
    }
    rep(i, 8){
        sort(V[i], V[i]+N, greater<ll>());
    }
    ll ans = 0;
    rep(i, 8){
        ll acc = 0;
        rep(j, M){
            acc += V[i][j];
        }
        if(acc > ans) ans = acc;
    }
    cout << ans << endl;
    return 0;
}

void solve(){}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(void){
    int H,W;
    ios :: sync_with_stdio(false);
    cin.tie(0);
    cin >> H >> W;
    if(H==1 || W ==1)
        cout<< 1;

    else if((H%2) == 0 || (W%2) == 0)
        cout << (((unsigned long long int)H*(unsigned long long int)W)/2) ;
    else
        cout << ((((unsigned long long int)H*(unsigned long long int)W)+1)/2) ;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(){
  int N, K, ans = 0, okashi = 0, score = 0, num ;
  cin >> N >> K ;
  int sunuke[N+1] ;
  for(int i=1;i<(N+1);i++){
    sunuke[i] = 0 ;
  }
  for(int i=0;i<K;i++){
    cin >> okashi ;
    for(int j=0;j<okashi;j++){
      cin >> num ;
      sunuke[num]++ ;
    }
  }
  for(int i=1;i<(N+1);i++){
    if(sunuke[i] == 0) ans++ ;
  }
  cout << ans << endl ;
  return 0 ;
}  

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  vector<int> wtoe(N, 0);
  for (int i=1; i<N; i++){
    wtoe.at(i) = wtoe.at(i-1);
    if (S.at(i-1) == 'W' ) wtoe.at(i)++; 
  }
  
  int etow = 0,res = 1000000;
  for (int i=N-1; i>=0; i--){
    if ( i !=  N-1 ) {
      if (S.at(i+1) == 'E' ) etow++;
    }
    int r = wtoe.at(i) + etow;
    res = min(res,r);
  }
  
  cout << res << endl;
  
}

Measured memory_bytes: 1796
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;

int main()
{
    int n, a;
    cin >> n;
    vector<int> table(n);
    rep(i, n-1){
        cin >> a;
        table[a-1]++;
    }

    rep(i, n){
        cout << table[i] << endl;
    }
}

Measured memory_bytes: 4052
n,m=gets.split.map &:to_i
n=m if n>m
s=gets.split.map &:to_i
s.sort!
sa=[]
for i in 0..m-2
  sa << s[i+1]-s[i]
end
kai=sa.zip((0..m-1).to_a).sort_by{|i|[-i[0],i[1]]}
sum=0
wa=0
for i in 0..n-2
  sum+=s[kai[i][1]]-s[wa]
  wa=kai[i][1]+1
end
sum+=s[m-1]-s[wa]
puts sum


Measured memory_bytes: 28212
// template version 1.8

// varibable settings {{{
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

#define int long long
#define INF 1e18
// #define INF 2147483647
#define MOD 1000000007
#define infile "../test/sample-1.in"
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;
// }}}

int n,k;
int t[2005][2005];

int calc(int a, int b, int c, int d){
  int res=0;
  res += t[c][d];
  res += t[a-1][b-1];
  res -= t[c][b-1];
  res -= t[a-1][d];
  return res;
}

int solve(){
  cin>>n>>k;
  rep(i, n){
    int x,y;
    char c;
    cin>>x>>y>>c;
    if (c=='W'){ x += k; }
    x %= 2*k;
    y %= 2*k;
    x++;y++;
    t[x][y]++;
  }
  rep(i, 1, 2*k+1)rep(j, 1, 2*k+1) t[i][j] = t[i][j-1]+t[i][j];
  rep(j, 1, 2*k+1)rep(i, 1, 2*k+1) t[i][j] = t[i-1][j]+t[i][j];

  int res=0;
  rep(a, 1, k+1)rep(b, 1, k+1){
    int num=0;
    num += calc(a, b, a+k-1, b+k-1);
    num += calc(1, 1, a-1, b-1);
    num += calc(1, b+k, a-1, 2*k);
    num += calc(a+k, 1, 2*k, b-1);
    num += calc(a+k, b+k, 2*k, 2*k);
    chmax(res, num);
    chmax(res, n-num);
  }
  cout << res << endl;
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 31616
X = int(input())


j = True
s = []
while j == True:
    for p in range(2, X):
        if X % p == 0:
            s.append(False)
        else:
            s.append(True)

    if all(s) == True:
        print(X)
        exit()
    else:
        X += 1
        s = []


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

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> arr(n);
	for (int i=0; i<n; i++) {
		cin >> arr[i];
	}
	sort(arr.begin(), arr.end());
	cout << accumulate(arr.begin(), arr.begin()+k, 0);
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define len(x) (int) (x.size())
using namespace std;
typedef long long ll;

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

    vector<int> myvs;
    for(int i = 0; i < n; i++) {
        cin >> value;
        myvs.push_back(value);
    }
    
    sort(myvs.begin(), myvs.end(), greater<>());


    ll totala = 0, totalb = 0;
    for(int i = 0; i < len(myvs); i++) {
        if(i % 2 == 0) {
            totala += myvs[i];
        }
        else {
            totalb += myvs[i];
        }
    }

    cout << totala-totalb << '\n';

    return 0;
}

Measured memory_bytes: 256
/// sultanov

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
     
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
 
using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type,
less<T>, rb_tree_tag, 
tree_order_statistics_node_update>;

using ll = long long;
using pii = pair<int, int>;                                   

const int MOD = 1e9 + 7;
const int INF32 = 1e9 + 1e2;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b, c;
    cin >> a >> b >> c;
    ll ans = min(b, c) * 2ll;
    b -= ans / 2ll;
    c -= ans / 2ll;
    if (!c) 
        ans += b;
    else {
        ans += min(a, c);
        int mn = min(a, c);
        a -= mn;
        c -= mn;
        if (c)
            ans++;
    }
    cout << ans;
    return 0;
}

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

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順

signed main(){
    int a,b;
    cin >> a >> b;
    cout << 6-a-b << endl;

    return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max<R>(x,0.0));}

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

// Problem Specific Parameter:

const ll inf=1LL<<50;
ll cost[310][310][310];
ll dp[310][310][310];
string board[310];

int main(void){
	int h,w;
	cin >> h >> w;
	rep(i,h) cin >> board[i];

	rep(j,w-1){
		rep(a,h+1)rep(b,h+1){
			cost[j][a][b]=0LL;
			if(a-1>=0 and b-1>=0) cost[j][a][b]=cost[j][a-1][b-1]+(board[a-1][j]==board[b-1][j+1]);
		}
	}


	rep(j,w-1){
		rrep(a,h+1)rrep(b,h+1){
			if(a==h and b==h) continue;
			dp[j][a][b]=inf;
			if(a+1<=h) chmin(dp[j][a][b],dp[j][a+1][b]+cost[j][a+1][b]);
			if(b+1<=h) chmin(dp[j][a][b],dp[j][a][b+1]+cost[j][a][b+1]);
		}
	}
	
	ll ans=0LL;
	rep(j,w-1) ans+=dp[j][0][0];
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 438656
#include<bits/stdc++.h>
const long long N = 1e5 + 5;
const long long inf = 1e18;
using namespace std;

typedef pair <long long, long long> ii;
vector <ii> adj[N];
priority_queue <ii, vector <ii>, greater <ii> > mq;

long long n, m, x, a, b, c, sum, cnt, d[N], ans = inf;
bool check[N];

int main(){
    cin >> n >> m >> x;
    for (long long i = 1; i <= n; i++) d[i] = inf;
    d[1] = 0;
    for (long long i = 1; i <= m; i++){
        cin >> a >> b >> c; sum += c;
        adj[a].push_back(ii(b, c));
        adj[b].push_back(ii(a, c));
    }
    mq.push(ii(0, 1));
    while (mq.size()){
        long long u = mq.top().second; mq.pop();
        if (check[u]) continue;
        check[u] = 1;
        for (long long i = 0; i < adj[u].size(); i++){
            long long v = adj[u][i].first, cost = adj[u][i].second;
            if (check[v]) sum -= cost;
            if (d[v] > d[u] + cost) {
                d[v] = d[u] + cost;
                mq.push(ii(d[v], v));
            }
        }
        ans = min(ans, d[u]*x+sum);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 17416
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
const ll inf = 1LL<<60;

int main()
{
  int n; cin >> n;
  int m; cin >> m;
  vector<int> s(m);
  vector<int> c(m);
  rep(i, m) cin >> s[i] >> c[i];
  for (int i=0; i<m; i++) {
    if (n>1 && s[i]==1 && c[i]==0) {
      cout << -1 << endl;
      return 0;
    }
    for (int j=i+1; j<m; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }

  string str = "";
  rep(i, n) str.push_back('0');
  rep(i, m) {
    str[s[i]-1] = c[i]+'0';
  }
  if (n > 1 && str[0] == '0') {
    str[0] = '1';
  }
  cout << stoi(str) << endl;

  return 0;
}


Measured memory_bytes: 256