akhauriyash/Code-Regression huggingface dataset:
# x はいる座標, kは移動できる回数, dが幅
x, k, d = map(int, input().split())
if(x < 0):
    x = abs(x)
# q は商、dが何個　にあるか
q = x // d
# r はあまり
r = x % d

if(k <= q):
    print(x - k*d)
if(q < k):
    k2 = k - q
    # d か -d 奇数回進める
    if(k2 % 2):
        print(min(abs(r -d), r + d))
    # d か -d 偶数回進める
    else:
        print(min(abs(r - 2*d), r ))


Measured memory_bytes: 9184
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <set>
#include <vector>
#include <map>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
main()
{
    int n;
    cin>>n;
    int b[n-1];
    rep(i,n-1)cin>>b[i];
    int ret=b[n-2]+b[0];
    for(int i=n-2;i>=0;i--)ret+=min(b[i],b[i-1]);
    cout<<ret<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <queue>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

  return 0;
}



Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] array = new int[2*N];
		for (int i=0; i<2*N; i++) array[i] = sc.nextInt();
		Arrays.sort(array);
		int sum = 0;
		for (int i=0; i<2*N; i+=2) sum += array[i];
		System.out.println(sum);
		sc.close();
	}

}

Measured memory_bytes: 9680
local mmi, mab = math.min, math.abs

local function uf_initialize(n)
  local parent = {}
  for i = 1, n do parent[i] = i end
  return parent
end

local function uf_findroot(idx, parent)
  while parent[idx] ~= idx do
    idx = parent[idx]
  end
  return idx
end

local function kruskal(n, line)
  -- line.c, line.i1, line.i2
  table.sort(line, function(a, b) return a.c < b.c end)
  local parent = uf_initialize(n)
  local totalcost = 0
  local used = 0
  local linenum = #line
  for i = 1, linenum do
    local c, i1, i2 = line[i].c, line[i].i1, line[i].i2
    local r1, r2 = uf_findroot(i1, parent), uf_findroot(i2, parent)
    parent[i1], parent[i2] = r1, r2
    if r1 ~= r2 then
      parent[r2] = r1
      parent[i2] = r1
      totalcost = totalcost + c
      used = used + 1
      if used == n - 1 then break end
    end
  end
  return totalcost
end

local n = io.read("*n")
local t = {}
for i = 1, n do
  local tbl = {}
  tbl.i, tbl.x , tbl.y = i, io.read("*n", "*n")
  t[i] = tbl
end

local line = {}

table.sort(t, function(a, b) return a.x > b.x end)
for i = 1, n - 1 do
  local tmp = {}
  tmp.c = t[i].x - t[i + 1].x
  tmp.i1, tmp.i2 = t[i].i, t[i + 1].i
  table.insert(line, tmp)
end

table.sort(t, function(a, b) return a.y > b.y end)
for i = 1, n - 1 do
  if t[i].y - t[i + 1].y < mab(t[i].x - t[i + 1].x) then
    local tmp = {}
    tmp.c = t[i].y - t[i + 1].y
    tmp.i1, tmp.i2 = t[i].i, t[i + 1].i
    table.insert(line, tmp)
  end
end

print(kruskal(n, line))


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


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

/* vector<int> A(N); 
    vector<pair<int, int> > tasks; ＃ソートした場合、１つ目でソート
　tie(b, a) = p.at(i); #pairを分割
    tasks.emplace_back(b, a)  ＃配列tasksの最後に(b,a)を追加
　xの二乗:  pow(x, 2.0) 
    小さい順: sort(v.begin(), v.end());
    大きい順: reverse(v.begin(), v.end());
    int: -2,147,483,648 ～ 2,147,483,647
    ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807
    // int型の2次元配列(3×4要素の)の宣言
    vector<vector<int>> data(3, vector<int>(4));
*/
 
int main() {
  
  int A, B, N, C, count=0, ans=0,mina=100000,minb=100000,min;
  cin >> A >> B >> N;
  vector<int> a(A); 
  vector<int> b(B); 
  vector<int> x(N); 
  vector<int> y(N); 
  vector<int> c(N); 
  rep(i,A){
  	cin >> a.at(i);
    if(mina>a.at(i)){
    	mina=a.at(i);
    }
  }
  rep(i,B){
  	cin >> b.at(i);
    if(minb>b.at(i)){
    	minb=b.at(i);
    }
  }
  min=mina+minb;
  
  rep(i,N){
  	cin >> x.at(i) >> y.at(i) >> c.at(i);
    count=a.at(x.at(i)-1)+b.at(y.at(i)-1)-c.at(i);
    if(min>count){
    	min=count;
    }
  }
  

  
  cout << min << endl;
}

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

long long sumall(long long N,int parts){//ありうる全ての和
  if(parts==1){
    return N;
  }
  long long top,other;
  top=N/pow(10,parts-1);
  other=N-top*pow(10,parts-1);
  return sumall(N,parts-1)+sumall(other,parts-1)+top*pow(2,parts-2);//これおかしい
}

int main() {
  long long S,Stest;
  int keta=0;
  cin>>S;
  Stest=S;
  while(Stest>0){
    Stest/=10;
    keta++;
  }
  //Sの桁数がわかった
  cout<<sumall(S,keta)<<endl;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main(void){
    // Your code here!
   int a, b, c;
   cin >> a >> b >> c;
   if(a == b){
       cout << c << endl;
   } else if (a == c){
       cout << b << endl;
   } else {
       cout << a << endl;
   }
}


Measured memory_bytes: 256
using System;
public class Hello{
    public static void Main(){
      var line=Console.ReadLine();
      int a=int.Parse(line.Split()[0]);
      int b=int.Parse(line.Split()[1]);
      string s=Console.ReadLine();
      bool flag=true;
      for(int i=0;i<a;i++){
        bool subflag=false;
        for(char j='0';j<='9';j++){
          if(s[i]==j)subflag=true;
        }
        if(!subflag)flag=false;
      }
      if(s[a]!='-')flag=false;
      for(int i=a+1;i<a+b+1;i++){
        bool subflag=false;
       for(char j='0';j<='9';j++){
        if(s[i]==j)subflag=true; 
       }
        if(!subflag)flag=false;
      }
      if(flag)Console.WriteLine("Yes");
      else Console.WriteLine("No");
    }
}

Measured memory_bytes: 11092
n, k = map(int, input().split())
a = list(map(int, input().split()))
l = []
for i in range(n):
    cur = 0
    for j in range(i, n):
        cur += a[j]
        l.append(cur)
for i in range(40, -1, -1):
    b = 1 << i
    l2 = []
    for j in l:
        if b & j:
            l2.append(j)
    if len(l2) >= k:
        l = l2
a = l[0]
for i in range(1, len(l)):
    a &= l[i]
print(a)

Measured memory_bytes: 37632
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

int main()
{
    vector<ll> R(5);
    vector<int> sa(5);
    vector<int> Co(5);
    int max = 0;
    ll ans = 0;
    ll FA = 10000000007;
    for (int i = 0; i < 5; i++)
    {
        cin >> R[i];
    }
    vector<int> P = {0, 1, 2, 3, 4};
    do{
        ans = 0;
        for (int i = 0; i < 5; i++)
        {
            while(ans % 10 != 0){
                ans++;
            }
            ans += R[P[i]];
        }
        FA = min(FA, ans);
    } while (next_permutation(P.begin(), P.end()));
    cout << FA << endl;
}


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

int main(){
  int n;
  while(cin>>n,n){
    int k[n];
    for(int i=0;i<n;i++)cin>>k[i];
    int ans=1;
    bool flag=false;
    for(int i=0;i<n;i++){
      if(k[i]>=2)flag=true;
      if(k[i] >= 1)ans++;
    }
    if(flag==false){
      cout << "NA" << endl;
    }else{
      cout << ans << endl;
    }

  }
  return 0;
}

Measured memory_bytes: 1196
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    string s="2019/04/30";
    string t;
    R(t);
    W(t<=s?"Heisei":"TBD");
    return 0;
}


Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
original_money=1000
money=1000
stock=0
buy_price=l[0]
for i in range(n-1):
    if buy_price<l[i]:
        money+=stock*l[i]
        stock=0
    if l[i+1]>l[i]:
        if stock==0:
            buy_price=l[i]
            stock=money//l[i]
            money-=stock*buy_price
    else:
        continue

if l[n-1]>buy_price and stock:
    money+=stock*l[n-1]

print(money)



Measured memory_bytes: 9016
A, B, C, D = map(int, input().split())

Alice = set([])
Bob = set([])

for i in range(A, B + 1):
  Alice.add(i)
for i in range(C, D + 1):
  Bob.add(i)

ans = Alice & Bob
ans = list(ans)
if len(ans) == 0:
  print(0)
  exit()
print(ans[-1] - ans[0])

Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

int main(void) {

    int N, W; cin >> N >> W;
    vector<ll> w(N), v(N); rep (i, N) cin >> w[i] >> v[i];
    vector<vector<ll> > dp(N+1, vector<ll>(W+1, 0));

    rep (i, N) {

        rep (j, W+1) {

            if (j < w[i]) dp[i+1][j] = dp[i][j];
            else dp[i+1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
        }

    }
    cout << dp[N][W] << endl;
    return 0;
}

Measured memory_bytes: 80256
n, k = map(int, input().split())
res_list = []
for i in range(k):
    di = int(input())
    a = [int(x) for x in input().split()]
    for aidi in a:
        if not aidi in res_list:
            res_list.append(aidi)

res = n
for i in range(1, n+1):
    if i in res_list:
       res -= 1
print(res)

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

int main() {
  string S;

  cin >> S;
  for(int i=0;i<S.size()-1;++i){
    char c = S.at(i);
    for(int j=i;j<S.size()-1;++j){
      if(c == S.at(j+1)){
        cout << "no" << endl;
        return 0;
      }
    }
  }
  cout << "yes" << endl;
  return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define cmdMax 10

typedef struct node *link;
struct node{
	int key;
	link left,right;
};

link insert(link head,link z){
	link y=NULL;
	link x=head;
	
	while(x!=NULL){
		y=x;
		if(z->key < x->key)x=x->left;
		else x=x->right;
	}
	
	if(y==NULL)head=z;
	else if(z->key < y->key)y->left=z;
	else y->right=z;
	return head;
}

void preorder(link u){
	if(u==NULL)return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}

void inorder(link u){
	if(u==NULL)return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}

int find(link u,int key){
	if(u==NULL)return 0;
	if(u->key==key)return 1;
	if(u->key>key)return find(u->left,key);
	return find(u->right,key);
}

int main(void){
	int m,i,key;
	char cmd[cmdMax];
	link head=NULL,z;
	scanf("%d",&m);
	for(i=0;i<m;i++){
		scanf("%s",cmd);
		if(!strcmp(cmd,"insert")){
			scanf("%d",&key);
			z = malloc(sizeof(*z));
			z->key=key;z->left=NULL;z->right=NULL;
			head=insert(head,z);
		}else if(!strcmp(cmd,"print")){
			inorder(head);
			printf("\n");
			preorder(head);
			printf("\n");
		}else if(!strcmp(cmd,"find")){
			scanf("%d",&key);
			if(find(head,key)!=0)printf("yes\n");
			else  printf("no\n");
		}
	}
	return 0;
}

Measured memory_bytes: 14240
first=int(input())

l=list()
ans=1

l.append(first)

def new_num(n):
    if n%2==0:
        return n/2
    else:
        return n*3+1

s=set(l)
new=first

while(len(l)==len(s)):
    new=new_num(new)
    l.append(new)
    s=set(l)
    ans+=1
    
print(ans)

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int SZ = 1 << 18;

template<class T>
struct segtree_max {
	vector<T> dat;

	const T inf = numeric_limits<T>::lowest();

	void init() {
		dat.resize(SZ * 2);
		rep(i, SZ * 2) dat[i] = inf;
	}

	void update(int pos, T x) {
		pos += SZ - 1;
		dat[pos] = x;

		while (pos > 0) {
			pos = (pos - 1) / 2;
			dat[pos] = max(dat[pos * 2 + 1], dat[pos * 2 + 2]);
		}
	}

	T get(int a, int b, int k = 0, int l = 0, int r = SZ) {
		if (b <= l || r <= a) return inf;
		if (a <= l && r <= b) return dat[k];
		return max(get(a, b, k * 2 + 1, l, (l + r) / 2), get(a, b, k * 2 + 2, (l + r) / 2, r));
	}
};

template<class T>
struct segtree_min {
	vector<T> dat;

	const T inf = numeric_limits<T>::max();

	void init() {
		dat.resize(SZ * 2);
		rep(i, SZ * 2) dat[i] = inf;
	}

	void update(int pos, T x) {
		pos += SZ - 1;
		dat[pos] = x;

		while (pos > 0) {
			pos = (pos - 1) / 2;
			dat[pos] = min(dat[pos * 2 + 1], dat[pos * 2 + 2]);
		}
	}

	T get(int a, int b, int k = 0, int l = 0, int r = SZ) {
		if (b <= l || r <= a) return inf;
		if (a <= l && r <= b) return dat[k];
		return min(get(a, b, k * 2 + 1, l, (l + r) / 2), get(a, b, k * 2 + 2, (l + r) / 2, r));
	}
};

int main() {
	int N, K; cin >> N >> K;
	vi p(N);

	segtree_min<int> S, D;
	segtree_max<int> T;
	S.init();
	T.init();
	D.init();

	rep(i, N) cin >> p[i];

	rep(i, N) {
		S.update(i, p[i]);
		T.update(i, p[i]);
		if (i + 1 < N) {
			D.update(i, p[i + 1] - p[i]);
		}
	}

	int ans = N - K + 1;

	bool f = 0;

	for (int l = 0; l <= N - K; ++l) {
		bool sorted = (D.get(l, l + K - 1) > 0);

		bool ng = 0;

		if (l) {
			int m = S.get(l, l + K - 1);
			int M = T.get(l, l + K - 1);

			if (M < p[l + K - 1] && m > p[l-1]) {
				ng = 1;
			}
		}

		if (sorted) {
			if (f) {
				ng = 1;
			}
			f = 1;
		}

		if (ng) {
			--ans;
		}
	}

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

Measured memory_bytes: 9216
def main():
    N = input()

    op_n = len(N)-1
    for i in range(2**op_n):
        op = ['-'] * op_n
        for j in range(op_n):
            if ((i >> j) & 1):
                op[op_n - 1 - j] = '+'
        ans = 0
        formula = N[0]+op[0]+N[1]+op[1]+N[2]+op[2]+N[3]
        ans = eval(formula)
        if ans == 7:
            print(formula+'=7')
            break


if __name__ == '__main__':
    main()


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

#define LL long long
#define Dl double
#define Pb push_back
#define Po pop_back
#define Mp make_pair
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)

using namespace std;

typedef vector<LL> Vl;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef vector<Pll> Vpl;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
#define X first
#define Y second

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s;
    cin >> s;
    
    map<char, LL> mp;
    
    for(auto i: s){
        mp[i]++;
    }
    
    for(auto i: mp){
        LL b = i.Y;
        if(b % 2)
            return cout << "No\n", 0;
    }
    
    cout << "Yes\n";
    return 0;
}


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

const int N = 2010, mod = 1e9+7;
int f[N];

int main(){
	int n;
	cin >> n;
	for(int i = 3; i <= n; i++){
		f[i] = 1;
	}
	for(int i = 4; i <= n; i++){
		for(int j = 3; j <= i-3; j++){
			f[i] = (f[i] + f[i - j]) % mod;
		}
	}	
	cout << f[n] << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

string s;
int q;
int cnt;
vector<char> vec1, vec2;

signed main() {
	cin >> s >> q;
	for (int i = 0; i < q; i++) {
		int t;
		cin >> t;
		if (t == 1)cnt++;
		else {
			int f;
			char c;
			cin >> f >> c;
			if ((f == 1 && !(cnt % 2)) || (f == 2 && (cnt % 2))){
                vec1.push_back(c);
            }
			else vec2.push_back(c);
		}
	}
	if (cnt % 2) {
		for (int i = (int)vec2.size() - 1; i >= 0; i--)cout << vec2[i];
		for (int i = (int)s.size() - 1; i >= 0; i--)cout << s[i];
		for (int i = 0; i < (int)vec1.size(); i++)cout << vec1[i];
		cout << endl;
	}
	else {
		for (int i = (int)vec1.size() - 1; i >= 0; i--)cout << vec1[i];
		cout << s;
		for (int i = 0; i < (int)vec2.size(); i++)cout << vec2[i];
		cout << endl;
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define ve vector
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or 
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 
struct point
{
    ll x,y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n;
    cin>>n;
    ve <ll> arr(n);
    ve <ll> fre(n+1);
    rep (i,0,n)
    {
        cin>>arr[i];
        fre[arr[i]]++;
    }
    ll ans=0;
    set <ll> s1;
    rep (i,0,n)
    {
        s1.insert(arr[i]);
    }
    for (auto x: s1)
    {
        if (fre[x]>1)
        {
            ans+=(fre[x]*(fre[x]-1))/2;
        }
    }
    // cout<<"ans.. "<<ans<<"\n";
    rep (i,0,n)
    {
        ll x=fre[arr[i]];
        ll ans1=ans;
        ans1-=(x*(x-1))/2;
        x--;
        ans1+=(x*(x-1))/2;
        // fre[arr[i]]--;
        // if (fre[arr[i]]>1)
        // {
        //     ll x=fre[arr[i]];
        //     ans-=(x*(x-1))/2;
        //     x-=1;
        //     ans+=(x*(x-1))/2;
        // }
        cout<<ans1<<"\n";
    }

}


Measured memory_bytes: 10624
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;string S;cin>>S;
  for(int i=0;i<S.length();i++){
    S[i]=S[i]+N;
  }
  
  for(int i=0;i<S.length();i++){
    if(S[i]>90)S[i]-=26;
  }
  
  cout<<S;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class A
{
    int Solve(List<int> L)
    {
        L.Sort();
        return Enumerable.Range(0, L.Count / 2).Sum(i => L[2 * i]);
    }

    static void Main() 
    {
        Console.ReadLine();
        Console.WriteLine(new A().Solve(Console.ReadLine().Split(' ').Select(int.Parse).ToList()));
    }
}

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

using namespace std;
using ull = unsigned long long;
using ll = long long;
using lli = long long int;
using ld = long double;
using pa = pair<int,int>;
using ppa = pair<pa,int>;
#define SORT(v, n) sort(v, v+n);
#define ALL(v) v.begin(),v.end()
#define VSORT(v) sort(ALL(v))
#define GRESORT(v) sort(ALL(v),greater<ll>())
#define REVERSE(v) reverse(ALL(v))
#define overlap(v) v.erase(unique(ALL(v)),v.end())
#define debug(x) cout << #x << ": " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i = (b-1); i >= a; i--)
#define rrep(i,n) RFOR(i,0,n)
#define INF INT_MAX
#define SUP INT_MIN
#define mins(a,b) a = min(a,b)
#define maxs(a,b) a = max(a,b)

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

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

const ll MOD = 1000000007;

ll pow_mod(ll a,ll b,ll mod){
    ll tmp = 1;
    a %= mod;
    if(b > 0){
        tmp = pow_mod(a, b/2, mod);
        if(b % 2) tmp = (((tmp*tmp)%mod)*a)%mod;
        else tmp = (tmp*tmp)%mod;
    }
    return tmp;
}

void solve() {
    int n,k,x,y; cin >> n >> k >> x >> y;
    if(n > k) cout << k * x + (n-k) * y << endl;
    else cout << n * x << endl;
}

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

    solve();

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
//#include <array>

int main()
{
    int y, m, d;
    scanf("%d/%d/%d", &y, &m, &d);
    if (m >= 5) {
        printf("TBD\n");
    } else {
        printf("Heisei\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define pb push_back

using namespace std;

const int N=1e5+5;

ll n,a[N],x,y,q,ans;

map<ll,ll>mp;

int main()
{
    cin >> n;
    for (int i=0;i<n;i++)
    {
        cin >> a[i];
        ans+=a[i];
        mp[a[i]]++;
    }
    cin >> q;
    while(q--)
    {
        cin >> x >> y;
        ans-=x*mp[x];
        ans+=y*mp[x];
        mp[y]+=mp[x];
        mp.erase(x);
        cout << ans << endl;
    }
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> b(n-1);
    for(int i = 0; i < n-1; i++) cin >> b[i];
    int ans = b[0] + b[n-2];
    for(int i = 1; i < n-1; i++){
        ans += min(b[i-1], b[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

int main()
{
    int N;
    cin >> N;
    vll A(N),B(N);
    cin >> A >> B;
    vll H;
    int L = 0;
    ll Lcnt = 0;
    REP(i,N){
        if(A[i] >= B[i]){
            H.pb(A[i]-B[i]);
        }else{
            Lcnt += B[i]-A[i];
            L++;
        }
    }
    
    sort(H.begin(),H.end(),greater<ll>());
    int ans = 0;
    if(H.size() != N){
        ll cnt = 0;
        bool flag = false;
        REP(i,H.size()){
            cnt += H[i];
            ans++;
            if(cnt >= Lcnt){
                ans += L;
                flag = true;
                break;
            }
        }
        if(!flag)ans = -1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5772
open Batteries

let input_ints ()  =
  read_line()
  |> String.split_on_char ' '
  |> List.map int_of_string

let main ()=
  let l = input_ints () in
  let a = List.nth l 0 in
  let b = List.nth l 1 in
  let c = List.nth l 2 in
  let d = List.nth l 3 in
  if (abs (a-b) <= d && abs (b-c) <= d) || abs (a - c) <= d then
    print_string "Yes\n"
  else
    print_string "No\n"

let () = main ()


Measured memory_bytes: 4992
N = int(input())
li = list(map(int, input().split()))

omori = 0
mini = 100000000000

for i in range(N):
    omori += li.pop(0)
    if 0 <= omori - sum(li) < mini:
        mini = omori - sum(li)
    if 0 <= sum(li) - omori < mini:
        mini = sum(li) - omori

print(mini)


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


#define pb push_back
#define popb pop_back
#define mt make_tuple 
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define piii pair<int,pii>
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repc(i,a,n) for(int i=a;i<n;++i)
#define  repd(i,a,n) for(int i=a;i>n;--i)
#define int ll
using namespace std;
using ll = long long;
const ll N = 3*1e5 +5 ;
const ll mod = 1e9+7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
const double pi=3.14159265358979323846 ;
typedef vector<ll> vi;


void solve(){
	int n,a;
	cin>>n;
	vi v(n+1,0);
	rep(i,n-1){
		cin>>a;
		v[a]++;
	}
	repc(i,1,n){
		cout<<v[i]<<" ";
	}
	cout<<0;
	return;
}	
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	solve(); 
	return  0;
}





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

using ll=long long;

int main() {
  int N; cin >>N;
  vector<int> a(N);
  rep(i,1,N) {
    int b; cin >>b;
    a[b-1]++;
  }
  rep(i,0,N) {
    cout <<a[i] <<endl;
  }
  return 0;
}


Measured memory_bytes: 4060
#include<iostream>
#include<cstdio>
#include<cmath>
#include<map>
#include<cstring>
using namespace std;
map<char,int>vis;
int main()
{
    char str[27];
    cin>>str;
    int cnt=0;
    vis.clear();
    for(int i=0;i<strlen(str);i++)
    {
        if(!vis[str[i]])
        {
            ++cnt;
            vis[str[i]]=1;
        }
    }
    if(cnt==strlen(str)) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n,m = myinput()
ab = mylistinput(m)

ab = mysort(ab,1,False)
# print(ab)

e = 0

count = 0
for i in range(m):
    a = ab[i][0]
    b = ab[i][1]
    if e <= a:
        count += 1
        e = b
print(count)

Measured memory_bytes: 64600
//set many funcs
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define inf 1145141919
#define llinf 1145141919810364364
#define mod 1000000007
 
int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
 
int main(void){
    long long q,h,s,d,n;
    scanf("%lld%lld%lld%lld%lld",&q,&h,&s,&d,&n);
    if(q*8<d){d=q*8;}
    if(h*4<d){d=h*4;}
    if(s*2<d){d=s*2;}
    if(q*4<s){s=q*4;}
    if(h*2<s){s=h*2;}
    printf("%lld\n",d*(n/2)+s*(n%2));
    return 0;
}

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

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

typedef long long ll;

using namespace std;

const ll MOD=1000000007;

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

	vector<int> C; // C := { floor(N/i) | i=1,2,...,N }
	for(int i=1;i*i<=n;i++){
		C.emplace_back(i);
		C.emplace_back(n/i);
	}
	sort(C.begin(),C.end());
	C.erase(unique(C.begin(),C.end()),C.end());
	int m=C.size();

/*
	// O(k*m^2) DP
	// dp[i][j] := ( i 個の数の並べ方で, 最後の数が (C[j-1], C[j]] に含まれるものの個数 )
	vector<vector<int>> dp(k+1,vector<int>(m));
	dp[0][0]=1;
	rep(i,k) rep(j,m) {
		ll h=C[j]-(j>0?C[j-1]:0);
		rep(l,m-j){
			dp[i+1][j]=(dp[i+1][j]+dp[i][l]*h)%MOD;
		}
	}

	ll ans=0;
	rep(j,m) ans=(ans+dp[k][j])%MOD;
	cout<<ans<<endl;
*/

	// O(k*m) DP
	// dp[i][j] := ( i 個の数の並べ方で, 最後の数が (0, C[j]] に含まれるものの個数 )
	vector<vector<int>> dp(k+1,vector<int>(m));
	rep(j,m) dp[0][j]=1;
	rep(i,k){
		dp[i+1][0]=dp[i][m-1];
		for(int j=1;j<m;j++){
			dp[i+1][j]=(dp[i+1][j-1]+1LL*dp[i][m-j-1]*(C[j]-C[j-1]))%MOD;
		}
	}

	cout<<dp[k][m-1]<<endl;

	return 0;
}


Measured memory_bytes: 25852
S = input()
L = len(S)
if(S[::-1]==S and S[:(L-1)//2:]==S[(L-1)//2-1::-1] and S[L-1:(L+3)//2-2:-1]==S[(L+3)//2-1::]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38516
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){
string s;
cin >> s;
REP(i,s.size()){
if(s[i] == ',') cout << " ";
else cout << s[i];
}
cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define wzh(x) cerr<<#x<<' '<<x<<endl
int t,n;
struct uzi{
  int k,l;
  bool operator < (const uzi & t)const{
    return k<t.k;
  }
}L[N],R[N];
int dx,dy;
int main() {
  ios::sync_with_stdio(false);
  for(cin>>t;t;t--){
    cin>>n;LL ans=0;dx=dy=0;
    for(int i=1;i<=n;i++){
      int k,l,r;
      cin>>k>>l>>r;
      if(l>r){
        ans+=r;
        L[++dx]={k,-l+r};
      }else if(l<r){
        ans+=l;
        R[++dy]={k,-r+l};
      }else ans+=l;
    }
    sort(L+1,L+1+dx);
    sort(R+1,R+1+dy);
    int x=1;
    priority_queue<int>q;
    for(int i=1;i<=n;i++){
      while(x<=dx&&L[x].k==i)q.push(L[x].l),x++;
      while(q.size()>i)q.pop();
    }
    while(!q.empty())ans-=q.top(),q.pop();
    x=dy;
    for(int i=n;i>=1;i--){
      while(x>=1&&R[x].k==i)q.push(R[x].l),x--;
      while(q.size()>n-i)q.pop();
    }
    while(!q.empty())ans-=q.top(),q.pop();    
    cout<<ans<<'\n';
  }
  return 0;
}

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

int main() {
    int n, a[100], ans=10000000, tmp;
    cin >> n;
    for(int i=1; i<=n; i++) cin >> a[i];

    for(int i=1; i<=100; i++) {
        tmp=0;
        for(int j=1; j<=n; j++) {
            tmp += (i-a[j])*(i-a[j]);
        }
        ans=min(ans, tmp);
    }
    cout << ans;
}

Measured memory_bytes: 256
module Main where

import           Control.Monad
import           Data.List

readInt :: String -> Int
readInt = read

main :: IO()
main = do
  [n,m,x,y] <- map readInt . words <$> getLine
  xs <- map readInt . words <$> getLine
  ys <- map readInt . words <$> getLine
  if solve x y xs ys
    then putStrLn "No War"
    else putStrLn "War"

solve :: Int -> Int -> [Int] -> [Int] -> Bool
solve x y xs ys =
  let
    overXtoY = [x+1..y]
    maxXs = maximum xs
    minYs = minimum ys
  in
    any (\z -> z > maxXs && z <= minYs) overXtoY


Measured memory_bytes: 1020
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
s = gets.chomp

ans = 0
tmp = 0
s.size.times do |i|
  if "ACGT".split(//).include? s[i]
    tmp += 1
  else
    tmp = 0
  end

  ans = tmp if ans < tmp
end
puts ans


Measured memory_bytes: 2172
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int main() {
  int n;
  while(cin>>n,n) {
    int I[n];
    REP(i,n) cin>>I[i];
    int s,a,c;
    double minH = INF;
    REP(S,16) REP(A,16) REP(C,16) {
      int R[n+1];
      R[0] = S;
      REP(i,n) R[i+1] = (A*R[i]+C) % 256;
      int num[256] = {};
      REP(i,n) num[(I[i]+R[i+1]) % 256]++;
      double H = 0;
      REP(i,256) {
        if (num[i]) {
          H -= (double)num[i]/n*log((double)num[i]/n);
        }
      }
      //cout << H << " " << S << " " << A << " " << C << endl;
      if (minH-EPS > H) {
        minH = H;
        s=S;a=A;c=C;
      }
    }
    cout << s << " " << a << " " << c << endl;
  }
}

Measured memory_bytes: 884
n=int(input())
S=[]
T=[]
U=""
for i in range(1,n+1):
    S.append(input())
for i in range(97,123):
    T.append(min(S[j].count(chr(i)) for j in range(len(S))))
for k in range(len(T)):
    U+=chr(k+97)*T[k]
print(U)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

// 1 << 3 : int "3" change to bit "100"
// rep(pattern, 1 << N) if (pattern & (1 << x)) cnt++

int main(){
    int n;
    vector<int> p;
    cin >> n;
    rep(i,n){
        int tmp;
        cin >> tmp;
        p.push_back(tmp);
    }

    int cnt = 0;
    rep(i,n-2){
        if(p[i] < p[i+1] && p[i+1] < p[i+2]){cnt++;}
        else if(p[i+2] < p[i+1] && p[i+1] < p[i]){cnt++;}
    }
    cout << cnt;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

typedef unsigned long long UL;
typedef long long LL;
typedef long double LD;
#define LP(i, a, b) for (LL i = int(a); i < int(b); i++)
#define LPE(i, a, b) for (LL i = int(a); i <= int(b); i++)
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<vector<PII> > WAL;
typedef vector<vector<int> > SAL;
#define Ep 1e-8
#define INF 1e9
#define LINF 1e18

LL const MOD = 1e9 + 7;
LL const MaxSize = 1e5 + 5;
//LL const MOD = 998244353;

/*

 https://atcoder.jp/contests/abc110/tasks/abc110_c
 #C - String Transformation
 */

//NOTE WORKS ONLY WHEN MOD IS PRIME
//test case, either = 1 or all = 1

//NOTE WORKS ONLY WHEN MOD IS PRIME
LL f[MaxSize], invF[MaxSize], r[MaxSize];

void preCalc() {
        r[1] = 1;
        f[1] = 1;
        invF[1] = 1;
        LL m = MOD;

        for (LL i = 2; i < MaxSize; ++i) {
                r[i] = (m - (m / i) * r[m % i] % m) % m;

                f[i] = (i * f[i - 1]) % MOD;
                invF[i] = (r[i] * invF[i - 1]) % MOD;
        }
}

LL choose(LL top, LL bottom) {
        if (top < bottom || top < 0 || bottom < 0)
                return 0;
        if (top == bottom || bottom == 0)
                return 1;

        LL bfs = (invF[bottom] * invF[top - bottom]) % MOD;

        //      cout << "ftop:" << top << " " << f[top] << endl;

        return (f[top] * bfs) % MOD;
}

LL N, K, A[MaxSize];

int main() {
	ios_base::sync_with_stdio(false);
	//freopen("/Users/georgeli/A_1.in", "r", stdin);
	cin >> N >> K;
	LP(i, 0, N)
		cin >> A[i];

	sort(A, A + N);

	preCalc();
	LL ans = 0;
	LP(i, K - 1, N){
		LL ps = A[i] * choose(i, K - 1);
		ans += ps;
		ans %= MOD;
	//	cout << i << " " << ps << endl;
	}

	LPE(i, 0, N - K + 1){
		ans -= A[i] * choose(N - i - 1, K - 1);
		if (ans < 0)
			ans += MOD;
		ans %= MOD;
	}

	cout << ans;




	return 0;
}


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

int main() {
  int n,j,i,k;
  cin>>n>>k;
  int h[n],dp[n]={};
  for(i=0;i<n;i++)
    cin>>h[i];
  for(i=0;i<n-1;i++){
    dp[i+1]=dp[i]+abs(h[i+1]-h[i]);
    for(j=1;j<k;j++){
      if(i-j>=0){
        dp[i+1]=min(dp[i+1] , dp[i-j]+abs(h[i+1]-h[i-j]));
      }
    }
  }
  cout << dp[n-1];
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using testimony = vector<pair<int, int>>;

int main() {
    int n; cin >> n;
    vector<testimony> ts(n);
    for (int i=0; i<n; ++i) {
        int a; cin >> a;
        for (int j=0; j<a; ++j) {
            int x, y;
            cin >> x >> y;
            x--;
            ts[i].push_back(make_pair(x, y));
        }
    }
    //cout << endl;
    int ans = 0;
    for (int bit = 1; bit < (1 << n); ++bit) {
        bool can = true;
        int cnt = 0;
        vector<int> people(n, -1); // honest = 1, unkind = 0
        //cout << bit << endl;
        for (int i=0; i<n; ++i) {
            if (bit & (1 << i)) {
                cnt++;
                people[i] = 1;
            }
            else people[i] = 0;
        }
        for (int i=0; i<n; ++i) {
            if (!(bit & (1 << i))) continue;
            people[i] = 1;
            for (auto p: ts[i]) {
                if (p.second) {
                    if (people[p.first] == 0) {
                        can = false;
                        //cout << "break" << endl;
                        break;
                    }
                    else people[p.first] = 1;
                }
                else {
                    if (people[p.first] == 1) {
                        can = false;
                        //cout << "break" << endl;
                        break;
                    }
                    else people[p.first] = 0;
                }
            }
            if (!can) break;
        }
        /*if (can) {
            for (int i: people) cout << i << " ";
            cout << endl;
            cout << cnt << endl;
        }
        cout << endl;*/
        if (can) ans = max(ans, cnt);
    }
    cout << ans << endl;
}

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

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

  int64_t l1=2, l2=1;

  rep(i, N)
  {
    l1 += l2;
    swap(l1, l2);
  }

  cout << l1;

}


Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long r = 0;
		for(int i=1;i<=n;i++) {
			if (i % 3 != 0 && i % 5 != 0) r += i;
		}
		
		System.out.println(r);
	}
}


Measured memory_bytes: 35772
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N, X, Y;
  cin >> N >> X >> Y;
  
  vector <int> data(N);
  
  for(int i = 1; i <= N-1; i++){
    for(int j = i+1; j <= N; j++){
      int a = j-i;
      int b = abs(X-i) + 1 + abs(j-Y);
      int c = min(a,b);
      
      data.at(c-1) += 1;
    }
  }
  
  for(int i = 0; i < N-1; i++){
    cout << data.at(i) << endl;
  }
}

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

b = 0
idx = 0
L = sum(A)
while (b<L/2):
    b += A[idx]
    idx += 1
a = b - A[max(0,idx-1)]
ans = min(L-2*a,2*b-L)
print(ans)


Measured memory_bytes: 89296
#include<stdio.h>
int main(void){
char word[1200];
	int i=0;
	fgets(word,1200,stdin);
	while(word[i]!='\0'&&word[i]!='\n'){
		if(word[i]>='A'&&word[i]<='Z'){
			word[i]+=0x20;
		}else if(word[i]>='a'&&word[i]<='z'){
			word[i]-=0x20;
		}
		i++;
	}
	for(i=0;word[i]!='\0';i++){
		printf("%c",word[i]);
	}
	return 0;
}

Measured memory_bytes: 2628
// Crt. 2020-01-10  07:44:23
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define N 200005
using namespace std;

int n, fa[N], cir[N], top, inc[N], sg[N], vis[N], now[N];
int tot, fir[N], nxt[N], to[N];

inline void addE(int u, int v) {
    nxt[++tot] = fir[u], fir[u] = tot, to[tot] = v;
}

void getcir() {
    int x = 1;
    while (!inc[x]) inc[x] = 1, x = fa[x];
    memset(inc, 0, sizeof inc);
    while (!inc[x]) cir[++top] = x, inc[x] = 1, x = fa[x];
}

void dfs(int u, int p) {
    for (int i = fir[u], v; i; i = nxt[i]) {
        v = to[i];
        if (inc[v] || p == v) continue;
        dfs(v, u);
    }
    for (int i = fir[u]; i; i = nxt[i])
        if (!inc[to[i]] && p != to[i]) vis[sg[to[i]]] = 1;
    while (vis[sg[u]]) ++sg[u];
    for (int i = fir[u]; i; i = nxt[i])
        if (!inc[to[i]] && p != to[i]) vis[sg[to[i]]] = 0;
}

int main(){
#ifdef LOCAL_JUDGE
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> n;
    for (int i = 1; i <= n; ++i)
        scanf("%d", fa + i), addE(fa[i], i);

    getcir();
    
    for (int i = 1; i <= top; ++i) dfs(cir[i], 0);

    for (int k = 0; k < 2; ++k) {
        int u; now[u = cir[1]] = sg[cir[1]] + k;

        while (fa[u] != cir[1]) {
            if (sg[fa[u]] == now[u]) now[fa[u]] = sg[fa[u]] + 1;
            else now[fa[u]] = sg[fa[u]];
            u = fa[u];
        }

        if (k == 0 && now[u] != now[fa[u]]) return puts("POSSIBLE"), 0;
        if (k == 1 && now[u] + 1 == now[fa[u]]) return puts("POSSIBLE"), 0;
    }

    puts("IMPOSSIBLE");

    return 0;
}


Measured memory_bytes: 7168
import copy
H,W,K = map(int,input().split())
c=[] #appendのために宣言が必要
while True:
    try:
        c.append(list(map(str,input())))

    except:
        break;
ans=0
patterns=[]
for i in range(2**(H+W)):
  tmp = [False] * (H+W)
  for j in range(H+W):
    if i >> j & 1:
      tmp[j] = True
  patterns.append(tmp)
  
for pattern in patterns:
  c_tmp=copy.deepcopy(c)
  counter=0
  #print("------------------")
  #print("pattern",pattern)
  for tf in pattern:
    if tf==True:
      if counter<H:#行
        for i in range(W):
          c_tmp[counter][i]="R"
      if counter>=H:#列
        #print(counter)
        for i in range(H):
          c_tmp[i][counter-H]="R"     
    counter+=1
  #print("c_tmp",c_tmp)
      
  num=0
  for row in c_tmp:
    num+=row.count("#")
  #print("num",num)
  #print("ans",ans)
  if num==K:
    ans+=1
    
print(ans)

Measured memory_bytes: 73312