akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<utility>
#include<iterator>
#include<regex>
#include<math.h>

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(lli i=0;i<j;i++)
#define rep1(i,j) for(lli i=1;i<=j;i++)
#define rep0d(i,j) for(lli i=j-1;i>=0;i--)
#define MAX 1000000007
typedef struct tree Tree;

using namespace std;

bool cmpf(pair<lli, lli> left, pair<lli, lli> right) {
	return left.first < right.first;
}


int main() {
	lli n;
	cin >> n;
	vector<lli> vec(n), ans;
	rep0(i, n)cin >> vec[i];
	lli tmp = vec[0],num=0;
	rep1(i, n-1) {
		if (tmp < vec[i]) {
			ans.push_back(num);
			num = 0;
		}
		else {
			num++;
		}
		tmp = vec[i];
	}
	ans.push_back(num);
	sort(rall(ans));
	cout << ans[0];
	
}


Measured memory_bytes: 2168
/*
 * a.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

//const int ids[] = {1, 2, 4, 3, 5, 6};

/* typedef */

typedef vector<int> vi;

struct Dice {
  static const int DN = 6;
  vi ds;

  // 0=X+(top), 1=Y+(front), 2=Z+(right), 3=Z-(left), 4=Y-(back), 5=Z-(bottom)
  Dice(vi &_ds): ds(_ds) {}
  Dice(const int _ds[]) { ds.assign(_ds, _ds + DN); }
  //Dice(): ds(ids, ids + DN) {}

  bool operator==(const Dice &d) const {
    for (int i = 0; i < DN; i++)
      if (ds[i] != d.ds[i]) return false;
    return true;
  }

  bool operator<(const Dice &d) const {
    for (int i = 0; i < DN; i++)
      if (ds[i] != d.ds[i]) return (ds[i] < d.ds[i]);
    return false;
  }

  inline int top()    { return ds[0]; }
  inline int front()  { return ds[1]; }
  inline int right()  { return ds[2]; }
  inline int left()   { return ds[3]; }
  inline int back()   { return ds[4]; }
  inline int bottom() { return ds[5]; }
  
  Dice rotx(int n = 1) { // 1, 2, 4, 3
    Dice r(*this);
    while (n--) {
      int t = r.ds[1];
      r.ds[1] = r.ds[3]; r.ds[3] = r.ds[4]; r.ds[4] = r.ds[2];
      r.ds[2] = t;
    }
    return r;
  }

  Dice roty(int n = 1) { // 2, 0, 3, 5
    Dice r(*this);
    while (n--) {
      int t = r.ds[2];
      r.ds[2] = r.ds[5]; r.ds[5] = r.ds[3]; r.ds[3] = r.ds[0];
      r.ds[0] = t;
    }
    return r;
  }

  Dice rotz(int n = 1) { // 0, 1, 5, 4
    Dice r(*this);
    while (n--) {
      int t = r.ds[0];
      r.ds[0] = r.ds[4]; r.ds[4] = r.ds[5]; r.ds[5] = r.ds[1];
      r.ds[1] = t;
    }
    return r;
  }

  void print() {
    for (int i = 0; i < DN; i++) printf("%d", ds[i]); putchar('\n');
  }

  /*
  static void alldices(set<Dice> &s) {
    Dice d;
    for (int z = 0; z < 4; z++) {
      Dice dz = d.rotz(z);
      for (int y = 0; y < 4; y++) {
	Dice dy = dz.roty(y);
	for (int x = 0; x < 4; x++)
	  s.insert(dy.rotx(x));
      }
    }
  }
  */
};

/* global variables */

int ids[6];

/* subroutines */

/* main */

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

  Dice d(ids);

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

  for (int i = 0; i < n; i++) {
    if (s[i] == 'E') d = d.roty(3);
    else if (s[i] == 'N') d = d.rotz(3);
    else if (s[i] == 'S') d = d.rotz(1);
    else if (s[i] == 'W') d = d.roty(1);
  }

  printf("%d\n", d.top());
  return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
typedef pair<ll,ll> P;
int N;
const int MN=1<<17;
int ch[MN][2],co[MN];
vector<P> vp[MN];
vector<P> tmp1,tmp2,tmp;

bool is_sorted(vector<P> vc){
	vector<P> a=vc;
	sort(all(a));
	return a==vc;
} 
vector<P> norm(vector<P>& vc){
	vector<P> a,b;
	for(P p:vc){
		if(a.empty() || a.back().sc!=p.sc) a.pb(p);
	}
	for(P p:a){
		if(b.empty() || b.back().fs!=p.fs) b.pb(p);
	}
	// if(is_sorted(vc) && !is_sorted(b)){
	// 	show(vc);
	// 	show(b);
	// 	assert(0);
	// }
	return b;
}
bool can(ll X){
	rep(i,N) vp[i].clear();
	for(int v=N-1;v>=0;v--){
		if(ch[v][0]==-1){
			vp[v].pb(P(co[v],co[v]));
		}else{
			tmp1.clear();tmp2.clear();tmp.clear();
			int a = ch[v][0], b = ch[v][1];
			int A = vp[a].size(), B = vp[b].size();
			int j = 0;
			rep(i,A){
				bool change=0;
				while(j<B && vp[a][i].sc + vp[b][j].fs <= X) j++,change=1;
				if(j==0) continue;
				if(change) tmp1.pb(P(vp[a][i].fs+co[v],vp[b][j-1].sc+co[v]));
			}
			j=0;
			swap(a,b);
			swap(A,B);
			rep(i,A){
				bool change=0;
				while(j<B && vp[a][i].sc + vp[b][j].fs <= X) j++,change=1;
				if(j==0) continue;
				if(change) tmp2.pb(P(vp[a][i].fs+co[v],vp[b][j-1].sc+co[v]));
			}
			tmp.assign(tmp1.size()+tmp2.size(),P(0,0));
			// if(!is_sorted(tmp1)){
			// 	show(vp[a]);
			// 	show(vp[b]);
			// 	show(tmp1);
			// 	assert(0);
			// }
			// if(!is_sorted(tmp2)){
			// 	show(tmp2);
			// 	assert(0);
			// }
			// sort(all(tmp1));
			// sort(all(tmp2));
			merge(all(tmp1),all(tmp2),tmp.begin());
			vp[v] = norm(tmp);
		}
		if(vp[v].empty()) return 0;
	}
	return 1;
}
int main(){
	cin>>N;
	rep(i,N) rep(j,2) ch[i][j]=-1;
	rep(i,N-1){
		int a,v;
		cin>>a>>v;
		a--;
		if(ch[a][0]==-1){
			ch[a][0]=i+1;
		}else{
			ch[a][1]=i+1;
		}
		co[i+1]=v;
	}
	ll ub=131072*40,lb=-1;
	while(ub-lb>1){
		ll m=(ub+lb)/2;
		if(can(m)) ub=m;
		else lb=m;
	}
	cout<<ub<<endl;
}

Measured memory_bytes: 33168
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;

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

char buf[1111111];

int dp[1111111][2];

int doit(int pos, int carry) {
  if (dp[pos][carry] != -1) return dp[pos][carry];
  int c = buf[pos] - '0' + carry;
  if (pos == 0 && c == 10) return dp[pos][carry] = 1;
  if (pos == 0) return dp[pos][carry] = min(c, 10-c + 1);
  if (c == 10) return dp[pos][carry] = doit(pos-1, 1);
  return dp[pos][carry] = min(c + doit(pos-1, 0), 10-c+doit(pos-1,1));
}

int main() {
  scanf("%s", buf);
  memset(dp, -1, sizeof dp);
  for (int i = 0; buf[i]; i++) doit(i, 0);
  printf("%i\n", doit(strlen(buf)-1, 0));
}


Measured memory_bytes: 9856
#include<stdio.h>


int main(void){

	char s[3];
	char t[3];
	int i,c;

	c = 0;

	scanf("%s",s);
	scanf("%s",t);

	for(i=0;i<3;i++){
		if(s[i] == t[i]){
			c++;
		}
	}

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


	return 0;
}

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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int a[3];
    for (int i = 0; i < 3; i++) {
        cin >> a[i];
    }

    // 処理
    sort(a, a + 3, greater<int>());
    int x = a[0] * 10 + a[1];

    // 出力
    cout << x + a[2] << endl;

    return 0;
}


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

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

    int N;
    cin >> N;

    vector<int> H(N);
    for (int i; i < N; ++i) cin >> H[i];

    int mx = 0, cnt = 0;
    for (int i=0; i<N; ++i) {
        if (mx <= H[i]) {
            cnt ++;
            mx = max(mx, H[i]);
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter
N = int(input())
D = list(map(int, input().split()))
count_D = Counter(D)
if count_D.most_common()[0][1] >= 3:
    print(0)
    sys.exit()
ans = 0
for b in range(2**13):
    tmp = [0]
    for d in range(13):
        if count_D[d] == 2:
            tmp += [d, 24-d]
        elif count_D[d] == 1:
            if (b & 1):
                tmp += [d]
            else:
                tmp += [24 - d]
        b = b >> 1
    time_gap = 12
    for i in range(len(tmp)):
        for j in range(i+1, len(tmp)):
            time_gap = min(time_gap, min(abs(tmp[j]-tmp[i]), 24-tmp[j]+tmp[i]))
    ans = max(ans, time_gap)
print(ans)

Measured memory_bytes: 74720
/**
 * 与えられた文字列の小文字と大文字を入れ替えるプログラムを作成してください。
 */

//スキャナつかうため

import java.util.Scanner;

public class Main {
	// プログラムのエントリポイント
	public static void main(String[] args) {
		// 入力ストリームの生成
		Scanner sc = new Scanner(System.in);

		while (true) {

			// 文字列を受け取る
			String moji = sc.nextLine();
			if (moji.equals("0")){
				break;
			} else {
				int intKekka = 0;
				// 受け取った文字数の配列の宣言
				char[] kowake = new char[moji.length()];
				// 受け取った文字の数処理を繰り返す
				for (int i = 0; i < moji.length(); i++) {

					kowake[i] = moji.charAt(i);
					intKekka += kowake[i] - 48;


				}
				System.out.println(intKekka);

			}

		}
	}
}

Measured memory_bytes: 17448
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second



signed main(){
  int n;
  cin>>n;
  int a[n];
  r(i,n)cin>>a[i];
  for(int i=101;i>=0;i--){
    int s=0,f=0;
    r(j,n){
      s+=a[j];
      s-=i;
      if(s<0)f++;
    }
    if(!f){
      cout<<i<<endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3124
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#define int long long
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
inline int Rand(){return rand()*32768+rand();}
int n,c,h[200005],dp[200005];
typedef pair<int,int> func;
vector<func>stk;
void show(){
	cerr<<"show func:"<<endl;
	for(int i=0;i<stk.size();i++){
		cerr<<-stk[i].first<<" "<<-stk[i].second<<endl;
	}
	cerr<<"end"<<endl;
}
void add_stack(int x){
	//a=h[i],b=h[i]^2+dp[i]
	func f3=make_pair(2ll*h[x],-h[x]*h[x]-dp[x]);
	while(stk.size()>=2){
		func f2=stk.back();stk.pop_back();
		func f1=stk.back();stk.pop_back();
		if((f3.second-f1.second)*(f2.first-f1.first)>(f2.second-f1.second)*(f3.first-f1.first)){
			stk.push_back(f1);
		}else{
			stk.push_back(f1);
			stk.push_back(f2);
			break;
		}
	}
	stk.push_back(f3);
}
int f(func f,int v){
	return -v*f.first-f.second;
}
int query(int v){
	int l=0,r=stk.size();
	while(r-l>1){
		int mid=(l+r)/2;
		if(f(stk[mid],v)<f(stk[mid-1],v))l=mid;
		else r=mid;
	}
	return f(stk[l],v);
}
signed main(){
	cin>>n>>c;
	for(int i=1;i<=n;i++)cin>>h[i];
	dp[1]=0;add_stack(1);
	for(int i=2;i<=n;i++){
		dp[i]=h[i]*h[i]+c+query(h[i]);
		add_stack(i); 
	}
	cout<<dp[n]<<endl;
	return 0;
}

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

using namespace std;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long  ll;
#define endl '\n'


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


const int MOD = 1000000007;

//////////////////////////////////////////

int n;

void Input() {

    cin >> n;
}

void Solve() {


    pair< pair<string , int> , int > p[110];

    int a;
    string s;

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

        cin >> s >> a;

        p[i] = make_pair(make_pair(s, -a), i);

    }

    sort(p, p+n);

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

        cout << p[i].second + 1 << endl;
    }



}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);
  Input();
  Solve();


  return 0;

}


Measured memory_bytes: 256
N = gets.to_i
A = [-Float::INFINITY] + gets.split.map(&:to_i).sort + [Float::INFINITY]
B = gets.split.map(&:to_i).sort
C = [-Float::INFINITY] + gets.split.map(&:to_i).sort + [Float::INFINITY]

def binary_search(ok:, ng:)
  while (ok - ng).abs > 1
    mid = (ok + ng) / 2

    if yield(mid)
      ok = mid
    else
      ng = mid
    end
  end

  yield(ok) ? ok : nil
end

ans = 0

B.each do |b|
  ai = binary_search(ok: 0, ng: N + 1) { |x| A[x] < b }
  ci = binary_search(ok: N + 1, ng: 0) { |x| C[x] > b }

  next unless (1..N).cover?(ai)
  next unless (1..N).cover?(ci)

  ans += ai * (N - ci + 1)
end

puts ans


Measured memory_bytes: 33104
package main

import (
	"fmt"
	"sort"
)

type area struct {
	x int
	y int
}

type areas []area

func (d areas) Len() int {
	return len(d)
}

func (d areas) Swap(i, j int) {
	d[i], d[j] = d[j], d[i]
}

func (d areas) Less(i, j int) bool {
	if d[i].x == d[j].x {
		return d[i].y < d[j].y
	}
	return d[i].x < d[j].x
}

func main() {
	var n int
	fmt.Scan(&n)
	ar := make(areas, n)
	for i := range ar {
		fmt.Scan(&ar[i].x, &ar[i].y)
	}
	if n == 1 {
		fmt.Println(1)
		return
	}
	sort.Sort(ar)
	mp := map[area]int{}
	for i := 0; i < n-1; i++ {
		buf := map[area]bool{}
		for j := i + 1; j < n; j++ {
			v := area{}
			v.x = ar[i].x - ar[j].x
			v.y = ar[i].y - ar[j].y
			if buf[v] {
				continue
			}
			mp[v]++
			buf[v] = true
		}
	}
	max := 0
	for k, v := range mp {
		if k.x == 0 && k.y == 0 {
			continue
		}
		if max < v {
			max = v
		}
	}
	fmt.Println(n - max)
}


Measured memory_bytes: 768
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
struct amida {
    int a, b;
};
bool comp(const amida& a, const amida& b) {
    return a.b<b.b;
}
int n, m, h, k;
int sc[1000], num[1000], res[1000];
amida ami[100000], scs[100000], ns[100000];
int main() {
    while (scanf("%d%d%d%d",&n,&m,&h,&k)) {
        if (!n&&!m&&!h&&!k) break;
        for (int i=0; i<n; i++) scanf("%d",&sc[i]);
        for (int i=0; i<m; i++) {
            scanf("%d%d",&ami[i].a,&ami[i].b);
        }
        sort(ami, ami+m, comp);
        for (int i=0; i<n; i++) num[i]=i;
        // number
        for (int i=0; i<m; i++) {
            ns[i].a=num[ami[i].a-1];
            ns[i].b=num[ami[i].a];
            swap(num[ami[i].a-1], num[ami[i].a]);
        }
        // score
        for (int i=m-1; i>=0; i--) {
            scs[i].a=sc[ami[i].a-1];
            scs[i].b=sc[ami[i].a];
            swap(sc[ami[i].a-1], sc[ami[i].a]);
        }
        // calc
        memset(res, 0, sizeof(res));
        int d=0;
        for (int i=0; i<m; i++) {
            res[ns[i].a]=scs[i].b;
            res[ns[i].b]=scs[i].a;
            if (0<=ns[i].a&&ns[i].a<k&&0<=ns[i].b&&ns[i].b<k) {
                continue;
            } else if (0<=ns[i].a&&ns[i].a<k) {
                d=min(d, scs[i].a-scs[i].b);
            } else if (0<=ns[i].b&&ns[i].b<k) {
                d=min(d, scs[i].b-scs[i].a);
            }
        }
        //printf("%d\n",d);
        ll ans=d;
        for (int i=0; i<k; i++) ans+=res[i];
        printf("%lld\n",ans);
    }
}

Measured memory_bytes: 1712
#include<stdio.h>
#include<string.h>


int main(void)
{
        int n,m,i,max=0,j,c=0;
        char s[100][11],t[100][11];
        scanf("%d",&n);
        for(i=0;i<n;i++){
                scanf("%s",s[i]);
        }
        scanf("%d",&m);
        for(i=0;i<m;i++){
                scanf("%s",t[i]);
        }
    for(i=0;i<n;i++){
                c=1;
        for(j=i+1;j<n;j++){
            if(strcmp(s[i],s[j])==0) c++;

        }
        for(j=0;j<m;j++){
            if(strcmp(s[i],t[j])==0) c--;
        }
                if(max<c) max=c;
    }

        if(max<0) printf("0\n");
        else printf("%d\n",max);



        return 0;
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))

def f(a):
  if (a % 2 == 0):
    if (a % 3 == 0 or a % 5 == 0):
      return 1
    else:
  	  return 0
  return 1

ans = list(map(f,A))
if (len(ans) == sum(ans)):
  print("APPROVED")
else:
  print("DENIED")

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

int main() {
  ll N,K; cin >> N >> K;
  vector<pair<ll, ll>> pairs(N);
  for (int i = 0; i < N; i++) cin >> pairs[i].first >> pairs[i].second;
  sort(pairs.begin(),pairs.end());
  
  ll ans = 0;
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    sum += pairs[i].second;
    if (sum >= K) {
      ans = pairs[i].first;
      break;
    }
  }
  
  cout << ans << endl;  
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n, r, p, c;
        int[] card = new int[50];
        int[] tmp = new int[50];
        while(true){
            n = sc.nextInt();
            r = sc.nextInt();
            if(n == 0 && r == 0) break;
            for(int i=0;i<n;i++){
                card[i] = n-i;
            }
            for(int i=0;i<r;i++){
                p = sc.nextInt();
                c = sc.nextInt();
                for(int j=0;j<c;j++){
                    tmp[j] = card[p-1+j];
                }
                for(int j=0;j<p-1;j++){
                    card[p-2-j+c] = card[p-2-j];
                }
                for(int j=0;j<c;j++){
                    card[j] = tmp[j];
                }
            }
            System.out.println(card[0]);
        }
    }
}


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

b = []
memo = a[0]
count = 0
for i in range(n):
    if a[i] == memo:
        count += 1
        if i == n-1:
            b.append(count)
    else:
        b.append(count)
        memo = a[i]
        count = 1


ans = 0
for j in b:
    ans += (j//2)

print(ans)

Measured memory_bytes: 3064
N = gets.to_i
a = gets.split.map(&:to_i)

sa = 0

(N/2).times{|i|
  sa += a[i] - a[N-i-1]
}

saex1 = sa
saex2 = sa

#きすうのとき
if N%2==1 then
  saex1 -= a[N/2]
  saex2 += a[N/2]
end

#puts saex1,saex2,""

#
idx1 = N/2-1
idx2 = N-(N/2)

(N/2-1).times{|i|
  saex1 -= a[idx1]*2
  saex2 += a[idx2]*2
  idx1-=1
  idx2+=1
  sa = saex1 if sa.abs>saex1.abs
  sa = saex2 if sa.abs>saex2.abs 
  #puts saex1,saex2,""
}

puts sa.abs
#puts satmp


Measured memory_bytes: 15244
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define inf 1000000007
using namespace std;
typedef pair<int,pair<int,int> > P;
int N;
ll seg[2][530000]; // 0:even, 1:odd range minimum
void init(int n_){
	N = 1;
	while(N<n_)N*=2;
	for(int i=0;i<2*N-1;i++){
		seg[0][i]=inf;
		seg[1][i]=inf;
	}
}

void update(int k,int a,int x){
	k += N-1;
	seg[x][k]=a;
	while(k>0){
		k = (k-1)/2;
		seg[x][k] = min(seg[x][k*2+1],seg[x][k*2+2]);
	}
}

ll query(int a,int b, int k, int l, int r,int x){ 
	if(r<=a || b<=l) return inf;
	if(a<=l && r<=b) return seg[x][k];
	else{
		ll vl = query(a,b,k*2+1,l,(l+r)/2,x);
		ll vr = query(a,b,k*2+2,(l+r)/2,r,x);
		return min(vl,vr);
	}
}
int inv[214514];
signed main(){
	int n;
	cin>>n;
	init(n);
	vector<int> ans;
	for(int i=0;i<n;i++){
		int tmp;
		cin>>tmp;
		update( i, tmp, i%2 );
		inv[tmp] = i;
	}
	priority_queue< P > que;
	que.push( mp( -query(0,n,0,0,N,0), mp(0,n-1) ) );
	while( !que.empty() ){
		P cur = que.top();que.pop();
		int lf = cur.second.first;
		int rg = cur.second.second;
		int mi = -cur.first;
		ans.pb(mi);
		int imi = inv[mi];
		int mi2 = query(imi+1,rg+1,0,0,N,(imi+1)%2);
		ans.pb(mi2);
		int imi2 = inv[mi2];
		if( imi-1 > lf){
			que.push( mp( -query(lf,imi,0,0,N,lf%2), mp(lf,imi-1) ) );
		}
		if( imi2-1 > imi+1){
			que.push( mp( -query(imi+1,imi2,0,0,N,(imi+1)%2), mp(imi+1,imi2-1) ) );
		}
		if( rg > imi2+1){
			que.push( mp( -query(imi2+1,rg+1,0,0,N,(imi2+1)%2), mp(imi2+1,rg) ) );
		}
	}
	for(int i=0;i<ans.size();i++){
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 14112
#include <iostream>

using namespace std;

int main(void)
{
    char str[1001], ord[8];
    int i, j, q, a, b;
    cin >> str >> q;
    
    for (i = 0; i < q; i++) {
	cin >> ord >> a >> b;
	if (ord[2] == 'i') {
	    for (j = a; j <= b; j++)
		cout << str[j];
	    cout << endl;
	} else if (ord[2] == 'p') {
	    char rep[b - a + 1];
	    cin >> rep;
	    for (j = 0; j < b - a + 1; j++)
		str[a + j] = rep[j];
	} else {
	    char buf[b - a + 1];
	    for (j = 0; j < b - a + 1; j++)
		buf[j] = str[a + j];
	    for (j = b - a; j >= 0; j--)
		str[b - j] = buf[j];
	}
    }

    return 0;
}

Measured memory_bytes: 1156
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
#pragma endregion

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }

    sort(a.begin(), a.end());
    map<ll, int> mp;
    for (int i=0; i<n; i++) {
        mp[a.at(i)]++;
    }
    int res = 0;
    for (int i=n-1; i>=0; i--) {
        if (mp[a.at(i)] == 0) continue;
        mp[a.at(i)]--;
        ll tmp = 1;
        while (tmp <= a.at(i)) {
            tmp *= 2;
        }
        ll dif = tmp - a.at(i);
        if (mp[dif] > 0) {
            mp[dif]--;
            res++;
        }
    }

    cout << res << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 26880
m, k = map(int, input().split())

n = 2 ** m

if k >= n:
    print(-1)
    exit()

if m == 0:
    print('0 0')
    exit()
elif m == 1:
    if k == 0:
        print('0 0 1 1')
    else:
        print(-1)
    exit()

ans = []
for i in range(n):
    if i == k:
        continue
    ans.append(i)

ans.append(k)

for i in range(n-1, -1, -1):
    if i == k:
        continue
    ans.append(i)

ans.append(k)

print(' '.join(map(str, ans)))

Measured memory_bytes: 31640
#include <stdio.h>

typedef struct{
  int team;
  int ans[10];
  int time[10];
  int anum;
  int tnum;
}data_t;

void BubbleSort(data_t data[], int n){  
  data_t temp;

  for(int i=n; 1<i; i--){
    for(int j=0; j<i-1 ; j++){
      if(data[j].anum < data[j+1].anum){
	temp = data[j];
	data[j] = data[j+1];
	data[j+1] = temp;
      }
    }
  }

  for(int i=n; 1<i; i--){
    for(int j=0; j<i-1; j++){
      if(data[j].anum==data[j+1].anum && data[j].tnum>data[j+1].tnum){
	temp = data[j];
	data[j] = data[j+1];
	data[j+1] = temp;
      }
    }
  }

  for(int i=n; 1<i; i--){
    for(int j=0; j<i-1 ;j++){
      if(data[j].anum==data[j+1].anum && data[j].tnum==data[j+1].tnum && data[j].team<data[j+1].team){
	temp = data[j];
	data[j] = data[j+1];
	data[j+1] = temp;
      }
    }
  }
}

int main(void){
  int M, T, P, R;
  int m, t, p, j;
  data_t data[50];
  while(1){
    scanf("%d%d%d%d", &M, &T, &P, &R);
    if(M==0 && T==0 && P==0 && R==0){
      break;
    }

    for(int i=0; i<T; i++){
      data[i].team = i+1;
      data[i].anum = 0;
      data[i].tnum = 0;
      for(int j=0; j<10; j++){
	data[i].ans[j] = 1;
	data[i].time[j] = 0;
      }
    }

    for(int i=0; i<R; i++){
      scanf("%d%d%d%d", &m, &t, &p, &j);
      if(j == 0){
	data[t-1].ans[p-1] = 0;
	data[t-1].time[p-1] += m;
      }else{
	data[t-1].time[p-1] += 20;
      }
    }
    for(int i=0; i<T; i++){
      for(int j=0; j<P; j++){
	if(data[i].ans[j] == 0){
	  data[i].anum++;
	  data[i].tnum += data[i].time[j];
	}
      }
    }
    BubbleSort(data, T);

    printf("%d", data[0].team);
    for(int i=1; i<T; i++){
      if(data[i].anum==data[i-1].anum && data[i].tnum==data[i-1].tnum){
	printf("=");
      }else{
	printf(",");
      }
      printf("%d", data[i].team);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 1036
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int m, n; 
  while (cin >> m >> n, m != 0) {
    int inf = 7368791 + 1;
    vector<int> hae(inf);
    int used = 0;
    int y = m;
    for (; ; y++) {
      if (hae[y]) continue;
      if (used >= n) break;
      int b = y; used += 1;
      for (int by = b; by < inf; by += b){
        hae[by] = true;
      }
    }
    cout << y << endl;
  }
}


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

using namespace std;

bool is_prime(int x){
    if(x == 1) return false;
    if(x == 2) return true;
    for(int i=2;i*i<=x;++i)
        if(x % i == 0)
            return false;
    return true;
}

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int x;
    cin >> x;

    while(1){
        if(is_prime(x)) {
            cout << x << '\n';
            break;
        }
        x++;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define deb(x) cout << #x << " = "<< x << "\n";

signed main() {
	//freopen("in.txt", "r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int n; cin >> n;
	vector<int> a(n+1, 0);
	int ans = 0;
	for(int i = 1; i <= n; i++) {
	    cin >> a[i];
	}
	for(int i = 1; i <= n; i++) {
	    if(a[i] < a[i-1]) {
	        ans += (a[i-1] - a[i]);
	        a[i] = a[i-1];
	    }
	}
	cout << ans;
}


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

#ifndef MAX
#define MAX 400000
#endif
template<class T>
class RAQ_RMQ {
public:
	int n;
	T dat[MAX], lazy[MAX], ZERO, DEFAULT;
	bool(*cmp)(T, T);
	void init(int n_,
		bool(*c)(T, T) = [](int a, int b) {return a < b; }, T d = INT_MAX) {
		cmp = c;
		DEFAULT = d;
		ZERO = T();
		n = 1; while (n < n_)n <<= 1;
		for (int i = 0; i < 2 * n - 1; i++) {
			dat[i] = lazy[i] = ZERO;
			if (i >= n - 1 + n_)dat[i] = DEFAULT;
		}
	}
	inline void push(int k) {
		if (lazy[k] == ZERO)return;
		dat[k] = dat[k] + lazy[k];
		if (k < n - 1) {
			lazy[k * 2 + 1] = lazy[k * 2 + 1] + lazy[k];
			lazy[k * 2 + 2] = lazy[k * 2 + 2] + lazy[k];
		}
		lazy[k] = ZERO;
	}
	inline void update_node(int k) {
		if (cmp(dat[k * 2 + 1], dat[k * 2 + 2]))dat[k] = dat[k * 2 + 1];
		else dat[k] = dat[k * 2 + 2];
	}
	inline void update(int a, int b, T x, int k, int l, int r) {
		push(k);
		if (r <= a || b <= l)return;
		if (a <= l&&r <= b) {
			lazy[k] = lazy[k] + x; push(k); return;
		}
		update(a, b, x, k * 2 + 1, l, (l + r) / 2);
		update(a, b, x, k * 2 + 2, (l + r) / 2, r);
		update_node(k);
	}
	inline T query(int a, int b, int k, int l, int r) {
		push(k);
		if (r <= a || b <= l)return DEFAULT;
		if (a <= l&&r <= b)return dat[k];
		T lb = query(a, b, k * 2 + 1, l, (l + r) / 2);
		T rb = query(a, b, k * 2 + 2, (l + r) / 2, r);
		update_node(k);
		if (cmp(lb, rb))return lb;
		return rb;
	}
	inline void update(int a, int b, T x) {
		update(a, b, x, 0, 0, n);
	}
	inline void update(int a, T x) {
		update(a, a + 1, x);
	}
	inline T query(int a, int b) {
		return query(a, b, 0, 0, n);
	}
	inline T query(int a) {
		return query(a, a + 1);
	}
};
RAQ_RMQ<int>seg;
int main() {
	int n, q; scanf("%d%d", &n, &q);
	seg.init(n);
	rep(i, q) {
		int a; scanf("%d", &a);
		if (a == 0) {
			int s, t, x; scanf("%d%d%d", &s, &t, &x); s--;
			seg.update(s, t, x);
		}
		else {
			int s; scanf("%d", &s); s--;
			printf("%d\n", seg.query(s));
		}
	}
}

Measured memory_bytes: 5304
N = int(input())
A = list(map(int, input().split()))

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    return gcd(b, a%b)

ans = A[0]
for a in A:
    ans = gcd(ans, a)
print(ans)

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

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

    int ans = 0;
    for(int cut = 0; cut < (int)s.size() - 1; cut++)
    {
        vector<bool> used(26, false);
        int cnt = 0;
        for(int si = 0; si < cut + 1; si++)
        {
            if (si <= cut + 1) {
                if (used.at(s.at(si) - 'a')) continue;
                else used.at(s.at(si) - 'a') = true;
                
                for(int i = cut + 1; i < (int)s.size(); i++)
                {
                    if (s.at(si) == s.at(i)) {
                        cnt++;
                        break;
                    }
                }
                
            }
        }
        ans = max(ans, cnt);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int H, W, h, w;
int ans[510][510];
int mx = 1e9 - 1;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> H >> W >> h >> w;
    if(h == 1 && w == 1){
        cout << "No" << endl;
        return 0;
    }
    mx /= (h * w - 1);
    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            ans[i][j] = mx;
        }
    }
    for(int i = h; i <= H; i += h){
        for(int j = w; j <= W; j += w){
            ans[i][j] = -(mx * (h * w - 1) + 1);
        }
    }
    ll sum = 0;
    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            sum += ans[i][j];
        }
    }
    if(sum <= 0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
        for(int i = 1; i <= H; i++){
            for(int j = 1; j <= W; j++){
                cout << ans[i][j] << (j != W ? " " : "\n");
            }
        }
    }
    return 0;
}

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

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

    ll N, K;
    cin >> N >> K;
    cout << min(N % K, K - N % K) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<unordered_map>
using namespace std;

struct team {
	int seikai = 0, matigai[10]{}, time = 0, ID;
};
bool operator <(team a, team b) {
	if (a.seikai != b.seikai)return a.seikai > b.seikai;
	else if (a.time != b.time)return a.time < b.time;
	return a.ID > b.ID;
}
int main() {
	int a, b, c, d;
	while (cin >> a >> b >> c >> d, a || b || c || d) {
		team f[51]{};
		f[0].time = f[0].seikai= 1 << 29;
		for (int i = 0; i < b; i++) {
			f[i+1].ID = i + 1;
		}
		for (int e = 0; e < d; e++) {
			int g, h, i, j; scanf("%d%d%d%d", &g, &h, &i, &j); i--;
			if (j) {
				f[h].matigai[i]++;
			}
			else {
				f[h].seikai++;
				f[h].time += f[h].matigai[i] * 20 + g;
			}
		}
		sort(f+1, f + b+1);
		for (int i = 1; i < b; i++) {
			cout << f[i].ID;
			if (f[i].seikai == f[i + 1].seikai&&f[i].time == f[i + 1].time)cout << '=';
			else cout << ',';
		}
		cout <<f[b].ID<< endl;
	}
}

Measured memory_bytes: 3180
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;

int main() {

    int a,b;
    char c;
    cin>>a>>c>>b;
    if(c=='+'){
        cout<<a+b<<endl;
    }else{

        cout<<a-b<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#ifndef DEBUG
#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i <= i##_len; ++i)
#define rep3(i, l, r) for (int i = l, i##_len = (r); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = l, i##_len = (r); i <= i##_len; ++i)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
typedef int64_t Int;
typedef long double Ld;

using namespace std;
template <class T>
using Graph = vector<vector<T>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 62;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

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

template <typename T>
inline T Gcd(T a, T b) {
    T c;
    while (b) {
        c = b;
        b = a % b;
        a = c;
    }
    return a;
}

Int Lcm(Int a, Int b) {
    if (a < b) {
        swap(a, b);
    }

    return a / Gcd(a, b) * b;
}

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

    string S;
    cin >> S;

    bool n = false, s = false, e = false, w = false;
    for (int i = 0; i < S.size(); i++) {
        switch (S[i]) {
        case 'N':
            n = true;
            break;
        case 'S':
            s = true;
            break;
        case 'E':
            e = true;
            break;
        case 'W':
            w = true;
            break;

        default:
            break;
        }
    }

    if (n == s && e == w) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3668
#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)


int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(6);

  int INF = 1000000;

  int n;
  while(cin>>n){
    if(n==-1) break;

    double x=1.0;
    double y=0.0;
    double ang=0.0;

    REP(i,n-1){
      double len = sqrt( x*x + y*y );
      double triL = len - tan(ang);
      x = cos(ang) * triL;
      y = 1/cos(ang) + sin(ang)*triL;
      ang = atan2(y,x);
    }
      cout << x << endl;
      cout << y << endl;
  }

  return 0;
}

Measured memory_bytes: 1348
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int n, m, e[100][100], ans;
bool can[100];
vi use;

void rec(int c){
	int sc = 0;
	rep(i, use.size()){
		int mn = inf;
		rep(j, use.size()) if(i != j) mn = min(mn, e[use[i]][use[j]]);
		sc += mn;
	}
	if(use.size() > 1) ans = max(ans, sc);
	if(c == n) return;
	
	if(can[c]){
		bool can2[100];
		rep(j, n) can2[j] = can[j];
		for(int j = c + 1; j < n; j++) if(!e[c][j]) can[j] = 0;
		use.pb(c);
		rec(c + 1);
		use.pop_back();
		rep(j, n) can[j] = can2[j];
	}
	rec(c + 1);
}

int main(){
	cin >> n >> m;
	rep(i, m){
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		e[a][b] = e[b][a] = c;
	}
	memset(can, 1, sizeof(can));
	rec(0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1268
from math import gcd

def euclid(A,B):
    if B==1:
        return 1,1-A
    else:
        q,r = A//B,A%B
        x1,y1 = euclid(B,r)
        return y1,x1-q*y1

N = int(input())
ans = 2*N
for i in range(1,2*N+1):
    if i**2>(2*N):
        break
    if (2*N)%i:
        continue

    A,B = i,(2*N)//i

    if gcd(A,B)!=1:
        continue

    x0,y0 = euclid(A,B)

    limit1 = (1-y0)//A
    if limit1*A+y0<1:
        limit1+=1

    limit2 = (x0+1)//B
    if limit2*B- x0<1:
        limit2+=1

    limit = max(limit1,limit2)

    tmp = (B*limit-x0)*A
    ans = min(ans,tmp)

    A,B = (2*N)//i,i

    x0,y0 = euclid(A,B)

    limit1 = (1-y0)//A
    if limit1*A+y0<1:
        limit1+=1

    limit2 = (x0+1)//B
    if limit2*B- x0<1:
        limit2+=1

    limit = max(limit1,limit2)

    tmp = (B*limit-x0)*A
    ans = min(ans,tmp)

print(ans)

Measured memory_bytes: 71264
using System;

namespace AtCoderTest
{
    class ABC166
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            if (s == "ABC")
            {
                Console.WriteLine("ARC");
            }
            else
            {
                Console.WriteLine("ABC");
            }
        }
    }
}


Measured memory_bytes: 25728
#include<iostream>
#include<string>
#include<set>
#include<algorithm>
using namespace std;

int main()
{
  int n,i;
  string s,head,tail;
  set<string> list;
  cin>>n;
  while(n-->0){
    cin>>s;
    list.clear();
    for(i=1;i<s.size();i++){
      head=s.substr(0,i);
      tail=s.substr(i);
      list.insert(head+tail);
      list.insert(tail+head);
      reverse(head.begin(),head.end());
      list.insert(head+tail);
      list.insert(tail+head);
      reverse(tail.begin(),tail.end());
      list.insert(head+tail);
      list.insert(tail+head);
      reverse(head.begin(),head.end());
      list.insert(head+tail);
      list.insert(tail+head);
    }
    cout<<list.size()<<endl;
  }
}

Measured memory_bytes: 1000
s=list(input())
t=list(input())
import collections
s_c=collections.Counter(s)
t_c=collections.Counter(t)
s_val, s_count=zip(*s_c.most_common())
t_val, t_count=zip(*t_c.most_common())
if list(s_count)==list(t_count):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 7216
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

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

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }


int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    int ans = 0;

    bool ok = true;
    while (true) {
        rep(i, n) {
            if (a[i] % 2 != 0) {
                ok = false;
                break;
            }
            a[i] /= 2;
        }
        if (!ok) break;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

const int INF = INT_MAX / 3;
vector<vector<int>> d;

int main() {
	while(1) {
		int n, m, s, g1, g2;
		cin >> n >> m >> s >> g1 >> g2;
		if(n == 0) break;
		--s; --g1; --g2;	
		d.assign(n, vector<int>(n, INF));	
	
		int from, to, cost;
		for(int i = 0; i < m; ++i) {
			cin >> from >> to >> cost;
			--from; --to;	
			d[from][to] = cost;
		}

		for(int i = 0; i < n; ++i) d[i][i] = 0;	

		for(int k = 0; k < n; ++k)
			for(int i = 0; i < n; ++i)
				for(int j = 0; j < n; ++j) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

		int ans = INF;
		for(int c = 0; c < n; ++c) {
			if(d[s][c] == INF || d[c][g1] == INF || d[c][g2] == INF) continue;	
			int tmp = d[s][c] + d[c][g1] + d[c][g2];	
			ans = min(tmp, ans);
		}

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

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

#define MAX_N 101000

int isPrime[ MAX_N + 1 ] = { 0, 0, 1 };

int compare( const void *, const void * );

int main( void ) {
	int i, j, N, P, cnt, p[ 30 ], sum[ 465 ];

	for ( i = 3; i <= MAX_N; i += 2 )
		isPrime[ i ] = 1;

	for ( i = 3; i * i <= MAX_N; i += 2 )
		if ( isPrime[ i ] )
			for ( j = i * 2; j <= MAX_N; j += i )
				isPrime[ j ] = 0;

	for ( ; scanf( "%d %d", &N, &P ), N != -1; printf( "%d\n", sum[ P - 1 ] ) ) {
		cnt = 0;
		for ( i = N + 1; cnt < 30; i++ )
			if ( isPrime[ i ] )
				p[ cnt++ ] = i;

		cnt = 0;
		for ( i = 0; i < 30; i++ )
			for ( j = i; j < 30; j++ )
				sum[ cnt++ ] = p[ i ] + p[ j ];

		qsort( sum, 465, sizeof(int), &compare );
	}

	return 0;
}

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

Measured memory_bytes: 1036
#include <iostream>
#include <vector>
#include <algorithm>

namespace alds
{

class ALMaximumProfit
{
public:
	void Run()
	{
		Init();
		Solve();
		Output();
	}

private:
	void Init()
	{
		std::cin >> m_numPoint;
		m_rateAtTime.assign(m_numPoint, 0);
		for (auto& r: m_rateAtTime)
		{
			std::cin >> r;
		}
	}

	void Solve()
	{
		int tmpMin = m_rateAtTime[0];
		for (auto itr = m_rateAtTime.cbegin() + 1; itr != m_rateAtTime.cend(); itr++)
		{
			m_maxProfit = std::max(*itr - tmpMin, m_maxProfit);
			tmpMin = std::min(*itr, tmpMin);
		}
	}

	void Output()
	{
		std::cout << m_maxProfit << std::endl;
	}

	int m_numPoint = 0;
	std::vector<int> m_rateAtTime;
	int m_maxProfit = std::numeric_limits<int>::min();
};

}

int main()
{
	class alds::ALMaximumProfit mp;
	mp.Run();
	return 0;
}



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

static const int MAX=100;
static const long long inf=(1LL<<32);

int n;
long long d[MAX][MAX];

void floyd(){
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            if(d[i][k]==inf) continue;
            for (int j=0;j<n;j++){
                if(d[k][j]==inf) continue;
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
}
int main(){
    int e,u,v,c;
    cin>>n>>e;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            d[i][j]=((i==j) ? 0 :inf);
        }
    }for(int i=0;i<e;i++){
        cin>>u>>v>>c;
        d[u][v]=c;
    }
    floyd();
    bool negative=false;
    for(int i=0;i<n;i++){
        if (d[i][i]<0) negative=true;
    }
    if(negative){
        cout<<"NEGATIVE CYCLE"<<endl;
    }else{
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(j) cout<<" ";
                if(d[i][j]==inf) cout<<"INF";
                else cout<<d[i][j];
            }
            cout<<endl;
        }
    }
}


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

using ll = long long;
using namespace std;

int x = 1;
vector<ll> tree(1 << 20 + 1);
ll query(ll z) {
	int b  = 1 + x, c = z + x;
	ll ans = 0;
	while (b <= c) {
		if (b % 2 == 1) ans = max(tree[b++], ans);
		if (c % 2 == 0) ans  = max(tree[c--], ans);
		b /= 2;
		c /= 2;
	}
	return ans;

}
void update(ll z) {
	int b =  z / 2;
	while (b >= 1) {
		tree[b] = max(tree[2 * b], tree[2 * b + 1]);
		b /= 2;
	}
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	vector<ll> h(n + 1), v(n + 1);
	for (int i = 1; i <= n; i++) cin >> h[i];
	for (int i = 1; i <= n; i++) cin >> v[i];
	while (x < n)	 x = x << 1;
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		tree[x + h[i]] = query(h[i]) + v[i];
		ans  = max(tree[x + h[i]], ans);
		update(x + h[i]);
	}
	cout << ans << '\n';
	return 0;
}




Measured memory_bytes: 22796
H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]

hl = []
wl = []
for h in range(H):
    if sum([0 if i == "." else 1 for i in A[h]]) > 0:
        hl.append(h)

for w in range(W):
    if sum([0 if A[i][w] == "." else 1 for i in range(H)]) > 0:
        wl.append(w)

for h in hl:
    line = []
    for w in wl:
        line.append(A[h][w])
    print(*line, sep="")


Measured memory_bytes: 44760
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int D, N; cin>>D>>N;
    vector<int> t(D);
    for(int i=0; i<D; i++) cin>>t[i];
    vector<int> a(N), b(N), c(N);
    for(int i=0; i<N; i++) cin>>a[i]>>b[i]>>c[i];

    vector<vector<int>> dp(N+10, vector<int>(1010, 0));

    vector<bool> valid(110, false);
    for(int i=0; i<N; i++){
        if(a[i] <= t[0] && t[0] <= b[i]){
            valid[c[i]] = true;
        }
    }

    for(int i=1; i<D; i++){
        for(int j=0; j<N; j++){
            for(int k=0; k<=100; k++){
                //if(dp[i][k] == 0) continue;

                if(a[j] <= t[i] && t[i] <= b[j]){
                    if(i == 1){
                        if(valid[k]) dp[i+1][c[j]] = max(dp[i+1][c[j]], dp[i][k] + abs(k - c[j]));
                    }
                    else{
                        dp[i+1][c[j]] = max(dp[i+1][c[j]], dp[i][k] + abs(k - c[j]));
                    }
                }
            }
        }
    }

    /*
    for(int i=0; i<=100; i++){
        cout << i << " " << dp[2][i] << endl;
    }*/

    int ans = 0;
    for(int i=0; i<=100; i++){
        ans = max(ans, dp[D][i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 3628