akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
long long H, n;
long long dp[(int)1e4+10];
struct monster {
	long long uron = 0, cost = 0;
	monster() {};
} a[1030];
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> H >> n;
	for(int i = 1; i <= n; ++i) cin >> a[i].uron >> a[i].cost;
	for(int i = 0; i <= H; ++i) dp[i] = 1e18;
	dp[0] = 0;
	for(long long i = 1; i <= H; ++i)
		for(long long j = 1; j <= n; ++j)
			if(i - a[j].uron < 0) dp[i] = min(dp[i], a[j].cost);
			else
			dp[i] = min(dp[i], dp[i - a[j].uron] + a[j].cost);
//	for(int i = 1; i <= H; ++i) cout << dp[i] << ' ';
	cout << dp[H];
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ms=1e9+7;
int N=3;
int mul(const ll &x,const ll &y){return x*y%ms;}
int add(const int &x,const int &y){return x+y<ms?x+y:x+y-ms;}
struct Matrix{
	int a[3][3]; Matrix(){memset(a,0,sizeof(a));}
	Matrix operator * (const Matrix &b){
		Matrix c;
		for (int k=0;k<N;k++)
		for (int i=0;i<N;i++)
		for (int j=0;j<N;j++){
			c.a[i][j]=add(c.a[i][j],mul(a[i][k],b.a[k][j]));
		}
		return c;
	}
}ans,b,c,d;
Matrix ksm(int y){
	Matrix ret,x=b;
	for (int i=0;i<N;i++) ret.a[i][i]=1;
	for (;y;y>>=1){
		if (y&1) ret=ret*x;
		x=x*x;
	}
	return ret;
}
int main(){
	for (int i=0;i<N;i++) ans.a[i][i]=1;
	b.a[0][0]=2; b.a[0][1]=1; b.a[0][2]=1;
	b.a[1][0]=2; b.a[1][1]=1; b.a[1][2]=2;
	b.a[2][0]=1; b.a[2][1]=0; b.a[2][2]=1;
	c.a[0][0]=1; c.a[0][1]=1; c.a[0][2]=1;
	c.a[1][0]=0; c.a[1][1]=1; c.a[1][2]=2;
	c.a[2][0]=0; c.a[2][1]=0; c.a[2][2]=1;
	d.a[0][0]=1; d.a[1][0]=2; d.a[2][0]=1;
	int n,m,las=0;
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++){
		int p; scanf("%d",&p);
		ans=ans*ksm(p-las-1); ans=ans*c;
		las=p;
	}
	ans=ans*ksm(n-las-1); ans=ans*d;
	printf("%d\n",ans.a[0][0]);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = list(map(int,input().split()))
q = int(input())
t = list(map(int,input().split()))

def linearSearch(A: [int], key: int):
    i = 0
    A[len(A)-1] = key
    while A[i] != key:
        i += 1
    return i != n

c = 0
s.append(-1)
for i in range(len(t)):
    if linearSearch(s, t[i]):
        c += 1
print(c)


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

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

using namespace std;

struct Data {
  int bit,t;
};

#define DAY 5
#define SELECT 310

int N,M,L;
vector<Data> info[DAY];
int dp1[DAY][SELECT][1<<9];
int dp2[DAY][SELECT];
int dp3[DAY+1][SELECT];

void compute() {
  // step 1
  memset(dp1,-1,sizeof dp1);
  rep(i,DAY) dp1[i][0][0] = 0;
  rep(day,DAY) {
    rep(select,L) {
      rep(state,(1<<N)) {
	if( dp1[day][select][state] == -1 ) continue;
	rep(k,(int)info[day].size()) {
	  if( state & info[day][k].bit ) continue;
	  int bit = state | info[day][k].bit;
	  int &e = dp1[day][select+1][bit];
	  e = max(e,dp1[day][select][state]+info[day][k].t);
	}
      }
    }
  }
  
  // step 2
  memset(dp2,-1,sizeof dp2);
  rep(i,DAY) dp2[i][0] = 0;
  rep(day,DAY) {
    rep(select,L+1) {
      rep(bit,(1<<N)) {
	dp2[day][select] = max(dp2[day][select],
			       dp1[day][select][bit]);
      }
    }
  }

  // step 3
  memset(dp3,-1,sizeof dp3);
  rep(i,DAY+1) dp3[i][0] = 0;
  
  int maxi = 0;
  int id = 0;

  rep(i,DAY){
    //rep(c,L+1) {
    for(int c=L;c>=0;--c) {
      if(dp3[i][c] == -1 ) continue;
      
      // rep(day,DAY) {    bitset<5> BIT(bit);

      rep(select,L+1) {
	//for(int select=L;select>=0;--select) {
	if( dp2[i][select] == -1 ) continue;

	if( c + select <= L ) {
	  dp3[i+1][c+select] = max(dp3[i+1][c+select],dp3[i][c]+dp2[i][select]);
	  maxi = max(maxi,dp3[i+1][c+select]);
	}
      }
    }
  }

  cout << maxi << endl;
}

int main() {
  cin >> N >> M >> L;
  rep(i,M) {
    int d,a,k,t;
    cin >> d >> a >> k >> t;
    int bit = 0;
    --a;
    REP(j,a,a+k) bit |= (1<<j);
    info[d].push_back((Data){bit,t});
  }
  compute();
  return 0;
}

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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	int n,m,i,j;
	scanf("%d %d",&n,&m);
	ll c[10][10];
	ll dist[10][10];
	for(i=0;i<=9;i++) {
		for(j=0;j<=9;j++){
			scanf("%lld",&c[i][j]);
			dist[i][j] = c[i][j];
			
		}
	}

	//floyd wharshall
	for(int k=0;k<=9;k++){
		for(i=0;i<=9;i++){
			for(j=0;j<=9;j++){
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);		
			}
		}
		
	}
	

	// for(i=0;i<=9;i++){
	// 	for(j=0;j<=9;j++){
	// 		if(j){printf(" ");}
	// 		printf("%d",dist[i][j]);
	// 	}
	// 	printf("\n");
	// }
	ll sum = 0;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			int bil;
			scanf("%d",&bil);
			if(bil==-1){continue;}
			sum+=dist[bil][1];
		}
	}
	printf("%lld\n",sum);
	return 0;
};

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
long long ans1,ans2,a[100100];
int n;
int main()
{
	scanf("%d",&n);
	for(int i = 1;i <= n;i++)scanf("%lld",&a[i]);
	sort(a + 1,a + n + 1);
	for(int i = n;i > 1;i--)
	{
		if(a[i] == a[i - 1] && ans1){ans2 = a[i];break;}
		if(a[i] == a[i - 1] && !ans1)ans1 = a[i],i--;
	}
	printf("%lld\n",ans1 * ans2);
}

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

using namespace std;

int xs[10];

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

	sort(xs, xs+10);
	reverse(xs, xs+10);
	for (int i = 0; i < 3; ++i)
		cout << xs[i] << endl;


	return 0;
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
int c[900][900],x,y,z,pp,n,co[901],t[901];
vector<int>v[900];
bool used[901];
void dfs(int p,int d){
  int f=0;
  if(used[v[p][0]]&&v[p].size()==1){
    pp=c[v[p][0]][p];
    if(d-pp>=x) x=d-pp;
  }
  used[p]=1;
  r(i,v[p].size()){
    if(!used[v[p][i]]){
      dfs(v[p][i],d+c[p][v[p][i]]);
      f++;
    }
  }
  if(!f)y+=c[p][v[p][0]];
}
main(){
  while(cin>>n,n){
    //msemset(c,0,sizeof(c));
    int sum=0,ans=1e9,ans1=0;
    r(i,900)v[i].clear();
    r(i,n-1)cin>>co[i];
    r(i,n-1)cin>>t[i];
    r(i,n-1){
      v[i+2].push_back(co[i]);
      v[co[i]].push_back(i+2);
      c[i+2][co[i]]=c[co[i]][i+2]=t[i];
      sum+=t[i];
    }
    r(i,n){
      x=y=z=pp=0;
      memset(used,0,sizeof(used));
      dfs(i+1,0);
      ans=min(ans,2*(sum-y)-(x-z));
    }
    cout<<sum+ans<<endl;
  }
}

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

int main(){
	long long a, b, c, d;
	cin >> a >> b >> c >> d;
	long long ans = a * c;
	ans = max(ans, a * d);
	ans = max(ans, b * c);
	ans = max(ans, b * d);
	cout << ans << endl;
}

Measured memory_bytes: 3632
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int a = sc.nextInt();
		for(int i = 1; i < N; i++) {
			int b = sc.nextInt();
			a = gcd(Math.max(a, b),Math.min(a, b));
			
		}
		System.out.println(a);
	}
	
	static int gcd(int a, int b) {
		int r;
		if (b == 0) return a;
		else {
			r = a%b;
			return gcd(b,r);
		}
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

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

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

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

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

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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

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

int main() {
  int N, C=0;
  string S;
  cin >> N >> S;
  for (int i=0; i<N-2; i++) {
    if (S[i]=='A' && S[i+1]=='B' && S[i+2]=='C') {
      C++;
    }
  }
  cout << C << endl;
} 

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	double n; cin >> n;
	if ((int)n % 2 == 0) {
		cout << (n / 2) / n << endl;
	}
	else {
		cout << ((n + 1) / 2) / n << endl;
	}
	cin >> n;
}

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

using namespace std;

int R, G, B, N;

int main() {
    cin >> R >> G >> B >> N;
    
    int ans = 0;
    for(int r=0;r*R<=N;r++){
        for(int g=0;g*G<=N;g++){
            if( (N - r*R - g*G) % B == 0 && r*R + g*G <= N ) ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;
ll ga, sa, ba, gb, sb, bb;

ll sol_A (ll i, std::vector<ll> &dp) {
  if ( dp[i] != -1 ) return dp[i];
  dp[i] = i;
  if ( i-ga >= 0 ) dp[i] = std::max( dp[i], sol_A(i-ga,dp)+gb );
  if ( i-sa >= 0 ) dp[i] = std::max( dp[i], sol_A(i-sa,dp)+sb );
  if ( i-ba >= 0 ) dp[i] = std::max( dp[i], sol_A(i-ba,dp)+bb );
  return dp[i];
}

ll sol_B (ll i, std::vector<ll> &dp) {
  if ( dp[i] != -1 ) return dp[i];
  dp[i] = i;
  if ( i-gb >= 0 ) dp[i] = std::max( dp[i], sol_B(i-gb,dp)+ga );
  if ( i-sb >= 0 ) dp[i] = std::max( dp[i], sol_B(i-sb,dp)+sa );
  if ( i-bb >= 0 ) dp[i] = std::max( dp[i], sol_B(i-bb,dp)+ba );
  return dp[i];
}


int main (void) {
  ll N; std::cin >> N;
  std::cin >> ga >> sa >> ba >> gb >> sb >> bb;

  std::vector<ll> dpA(N+1,  -1);
  ll NN  = sol_A(N, dpA);

  std::vector<ll> dpB(NN+1, -1);
  ll ans = sol_B(NN, dpB);

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

Measured memory_bytes: 346368
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int n;
double k, ans;

int main(){
	cin >> n >> k;
	ans = 0.0;
	for (int i = 1; i <= n; ++i){
		ans += pow(0.5, max(0.0, ceil(log2(k/i))));
	}
	cout << fixed << setprecision(10) << (ans/n);
}

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

using namespace std;
using ll  = long long;
using ii  = pair < int , int >;
using i3  = pair < int , ii >;
using vi  = vector < int >;
using vii = vector < ii >;
using vi3 = vector < i3 >;

const int N = 2e5 + 5;
const ll INF = 1e12;
const double eps = 1e-9 , PI = acos(-1);

int n , k;
int h[N];
ll dp[N];

void solve(){
    scanf("%d %d" , &n , &k);

    for(int i = 0 ; i < n ; i ++){
        scanf("%d" , &h[i]);
        dp[i] = INF;
    }

    dp[0] = 0;
    for(int i = 1 ; i < n ; i ++)
        for(int j = 1 ; j <= k ; j ++)
            if(i - j >= 0)dp[i] = min(dp[i] , dp[i-j] + 1ll*abs(h[i] - h[i-j]));

    printf("%lld\n" , dp[n-1]);
}

main(){
    int t = 1;
    //scanf("%d" , &t);

    while( t -- ){
            solve();
    }

    return 0;
}





Measured memory_bytes: 1408
#include <iostream>
#include <math.h>
#include <algorithm>
#include <queue>
#include <map>
#include <list>
//#include <bits/stdc++.h>


using namespace std;

#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
typedef long long ll;

int main(){
    ll n;
    ll mx=1,mx2=0;
    cin >> n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++){
        cin >> a[i];
        if(mx<a[i]){
            mx2=mx;
            mx=a[i];
        }
        else if(mx2<a[i]&&a[i]<=mx){mx2=a[i];}
        }
    for(ll j=0;j<n;j++){
        if(a[j]==mx){cout  << mx2<<endl;}
        else{cout << mx  << endl;}
    }

    return 0;
}

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

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

#define USE_COLORED 1

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

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

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

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

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	std::string w;
	std::cin >> w;
	int flags = 0;
	for (auto ch : w) {
		flags ^= (1 << (ch - 'a'));
	}
	if (flags == 0) {
		std::cout << "Yes\n";
	} else {
		std::cout << "No\n";
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define s(s) sort(s.begin(),s.end())
#define r(s) reverse(s.begin(),s.end())
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a + 1 <= c * 2) {
		for (int i = a; i <= b; i++)cout << i << endl;
	}
	else {
		rep(i, c)cout << a + i << endl;
		for (int i = c - 1; i >= 0; i--)cout << b - i << endl;
	}
	return 0;
}

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

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

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;

  int cnt[10][10] = {{}};
  int ans = 0;
  for ( int i = 1; i <= N; i++ ) {
    int j = i;
    while ( j >= 10 ) j /= 10;
    cnt[j][i%10]++;    
  }

  for ( int i = 1; i <= N; i++ ) {
    int j = i;
    while ( j >= 10 ) j /= 10;  
    ans += cnt[i%10][j];
  }

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


Measured memory_bytes: 256
N = int(input())
*h, = map(int, input().split())
dp = [float('inf') for _ in range(N)]
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(N-1):
  dp[i+1] = min(dp[i]+abs(h[i+1]-h[i]), dp[i-1]+abs(h[i+1]-h[i-1]))
print(dp[N-1])

Measured memory_bytes: 55032
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
    int n,k;
    cin>>n>>k;
    int num[110];
    memset(num,-1,sizeof(num));
    rep(i,0,k){
    	int a,b;
    	cin>>a>>b;
    	a--; b--;
    	num[a]=b;
    }
    //dp[i][j][k]??????i+1??\??????j+1?????????????????????k+1??\??£?¶???§?£???????????????¨????????¶????????°???10000??§?????£??????????????\???
    int dp[110][3][2]={};
    if(num[0]==-1) rep(i,0,3) dp[0][i][0]=1;
    else dp[0][num[0]][0]=1;
    rep(i,1,n){
    	//?£????????????????????±??????£??????????????´???
    	if(num[i]==-1){
    		rep(j,0,3){
    			dp[i][j][1]=(dp[i][j][1]+dp[i-1][j][0])%10000;
    			rep(k,0,3){
    				if(j==k) continue;
    				dp[i][j][0]=(dp[i][j][0]+dp[i-1][k][0]+dp[i-1][k][1])%10000;
    			}
    		}
    	}
    	//?£????????????????????±??????£???????????´???
    	else{
    		int id=num[i];
    		dp[i][id][1]=(dp[i][id][1]+dp[i-1][id][0])%10000;
    		rep(k,0,3){
    			if(id==k) continue;
    			dp[i][id][0]=(dp[i][id][0]+dp[i-1][k][0]+dp[i-1][k][1])%10000;
    		}
    	}
    }
    int sum=0;
    rep(i,0,3) rep(j,0,2) sum+=dp[n-1][i][j];
    o(sum%10000);
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,k;
	cin>>n>>k;
	long double ch[200010];
	for(ll i=0;i<n;i++){
		cin>>ch[i];
	}
	long double sum1=0;
	for(ll i=0;i<k;i++){
		long double now=(ch[i]+1)/2;
		sum1+=now;
	}
	long double ans=sum1;
	for(ll i=k;i<n;i++){
		sum1+=(ch[i]+1)/2-(ch[i-k]+1)/2;
		ans=max(sum1,ans);
	}
	printf("%.10Lf",ans);
	// your code goes here
	return 0;
}

Measured memory_bytes: 6892
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while(in.hasNext()) {
			String pile = in.nextLine();
			if(pile.equals("-")) return;
			int m = in.nextInt();
			for(int i=0;i<m;i++) {
				int p = in.nextInt();
				String l = pile.substring(0, p);
				String r = pile.substring(p);
				pile = r + l;
			}
			in.nextLine();
			System.out.println(pile);
		}
	}
}

Measured memory_bytes: 26216
L = [int(x) for x in input().split()]

L.sort()
M = max(L)
for i in range(3):
    L[i] -= M
    
ans = -L[1]
L[0] += ans
if L[0]%2 == 0:
    ans -= L[0]//2
else:
    ans -= (L[0]-1)//2-1
    
print(ans)

Measured memory_bytes: 3064
n, d = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(n)]

ans = 0

for i in range(n):
    p = ls[i][0]
    q = ls[i][1]
    if (p ** 2 + q ** 2) ** 0.5 <= d:
        ans += 1

print(ans)

Measured memory_bytes: 45648
#include<cstdio>
#include<vector>
#include<set>
using namespace std; 
set<int> table;
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int temp;
		bool flag = true;
		scanf("%d",&temp);
		set<int>::iterator it;
		//find
		it = table.find(temp);
		if(it==table.end()) table.insert(temp);
		else table.erase(it); 
	} 
	printf("%d",table.size());
	return 0; 
} 

Measured memory_bytes: 4864
#include<stdio.h>
 
int n, A[20];
 
int solve(int i, int m){
  if( m == 0 ) return 1;
  if( i >= n ) return 0;
  int res = solve(i+1, m) || solve(i+1, m-A[i]);
  return res;
}
 
int main(){
  int q, M, i;
 
  scanf("%d", &n);
  for( i = 0 ; i < n ; i++ ){
    scanf("%d", &A[i]);
  }
 
  scanf("%d", &q);
  for( i = 0 ; i < q ; i++ ){
    scanf("%d", &M);
    if( solve(0, M) ) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}


Measured memory_bytes: 2064
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;
 
#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first                 
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back  
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()           
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   N     =  3e5+5;
const ll   mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   LEVEL =  log2(N)+1;

ll test = 1, n, a[N], ct = 0;

void solve(){
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a+1,a+n+1);
	for(int i = 1; i <= n; i++){
		for(int j = i+1; j <= n; j++){
			for(int k = j+1; k <= n; k++){
				if(a[i] == a[j] or a[i] == a[k] or a[j] == a[k]) continue;
				if(a[i]+a[j] > a[k]) ct++;
			}
		}
	}
	deb1(ct)
}

int main(){
	GODSPEED;
	//cin>>test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
static long long INF = (1LL<<62);

int N, C;
vector<vector<int>> D;
vector<vector<int>> GC0, GC1;

int DF[4][32] = {0};
void calcDF(){
	for(int g=0; g<3; g++){
		for(int c=0; c<C; c++){
			int r = 0;
			for(int i=0; i<N; i++){
				for(int j=0; j<N; j++){
					if((i+j)%3 != g) continue;
					r += D[GC0[i][j]][c];
				}
			}
			DF[g][c] = r;
		}
	}
}

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

	cin >> N >> C;
	D.assign(C, vector<int>(C, 0));
	GC0.assign(N, vector<int>(N, 0));
	GC1.assign(N, vector<int>(N, 0));
	for(int i=0; i<C; i++){
		for(int j=0; j<C; j++){
			int d; cin >> d;
			D[i][j] = d;
		}
	}
	for(int i=0; i<N; i++){
		for(int j=0; j<N; j++){
			int c; cin >> c; c--;
			GC0[i][j] = c;
		}
	}

	calcDF();
	LL ans = INF;
	for(int i=0; i<C; i++){
		for(int j=0; j<C; j++){
			if(j == i) continue;
			for(int k=0; k<C; k++){
				if(k==i || k==j) continue;
				LL w = DF[0][i]+DF[1][j]+DF[2][k];
				if(ans > w){
					ans = w;
				}
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 5760
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")

#include <bits/stdc++.h>

using namespace std;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
#define s second
#define f first


struct BIT {
    vector<long long> v;

    BIT(int s) {
        resize(s);
    }

    void clear() {
        v.clear();
    }

    BIT() {
    }

    void resize(int s) {
        s = 1 << (int) ceil(log(1.0 * s) / log(2.) + 1e-9);
        v.resize(s);
    }

    long long get(int i) {
        i++;
        long long r = 0;
        while (i) {
            r += v[i - 1];
            i -= i & -i;
        }
        return r;
    }

    void add(int i, long long val) {
        i++;
        while (i <= (int) v.size()) {
            v[i - 1] += val;
            i += i & -i;
        }
    }

    int find(long long val) {
        int s = 0;
        int m = v.size() >> 1;
        while (m) {
            if (v[s + m - 1] < val)
                val -= v[(s += m) - 1];
            m >>= 1;
        }
        return s;
    }
};


int main() {

    int n, m;
    scanf("%d %d", &n, &m);
    vector<piii> vp(n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &vp[i].second.f, &vp[i].s.s);
        vp[i].first = vp[i].second.s - vp[i].second.f + 1;
    }
    sort(vp.begin(), vp.end());

    BIT bit(400005);
    int ind = 0;
    for (int i = 1; i <= m; i++) {
        while(ind < vp.size() && i > vp[ind].f){
            bit.add(vp[ind].s.f, 1);
            bit.add(vp[ind].s.s+1, -1);
            ind++;
        }
        int res = 0;
        for(int j=i; j<=m; j+=i){
            res += bit.get(j);
        }
        res += (int)vp.size() - ind;
        printf("%d\n", res);
    }
}


Measured memory_bytes: 8576
#include<iostream>
//#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
#define int long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e5+10;
int const M2=1e6+10;
int const M3=1e3+10;
int mod=1e9+7;
map<int,int>mark;
int a[M];
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
main(){
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int n;
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++){
        cin>>a[i];
        if(!mark[a[i]])
            mark[a[i]]=1,ans++;
        else
            mark[a[i]]=0,ans--;
	}
    cout<<ans;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    string n;
    cin>>n;
    ll ans=0;
    rep(0,i,n.length())ans+=n[i]-'0';
    if(ans%9==0)cout<<"Yes";
    else cout<<"No";
    
}

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

using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define INF (ll)2e9
#define MOD ((ll)1e9+7)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define bit(n) (1LL<<(n))

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;
}

template<class InputIterator>
InputIterator adv(InputIterator x, typename std::iterator_traits<InputIterator>::difference_type n) {
    advance(x, n);
    return x;
}

class mod {
    static ll fact[];
public:

    template<class... A>
    static ll mul(A... args) {
        ll res = 1;
        for (ll i : std::initializer_list < ll > {args...}) {
            res = (res * i) % MOD;
        }
        return res;
    }

    static ll power(ll base, ll exp) {
        if (exp == 0) return 1;
        if (exp & 1) {
            return mul(base, power(base, exp - 1));
        } else {
            ll p = power(base, exp / 2);
            return mul(p, p);
        }
    }

    static ll factorial(int n) {
        if (fact[n] != 0) return fact[n];
        if (n == 0) return 1;
        return fact[n] = mul(n, factorial(n - 1));
    }

    static ll inverse(int n) {
        return power(n, MOD - 2);
    }

    static ll comb(int n, int r) {
        if (r < 0 || r > n) return 0;
        return mul(factorial(n), inverse(factorial(n - r)), inverse(factorial(r)));
    }

    template<class... A>
    static ll div(ll dividend, A... args) {
        ll res = dividend;
        for (ll i : std::initializer_list < ll > {args...}) {
            res = mul(res, inverse(i));
        }
        return res;
    }

    template<class... A>
    static ll add(A... args) {
        ll res = 0;
        for (ll i : std::initializer_list < ll > {args...}) {
            res = (res + i) % MOD;
        }
        return res;
    }

    template<class... A>
    static ll sub(ll l, A... args) {
        ll res = l;
        for (ll i : std::initializer_list < ll > {args...}) {
            res = (res - i + MOD) % MOD;
        }
        return res;
    }
};

ll mod::fact[(int) 1e6 + 1];

int ni() {
    int i;
    cin >> i;
    return i;
}

ll nll() {
    ll l;
    cin >> l;
    return l;
}

int main() {
    ll x = nll();

    ll ans = x / 11 * 2;
    ll left = x - x/11 * 11;
    if (1 <= left && left <= 6) ans += 1;
    else if (7 <= left) ans += 2;

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

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

signed main() {
	int i, n;
	cin >> n;
	int max = -1,cnt = 0;
	rep(i, n) {
		int h;
		cin >> h;
		if (h >= max) {
			cnt++;
			max = h;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n

    def find(self,x): #要素xが属するグループの根を返す
        #根ならその番号を返す
        if self.parents[x]<0: 
            return x 
        # 根でないなら、親の要素で再検索
        else:
            # 走査していく過程で親を書き換える
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    
    def union(self,x,y): #要素xが属するグループと要素yが属するグループとを併合する
        #根を探す
        x=self.find(x)
        y=self.find(y)

        if x==y:
            return
        if self.parents[x]>self.parents[y]: #グループの大きい方に合わせる
            x,y=y,x

        self.parents[x]+=self.parents[y] #x(根)の要素にｙ(根)のグループの要素数をプラスする(要素の値は負の数で表される)
        self.parents[y]=x

    def size(self,x): #要素xが属するグループのサイズ（要素数）を返す
        return -self.parents[self.find(x)]
    
    def same(self,x,y): #要素x, yが同じグループに属するかどうかを返す
        return self.find(x)==self.find(y)

    def members(self,x): #要素xが属するグループに属する要素をリストで返す
        root=self.find(x)
        return [i for i in range(self.n) if self.find(i)==root]
    
    def roots(self): #すべての根の要素をリストで返す
        return [i for i ,x in enumerate(self.parents) if x<0]

    def group_count(self): #グループの数を返す
        return len(self.roots())

    def all_group_members(self): #{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
        return {r:self.members(r) for r in relf.roots()}

    def __str__(self): #ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す (print()での表示用)
        return '\n'.join('{}:{}'.format(r,self.members(r)) for r in self.roots())

N,M=map(int,input().split())
uf=UnionFind(N)

#友達関係
for i in range(M):
    a,b=map(int,input().split())
    uf.union(a-1,b-1)

ans=0
roots=uf.roots()

for i in roots:
    ans=max(ans,uf.size(i))

print(ans)


Measured memory_bytes: 18480
#include <bits/stdc++.h>
#define INF 1000000009
using namespace std;

int n,m,k,x,y;
char c[1000][1000];
bool vis[1000][1000];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};

int main()
{
	cin>>n>>m>>k;
	for(int i=0;i<n;i++){
	    scanf("%s",&c[i]);
	    for(int j=0;j<m;j++) if(c[i][j]=='S') x=i,y=j;
    }
    int ans=min(min(x,y),min(n-x-1,m-y-1));
    vis[x][y]=true;
    if(ans%k==0) ans=ans/k;
    else ans=ans/k+1;
    int minv=ans+1;
    queue<pair<int,pair<int,int> > > q;
    q.push(make_pair(0,make_pair(x,y)));
    while(!q.empty())
    {
    	pair<int,pair<int,int> > t=q.front();q.pop();
    	if(t.first>=k) continue;
		for(int w=0;w<4;w++){
			int nx=t.second.first+dx[w],ny=t.second.second+dy[w];
			if(nx<0||ny<0||nx>=n||ny>=m) continue;
			if(c[nx][ny]=='#') continue;
			if(vis[nx][ny]) continue;
			vis[nx][ny]=true;
			int res=min(min(nx,ny),min(n-nx-1,m-ny-1));
			if(res%k==0) res=res/k;
			else res=res/k+1;
			minv=min(minv,res+1);
			q.push(make_pair(t.first+1,make_pair(nx,ny)));
		}
	}
	cout<<minv<<endl;
	return 0;
}
/*
7 7 1
######.
#####..
####..#
###..##
##..###
#S.####
..#####

HAHA!
*/

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
Scanner scan=new Scanner(System.in);
int a=scan.nextInt();
int b=scan.nextInt();
int c=scan.nextInt();
int d=scan.nextInt();
int densya=a<=b?a:b;
int bus=c<=d?c:d;
System.out.println(densya+bus);
	}
	}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

const int N = 2e5 + 10;
int a[N];
int b[N];
int n, k;

int getSub(int a, int b, int c){
	int l = 0, r = 1e7;
	int ans = 1e7;
	while(l <= r){
		int mid = (l+r)/2;
		if((a-mid)*b <= c){
			ans = mid;
			r = mid-1;
		}
		else
			l = mid+1;
	}
	return ans;
}


bool possible(int x){
	int q = k;
	for(int i = 0; i < n; i++){
		int temp = a[i]*b[i];
		if(temp <= x)
			continue;
		int w = getSub(a[i],b[i],x);
		if(w > q){
			return false;
		}
		q -= w;
	}
	return true;
}


int32_t main(){
	cin >> n >> k;
	
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = 0; i < n; i++)
		cin >> b[i];
	sort(a,a+n);
	reverse(a,a+n);
	sort(b,b+n);
	

	
	int l = 0, r = 2e12;
	
	int ans = 2e12;
	
	while(l <= r){
		int mid = (l+r)/2;
		if(possible(mid)){
			ans = mid;
			r = mid-1;
		}
		else
			l = mid+1;
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3456
#include <iostream>
#include <string>
#include <vector>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  int xorall = 0;
  REP(i, N) {
	cin >> A[i];
	xorall ^= A[i];
  }
  REP(i, N) {
	cout << (A[i] ^ xorall) << " ";
  }
  cout << endl;
}

Measured memory_bytes: 4048
#include <stdio.h>
int n, k, x, y, z;
int a[200000];
int b[200000];
int main() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", a + i);
	}
	for (int j = 0; j < k; j++) {
		for (int i = 0; i < n; i++)b[i] = 0;
		for (int i = 0; i < n; i++) {
			x = i - a[i];
			y = i + a[i];
			if (x < 0)x = 0;
			b[x]++;
			y++;
			if (y < n)b[y]--;
		}
		for (int i = 1; i < n; i++) {
			b[i] += b[i - 1];
		}
		for (int i = 0; i < n; i++) {
			a[i] = b[i];
		}
		z = 1;
		for (int i = 0; i < n; i++) {
			if (a[i] < n)z = 0;
		}
		if (z)break;
	}
	for (int i = 0; i < n; i++) {
		if (i < n - 1)printf("%d ", a[i]);
		else printf("%d\n", a[i]);
	}
}

Measured memory_bytes: 3288
n, m = map(int,input().split())

class unionfind():
    def __init__(self,n):
        self.li = [-1]*(n+1)

    def find(self, x):
        if self.li[x]<0:
            return x
        else:
            self.li[x] = self.find(self.li[x])
            return self.li[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return;
        if x>y:
            x, y = y, x
        self.li[x]+=self.li[y]
        self.li[y] = x

x = unionfind(n)
ans = 0
for _ in range(m):
    a,b = map(int,input().split())
    x.union(a,b)
print(-min(x.li))

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

using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define mp make_pair
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

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

inline tuple<ll, ll> rotate45(tuple<ll, ll> point) { ll x = get<0>(point), y = get<1>(point); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }
void out_sequence(vector<ll> &out) { REP(i, out.size()) { cout << out[i]; if (i == out.size() - 1) cout << endl; else cout << " "; } }

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	ll N; cin >> N;
	string s; cin >> s;

	map<pair<string, string>, ll> p;
	for (int i = 0; i < 1<<N; i++) {
		string t1, t2;
		REP(j, N)
			if (i & (1<<j)) t1.push_back(s[j]);
			else t2.push_back(s[j]);
		p[{t1, t2}]++;
	}

	//for (auto i = p.begin(); i != p.end(); ++i) {
	//	cout << i->first.first << " " << i->first.second << ", " << i->second << endl;
	//}

	ll ans = 0;
	auto s2 = s.substr(N, N);
	reverse(all(s2));
	for (int i = 0; i < 1<<N; i++) {
		string t1, t2;
		REP(j, N)
			if (i & (1<<j)) t1.push_back(s2[j]);
			else t2.push_back(s2[j]);
		//reverse(all(t1));
		//reverse(all(t2));
		ll add = p[{t2, t1}];
		//if (add) cout << "found : " << t2 << " " << t1 << endl;
		ans += add;
	}
	cout << ans << endl;

	return 0;	
}

Measured memory_bytes: 91904
// Aizu 1165: Pablo Squarson's Headache
// 2017.9.13 bal4u@uu

#include <stdio.h>

typedef struct { int r, c; } T;
T tbl[202];

int main()
{
	int n, i, m, d, r, c, r1, r2, c1, c2;

	while (scanf("%d", &n) && n) {
		tbl[0].r = tbl[0].c = r1 = r2 = c1 = c2 = 200;
		for (i = 1; i < n; i++) {
			scanf("%d%d", &m, &d);
			r = tbl[m].r, c = tbl[m].c;
			if      (d == 0) c--;
			else if (d == 1) r++;
			else if (d == 2) c++;
			else             r--;
			tbl[i].r = r, tbl[i].c = c;
			if (r < r1) r1 = r;
			if (r > r2) r2 = r;
			if (c < c1) c1 = c;
			if (c > c2) c2 = c;
		}
		printf("%d %d\n", c2-c1+1, r2-r1+1); 
	}
	return 0;
}

Measured memory_bytes: 1720
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define pq priority_queue
#define st first
#define nd second

using namespace std;
typedef long long ll;
ll const inf = 1e9;
ll const mod = 998244353;

int main()
{
    int n, k;
    cin >> n >> k;
    int a[n];
    fr(i, 0, n){
        cin >> a[i];
    }
    sort(a, a + n);
    int l = 0, r = k - 1;
    int ans = 1e9;
    while(r < n){
        ans = min(ans, a[r] - a[l]);
        l ++, r ++;
    }

    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 640
#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(){
	int n;
    string s;
    cin >> n >> s;
    for(int i=0;i<s.size();i++){
    	for(int j=0;j<n;j++){
        	if(s[i]!='Z'){
            	s[i]++;
            }else{
              	s[i]='A';
            }
        }
    }
    cout << s << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
mod = 10**9+7

ans = 0
for i in range(k, n+2):
    min_ = i*(i+1)//2
    max_ = (n+1)*(n+2)//2-(n+1-i)*(n+1-i+1)//2
    #print(min_, max_)
    ans += max_ - min_ +1
print(ans%mod)


Measured memory_bytes: 63764
/*

Code for problem D by cookiedoth
Generated 08 Jun 2020 at 07.26 PM


█▒▒▒▒▒▒▒▒▒
10%
███▒▒▒▒▒▒▒
30%
█████▒▒▒▒▒
50%
███████▒▒▒
70%
██████████
100%

z_z
>_<
o_O

*/

#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <complex>
#include <cassert>
#include <random>
#include <cstring>
#include <numeric>
#define ll long long
#define ld long double
#define null NULL
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define debug(a) cerr << #a << " = " << a << endl
#define forn(i, n) for (int i = 0; i < n; ++i)
#define sz(a) (int)a.size()

using namespace std;

template<class T> int chkmax(T &a, T b) {
	if (b > a) {
		a = b;
		return 1;
	}
	return 0;
}

template<class T> int chkmin(T &a, T b) {
	if (b < a) {
		a = b;
		return 1;
	}
	return 0;
}

template<class iterator> void output(iterator begin, iterator end, ostream& out = cerr) {
	while (begin != end) {
		out << (*begin) << " ";
		begin++;
	}
	out << endl;
}

template<class T> void output(T x, ostream& out = cerr) {
	output(x.begin(), x.end(), out);
}

void fast_io() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

const int MOD = 1e9 + 7;

void add(int &a, int b) {
	a += b;
	if (a >= MOD) {
		a -= MOD;
	}
}

int mul(int a, int b) {
	return (1LL * a * b) % MOD;
}

int power(int a, int deg) {
	int res = 1;
	for (; deg; deg >>= 1, a = mul(a, a)) {
		if (deg & 1) {
			res = mul(res, a);
		}
	}
	return res;
}

int inverse(int a) {
	return power(a, MOD - 2);
}

const int MX = 1e7 + 10;
int fact[MX], inv[MX], _fact[MX];

void calc_fact() {
	inv[1] = 1;
	for (int i = 2; i < MX; ++i) {
		inv[i] = mul(MOD - MOD / i, inv[MOD % i]);
	}
	fact[0] = 1;
	_fact[0] = 1;
	for (int i = 1; i < MX; ++i) {
		fact[i] = mul(fact[i - 1], i);
		_fact[i] = mul(_fact[i - 1], inv[i]);
	}
}

int func(int a, int b, int c) {
	return mul(mul(fact[a + b + c], a), inv[a + b]);
}

int C(int n, int k) {
	return (k > n ? 0 : mul(fact[n], mul(_fact[k], _fact[n - k])));
}

int A, n;

signed main() {
	fast_io();
	calc_fact();
	cin >> n >> A;
	int ans = 0;
	for (int i = 0; i <= A; ++i) {
		int c = max(0, A - 1 - i);
		for (int bad = 0; bad <= i; ++bad) {
			int sign = (bad % 2 ? MOD - 1 : 1);
			int curC = C(i, bad);
			add(ans, mul(sign, mul(curC, func(i - bad, n - A, c))));
		}
	}
	cout << ans << "\n";
}


Measured memory_bytes: 120796
use std::io::stdin;fn main() {let mut st = String::new();stdin().read_line(&mut st).unwrap();let (n,x,y) = {let k:Vec<i32> = st.trim().split(" ").map(|x| x.parse().unwrap()).collect();(k[0],k[1],k[2])};let mut r:[i32;2*1000+2]=[0; 2*1000+2];for i in 1..n {for j in (i+1)..(n+1) {r[*[j-i,(i-x).abs()+1+(j-y).abs(),(i-y).abs()+(j-y).abs()].iter().min().unwrap() as usize]+=1;};};for i in 1..n {println!("{}", r[i as usize]);}}

Measured memory_bytes: 4352
// Copyright 2019 yaito3014
#include "bits/stdc++.h"
using namespace std;
using namespace literals;

int main() {
  cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false);
  int H, W, A, B;
  cin >> H >> W >> A >> B;
  for (int h = 0; h < H; ++h) {
    for (int w = 0; w < W; ++w)
      if(h<B)cout << (w < A ? 1 : 0);
      else cout << (w < A ? 0 : 1);
    cout << '\n';
  }
}

Measured memory_bytes: 1280
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n, c, k, x, y, ans = 1, i;
    vector <int> v;
    
    scanf("%d %d %d", &n, &c, &k);
    
    for (i = 0; i < n; i++) {
        int x;
        
        scanf("%d", &x);
        
        v.push_back(x);
    }
    
    sort(v.begin(), v.end());
    
    x = 1;
    y = v[0];
    
    for (i = 1; i < n; i++) {
        if (x + 1 <= c && v[i] - y <= k) {
            x++;
        } else {
            ans++;
            x = 1;
            y = v[i];
        }
    }
    
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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 ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  if (n==3 || n==5 || n==7) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
from functools import reduce

def gcd(x,y):
    if x % y == 0:
        return y
    return gcd(y, x % y)

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

n = [int(input()) for _ in range(int(input()))]
print(lcm(*n))


Measured memory_bytes: 3572
#include <stdio.h>

int main(){
  int n;
  int i, j;
  int max = 0, max2 = 0;
  int r = 0;

  scanf("%d",&n);

  int a[n];

  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  for(i=0;i<n;i++){
    if(a[i] > max){
      max = a[i];
    }
  }

  for(i=0;i<n;i++){
    if(a[i] == max && r == 0){
      for(j=0;j<n;j++){
        if(i == j)continue;
        if(a[j] > max2){
          max2 = a[j];
        }
      }
      printf("%d\n",max2);
      r++;
      continue;
    }
    printf("%d\n",max);
  }

  return 0;
}

Measured memory_bytes: 2304
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define M 10000
#define E 500000
   
typedef struct edge {
    int from, to, cost;
} Ed;
Ed e[E];
int d[M];
   
void sp(int,int);
  
int main(int argc,char* argv[])
{
    int vn, en, an;
    int i, j, vi;
    scanf("%d", &vn);
   
    en=0;
    for(i=0; i<vn; i++) {
        scanf("%d", &vi);
        scanf("%d", &an);
        for(j=1; j<=an; j++) {
            e[en].from=vi;
            scanf("%d %d", &e[en].to, &e[en].cost);
            en++;
        }
    }
       
    sp(vn, en);
    for(i=0; i<vn; i++) {
        printf("%d %d\n", i, d[i]);
    }
    return 0;
}
void sp(int vn, int en)
{
    int i, new=1;
    for(i=1; i<vn; i++) d[i]=INT_MAX;
       
    while(new) {
        new=0;
        for(i=0; i<en; i++) {
            if(d[e[i].from] !=INT_MAX && d[e[i].from]+e[i].cost < d[e[i].to]) {
                d[e[i].to] = d[e[i].from]+e[i].cost;
                new++;
            }
        }
    }
}

Measured memory_bytes: 6460