akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
const long long llINF = 9223372036854775807;
const int INF = 2147483647;
const int maxn = 2e5 + 7;
const int maxm = 1e6 + 7;
const int ALP = 26;
const long long mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-8;

int H,W;
char pic[40][40];
queue<pair<int,int> > Q;

int dis[23][23];

int ans;

bool can_go(int x,int y)
{
	return x>=1 && x<=H && y>=1 && y<=W && pic[x][y]=='.' && dis[x][y] == -1;
}

int solve(int sx,int sy)
{
	memset(dis,-1,sizeof(dis));
	Q.push(make_pair(sx,sy));
	dis[sx][sy]=0;

	while(!Q.empty())
	{
		pair<int,int> tmp=Q.front();
		Q.pop();
		if(can_go(tmp.first+1,tmp.second))
		{
			dis[tmp.first+1][tmp.second]=dis[tmp.first][tmp.second]+1;
			Q.push(make_pair(tmp.first+1,tmp.second));
		}
		if(can_go(tmp.first-1,tmp.second))
		{
			dis[tmp.first-1][tmp.second]=dis[tmp.first][tmp.second]+1;
			Q.push(make_pair(tmp.first-1,tmp.second));
		}
		if(can_go(tmp.first,tmp.second-1))
		{
			dis[tmp.first][tmp.second-1]=dis[tmp.first][tmp.second]+1;
			Q.push(make_pair(tmp.first,tmp.second-1));
		}
		if(can_go(tmp.first,tmp.second+1))
		{
			dis[tmp.first][tmp.second+1]=dis[tmp.first][tmp.second]+1;
			Q.push(make_pair(tmp.first,tmp.second+1));
		}
	}
}

void check()
{
	for(int i=1;i<=H;i++)
		for(int j=1;j<=W;j++)
			ans=max(ans,dis[i][j]);
}

int main()
{
	//freopen("1.in","r",stdin);
	scanf("%d%d",&H,&W);
	for(int i=1;i<=H;i++)
		scanf("%s",pic[i]+1);

	for(int sx=1;sx<=H;sx++)
	{
		for(int sy=1;sy<=W;sy++)
		{
			if(pic[sx][sy]=='.')
				solve(sx,sy);
			check();
		}
	}
	
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
from bisect import bisect_left, bisect_right

Q=int(input())
llr=[]
maxr=1
for i in range(Q):
    l,r=map(int,input().split())
    if r>maxr:
        maxr=r
    llr.append([l,r])
def isprime(n):
    if n==1:
        return 0
    m=int(n**(1/2))
    for i in range(2,m+1):
        if n%i==0:
            return 0
            break
    return 1
l2017=[]
for i in range(1,maxr+1,2):
    if isprime(i) and isprime((i+1)/2):
        l2017.append(i)
for i in range(Q):
    il=bisect_left(l2017,llr[i][0])
    ir=bisect_right(l2017,llr[i][1])
    print(ir-il)

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

ll P[52], S[52];
int main(){
  ll n, k; cin >> n >> k;
  P[0] = S[0] = 1;
  for(ll i = 1; i <= n; i++){
    P[i] = 2*P[i-1] + 1;
    S[i] = 2*S[i-1] + 3;
  }
  ll ans = 0, cnt = n, num = k;
  while(num){
    if(num*2 > S[cnt]){
      if(cnt >= 1) ans += P[cnt-1];
      ans++;
      if(cnt >= 1) num -= S[cnt-1] + 2;
      else break;
    }
    else{
      num--;
    }
    cnt--;
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1) 

const ll INF = 10010001010;
const int inf = 2000000000;


typedef tuple<string, int, int> TUP;

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

int main()
{
    int X1, Y1, X2, Y2;
    cin >> X1 >> Y1 >> X2 >> Y2;
    int height = abs(Y2 - Y1);
    cout << X2 - Y2 + Y1 << " " << Y2 + X2 - X1 << " " << X1 - Y2 + Y1 << " " << Y1 + X2 - X1 << endl;
}


Measured memory_bytes: 256
S = input()
K = int(input())

A = [" " for _ in range(len(S))]

zan = K
for i in range(len(S)):
  n = (ord('z') - ord(S[i]) + 1) % 26 # aに変換するのに必要な回数
  if zan >= n:
    zan -= n
    A[i] = 'a'
  else:
    A[i] = S[i]

if zan > 0:
  A[-1] = chr((ord(A[-1]) - ord('a') + zan)%26 + ord('a'))
print("".join(A))

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

int main() {
  string S;
  cin >> S;
  
  int size = S.length();
  int hug=0;
  
    for(int i=0;i<(size/2);i++){
      if(S[i] != S[size-i-1]) hug++;
    }

  
  cout << hug << endl;
}


Measured memory_bytes: 384
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int x[] = new int[N];
    int y[] = new int[N];
    for(int i = 0; i < N; ++i){
      x[i] = sc.nextInt();
      y[i] = sc.nextInt();
    }
    double sum = 0;
    for(int i = 0 ; i < N; ++i){
      for(int j = i+1 ; j < N; ++j){
        int xx= x[i]-x[j];
        int yy= y[i]-y[j];
        int r= xx*xx + yy*yy;
        sum += Math.sqrt(r);
      }
    }
    System.out.println(sum * 2/N);
  }
}

Measured memory_bytes: 36012
#include<iostream>
#include<string>

int main(){
  std::string s;
  std::cin >> s;
  int n = s.size(), a, z;
  for(int i = 0; i < n; i++){
    if(s[i] == 'A'){
      a = i;
    break;
    }
  }
  for(int i = n - 1; i > -1 ; i--)
    if(s[i] == 'Z'){
      z = i;
      break;
    }
  std::cout << z - a + 1 << std::endl;
  return 0;
}

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

int main(){
int N, w = 0;  
string S;
 cin >> N >> S;
int E[N] = {};  
  
int e = 0;  
  
  for(int i = 0;i < N;i++){
  if(S.at(i) == 'E'){
   e++;
  }
  else {
  w++;
  }
    
  E[i] = e;  
  }
  
int mi;

  if(S.at(0) == 'E') mi = e - 1;
  else mi = e;
  
  for(int i = 1;i < N;i++){
    mi = min(mi, i - E[i - 1] + e - E[i]);   
  }

 cout << mi << endl;
  return 0;
  
}

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

#define ll long long
#define ld long double
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n,m;
    cin >> n >> m;
    cout << n*n - m << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>  
#include <algorithm>  
using namespace std;  
  
void print_A(int A[],int n){  
    for (int i = 0 ;i<n;i++) {  
        if (i!=n-1 )printf("%d ",A[i]);  
        else printf("%d",A[i]);  
    }  
    printf("\n");  
    return ;  
}  
  
int selectionsort(int A[],int n ){  
    int count = 0;  
    for(int i =0;i<n-1;i++){  
        int y=i;  
        for(int j=i;j<n;j++) if(A[j]<A[y]) y=j;  
        if(A[y]<A[i]) {  
            swap(A[i],A[y]);  
            count++;  
        }  
    }  
    return count;  
}  
  
int main (){  
    int n,A[110];  
    scanf("%d",&n);  
    for(int i=0;i<n;i++) scanf("%d",&A[i]);  
    int a=selectionsort(A,n);  
    print_A(A,n);  
    printf("%d\n",a);  
    return 0;  
}  



Measured memory_bytes: 2696
class UnionFind():
    def __init__(self, n=0):
        self.d = [-1]*n
    
    def find(self, x):
        if self.d[x] < 0: return x
        self.d[x] = self.find(self.d[x])
        return self.d[x]

    def unite(self, x, y):
        x,y=self.find(x),self.find(y)
        if x==y:return False
        if self.d[x] > self.d[y]: x,y=y,x
        self.d[x] += self.d[y]
        self.d[y] = x
        return True

    def same(self, x,y): return self.find(x)==self.find(y)
    def size(self,x): return -self.d[self.find(x)]
    
N,M=map(int,input().split())
uf = UnionFind(N+1)
for i in range(M):
  a,b=map(int,input().split())
  uf.unite(a,b)
  
print(-min(uf.d))

Measured memory_bytes: 14616
#include <stdio.h>

int main(void){
        int n, i, a, p;
        scanf("%d", &n);
        a = n/100;
        p = a + a*10 + a*100;
        if(p < n)       printf("%d\n", a+1 + (a+1)*10 + (a+1)*100);
        else            printf("%d\n", p);
        return 0;
}

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

int main(){

    int N;
    char s[4];

    scanf("%d",&N);
    s[3] = '\0';
    sprintf(s,"%d", N);

    int judge = 0;
    int i;

    for(i = 0; i < 3; i++){
        if(s[i] == '7'){
            judge = 1;
        }
    }

    if(judge == 0){
        printf("No");
    }else{
        printf("Yes");
    }
}

Measured memory_bytes: 1736
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int K;

//最小公倍数、最大公約数
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}

int lcm(int a,int b){
	return a/gcd(a,b)*b;
}

signed main(){
	cin>>N>>K;
	cout<<min(N%K,K-N%K)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
int A, B;
string S;

int main(void){
	//IO("test.in", "test.out");
	cin >> A >> B >> S;
	if(S.length() != A + B + 1) printf("Yes\n");
	else{
		bool v = true;
		for(int i = 0; i < S.length(); i++)
			if((i == A && S[i] != '-') || (i != A && (S[i] - '0' < 0 || S[i] - '0' > 9))) v = false;
		if(v) printf("Yes\n");
		else printf("No\n");
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fo(i, a, b)     for (int i=a; i<(b); i++)
#define forev(i, b, a)     for (int i = (b)-1; i >= a; i--)
typedef long long int    lli;
typedef long double        ld;
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define enl    "\n"
#define fast    ios_base::sync_with_stdio(0); cin.tie(0);
// #define PI 3.1415926535897932384626
// const int MOD = 1000000007; // const ll INF = 1e18; // const int MX = 100001;
//==================================================================================

int main() {
    fast;
    // int t; cin >> t; while (t--)
    int n, k; cin >> n >> k;
    int p[n];
    fo(i, 0, n) cin >> p[i];

    sort(p, p + n);
    int ans = 0;

    fo(i, 0, k) ans += p[i];

    cout << ans;


    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;

typedef struct {
	int b, c;
}Card;

bool compare(Card c1, Card c2) {
	return c1.c < c2.c;
}

int main()
{
	int n, m;
	priority_queue<int, vector<int>, greater<int>> A;
	vector<Card> card;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		A.push(tmp);
	}
	for (int i = 0; i < m; i++) {
		int b, c;
		cin >> b >> c;
		card.push_back({ b,c });
	}

	sort(card.begin(), card.end(),compare);
	long long sum = 0;
	for (int i = m-1; i >= 0; i--) {
		while(card[i].b--) {
			int tmp = A.top();
			if (tmp < card[i].c) {
				A.pop();
				A.push(card[i].c);
			}
			else {
				break;
			}
		}
	}
	while (!A.empty()) {
		sum += A.top();
		A.pop();
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1784
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int x = sc.nextInt();
        
        int sum = 0;
        int cnt = 0;
        
        while(true) {
            cnt++;
            sum += Math.max(h,w);
            if (sum >= x) {
                break;
            }
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
//One implementation to rule them all?
#define db 				double
#define ll 				long long int
//#define ld				long long double
//#define int 			long long int
#define ull 			unsigned long long
#define fi 				first
#define se 				second
#define rep(i,a,n)      for(int i=a;i<n;i++)
#define repr(i,n,b)     for(int i=n;i>=b;i--)
#define endl 			'\n'
#define mem(a,b) 		memset(a, b, sizeof a)
#define mkp 			make_pair
#define pb 				push_back
#define max3(a,b,c) 	max(a,max(b,c))
#define min3(a,b,c) 	min(a,min(b,c))
#define w(t)            int t; cin>>t; while(t--)
#define all(a)			a.begin(), a.end()
#define sz(a)           int((a).size())
#define tr(container, it) \
for(auto it = container.begin(); it != container.end(); it++)
using namespace std;
typedef vector < int > vii;
typedef vector < ll > vll;
typedef vector < vii > vvi;
typedef pair < int,int > pii;
const db PI = atan2(0.0, -1.0);
const int INF = 0x3f3f3f3f;
const ll LINF = (ll)2e18;
db eps       =			0.000001;
ll mod       =			(1e9+7);   //998244353
void print(vector <int> &arr){
    for(int i=0;i<arr.size();i++)
        cout<<arr[i]<<" ";
    
    cout<<endl;
}
void printll(vector <ll> &arr){
    for(int i=0;i<arr.size();i++)
        cout<<arr[i]<<" ";
    
    cout<<endl;
}

ll ncr(ll n, ll r)
{
    r=min(r,n-r);
    ll A[r],i,j,B[r];
    iota(A,A+r,n-r+1);  
    iota(B,B+r,1);     

    ll g;
    for(i=0;i<r;i++)
    for(j=0;j<r;j++)
    {
        if(B[i]==1)
            break;
        g=__gcd(B[i], A[j] );
        A[j]/=g;
        B[i]/=g;
    }
    ll ans=1;
    for(i=0;i<r;i++)
        ans=(ans*A[i]%mod);
    return ans;
}
const int SIZE=200001;
bool judgePermutation(int a[], int n){
    static int used[SIZE+1];
    for(int i = 1; i <= n; i++) used[i] = 0;
    for(int i = 0; i < n; i++) used[a[i]] = 1;
    for(int i = 1; i <= n; i++) {
        if(!used[i]) return 0;
    }
    return 1;
}
//DSU Implementation
void init(int idx[], int sz[],int n){
	rep(i,0,n) idx[i]=-1, sz[i]=1;
}
int root(int index, int idx[]){
	while(index!=idx[index]){
		index=idx[index];
	}
	return index;
}
bool qfind(int p, int q, int idx[]){
	return root(p,idx)==root(q,idx);
}
void qunion(int p, int q, int idx[], ll sz[]){
	int rootp=root(p,idx), rootq=root(q,idx);
	if(rootp==rootq) return;
	idx[rootq]=rootp;
	sz[rootp]+=sz[rootq];
}


int main(){	
//CONDITION && cout << "YES" || cout << "NO"; cout << '\n';
//////////////////////////////////////////////////////////////////////
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cerr.tie(NULL);
//For fast IO
///////////////////////////////////////////////////////////////////// 
//  std::cout.unsetf ( std::ios::floatfield );  // floatfield not set
//  std::cout.precision(10);
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	int k;
	string s;
	cin>>k>>s;
	if(s.size()<=k) cout<<s<<endl;
	else{
		rep(i,0,k) cout<<s[i];
		cout<<"..."<<endl;
	}
	return 0;
    }

Measured memory_bytes: 3652
//Name: City Merger
//Level:
//Category:
//Note:

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <array>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>

using namespace std;

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

struct H {
    size_t operator()(const pair<int,int> &p) const {
        return p.first * 100 + p.second;
    }
};

bool solve() {
    int N;
    cin >> N;
    if(!N) return false;

    vector<string> v;
    TIMES(_, N) {
        string s;
        cin >> s;
        v.push_back(s);
    }
    vector<string> cities;
    TIMES(i, N) {
        const string &s = v[i];
        if(any_of(v.begin(), v.end(), [&s](const string &str) {
                    return str != s && str.find(s) != string::npos;
                    })) continue;
        cities.push_back(s);
    }
    const int M = cities.size();
    vector<vector<int>> merged_len(M, vector<int>(M, 0));
    TIMES(i, M) {
        const string &s1 = cities[i];
        TIMES(j, M) {
            const string &s2 = cities[j];
            const int lim = min(s1.size(), s2.size());
            merged_len[i][j] = s2.size();
            for(int l = lim; l > 0; --l) {
                const string tail = s1.substr((int)s1.size()-l);
                const string head = s2.substr(0, l);
                if(tail == head) {
                    merged_len[i][j] -= l;
                    break;
                }
            }
        }
    }
    unordered_map<pair<int,int>,int,H> memo;
    priority_queue<pair<int,pair<int,int>>> q;
    TIMES(i, M) {
        const int len = cities[i].size();
        const auto tag = make_pair(1<<i, i);
        q.push(make_pair(-len, tag));
        memo[tag] = len;
    }
    int ans = 0;
    while(!q.empty()) {
        const int len = -q.top().first;
        const int used = q.top().second.first;
        const int last = q.top().second.second;
        q.pop();
        if(memo[make_pair(used, last)] < len) continue;
        if(used == (1<<M)-1) {
            ans = len;
            break;
        }
        //cout << len << ' ' << used << ' ' << last << endl;
        TIMES(i, M) {
            if(used & (1<<i)) continue;
            const int nlen = len + merged_len[last][i];
            const auto ntag = make_pair(used | (1<<i), i);
            if(memo.count(ntag) == 0 || memo[ntag] > nlen) {
                memo[ntag] = nlen;
                q.push(make_pair(-nlen, ntag));
            }
        }
    }
    cout << ans << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

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

int main()
{
    int h, w, k;
    cin >> h >> w >> k;
    string s[6];
    for(int i = 0; i < h; i++) cin >> s[i];
    int ans = 0;
    for(int b = 0; b < (1 << (h + w)); b++){
        char c[6][6];
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++) c[i][j] = s[i][j];
        }
        for(int i = 0; i < h; i++){
            if((b >> i) & 1){
                for(int j = 0; j < w; j++) c[i][j] = '.';
            }
        }
        for(int j = 0; j < w; j++){
            if(b >> (h + j) & 1){
                for(int i = 0; i < h; i++) c[i][j] = '.';
            }
        }
        int d = 0;
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(c[i][j] == '#') d++;
            }
        }
        if(d == k) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;
ll mod = pow(10,9) + 7;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}


int main(void){
    vector<int> v(101,0);
	int a,b,c; cin >> a >> b >> c;
	v[a]++;
	v[b]++;
	v[c]++;
	int count = 0;
	rep(i,101){
		if (v[i] > 0){
			count++;
		}
	}
	cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long int ll;

int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        ll ans=0;
        ll d=600/n;
        for(int i=0;i<d;i++){
            ans+=n*i*n*i*n;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3220
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b,a%b));
}

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll q,h,s,d;
    ll n;
    cin>>q>>h>>s>>d>>n;
    ll onel,twol;
    onel=min(min(q*4,h*2),s);
    twol=min(onel*2,d);
    if(n%2==0){
        cout<<twol*(n/2)<<endl;
    }else{
        cout<<onel+twol*((n-1)/2)<<endl;
    }
    return 0;
}

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

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

    int n;
    cin >> n;
    ll k = 0;
    vector<ll> a(n), b(n);
    vector<pair<ll, ll>> c(n), d, e;
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) {
        cin >> b[i];
        c[i].first = b[i];
        c[i].second = i;
    }
    int t = 0;
    while (c.size() > 0 && t <= 100) {
        t++;
        sort(c.begin(), c.end(), greater<pair<ll, ll>>());
        for (auto q : c) {
            int j = q.second;
            ll x = (b[j] - a[j]) / (b[(j + 1) % n] + b[(j + n - 1) % n]);
            k += x;
            b[j] -= x * (b[(j + 1) % n] + b[(j + n - 1) % n]);
            if (a[j] != b[j])
                d.push_back(q);
            q.second = b[j];
        }
        c = d;
        d = e;
    }
    if (t > 100)
        k = -1;
    cout << k << endl;
    return 0;
}


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

int main(void) {
    int n;
    string s;
    cin >> n >> s;
    int r = 0, b = 0;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] == 'R') {
            ++r;
        }
        else {
            ++b;
        }
    }
    if (r > b) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    return 0;
}

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

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;(i)>=0;(i)--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())

typedef long long ll;


int main(){

    int sum=0;
    REP(i,4){
        int t; cin>>t;
        sum+=t;
    }
    
    cout<<sum/60<<endl<<sum%60<<endl;
    
    return 0;
}

Measured memory_bytes: 3084
n=int(input())

card={}
card_key=set([])

for _ in range(n):
  temp=input()
  if temp in card_key:
    card[temp]+=1
  else:
    card_key.add(temp)
    card[temp]=1

m=int(input())

for _ in range(m):
  temp=input()
  if temp in card_key:
    card[temp]-=1
  else:
    card_key.add(temp)
    card[temp]=-1
#print(card)
result=0
for item in card_key:
  result=max(result,card[item])
print(result)


Measured memory_bytes: 38384
//「硬度フェスティバル」(https://beta.atcoder.jp/contests/cf16-relay-open/tasks/relay_c)

#include<iostream>
#include<vector>

int main(){
	//標準入力
	size_t N;
	std::cin>>N;
	//2^18は18bitで表現できるので、size_tで表現できる
	size_t num=1;
	for(size_t i=0;i<N;i++){num*=2;}
	std::vector<int> A(num,0);
	for(size_t i=0;i<num;i++){
		std::cin>>A[i];
	}

	//処理
	//がんばって全探索
	//配列確保するとコストが大きいので、トーナメント表Aをどんどん更新していく感じで
	for(size_t depth=0;depth<N;depth++){
		//残っている石の数を求める
		size_t leftNum=num;
		for(size_t i=0;i<depth;i++){ leftNum/=2; }
		//トーナメントを進める
		for(size_t i=0;i*2+1<leftNum;i++){
			//A[i*2]とA[i*2+1]の対戦結果を計算
			size_t result;
			if(A[i*2]<A[i*2+1]){
				result=A[i*2+1]-A[i*2];
			}else if(A[i*2]==A[i*2+1]){
				result=A[i*2];
			} else{
				result=A[i*2]-A[i*2+1];
			}
			//結果格納
			A[i]=result;//A[i]はこの深さでの対戦では以後用いないので更新してOK
		}
	}

	//出力
	std::cout<<A[0]<<std::endl;

	return 0;
}


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

int main() {
  
  int a,b,c;
  cin >> a >> b >> c;
  
  cout << a*b/2 << endl;
  
}


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

namespace EcostCB
{
    class Program
    {
        static void Main(string[] args)
        {
            // スペース区切りの整数の入力
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int K = int.Parse(input[1]);
            int[] h = new int[N+1];
            string[] inputH = Console.ReadLine().Split(' ');

            for (int i = 1; i <= N; i++)
            {
                h[i] = int.Parse(inputH[i-1]);
            }
            int[] cost = new int[N+1];
            for (int i = 0; i <= N; i++)
            {
                cost[i] = 10000;
            }
            cost[1] = 0;
            cost[2] =Math.Abs( h[2] - h[1]);
            List<int> cost_List = new List<int>();
            for (int j =3 ; j <= N; j++)
            {
                cost_List.Clear();
                for (int i = 1; i <= K; i++)
                {
                    if (j - i > 0)
                    {
                    int c = cost[j - i] + Math.Abs(h[j] - h[j - i]);
                    cost_List.Add(c);
                    }
                }
                cost[j] = cost_List.Min();
            }
            Console.WriteLine(cost[N]);
        }
    }
}


Measured memory_bytes: 26208
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

int gcd(int a, int b)
{
	if (a%b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a%b));
	}
}

int lcm(int a, int b)
{
	return a * b / gcd(a, b);
}

int main()
{
	int n, m;
	cin >> n >> m;
	vector<ll> xl(m);
	rep(i, m) {
		cin >> xl[i];
	}
	sort(xl.begin(), xl.end());
	vector<ll> dist;
	rep(i, m) {
		if (i + 1 >= xl.size()) break;
		dist.push_back(abs(xl[i + 1] - xl[i]));
	}
	sort(dist.begin(), dist.end());
	ll ans = 0;
	if (dist.size() >= 1) {
		rep(i, dist.size()) {
			ll last = dist.size() - (n - 1);
			if (last < 0) break;
			if (i >= last) break;
			ans += dist[i];
		}
	}
	cout << ans << endl;
	//cout << fixed << setprecision(10) << ans << endl;
	system("pause");
}



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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define PI 3.1415926535897932385 //pi
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main()
{
    lol result{0};
    lol n; cin >> n;
    //int k; cin >> k;
    /*
    vector<int> a(n);
    REP(i, n)
    {
        cin >> a[i];
    }
    */
   if(n >= 400 && n < 600)
   {
       result = 8;
   }
   else if(n < 800)
   {
       result = 7;
   }
   else if(n < 1000)
   {
       result = 6;
   }
   else if(n < 1200)
   {
       result = 5;
   }
   else if(n < 1400)
   {
       result = 4;
   }
   else if(n < 1600)
   {
       result = 3;
   }
   else if(n < 1800)
   {
       result = 2;
   }
   else if(n < 2000)
   {
       result = 1;
   }

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<queue>
using namespace std;
#define int long long
priority_queue<int>q;
int n,m,x,a,ans;
signed main(){
	scanf("%lld%lld",&n,&m);
	for(register int i=1;i<=n;i++){
		scanf("%lld",&a);
		q.push(a);
	}
	while(m--){
		x=q.top();
		q.pop();
		q.push(x>>1);
	}
	while(!q.empty()){
		ans+=q.top();
		q.pop();
	}
	printf("%lld",ans);
}

Measured memory_bytes: 1400
using System;

namespace ABC131_C___Anti_Division
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            var A = read[0];
            var B = read[1];
            var C = read[2];
            var D = read[3];
            var lcmCD = C * D / GCD(C, D);
            long result = (B - A + 1) - (B / C - (A - 1) / C) - (B / D - (A - 1) / D) + (B/lcmCD - (A-1)/lcmCD);

            Console.WriteLine(result);




        }

        static long GCD(long A, long B)
        {
            if (B > A) return GCD(B, A);
            if (A % B == 0)
            {
                return B;
            }
            else
            {
                return GCD(B, A % B);
            }
        }
    }
}


Measured memory_bytes: 13140
#include"bits/stdc++.h"
#define ll long long int
using namespace std;
unordered_map<ll,ll>sign;
vector<ll>g[100001];
bool vis[100001];
void bfs(ll node) {
    queue<ll>q;
    q.push(node);
    vis[node] = true;
    while(!q.empty()) {
        ll u = q.front();
        q.pop();
        for(auto&p:g[u]) {
            if(vis[p]==false) {
                q.push(p);
                vis[p]=true;
                if(sign[p]==-1) {
                     sign[p] = u;
                }
            }
        }
    }
}
int main()
{
    ll n,m;
    cin>>n>>m;
    ll x,y,i;
    for(i=0;i<m;i++) {
        cin>>x>>y;
        sign[x]=-1;
        sign[y]=-1;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    memset(vis,false,sizeof(vis));
    bfs(1);
    for(i=2;i<=n;i++) {
        if(sign[i]==-1) {
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"Yes\n";
    for(i=2;i<=n;i++) {
        cout<<sign[i]<<"\n";
    }
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  while (A > 0 && C > 0) {
    C -= B;
    if (C <= 0) {
      cout << "Yes" << endl;
      break;
    }
    A -= D;
    if (A <= 0) {
      cout << "No" << endl;
      break;
    }
  }
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

ll mod = 1000000007;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    rep(i, 60){
        ll one = 0, zero = 0;
        rep(j,n){
            if ( (a[j]>>i) & 1) one++;
            else zero++;
        }
        ll now = one * zero % mod;
        rep(j, i) now = 2 * now % mod;
        ans += now;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5588
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=50010;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n;
    cin>>n;
    ll ar[n];
    for(ll i=0;i<n;++i){cin>>ar[i];}

    stack<pi> stack1,stack2,extra;

    ll leftg1[n],leftg2[n],rightg1[n],rightg2[n];

    for(int i=0;i<n;++i)
    {
        leftg1[i]=leftg2[i]=-1;
        rightg1[i]=rightg2[i]=n;
    }

    for(ll i=0;i<n;++i)
    {
        while(!stack1.empty()&&stack1.top().first<ar[i])
        {
            rightg1[stack1.top().second]=i;
            extra.push(stack1.top());
            stack1.pop();
        }
        while(!stack2.empty()&&stack2.top().first<ar[i])
        {
            rightg2[stack2.top().second]=i;
            stack2.pop();
        }
        while(!extra.empty())
        {
            stack2.push(extra.top());
            extra.pop();
        }
        stack1.push(mp(ar[i],i));
    }

    while(!stack1.empty())
    {
        rightg1[stack1.top().second]=n;
        stack1.pop();
    }
    while(!stack2.empty())
    {
        rightg2[stack2.top().second]=n;
        stack2.pop();
    }

    for(ll i=n-1;i>=0;--i)
    {
        while(!stack1.empty()&&stack1.top().first<ar[i])
        {
            leftg1[stack1.top().second]=i;
            extra.push(stack1.top());
            stack1.pop();
        }
        while(!stack2.empty()&&stack2.top().first<ar[i])
        {
            leftg2[stack2.top().second]=i;
            stack2.pop();
        }
        while(!extra.empty())
        {
            stack2.push(extra.top());
            extra.pop();
        }
        stack1.push(mp(ar[i],i));
    }

    while(!stack1.empty())
    {
        leftg1[stack1.top().second]=-1;
        stack1.pop();
    }
    while(!stack2.empty())
    {
        leftg2[stack2.top().second]=-1;
        stack2.pop();
    }

    ll ans=0;

    for(ll i=0;i<n;++i)
    {
        ans+=ar[i]*((rightg1[i]-i)*(leftg1[i]-leftg2[i])+(rightg2[i]-rightg1[i])*(i-leftg1[i]));
        //cout<<leftg1[i]<<" "<<leftg2[i]<<" "<<rightg1[i]<<" "<<rightg2[i]<<endl;
    }

    cout<<ans<<endl;

    return (0);
}


Measured memory_bytes: 5632
//
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
//
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// solution 
#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input!{
        N: usize,
        A: usize,
        B: usize,
        C: usize,
        D: usize,
        E: usize,
    }

    let trans = [A, B, C, D, E];
    let (_mind, min) = trans.iter().enumerate().min_by_key(|&t| t.1).unwrap();

    println!("{}", 4 + ((N + min - 1) / min)); 
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<climits>
using namespace std;
int main()
{
	int n;
	cin >> n;
	
	vector<int> p;
	for (int i=0; i<n; i++) {
		int tmp;
		cin >> tmp;
		p.push_back(tmp);
	}
	
	int min = INT_MAX;
	for (int i=1;i<=100; i++) {
		int total = 0;
		for (int j=0; j<n; j++) {
			total += (p[j]-i)*(p[j]-i);
		}
		if (min > total) {
			min = total;
		}
	}
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 256
import math
N, K = map(int, input().split())
p = 0
if N <= K:
    for n in range(N):
        p += (1/N) * (1/2) ** math.ceil((math.log2(K/(n+1))))
else:
    for n in range(K-1):
        p += (1/N) * (1/2) ** math.ceil((math.log2(K/(n+1))))

    p += (N-K+1)/N
        
print(p)

Measured memory_bytes: 3064
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub trait BinarySearch<T> {
    fn lower_bound(&self, &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}

fn main() {
    let n: usize = read();
    let a = read_vec::<i64>();

    let mut former_heap = BinaryHeap::new();
    for i in 0..n {
        former_heap.push(-a[i]);
    }
    let mut former_sums = vec![0i64; n + 1];
    former_sums[0] = a.iter().take(n).sum::<i64>();
    for i in 0..n {
        let smallest_former = -former_heap.pop().unwrap();
        former_sums[i + 1] = former_sums[i];
        if a[i + n] > smallest_former {
            former_sums[i + 1] += a[i + n] - smallest_former;
        }
        former_heap.push(-max(smallest_former, a[i + n]));
    }

    let mut latter_heap = BinaryHeap::new();
    for i in n * 2..n * 3 {
        latter_heap.push(a[i]);
    }
    let mut latter_sums = vec![0i64; n + 1];
    latter_sums[0] = a.iter().skip(2 * n).sum::<i64>();
    for i in 0..n {
        let largest_latter = latter_heap.pop().unwrap();
        latter_sums[i + 1] = latter_sums[i];
        if a[2 * n - i - 1] < largest_latter {
            latter_sums[i + 1] += a[2 * n - i - 1] - largest_latter;
        }
        latter_heap.push(min(largest_latter, a[2 * n - i - 1]));
    }

    println!(
        "{}",
        (0..n + 1)
            .map(|i| former_sums[i] - latter_sums[n - i])
            .max()
            .unwrap()
    );
}


Measured memory_bytes: 13560
parseInt(x) = parse(Int, x)
parseArray(x::Array{SubString{String}, 1}) = map(parseInt, x)

function main()
  N,M= readline() |> split |> parseArray
  a = zeros(Int, N)
  a[1] = 1
  N>=2 && (a[2] = 2)
  for _ in 1:M
    i = readline() |> parseInt
    a[i] = -1
  end

  N>=2 && a[2]!=-1 && a[1]==-1 && (a[2]=1)

  for i in 3:N
    a[i]==-1 && continue
    a[i-2] != -1 && (a[i]+=a[i-2])
    a[i-1] != -1 && (a[i]+=a[i-1])
    a[i]%=1_000_000_007
  end

  println(a[N])
end

main()


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

/*freopen("testcases/17.in", "r", stdin);
    freopen("output.txt", "w", stdout);*/

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int br1=0,br2=0;
	string s;
	cin >> s;
	if(s[0]=='A')
        br1++;
    else
        br2++;
    if(s[1]=='A')
        br1++;
    else
        br2++;
    if(s[2]=='A')
        br1++;
    else
        br2++;
    if(br1>0 && br2>0)
        cout << "Yes";
    else
        cout << "No";
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
#define MAX 1100
#define INF ((int)1e9+9)

int main(){
	int A[MAX], n, q, b, e;
	
	cin>>n;
	
	for(int i = 0; i < n; i++){
		cin>>A[i];
	}
	
	cin>>q;
	
	for(int i = 0; i < q; i++){
		cin>>b>>e;
		for(int j = 0; j < (e-b)/2; j++){
			swap(A[j+b],A[e-j-1]);
		}
	}

	for(int i = 0; i < n; i++){
		cout<<(i?" ":"")<<A[i];
	}
	cout<<endl;
	
	return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
	using namespace std;
	#define sim template < class c
	#define ris return * this
	#define dor > debug & operator <<
	#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
	sim > struct rge { c b, e; };
	sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
	sim > auto dud(c* x) -> decltype(cerr << *x, 0);
	sim > char dud(...);
	struct debug {
	#ifdef LOCAL
	~debug() { cerr << endl; }
	eni(!=) cerr << boolalpha << i; ris; }
	eni(==) ris << range(begin(i), end(i)); }
	sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
	}
	sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
	}
	#else
	sim dor(const c&) { ris; }
	#endif
	};
	#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
	#define deb debug()
	#define lel(...) deb << " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
	#define ll long long
	#define all(x) (x).begin(), (x).end()
	// 
using namespace std;
 
const int N = 50010;
ll mod = 998244353;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} 


int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k;
	cin >> k >> n;
	vector<int> tab;
	for (int a = 1; a <= n; a++) {
		int x;
		cin >> x;
		tab.push_back(x);
	}
	tab.push_back(tab[0] + k);
	int maks = 0;
	for (int a = 1; a < tab.size(); a++) {
		maks = max(maks, tab[a] - tab[a - 1]);
	}
	cout << k - maks << endl;


	
	
	return 0;
}

Measured memory_bytes: 1400
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    s=sum(A)
    t=sum(a**2 for a in A)
    print((s**2-t)//2)
resolve()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define forna(i,a,n) for(int i=a;i<n;i++)
typedef long long int lli;
using namespace std;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lli t,n;string s;
// cin>>t;
// while(t--){
cin>>n;
unordered_map<string,int>m;
forna(i,0,n) {cin>>s;m[s]++;}
cout<<"AC x "<<m["AC"]<<endl;
cout<<"WA x "<<m["WA"]<<endl;
cout<<"TLE x "<<m["TLE"]<<endl;
cout<<"RE x "<<m["RE"]<<endl;
}


Measured memory_bytes: 3676
#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
const int MN=2e5+5;
int n,a[MN];
int main(){
	scanf("%d",&n);
	for(reg int i=1;i<=n;i++)scanf("%d",a+i),a[i]-=i;
	sort(a+1,a+1+n);reg ll res=0;
	for(reg int i=1;i<=n;i++)res+=abs(a[i]-a[(n+1)>>1]);
	cout<<res<<endl;
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define REREP(i,n) for(int i=int(n-1); i>=0; i--)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define REFOR(i,m,n) for(int i=int(n-1); i>=int(m); i--)
#define ALL(obj) (obj).begin(),(obj).end()
 
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VD vector<double>
#define VVD vector<vector<double>>
#define VVVD vector<vector<vector<double>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VVVL vector<vector<vector<ll>>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define VVVB vector<vector<vector<bool>>>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVVS vector<vector<vector<string>>>
 
#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<ll,ll>
#define VPII vector<pair<int,int>>
#define VVPII vector<vector<pair<int,int>>>
#define VVVPII vector<vector<vector<pair<int,int>>>>
#define VPLL vector<pair<ll,ll>>
#define VVPLL vector<vector<pair<ll,ll>>>
#define VVVPLL vector<vector<vector<pair<ll,ll>>>>
 
#define SUMI(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SUMD(obj) accumulate((obj).begin(), (obj).end(), 0.)
#define SUML(obj) accumulate((obj).begin(), (obj).end(), 0LL)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

#define PB push_back
#define Cout(str) cout << str << endl

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const ll EPS = (ll)1e-8;

int main(){
	int n,m;
	int a,b,c;
	int sum;
	string str;
	string s,t;
	char ch;
	VI vi;
	vector<char> vc;
	VS vs;
	int reserve_vi = 100;
	map<int, int> table; 
	string str2, str3;

	//cin >> n >> m;
	//cin >> a >> b;
	//cin >> a >> b >> c;
	//cin >> str;
	cin >> str >> str2 >> str3;
	//cin >> n;
	
	//cin >> s >> t;
	//cin >> c;

	cout << str[0] << str2[0] << str3[0] << endl;

	//cout << accumulate(vi.begin(), vi.begin()+n, 0) << endl;

	//swap(a, b);
	//vi.resize(N);
	//fill(vi.begin(), vi.end(), 1);
	//vi.reserve(reserve_vi);
	//vi.PB(n);

	//vc.resize(5);
	//vc[i] = (str[i]);

	//sort(vc.begin(), vc.end(), greater<char>());
	//sort(vc.begin(), vc.end());

	//for(auto itr = table.begin(); itr != table.end(); ++itr) {
	return 0;
}



Measured memory_bytes: 256
eval"A,B,_,*I="+`dd`.split*?,+"
s,t=[A,B].map{|a|[-F=1e15,*I.shift(a),F]}
I.map{|x|p s[s#{a='.bsearch_index{|y|y>x}-1,2].map{|'}s|t[t#{a}t|[s,t].map{|y|(x-y).abs}.min+(t-s).abs}.min}.min}"

Measured memory_bytes: 99504
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
    ll n;cin>>n;
    ll amt =1000;
    int m=0;
    ll stocks=0;
    ll mi = INT_MAX;
    vector<int>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=1;i<n;i++){
      if(a[i-1]<a[i]){
        stocks+=amt/a[i-1];
        amt= amt - stocks*a[i-1];
        amt+=a[i]*stocks;
        stocks=0;
      }
    }

    cout<<max(1000LL,amt);

    return 0;
}


Measured memory_bytes: 3544
N, M, D = map(int, input().split())
A = []
for _ in range(N):
	A.append(list(input()))

r = 0
for n in range(N):
	for m in range(M):
		if A[n][m]=='#':
			pass
		elif A[n][m]=='.':
			if m+D>M:  # 水平方向
				pass
			else:
				if A[n][m:m+D].count('#')==0:
					r += 1
			if n+D>N:  #水平方向
				pass
			else:
				temp = True
				for i in range(1, D):
					if A[n+i][m]=='#':
						temp = False
						break
				if temp==True: r += 1

print(r)



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

int n, q;
int p[100000], d[100000];

int find(int x) {
	if (p[x] == x)
		return x;
	else {
		int xp = p[x];
		p[x] = find(xp);
		d[x] += d[xp];
		return p[x];
	}
}

void relate(int x, int y, int z) {
	int xp = find(x), yp = find(y);

	if (xp != yp) {
		p[yp] = xp;
		d[yp] = d[x] + z - d[y];
	}
}

int main()
{
	cin >> n >> q;

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

	for (int i = 0; i < q; i++) {
		int c, x, y, z;

		cin >> c;

		if (c == 0) {
			cin >> x >> y >> z;
			relate(x, y, z);
		}
		else {
			cin >> x >> y;
			if (find(x) == find(y))
				cout << d[y] - d[x] << endl;
			else
				cout << "?" << endl;
		}
	}
}



Measured memory_bytes: 3876