akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 10000000

int main() {
  int n, ma, mb;
  cin >> n >> ma >> mb;
  int a[n], b[n], c[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  const int MAX_A = n * 10 + 1;
  const int MAX_B = n * 10 + 1;
  int dp[n + 1][MAX_A][MAX_B];
  for (int i = 0; i < n + 1; i++) {
    for (int j = 0; j < MAX_A; j++) {
      for (int k = 0; k < MAX_B; k++) {
        dp[i][j][k] = INF;
      }
    }
  }
  dp[0][0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < MAX_A; j++) {
      for (int k = 0; k < MAX_B; k++) {
        dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
        if (j + a[i] < MAX_A && k + b[i] < MAX_B) {
          dp[i + 1][j + a[i]][k + b[i]] = min(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
        }
      }
    }
  }
  int ans = INF;
  for (int i = 1; i < MAX_A; i++) {
    for (int j = 1; j < MAX_B; j++) {
      if (j * ma != i * mb) continue;
      ans = min(ans, dp[n][i][j]);
    }
  }
  if (ans < INF) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

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

ll g(ll n) {return n*(n+1)/2;}

int main()
{   
    ll n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        ans += i * g(n/i);
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main()
{
    int N;
    scanf("%d", &N);
    vector<int> A(N);
    for(auto it=A.begin(); it!=A.end(); it++){
        scanf("%d", &(*it));
    }

    auto print=[&A]{
        for(auto it=A.begin(); it!=A.end(); it++){
            if(it!=A.begin()){
                printf(" ");
            }
            printf("%d", *it);
        }
        printf("\n");
    };

    int cnt=0;
    for(int i=0; i<N; i++){
        int min_j=i;
        for(int j=i; j<N; j++){
            if(A[j]<A[min_j]){
                min_j=j;
            }
        }
        swap(A[i], A[min_j]);
        if(i!=min_j){
            cnt++;
        }
    }
    print();
    printf("%d\n", cnt);
    return 0;
}

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

int main() {
    string S,T;
    cin >> S >> T;
    S += S;
    bool itti = false;

    for(int i=0; i<T.size(); i++){
        string U = S.substr(i,T.size());
        if(U==T){
            itti = true;
        }
    }

    if(itti){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FI first
#define SE second

using namespace std;

long long x[1005],y[1005],z[1005];
int a,b,c,k;
map<int,map<int,map<int,bool> > > maap;

priority_queue< pair<long long, pair<int,pair<int,int> > > >PQ;
pair<long long, pair<int,pair<int,int> > > curr;

int main(){
    scanf("%d%d%d%d",&a,&b,&c,&k);
    for(int i =0;i<a;i++) scanf("%lld",&x[i]);
    for(int i =0;i<b;i++) scanf("%lld",&y[i]);
    for(int i =0;i<c;i++) scanf("%lld",&z[i]);

    sort(x,x+a);
    sort(y,y+b);
    sort(z,z+c);

    PQ.push({ x[a-1]+y[b-1]+z[c-1],{a-1,{b-1,c-1} } });

    while(1){
        curr = PQ.top();
        a = curr.SE.FI;
        b = curr.SE.SE.FI;
        c = curr.SE.SE.SE;
        maap[a][b][c] =1;
        PQ.pop();
        printf("%lld\n",curr.FI);
        k--;
        if(k==0) break;

        if(a-1>=0 && maap[a-1][b][c]==0)PQ.push({ x[a-1]+y[b]+z[c],{a-1,{b,c} } }),maap[a-1][b][c]=1;
        if(b-1>=0 && maap[a][b-1][c]==0)PQ.push({ x[a]+y[b-1]+z[c],{a,{b-1,c} } }),maap[a][b-1][c]=1;
        if(c-1>=0 && maap[a][b][c-1]==0)PQ.push({ x[a]+y[b]+z[c-1],{a,{b,c-1} } }),maap[a][b][c-1]=1;
    }
    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
Int dp[4][1010][1010];
Int di[1123456];
Int nt[4][1123456];
signed main(){
  Int h,w,n;
  while(cin>>h>>w>>n,h){
    string s;
    cin>>s;
    vector<string> c(h);
    for(Int i=0;i<h;i++) cin>>c[i];

    auto calc=[](char c){return c=='R'?1:-1;};
    memset(di,0,sizeof(di));
    memset(nt,-1,sizeof(nt));
    di[0]=0;
    for(Int i=0;i<n;i++)
      di[i+1]=(di[i]+calc(s[i])+4)%4;
    
    //for(Int i=0;i<=n;i++) cout<<i<<":"<<di[i]<<endl;
    {
      Int nd[4]={-1,-1,-1,-1};
      for(Int i=n;i>=0;i--){
	nd[di[i]]=i;
	for(Int j=0;j<4;j++) nt[j][i]=nd[j];
      }
    }
    
    
    using T = tuple<Int, Int, Int>;
    memset(dp,-1,sizeof(dp));
    vector<queue<T> > q(n+1);

    auto in=[&](Int y,Int x){return 0<=y&&y<h&&0<=x&&x<w;};
    Int dy[]={-1,0,1,0};
    Int dx[]={0,1,0,-1};
    Int d=0,y,x;
    for(Int i=0;i<h;i++)
      for(Int j=0;j<w;j++)
	if(c[i][j]=='S') y=i,x=j;

    dp[d][y][x]=0;
    q[0].emplace(d,y,x);

    Int ans=0;
    for(Int i=0;i<=n;i++){
      while(!q[i].empty()){
	tie(d,y,x)=q[i].front();q[i].pop();
	if(dp[d][y][x]<i) continue;
	if(c[y][x]=='G'){
	  ans=1;
	  break;
	}
	for(Int k=0;k<4;k++){
	  Int nd=k,ny=y+dy[k],nx=x+dx[k],ni=nt[k][i];
	  if(ni<0) continue;
	  if(!in(ny,nx)||c[ny][nx]=='#') continue;
	  if(dp[nd][ny][nx]<0||dp[nd][ny][nx]>ni){
	    dp[nd][ny][nx]=ni;
	    q[ni].emplace(nd,ny,nx);
	  }
	}
      }
      if(ans) break;
    }
    
    cout<<(ans?"Yes":"No")<<endl;
  }
  return 0;
}



Measured memory_bytes: 83508
def main():
    buf = input()
    S = buf
    total = split_sum(S)
    print(total)

def split_sum(S):
    total = 0
    for i in range(int(2 ** (len(S) - 1))):
        factor = 1
        mask = 0b0000000001
        for j in range(len(S)):
            total += int(S[-j - 1]) * factor
            if i & (mask << j):
                factor = 1
            else:
                factor *= 10
    return total

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<ll> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,a,b) for(i=a;i<=b;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
 
ll rui(ll abc,ll bed){
	//aのb乗を計算する
	if(bed==0){return 1;}
	else{
		ll ced = rui(abc,bed/2);
		ced *= ced;
		ced %= mod;
		if(bed%2==1){ced*=abc; ced%=mod;}
		return ced;
	}
}

ll i,j,k,ii,jj;
ll n,m,sum,num;
ll a,b,c,d,e,ans;
ll x[500005],y[500005],z[500005];
ll ma,mi;
char s[100005],t[100005];
double aa;

int main(){
	cin>>a>>b;
	if(a+b==15)p("+");
	if(a*b==15)p("*");
	if(a+b!=15 && a*b!=15)p("x");

	return 0;
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(ll i=ll(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}



int main()
{
    ll n;
    cin>>n;
    if(n%2!=0){
        cout<<0<<endl;
        return 0;
    }
    ll ans = 0;
    n /= 2;
    for(ll i = 5; n/i>=1;i*=5){
        ans += n/i;
    }
    // repi(i,1,18){
    //     ans += (n/10);
    //     ans += (n/100);
    //     // ans += (n/50+1)/2;
    //     n/=10;
    // }
    cout<<ans<<endl;
	return 0;
}

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

struct card{ char suit,value; };
  
void bubble(struct card a[],int n){
  for(int i=0;i<n;i++){
    for(int j=n-1;j>=i;j--){
      if(a[j].value<a[j-1].value) swap(a[j],a[j-1]);
    }
  }
}

void selection(struct card a[],int n){
  for(int i=0;i<n;i++){
    int minj=i;
    for(int j=i;j<n;j++){
      if(a[j].value<a[minj].value) minj=j;
    }
    swap(a[i],a[minj]);
  }
}

int main(){
  int n;
  card c1[100],c2[100];
  char c;
  bool b=true;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>c1[i].suit>>c1[i].value;
    c2[i]=c1[i];
  }
  bubble(c1,n);
  selection(c2,n);
  for(int i=0;i<n;i++){
    if(i>0) cout<<" ";
    cout<<c1[i].suit<<c1[i].value;
  }
  cout<<endl;
  cout<<"Stable"<<endl;
  for(int i=0;i<n;i++){
    if(i>0) cout<<" ";
    cout<<c2[i].suit<<c2[i].value;
  }
  cout<<endl;
  for(int i=0;i<n;i++){
    if(c1[i].suit!=c2[i].suit) b=false;
  }
  if(b) cout<<"Stable"<<endl;
  else cout<<"Not stable"<<endl;
  return 0;
}



Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int kk(string s){
  int res=0;
  r(i,s.size()){
    if(s[i]==',')break;
    else{
      res*=10;
      res+=s[i]-'0';
    }
  }
  return res;
}
int main(){
  set<int>se,de;
  string s;
  int p=0;
  map<int,int>v;
  while(getline(cin,s)){
    if(s=="")p++;
    else{
      if(!p){
        int x=kk(s);
        v[x]++;
        se.insert(x);
      }
      else{
        int x=kk(s);
        if(se.count(x))de.insert(x);
        v[x]++;
      }
    }
  }
  for(map<int,int>::iterator it=v.begin();it!=v.end();it++){
    int x=(*it).first,y=(*it).second;
    if(de.count(x))cout<<x<<' '<<y<<endl;
  }
}

Measured memory_bytes: 3024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	int n, x;
	cin >> n >> x;
	vector<int> l(n);
	for (int i = 0; i < n; i++)cin >> l[i];

	int pos = 0, count = 1;

	for (int i = 0; i <n; i++)
	{
		pos += l[i];
		if (pos <= x)count++;
		else break;
	}

	cout << count << endl;
}

Measured memory_bytes: 256
n, p, q = STDIN.readlines
n = n.to_i
p, q = [p, q].map {|x| x.split(' ').map(&:to_i) }
if 0 > (q <=> p)
  p, q = q, p
end

f = nil

[*1..n].permutation.with_index(1).each do |x, i|
  if f.nil?
    if x == p
      f = i
    end
  end
  if f
    if x == q
      puts i - f
      break
    end
  end
end


Measured memory_bytes: 2172
#include<cstdio>
#include<algorithm>
#define M 100
using namespace std;

int n,q;
int c[300100],x;

int main(){
  scanf("%d%d",&n,&q);
  int lim = 0;
  for(int i=0;i<n;i++){ scanf("%d",&c[i]); lim = max(lim,c[i]); }
  sort(c,c+n);
  int m[M] = {0};
  for(int i=1;i<=M;i++){
    for(int j=0;j<n;j++)m[i] = max(m[i],c[j]%i);
  }

  for(int i=0;i<q;i++){
    scanf("%d",&x);
    if(x<=M)printf("%d\n",m[x]);
    else{
      int res = 0;
      for(int j=1;j*x<=lim;j++){
	int tmp = lower_bound(c,c+n,j*x) - c;
	if(tmp)res = max(res,c[tmp-1]%x);
      }
      printf("%d\n",res);
    }
  }
}

Measured memory_bytes: 2212
# -*- coding: utf-8 -*-
import sys
N,K=map(int, sys.stdin.readline().split())
S=sys.stdin.readline().strip()
L=[]
cnt=0
for i,x in enumerate(S):
    if i==0:
        cnt+=1
        prev=x
    else:
        if prev==x: #前の文字と今の文字が同じ
            cnt+=1
        else:       #前の文字と今の文字が異なる
            L.append(cnt)
            cnt=1
        prev=x
else:
    L.append(cnt)

print sum(L)-max(1,len(L)-2*K)


Measured memory_bytes: 36892
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   string s;
   cin >> s;
   if (s == "AAA" || s == "BBB")
      cout << "No" << endl;
   else
      cout << "Yes" << endl;

   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int A,B,C,K,ans;
  	cin>>A>>B>>C>>K;
  	if(K<=A)
    {
    	cout<<K<<endl;
    }
  	else
    {
    	K=K-A;
      	if(K<=B)
        {
        	ans=A;
          	cout<<ans;
        }
      	else
        {
        	K=K-B;
          	ans=A-K;
          	cout<<ans;
        }
    
    }
  	

 return 0;

}

Measured memory_bytes: 3588
#include <iostream>
using namespace std;
using ll = long long;

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

template<typename T>T gcd(T a, T b){return b?gcd(b,a%b):a;}


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

  ll a[N];
  rep(i, N)
    cin >> a[i];

  int count = -1;
  ll lcm = 1;
  rep(i, N) {
    int c = 1;
    while (a[i] % 2 == 0) {
      a[i] /= 2;
      c *= 2;
    }
    if (count == -1)
      count = c;
    else if (count != c) {
      cout << 0 << endl;
      return 0;
    }
    lcm = lcm / gcd(lcm, a[i]) * a[i];
    if (lcm > M) {
      cout << 0 << endl;
      return 0;
    }
  }
  cout << (M / (count/2 * lcm) + 1) / 2 << endl;

  return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define MOD ((int)(1e9) + 7)
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define filename "lynext"
#define freop freopen(filename ".cik","w",stdout);freopen(filename ".gir","r",stdin)
const int N = ((int)1e5) + 5;
const int M = ((int)1e3) + 5;
typedef long long int lli;

int n,m;
lli sum;

int power(int x, int y)
{
    int res = 1;

    while (y > 0)
    {
        if (y & 1)
            res = res * x;

        y = y >> 1;
        x = x * x;
    }
    return res;
}

priority_queue<int> pq;

int main ()
{
	fast;
	//freop;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		int a;
		cin >> a;
		pq.push(a);
	}
	int t = 0;
	while (m--)
		t = pq.top(),pq.pop(),pq.push(t / 2);
	while (!pq.empty())
		sum += pq.top(),pq.pop();
	cout << sum << "\n";
}


Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>
#include <queue>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF=1<<29;
ll mod=1000000007;

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

	double N,two=2;
	cin>>N;
	vector<double> A(N);
	for(int i=0;i<N;i++) cin>>A[i];
	sort(A.begin(),A.end());
	if(N==2){
		cout<<(A[0]+A[1])/two<<endl;
	}else{
		double tmp=(A[0]+A[1])/two;
		for(int i=2;i<N;i++){
			tmp=(tmp+A[i])/two;
		}
		cout<<tmp<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
/*
* ID: juryc
* PROG: Poor
* LANG: C++
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c; cin>>a>>b>>c;
set<int> st;
st.insert(a); st.insert(b);  st.insert(c); 
int sz=st.size();
if(sz==2) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}

Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;
 
 
string res;
 
int counter;
 
int query(string& s){
    ++counter;
    cout<<"? "<<s<<endl;
    int ret;
    cin>>ret;
    return ret;
}
 
const int m = 62;
int cnt[62][200], n;
string ans, cha;
 
void solve(int l, int r){
    if(l+1==r){
        rep(i,m)if(cnt[i][r]!=cnt[i][l]){
            ans[l]=cha[i];
            return;
        }
    }
    int mid=(l+r)/2;
    int sum = 0, num = 0;
    vector<int> c(m);
    int j = -1;
    vector<int> rem;
    REP(i,0,m){
        if(cnt[i][l]==cnt[i][r]){
            cnt[i][mid]=cnt[i][l];
            sum -= cnt[i][l];
            j=i;
        }
        else rem.push_back(i);
    }
    if(j == -1){
        for(auto i : rem){
            if(i == 0)continue;
            string s(n, 'a');
            REP(k,0,mid)s[k]=cha[i];
            c[i] = query(s) - n + cnt[0][n];
            sum += c[i];
            num++;
        }
        assert((mid+sum)%(num+1)==0);
        int ret = (mid + sum)/(num + 1);
        cnt[0][mid]=cnt[0][0]+ret;
        REP(i,1,m){
            if(cnt[i][l]==cnt[i][r]){
                continue;
            }
            cnt[i][mid]=cnt[i][0]-c[i]+ret;
        }
    }
    else {
        sum += cnt[j][l];
        for(auto i : rem){
            if(i == rem.back()){
                c[i] = (rem.size()+1)*cnt[j][mid] - sum - mid;
                continue;
            }
            string s(n, cha[j]);
            REP(k,0,mid)s[k]=cha[i];
            c[i] = query(s) - n + cnt[j][n];
            sum += c[i];
        }
        for(auto i : rem){
            cnt[i][mid]=cnt[i][0]-c[i]+cnt[j][mid];
        }
    }
    solve(l,mid);
    solve(mid,r);
}
 
int main(){
    rep(i,26)cha += 'a'+i;
    rep(i,26)cha += 'A'+i;
    rep(i,10)cha += '0'+i;
    vector<int> c(m); 
    rep(i,m){
        string s(128,cha[i]);
        c[i]=query(s);
        n += 128 - c[i];
    }
    rep(i,m)cnt[i][n]=128-c[i];
    ans.resize(n, '-');
    solve(0,n);
    if(counter>761){
        cout<<3<<endl;
    }
    cout<<"! "<<ans<<endl;
}

Measured memory_bytes: 3780
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
#define INF 99999999
typedef std::pair<int,int> pii;

int main(){
    int N;
    std::cin >> N;
    std::list<int> ls;
    std::list<int> :: iterator it;
    std::string input;
    int input_n,com;
    for (int i = 0; i < N; i++) {
        std::cin >> input;
        if (input == "insert") {
            com = 1;
            std::cin >> input_n;
        }
        else if(input=="delete"){
            com = 2;
            std::cin >> input_n;
        }
        else if(input=="deleteFirst"){
            com = 3;
        }
        else {
            com = 4;
        }
        
        switch (com) {
            case 1:
                ls.push_front(input_n);
                break;
            case 2:
                for (it = ls.begin(); it!= ls.end(); it++) {
                    if (*it == input_n) {
                        ls.erase(it);
                        break;
                    }
                }
                break;
            case 3:
                ls.pop_front();
                break;
            case 4:
                ls.pop_back();
                break;
        }

    }
    it = ls.begin();
    std::cout << *it;
    it++;
    while (it!= ls.end()) {
        std::cout << " " << *it;
        it++;
    }
    std::cout << std::endl;
    return 0;
}


Measured memory_bytes: 34360
#!/usr/bin/env python3
#ABC118 C

n = int(input())
a = list(map(int,input().split()))
a.sort()
c = a.count(0)
mi = 10**9
while 1:
    for i in range(c+1,n):
        a[i] = a[i] % a[c]
    a.sort()
    c = a.count(0)
    if a[-2] == 0:
        break
print(a[-1])


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
 
priority_queue<int,vector<int>,greater<int>>ans;
void dfs(int k){
    if(k>=1e10){return;}
    else{
        if(k%10==0){ans.push(k*10);ans.push(k*10+1);dfs(k*10);dfs(k*10+1);}
        else if(k%10==9){ans.push(k*10+8);ans.push(k*10+9);dfs(k*10+8);dfs(k*10+9);}
        else{
            ans.push(k*10+k%10-1);dfs(k*10+k%10-1);
            ans.push(k*10+k%10);dfs(k*10+k%10);
            ans.push(k*10+k%10+1);dfs(k*10+k%10+1);
        }
    }
}
 
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int k;cin>>k;
    for(int i=1;i<=9;i++){
        ans.push(i);
        dfs(i);
    }
    for(int i=0;i<k-1;i++){
        ans.pop();
    }
    cout<<ans.top()<<endl;
}

Measured memory_bytes: 10604
#include <iostream>
using namespace std;
int main() {

int a,b;
cin>> a;
char c;
cin>>c>>b;

if(c=='+'){
int sum =0;
sum= a+b;
cout << sum;  
}else if(c=='-'){
  int sub =0;
  sub = a-b;
  cout<<sub;
}
}

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

int main() {
  int n;
  cin >> n;
  vector<int>data(n);
  for(int i = 0;i < n;i++){
    cin >> data.at(i);
  }
  sort(data.begin(),data.end());
  cout << data.at(n-1)-data.at(0) << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] sports = new int[n];
        for (int i = 0; i < n; i++) {
            sports[i] = sc.nextInt();
        }
        int[] counts = new int[n];
        for (int i = 0; i < m; i++) {
            int x = sc.nextInt();
            int idx = 0;
            while (sports[idx] > x) {
                idx++;
            }
            counts[idx]++;
        }
        int max = 0;
        int maxIdx = 0;
        for (int i = 0; i < n; i++) {
            if (max < counts[i]) {
                max = counts[i];
                maxIdx = i + 1;
            }
        }
        System.out.println(maxIdx);
    }
}


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

int main() {
  
  int s;
  cin >> s;
  
  vector<int> S(1000000);
  S.at(0) = s;
  bool flag = false;
  
  for (int i=0;i<1000000;i++) {
    if (S.at(i)%2 == 0)
      S.at(i+1) = S.at(i)/2;
    else
      S.at(i+1) = 3*S.at(i)+1;
    for (int j=0;j<i+1;j++) {
      if (S.at(j) == S.at(i+1)) {
        cout << i+2 << endl;
        flag = true;
        break;
      }
    }
    if (flag)
      break;
  }
  
  
}

Measured memory_bytes: 4096
N,M = map(int, input().split(" "))

X = []

X = list(map(int, input().split(" ")))

X.sort()
#print(X)

Y = []

for i in range(M-1):
    ans1 = abs(X[i+1]-X[i])
    Y.append(ans1)

Y.sort()
#print(Y)

kazu = len(Y)

kazu= kazu- (N-1)

ans2 = 0
for j in range(kazu):
    ans2 = ans2 + Y[j]

print(ans2)


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

int main() {
  int ans = 0;
  for (int i = 0; i < 4; i++){
    char c;
    cin >> c;
    
    if (c == '+') {
      ans++;
    } else {
      ans--;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3588
#include<stdio.h>
int main(void)
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(x<r){
		printf("No\n");
	}
	else if(W<x+r){
		printf("No\n");
	}
	else if(y<r){
		printf("No\n");
	}
	else if(H<y+r){
		printf("No\n");
	}
	else{
		printf("Yes\n");
	}
	return 0;
}



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

int main() {
    long long Q, H, S, D, N;
    cin >> Q >> H >> S >> D >> N;
    long long ans = 0;

    long long a1 = Q * 4;
    long long b1 = H * 2;
    long long c1 = S;
    long long min1l = min({a1, b1, c1});
    ans += min1l * (N % 2);

    long long a2 = Q * 8;
    long long b2 = H * 4;
    long long c2 = S * 2;
    long long d2 = D;
    long long min2l = min({a2, b2, c2, d2});
    ans += min2l * (N / 2);

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

Measured memory_bytes: 256
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

a,b,c,d = map(int, input().split())

#b-a分を回してみるのは10**18なので間に合わない

#A以上B以下の整数でXで割り切れない個数を言い換えると
#Bが整数Xで割り切れない個数 - (A-1)が整数Xで割り切れない個数となる

#次にBが整数Xで割り切れない個数を考える。
#Bが整数Xで割り切れる個数は、B//Xなので、割り切れない個数は B-B//Xとなる

#次にBが整数XとYで割り切れない個数を考える
#B -B//X -B//Y + 2B//(X*Y)としたいところだが
#XとYでも割り切れるものは、B//(X*Y)ではなく、B//LCM(X,Y)となる
# X = 4, Y = 6だと 24で割り切れる個数となるが
# 12は、4と6でも割り切れるが24では割り切れない
#よってXとYの最小公倍数となる

import math

def lcm(x, y):
    return x // math.gcd(x, y) * y

def func(val, x, y):
    return val-val//x-val//y+val//lcm(x,y)

ans = (func(b,c,d)-func(a-1,c,d))
print(ans)



Measured memory_bytes: 9124
N,yen=map(int,input().split())
count=0
end=0
man=0
gosen=0
sen=0
# print(N)
# print(yen)

for i in range(N+1):
    if end==1:
        break
    for j in range(N-i+1):
        # print(i)
        # print(j)
        k=N-i-j
        # print(k)
        sum=i*10000+j*5000+k*1000
        # print(sum)
        if sum==yen:
            man=i
            gosen=j
            sen=k
            end=1
            break

if man==0 and gosen==0 and sen==0:
    print("-1 -1 -1")
else:
    print(str(man)+" "+str(gosen)+" "+str(sen))


Measured memory_bytes: 3064
s = input()
cnt = 0
ans = s[0]
for i in range(1, len(s)):
    if s[i] == ans[-1]:
        if s[i] == '0':
            ans += '1'
        else:
            ans = '0'
        cnt += 1
    else:
        ans += s[i]
print(cnt)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int m;
  cin >> m;
  cout << 24*2-m << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int input;
	int ryokin;
	while(1) {
		scanf("%d",&input);
		if(input==-1)break;
		ryokin=0;
		if(input>30) {
			ryokin+=160*(input-30);
			input=30;
		}
		if(input>20) {
			ryokin+=140*(input-20);
			input=20;
		}
		if(input>10) {
			ryokin+=125*(input-10);
			input=10;
		}
		ryokin+=1150;
		printf("%d\n",4280-ryokin);
	}
	return 0;
}

Measured memory_bytes: 0
A, B = [int(_) for _ in input().split()]

if B - A < 4:
    y = A - 1
    x = 0
else:
    y = B - 4 - B % 4 + A % 4
    x = A if A % 2 else y
for i in range(y + 1, B + 1):
    x ^= i
print(x)


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

if K >= N:
  print(1)
  exit()

idx = A.index(1)
if 0 <= idx <= K - 1 or N - 1 - (K - 1) <= idx <= N - 1:
  ans = N // (K - 1) if N % (K - 1) == 0 else N // (K - 1) + 1
  print(ans)
  exit()

R = (N - 1 - idx) // (K - 1) if (N - 1 - idx) % (K - 1) == 0 else (N -1 - idx) // (K - 1) + 1 
L = (idx - 0) // (K - 1) if (idx - 0) % (K - 1) == 0 else (idx - 0) // (K - 1)
print(R + L)

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

int main(){
  int N;  cin >> N;
  vector<int> d;
  for(int i = 0;i < N;i++){
    int dn; cin >> dn;
    d.push_back(dn);
  }

  sort(d.begin(),d.end());

  int max = 0;
  int count = 0;
  for(int i = 0;i < N;i++){
    if(max < d[i]){
      max = d[i];
      count++;
    }
  }

  cout << count << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    while(1){
        int x,y,s;
        scanf("%d %d %d",&x,&y,&s);
        if(x==0)break;
        int max=0;
        for(int i=1;i<=s;i++)for(int j=1;j<=s;j++){
            if(i*(100+x)/100+j*(100+x)/100==s)if(max<i*(100+y)/100+j*(100+y)/100)max=i*(100+y)/100+j*(100+y)/100;
        }
        printf("%d\n",max);
    }
    return 0;
}



Measured memory_bytes: 2036
#include <stdio.h>
int main(){
 
  int n,i,j,k,c[4][13],y;
  char x;
 
  for (i = 0; i < 4; i++){
 
    for (j = 0; j < 13; j++){
 
      c[i][j]=0;
 
    }
 
  }
 
  scanf("%d",&n);
 
  for (k = 0; k < n*2; k++){
 
    scanf("%c %d",&x,&y);
 
    if (x == 'S'){
 
      c[0][y-1]=1;
 
    } else if (x == 'H'){
 
      c[1][y-1]=1;
 
    } else if (x == 'C'){
 
      c[2][y-1]=1;
 
    } else if (x == 'D'){
 
      c[3][y-1]=1;
 
    }
 
  }
 
    for (i = 0; i < 4; i++){
 
      for (j = 0; j < 13; j++){
 
    if (c[i][j] == 0){
 
      if (i == 0){
 
        printf("S %d",j+1);
 
      } else if (i == 1){
           
          printf("H %d",j+1);
           
      } else if (i == 2){
          
          printf("C %d",j+1);
           
          } else if (i == 3){
           
          printf("D %d",j+1);
 
        }
 
      printf("\n");
 
    }
 
      }
 
    }
     
    return 0;         
 
}


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

int main()
{
    int N, M;
    std::cin >> N >> M;
    std::vector<int> x(N + 1);
    for (int i = 0; i < M; i++) {
        int L, R;
        std::cin >> L >> R;
        L--; R--;
        x[L]++;
        x[R + 1]--;
    }

    for (int i = 1; i < N; i++)
        x[i] += x[i - 1];

    int valid_ic_card_count = 0;
    for (int i = 0; i < N; i++) {
        if (x[i] == M)
            valid_ic_card_count++;
    }

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


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
    int n, d;
    cin >> n >> d;
    vector<long long int> x(n), y(n);
    for(int i = 0; i < n; i++) cin >> x[i] >> y[i];

    int ans = 0;
    long long int limd = d;
    limd = limd * limd;
    for(int i = 0; i < n; i++){
        if(x[i]*x[i]+y[i]*y[i] <= limd) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6420
#define w 200001
p;main(n,m,j,i){
  long int k,a[w],A[w],b[w],B[w];
  scanf("%d%d%ld",&n,&m,&k);
  for(i=0;i<n;i++){
    scanf("%ld",&a[i]);
    //(i==0)&&(A[i]=B[i]=0);
    A[i+1]=A[i]+a[i];
  }
    
  for(i=0;i<m;i++){
    scanf("%ld",&b[i]);
    //if(i==0){B[i]=0;}
    B[i+1]=B[i]+b[i];
  }
  int mo=m;
        
  for(i=0;i<=n;i++){
    if(A[i]>k)break;
            
    for(j=mo;j>=0;j--){
      if(A[i]+B[j]<=k){
        if(i+j>p)p=i+j;
        mo=j;
        break;
      }
    }
  }
  printf("%d",p);
}

Measured memory_bytes: 7972
# stdin
INPUT_SENTENCES = 1
ss = [input() for i in range(INPUT_SENTENCES)][0].split()
K = int(ss[0])
X = int(ss[1])
# around X
black_min = X - K
black_max = X + K
print(' '.join([str(i) for i in range(black_min+1, black_max)]))

Measured memory_bytes: 3064
while(1):
    n,x=map(int,input().split())
    if(n==x==0):
        break
    count=0
    for i in range(1,min(n+1,x-2)):
        for j in range(i+1,min(n+1,(x-i)//2+1)):
            if(j+1 <= x-i-j <=n):
                count+=1
    print(count)


Measured memory_bytes: 5600
// C - Lining Up
// https://atcoder.jp/contests/arc066/tasks/arc066_a?lang=en

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define MAX 100000 + 4
ll n;
ll a[MAX];

int main() {
  scanf("%lld", &n);
  for (ll i=0; i<n; i++)
    scanf("%lld", &a[i]);

  ll b[n] = {0};
  ll start = 2;
  if (n%2==0) {
    // even
    start = 1;
    for (ll i=start; i<n; i+=2) {
      b[i] = 2;
    }
  } else {
    // odd
    start = 2;
    for (ll i=start; i<n; i+=2) {
      b[i] = 2;
    }
    b[0] = 1;
  }

  for (ll i=0; i<n; i++) {
    b[a[i]]--;
  }

  bool all_zero = true;
  for (ll i=0; i<n; i++) {
    if (b[i] != 0) {
      all_zero = false;
      break;
    }
  }
  if (!all_zero) {
    printf("0\n");
  } else {
    ll sum=1;
    ll mod=pow(10, 9) + 7;
    for (ll i=1; i<=n/2; i++) {
      sum = (sum * 2) % mod;
    }
    printf("%lld\n", sum);
  }
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using ull = unsigned long long;

typedef pair< int, int > Pi;
typedef pair< long long, long long > P;
typedef pair< long long, P > PP;
typedef pair< P, P > PPP;

const long long MOD = 1e9 + 7;
const long long INF = 5e18;
const int di[4] = { 1,0,-1,0 };
const int dj[4] = { 0,1,0,-1 };

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()

int n,ans;
int cnt[110];

void input(){
	cin>>n;
	return;
}

void solve(){
	for(int i=2;i<=n;i++){
		int j=i;
		for(int k=2;k<=n;k++){
			while(j%k==0){
				cnt[k]++;
				j/=k;
			}
		}
	}
	for(int i=2;i<=n;i++){
		if(cnt[i]>73)ans++;
	}
	for(int i=2;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(i==j)continue;
			if(cnt[i]>1&&cnt[j]>23)ans++;
		}
	}
	for(int i=2;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(i==j)continue;
			if(cnt[j]>1&&cnt[i]>23)ans++;
		}
	}
	for(int i=2;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(i==j)continue;
			if(cnt[i]>3&&cnt[j]>13)ans++;
		}
	}
	for(int i=2;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(i==j)continue;
			if(cnt[j]>3&&cnt[i]>13)ans++;
		}
	}
	for(int i=2;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(i==j)continue;
			for(int k=j+1;k<=n;k++){
				if(i==k||j==k)continue;
				if(cnt[i]>1&&cnt[j]>3&&cnt[k]>3)ans++;
				if(cnt[j]>1&&cnt[i]>3&&cnt[k]>3)ans++;
				if(cnt[k]>1&&cnt[i]>3&&cnt[j]>3)ans++;
			}
		}
	}
	cout<<ans<<endl;
	return;
}

int main(){
	input();
	solve();
	return 0;
}


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

using namespace std;

int main()
{
    int n,m,c;
    cin >> n >> m >> c;

    vector<int> b(m);
    for(int i=0;i<m;i++) cin >> b[i];

    int cnt=0;
    for(int i=0;i<n;i++){
        int sum=c;
        for(int j=0;j<m;j++){
            int a;
            cin >> a;
            sum+=a*b[j];
        }
        if(sum>0) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    A = LI()
    Q = I()
    d = collections.Counter(A)
    ans = []
    cursum = sum(A)
    for i in range(Q):
        b, c = LI()
        cursum -= b * d[b]
        d[c] += d[b]
        cursum += c * d[b]
        d[b] = 0
        ans.append(cursum)
    for a in ans:
        print(a)


main()



Measured memory_bytes: 102848
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<ll,ll>;


ll m=1000000007;

ll mod=1e9+7;
ll dp[2000+4];


int main()
{
 ll n,k;
 cin>>n>>k;
 vector<ll>p(n);
 vector<ll>c(n);
 rep(i,n)cin>>p[i];
 rep(i,n)cin>>c[i];
 rep(i,n)p[i]--;
 
 ll ans=-1000000000000; 
 rep(i,n){
     ll now=i;
     ll cnt=0;
     ll tot=0;
     while(1){
        now=p[now];
        tot+=c[now];
        cnt++;
        if(now==i)break;
     }
     now=i;
     ll sum=0;
     ll tmp=k;
     ll tmp2=0;
     while(0<tmp){
        now=p[now];
        tmp--;
        tmp2++;
        sum+=c[now];
        ans=max(ans,sum);
        if(0<tot){
         ll e=tmp/cnt;
         ans=max(ans,sum+tot*e);
        }
        if(tmp2==cnt+1)break;
     }
 }
 cout<<ans<<endl;
}
 


 

 




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

using namespace std;
using ll = long long int;

int main() {
	ll n;
	cin>>n;
	ll arr[n];
	ll sum = 0;
	for(ll i = 0; i < n; i++) {
		cin>>arr[i];
		sum ^= arr[i];
	}
	for(ll i = 0; i < n; i++) {
		cout<<(sum^arr[i])<<" ";
	}
	cout<<endl;
	return 0;
}


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

int main()
{
    string L;
    cin>>L;

    long long M = 1000000007;
    size_t N = L.size();
    vector<long long> e2(N+1), e3(N+1);
    e2[0] = e3[0] = 1;
    for (size_t i=1; i<=N; i++)
    {
        e2[i] = e2[i-1]*2%M;
        e3[i] = e3[i-1]*3%M;
    }

    int c = 0;
    long long ans = 0;
    for (size_t i=0; i<N; i++)
        if (L[i]=='1')
        {
            ans += e2[c]*e3[N-i-1];
            ans %= M;
            c++;
        }
    ans += e2[c];
    ans %= M;
    cout<<ans<<endl;
}


Measured memory_bytes: 2112
#include<iostream>
#include<string.h>

using namespace std;

int main(void){
	int n,m,hanaSum,taroSum,hanacr,tarocr,gap,hana[100],taro[100];
	
	while(cin>>n>>m,n&&m){
		
		hanaSum=0;
		taroSum=0;
		hanacr=0;
		tarocr=0;
		memset(taro,0,sizeof(taro));
		memset(hana,0,sizeof(hana));
		
		for(int i=0;i<n;i++){
			cin>>taro[i];
			taroSum=taroSum+taro[i];
		}
		for(int i=0;i<m;i++){
			cin>>hana[i];
			hanaSum=hanaSum+hana[i];
		}
		
		gap=hanaSum-taroSum;
		
		
		
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if(gap==2*(hana[j]-taro[i])){
					tarocr=taro[i];
					hanacr=hana[j];
					break;
				}
			}
			if(tarocr && hanacr){
				break;
			}
		}
		if(tarocr==0 && hanacr==0){
			cout<<-1<<endl;
		}else{
			cout<<tarocr<<" "<<hanacr<<endl;
		}
	}
	
	
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <stack>
#include <cctype>
#include <cmath>

using namespace std;

/* typedef */

typedef long long ll;

/* constant */

const int INF = 1 << 30;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */

/* function */
void printVec(vector<int> &vec);

/* main */
int main(){

    int n; cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    
    int q; cin >> q;
    int l, r, t;
    for (int i = 0; i < q; i++) {
        cin >> l >> r >> t;
        // swap_ranges(begin, end, swap_begin);
        // begin ~ end <-> swap_begin ~ swap_begin + (end - begin)
        swap_ranges(v.begin() + l, v.begin() + r, v.begin() + t);
    }

    printVec(v);

    return 0;
}

void printVec(vector<int> &vec) {
    for (int i = 0; i < vec.size(); i++) {
        if (i) cout << ' ' ;
        cout << vec[i];
    } cout << '\n';

}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define endl '\n'
#define debug(X) cout << #X << " = " << X << endl

using namespace std;

const int MD = 1e9 + 7;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	#ifdef UTP
	freopen("input.txt", "r", stdin);
	#endif
	int n; cin >> n;
	string s; cin >> s;
	map<char, int> freq;
	for (char c : s)
        freq[c]++;
    long long ans = 1;
	for (auto f : freq)
        ans = (ans * (f.second + 1)) % MD;
    cout << ans - 1 << endl;
	return 0;
}


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

vector<vector<int> > c(10,vector<int>(10));
int mp=1e9;

void dfs(int A,int sum){
  for(int i=0;i<10;i++){
    if(i==A){
      continue;
    }
    if(sum+c.at(A).at(i)<mp){
      if(i==1){
        mp=sum+c.at(A).at(i);
      }else{
        dfs(i,sum+c.at(A).at(i));
      }
    }
  }
}

int main(){
  int H,W;
  cin >> H >> W;
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      cin >> c.at(i).at(j);
    }
  }
  vector<int> v(10);
  for(int i=0;i<10;i++){
    mp=c.at(i).at(1);
    dfs(i,0);
    v.at(i)=mp;
  }
  int64_t ans=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      int A;
      cin >> A;
      if(A==-1){
        continue;
      }
      if(A==1){
        continue;
      }
      ans+=v.at(A);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
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; }
typedef long long ll;
typedef pair<int,int> P;

bool check(vector<P>& s){
    sort(s.rbegin(),s.rend());
    int h=0;
    for(auto p:s){
        if(h+p.first<0)return false;
        h+=p.second;
    }
    return true;
}

int main(){
    int n;
    cin >> n;
    vector<P> p;
    vector<P> m;
    int total = 0;
    rep(i,n){
        string s;
        cin >> s;
        int t=0,d=0;
        for(char c:s){
            if(c=='(')t++;
            else t--;
            chmin(d,t);
        }
        if(t>0)p.push_back(make_pair(d,t));
        else m.push_back(make_pair(d-t,-t));
        total += t;
    }
    if(check(p)&&check(m)&&total==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 11316
n=int(input())
import numpy as np
ab=np.array([[int(j)for j in input().split()]for i in range(n)])
a=np.median(ab[:,0])
b=np.median(ab[:,1])
if n%2:
    print(int(b-a+1))
else:
    print(int(2*b-2*a+1))

Measured memory_bytes: 63296
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())

int m, k;

void solve() {
  cin >> m >> k;
  if (k >= (1<<m)) {
    cout << -1 << endl;
    return;
  }
  if (m == 0) {
    cout << 0 << " " << 0 << endl;
    return;
  }
  if (m == 1) {
    if (k == 0) {
      cout << 0 << " " << 0 << " " << 1 << " " << 1 << endl;
      return ;
    }
    cout << -1 << endl;
    return;
  }
  REP(i, (1<<m)) if(i!=k){
    cout << i << " ";
  }
  cout << k << " ";
  for(int i = (1<<m)-1; i >= 0; i--) if(i!=k) {
    cout << i << " ";
  }
  cout << k << " " << endl;
}

int main() {
	solve();
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

string S;
long long K;

long long solve(string V) {
	vector<int> R; int cnt = 0;
	for (int i = 0; i < V.size(); i++) {
		cnt += 1;
		if (i + 1 == V.size() || V[i] != V[i + 1]) {
			R.push_back(cnt); cnt = 0;
		}
	}

	int ans = 0;
	for (int i = 0; i < R.size(); i++) ans += R[i] / 2;
	return ans;
}

int main() {
	cin >> S >> K;
	
	string S1 = S;
	string S2 = S + S;
	long long A1 = solve(S1);
	long long A2 = solve(S2);

	bool flag = false;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] != S[(i + 1) % S.size()]) flag = true;
	}
	if (flag == true) {
		cout << A1 + (A2 - A1) * (K - 1LL) << endl;
	}
	else {
		cout << 1LL * (long long)S.size() * K / 2LL << endl;
	}
	return 0;
}

Measured memory_bytes: 3576
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n;
    cin >> n;
    int ret = 0;
    vector<int> v(n), c(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> c[i];
        ret += max(0, v[i] - c[i]);
    }
    cout << ret << endl;
}


Measured memory_bytes: 256
/*
ID: amagica1
TASK: ariprog
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define NINF -INF
#define mp make_pair
#define boost() cin.tie(0); cin.sync_with_stdio(0)
#define For(i, a, b) for(int i=a; i<b; i++)
#define FOR(i, a, b) for(int i=a; i<=b; i++)
#define Rev(i, a, b) for(int i=a; i>b; i--)
#define REV(i, a, b) for(int i=a; i>=b; i--)
typedef long long ll;
typedef long double ld;
typedef int64_t l;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
const ll MOD = 1e9 + 7;
const int MAXN = 1000005;
ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
int N; string s;
int main() {
    //-----------FILE------------//
    // freopen("ariprog.in", "r", stdin);
    // freopen("ariprog.out", "w", stdout);
    //----------------------------//
    cin >> N >> s; string ret="";
    for(int i=0; i<s.length(); i++) {
        int t = (s[i] + N); if(t > 'Z') t -= 26;
        ret += (char)t;
    }
    cout << ret << '\n';
}


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

const int N = 2e5 + 5;
typedef long long LL;

int n, a[N], b[N];
LL ans;
map <int, int> M;

int main() {
	cin>>n;
	for(int i = 1; i <= n; i++) 
		cin>>a[i], b[i] = a[i];
	sort(b + 1, b + n + 1);
	for(int i = 1; i <= n; i++)
	    M[b[i]] = i;
	for(int i = 1; i <= n; i++)
	    a[i] = M[a[i]];
	for(int i = 1; i <= n; i++) 
		if(a[i]%2 != i%2) ans++; 
	cout<<ans/2<<endl;
	return 0;
}

Measured memory_bytes: 9100
N, K = map(int, input().split())
l = []
cmin = 0
cmax = 0
for i in range(K, N+2):
  cmin = 0
  cmax = 0
  cmin = i * (i-1) / 2
  cmax = (2*N - i + 1) * i / 2
  dif = cmax - cmin + 1
  l.append(dif)
print(int(sum(l)%(10**9 + 7)))

Measured memory_bytes: 16844
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
int main(){
  string s,t; cin>>s>>t;
  vector<char> vs,vt;
  rep(i,0,s.size()){
    vs.pb(s[i]);
  }
  rep(i,0,t.size()){
    vt.pb(t[i]);
  }
  sort(all(vs));
  sort(all(vt));
  reverse(all(vt));
  string s2="", t2="";
  rep(i,0,s.size()){
    s2 += vs[i];
  }
  rep(i,0,t.size()){
    t2 += vt[i];
  }
  string ans;
  if(s2<t2){
    ans = "Yes";
  }else{
    ans = "No";
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256