akhauriyash/Code-Regression huggingface dataset:
l = ["z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y"]
l2 = [0]*11

n = int(input())
for i in range(11):
  p = 0
  q = 0
  p = n%26
  if n==0 and p==0:
    l2[i]=""
  else:
    l2[i]=l[p]
    if p ==0:
      q = n - 26
    else:
      q = n - p
    n = q//26
print(l2[10]+l2[9]+l2[8]+l2[7]+l2[6]+l2[5]+l2[4]+l2[3]+l2[2]+l2[1]+l2[0])

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

int main(){
	int N, D;
	cin >> N >> D;
	int can = 2 * D + 1;
	int ans;
	if(N < can) ans = 1;
	else if(N % can == 0) ans = N / can;
	else ans = N / can + 1;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
#define mod(int)(1000000007)
using namespace std;
signed main() {
	int n = 0, ok = 100; string s, t; cin >> s >> t;
	if (s.size() < t.size()) { cout << "UNRESTORABLE" << endl; return 0; }
	for (int h = 0; h <= s.size() - t.size(); h++) {
		for (int i = 0; i < t.size(); i++) {
			if (s[h + i] != t[i] && s[h + i] != '?') {
				n = 1; break;
			}
		}
		if (n == 0) { ok = h; }
		n = 0;
	}
	if (ok == 100) { cout << "UNRESTORABLE" << endl; }
	else {
		for (int h = 0; h < s.size(); h++) {
			if (h >= ok && h < ok + t.size()) {
				cout << t[h - ok];
			}
			else {
				if (s[h] == '?') { cout << 'a'; }
				else { cout << s[h]; }
			}
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<min(a,b)+min(c,d)<<endl;
}










Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i = 0 ; i < n ; ++i)
#define rep1(i,n) for(int i = 1 ; i <= n ; ++i)
using namespace std;
typedef long long ll;
int n,wmax;
int w[110];
ll v[110];
ll dp[110][100010];
int main()
{
  cin >> n >> wmax;
  rep(i,n) cin >> w[i] >> v[i];

  rep(i,n+1){
    rep(j,wmax+1){
      dp[i][j] = 0;
    }
  }

  rep(i,n){
    rep(j,wmax+1){
      if(j-w[i]<0) dp[i+1][j] = dp[i][j];
      else dp[i+1][j] = max( dp[i][j] , dp[i][j-w[i]] + v[i] );
    }
  }
  
  cout << dp[n][wmax] << "\n";
  return 0;
}


Measured memory_bytes: 80128
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in )){
            while(true){
                int n = sc.nextInt();
                if (n == 0) {
                    break;
                }
                int[] scores = new int[n];
                double ave = 0, var = 0;
                for (int i = 0; i < scores.length; i++) {
                    scores[i] = sc.nextInt();
                    ave += scores[i];
                }
                ave = ave / scores.length;
                for (int i = 0;i < scores.length; i++){
                    var += (scores[i]-ave)*(scores[i]-ave);
                }
                var = var/ scores.length;

                System.out.println(Math.sqrt(var));
            }
        }
    }
}



Measured memory_bytes: 31744
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define llu unsigned long long
#define U unsigned int
#define SIZE 1000002
#define pie 3.14159265358979323
#define minuss 1e-6
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{

    ll t,n;
    cin>>t>>n;
    ll s[t+5];
    ll sum=0;
    for(int i=0; i<t; i++)
        cin>>s[i];

    sort(s,s+t);
    for(int i=0; i<t-n; i++)
    {
        sum=sum+s[i];
    }
    cout<<sum<<endl;

}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
using namespace std;
//using namespace __gnu_pbds;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long 
#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,arr,n) for(int i=arr;i<=n;i++)
#define repd(i,arr,n) for(int i=arr;i>=n;i--)
#define trav(arr,x) for(auto& arr:x)
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(arr) arr.size()
#define pi 3.14159265358979323846
#define MAX 500003
#define vi vector<int>
#define pii pair<int,int>
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int,vi,greater<int> >
//#define endl "\n"
 
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
const int mod=998244353;
int power(int a,int b)
{
    int ans=1;
    while(b)
    {
        if(b&1)
        {
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b>>=1;
    }
    return ans;
}

int32_t main()
{
    fast;
    int n;
    cin>>n;
    int ans=0;
    repa(i,1,n)
    {
        int val=n/i;

        val*=(val+1);
        val/=2;
        val*=i;
        ans+=val;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3644
package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func Create(A *[]int, L int) bool {
  S := make([][]int, 0)
  S = append(S, []int{0, 0})
  for _, a := range (*A) {
    if S[len(S) - 1][0] < a {
      if S[len(S) - 1][1] == 1 {
        S[len(S) - 1][0] = a
      } else {
        S = append(S, []int{a, 1})
      }
    } else {
      head, tail := 0, len(S) - 1
      for 1 < tail - head {
        body := (head + tail) / 2
        if S[body][0] < a {
          head = body
        } else {
          tail = body
        }
      }
      S = S[:tail + 1]
      S[tail][0] = a
      for i := tail; 0 <= i; i-- {
        if i == 0 {
          return false
        } else if S[i][1] < L {
          T := make([][]int, 0)
          j := i
          k := S[i][0]
          S[i][0]--
          if S[i][0] == S[i - 1][0] {
            j--
            if S[j][1] - S[i][1] == 1 {
              S[j][0]++
            } else {
              T = append(T, []int{k, S[i][1] + 1})
            }
          } else {
            T = append(T, []int{k, S[i][1] + 1})
          }
          if k < a {
            T = append(T, []int{a, 1})
          }
          S = append(S[:j + 1], T...)
          break
        }
      }
    }
  }
  return true
}

func main() {
  N := NextInt()
  A := NextIntVec()
  high, low := N, 0
  for 1 < high - low {
    med := (high + low) / 2
    if Create(&A, med) {
      high = med
    } else {
      low = med
    }
  }
  Write(high)
  Output()
}

Measured memory_bytes: 12800
n, m = map(int, input().split())
apple = []
for _ in range(n):
    apple.append(list(map(int, input().split())))
apple = sorted(apple)
msum = 0
ans = 0
for i in apple:
    msum += i[1]
    if msum < m:
        ans += (i[0]*i[1])
    elif msum == m:
        ans += (i[0]*i[1])
        break
    else:
        a = m - (msum - i[1])
        ans += (i[0]*a)
        break
print(ans)

Measured memory_bytes: 61528
## coding: UTF-8

K = int(input())

tmp = 0
stat = True
for i in range(1, K+10):
    tmp *= 10
    tmp %= K
    tmp += 7
    tmp %= K
    #print(i, tmp)
    if(tmp == 0):
        print(i)
        stat = False
        break

if(stat):
    print(-1)



'''
seven = []
tmp = 0
for i in range(10**4+10):
    tmp *= 10
    tmp += 7
    seven.append(tmp)


#OK = []
#kasetu = []
#for K in range(1):


#K = 999983
#tmp = 0

for K in range(1, 200):
    for j in range(10**4 + 10):
        #tmp *= 10
        #tmp += 7
        if(seven[j] % K == 0):
        #if(tmp % K == 0):
            print('K:{}, j+1:{}, seven[j]/K:{}'.format(K, j+1, seven[j]/K))
            #print('K:{}, j+1:{}, tmp:{}'.format(K, j+1, tmp))
            #OK.append(K)
            break
        #if( K % 2 != 0 and K % 5 != 0):
            #kasetu.append(K)

#print(OK)
#print(kasetu)
#print(OK == kasetu)
'''


Measured memory_bytes: 63324
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    string w;
    cin >> w;
    int num[26] = {0};
    rep(i, (int)w.size()) {
        ++num[w[i]-'a'];
    }
    rep(i, 26) {
        if (num[i]%2==1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

	int Month, Day,month;
	int count = 0;
	scanf("%d %d", &Month, &Day);

	for (month = 4; month <= Month; month++) {
		for (int d2 = 2; d2 <= (Day / 10); d2++) {
			for (int d1 = 2; d1 <= 9; d1++) {

				if (month == (d1*d2)&&((d1+(d2*10))<=Day)) {
					count++;
				}
			}
		}
	}
	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 100'000;
const int LOGN = 19;

int n, m, k;

void solve(int test) {
  string s;
  cin >> n >> s;
  set<int> st1, st2, st3;
  for (char c : s) {
    c -= '0';
    for (int x : st2) {
      st3.insert(x * 10 + c);
    }
    for (int x : st1) {
      st2.insert(x * 10 + c);
    }
    st1.insert(c);
  }
  cout << st3.size() << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 384
use proconio::{input,fastout};

#[fastout]
fn main() {
  input! {
    m1: usize,
    d1: usize,
    m2: usize,
    d2: usize,
  }
  let ans = if m1 < m2 {
    1
  } else {
    0
  };
  println!("{}",ans);
}

Measured memory_bytes: 2180
#ABC146-B ROT N
N = int(input())
S = input()

ans = []
for c in S:
    letter_offset = ord(c) - ord('A') + N # ord: int→ascii
    if letter_offset < 26:
        ans.append(chr(letter_offset + ord('A')))               # chr: ascii→int
    else:
        ans.append(chr(letter_offset - 26 + ord('A')))
print("".join(ans))

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const ll MOD = 1e9+7;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"[";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"]";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&p)
{o<<"{"<<p.first<<", "<<p.second<<"}";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj)
{o<<"{";for(auto itr=obj.begin();itr!=obj.end();++itr)o<<(itr!=obj.begin()?", ":"")<<*itr;o<<"}";return o;}


const int N = 1e5;
vector<bool> visited(N,false);
vector<int> cnt(N,0);
vector<vector<int>> G(N);
set<P> ans;

void dfs(int n, int par){
  visited[n] = true;

  for(auto t : G[n]){
    if(t != par && !visited[t]) {
      dfs(t,n);
      if(cnt[t]%2==1){
        int x=t,y=n;
        if(x>y) swap(x,y);
        ans.erase(P(x,y));
        ans.insert(P(y,x));
        cnt[x]--; cnt[y]++;
      }
    }
  }
  return;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n,m,a,b;
  cin >> n >> m;

  if(m%2==1){
    cout << -1 << endl;
    return 0;
  }
  for(int i=0; i<m; i++){
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);

    if(a>b) swap(a,b);
    cnt[a]++; 
    ans.insert(P(a,b));
  }
  dfs(a,-1);

  for(auto p : ans){
    cout << p.first+1 << " " << p.second+1 << endl;
  }

  return 0;
}


Measured memory_bytes: 22912
#include<stdio.h>
int nxt[200000];
int bfr[200000];
bool out[200000];
int a[200000];
int q[1000];

int main(){
	int n,m,k,i,j;
	scanf("%d %d %d",&n,&m,&k);
	for(i=0;i<m;i++)scanf("%d",&a[i]);
	for(i=0;i<k;i++)scanf("%d",&q[i]);
	for(i=0;i<n;i++){
		nxt[i]=(i+1)%n;
		bfr[i]=(i+n-1)%n;
		out[i]=false;
	}
	int p=0;
	for(i=0;i<m;i++){
		for(j=0;j<a[i];j++){
			if(a[i]%2==0)p=nxt[p];
			else p=bfr[p];
		}
		out[p]=true;
		bfr[nxt[p]]=bfr[p];
		nxt[bfr[p]]=nxt[p];
		p=nxt[p];
	}
	for(i=0;i<k;i++)printf("%d\n",out[q[i]]?0:1);
	return 0;
}

Measured memory_bytes: 3568
K,X = map(int,input().split())
lower = X-(K-1) if X-(K-1)>-1000001 else -1000000
upper = X+(K-1) if X+(K-1)<1000001 else 1000000
result=""
for i in range(lower,upper+1):
    result = result+str(i)+" "
print(result[:-1])

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

int GCD(int a, int b);

int main() {
	int K;
	ll sum = 0;

	cin >> K;

	for (int i = 1; i <= K; i++) {
		for (int j = 1; j <= K; j++) {
			for (int k = 1; k <= K; k++) {
				sum += GCD(GCD(i, j),k);
			}
		}
	}

	cout << sum << endl;
	return 0;
}

int GCD(int a, int b) {
	if (a < b) swap(a, b);
	int r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
 
int h[100000], mCost[100000];
int Nstones;
 
int main() {
	scanf("%d", &Nstones);
	for (int i = 0; i < Nstones; i++) {
		scanf("%d", &h[i]);
	}
	mCost[1] = abs(h[0] - h[1]);
	for (int i = 2; i < Nstones; i++) {
		mCost[i] = min(abs(h[i] - h[i - 1]) + mCost[i - 1], abs(h[i] - h[i - 2]) + mCost[i - 2]);
	}
	printf("%d", mCost[Nstones - 1]);
}

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


int main(int argc, char *argv[]) {
  // C-style stdio functions should not be used.
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  int A, B; cin >> A >> B;
  if (B % A == 0) cout << A + B << endl;
  else            cout << B - A << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int limit = 100010;
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d) {
	depth[v] = d;
	for (auto &e : tree[v]) {
		if (e.to == p) continue;
		dfs(e.to, v, d + e.cost);
	}
}

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

	for (int i = 0; i < n - 1; ++i) {
		int a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		tree[a].push_back({b, c});
		tree[b].push_back({a, c});
	}

	int q, k;
	cin >> q >> k;
	k--;

	dfs(k, -1, 0);
	for (int i = 0; i < q; ++i) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		cout << depth[x] + depth[y] << endl;
	}

	return 0;
}

Measured memory_bytes: 14336
#include <iostream>
// #include <cassert>
#include <vector>
#include <algorithm>
#include <climits>


// #include <deque>
// #include <stack>
// #include <set>
// #include <map>
// #include <string>
// #include <unordered_set>
// #include <unordered_map>
// #include <queue>
// #include <tuple>

// #include <cmath>
// #include <numeric>

using namespace std;
typedef long long ll;
typedef long l;
typedef pair<long,long> pll;
typedef pair<int,int> pii;
typedef pair<int,long> pil;
typedef pair<long,int> pli;
const char el = '\n';

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


    string s; cin>>s; cin.ignore();
    int Q;
    cin>>Q;
    cin.ignore();
    string prefix ="";
    string suffix = "";
    bool isreversed=false;
    int T, F; char ch;
    for (int t=0; t<Q; ++t) {
        cin>>T;
        if (T==1) {
            isreversed = !isreversed;
        } else {
            cin>>F>>ch; cin.ignore();
            if ( (!isreversed && F==2) || (isreversed && F==1) ) {
                suffix +=ch;
            } else {
                prefix += ch;
            }

        }
        
    }

    reverse(prefix.begin(),prefix.end());

    string ans = prefix+s+suffix;
    if (isreversed) {
        reverse(ans.begin(),ans.end());
    }

    cout<<ans<<el;
    
    // long n, m;
    // cin>>n>>m; cin.ignore();

}



Measured memory_bytes: 1300
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int x,n; cin >> x >> n;
    map<int,bool> ng;
    rep(i,n){
        int p; cin >> p;
        ng[p]=true;
    }
    int res=-100, min=INF;
    for(int i=-150; i<=150; i++){
        if(ng[i]==true)continue;
        if(abs(x-i)<min){
            min=abs(x-i);
            res=i;
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
char s[N], a[N], b[N];

int main()
{
	int q;
	scanf("%s%d", s, &q);
	int n = strlen(s);
	int flag = 1;
	int na = 0, nb = 0;
	while (q--) {
		int t, f; char c;
		scanf("%d", &t);
		if (t == 1) {
			flag = !flag;
		} else {
			scanf("%d %c", &f, &c);
			if (flag) {
				if (f == 1) a[na++] = c;
				else b[nb++] = c;
			} else {
				if (f == 1) b[nb++] = c;
				else a[na++] = c;
			}
		}
	}
	if (flag) {
		for (int i = na-1; i >= 0; i--) putchar(a[i]);
		for (int i = 0; i < n; i++) putchar(s[i]);
		for (int i = 0; i < nb; i++) putchar(b[i]);
	} else {
		for (int i = nb-1; i >= 0; i--) putchar(b[i]);
		for (int i = n-1; i >= 0; i--) putchar(s[i]);
		for (int i = 0; i < na; i++) putchar(a[i]);
	}
	return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define pai 3.1415926535

int main(void) {
	char S[16];
	scanf("%s", S);

	int count = 0;
	for (int i = 0; i < strlen(S); i++) {
		if (S[i] == 'x') {
			count++;
		}
	}

	if (15-count>=8 ) {
		printf("YES\n");
	}
	else {
		printf("NO\n");
	}


	return 0;
}

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

int main() {
	int pas[3] = {}, juice[2] = {};
	int pm = 0, jm = 0;
	std::cin >> pas[0] >> pas[1] >> pas[2] >> juice[0] >> juice[1];

	pm = std::min({pas[0],pas[1],pas[2]});
	jm = std::min(juice[0],juice[1]);

	std::cout << pm + jm - 50 << std::endl;

	return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
signed main(void){
    string s; int k;
    cin>>s>>k;
    string tmp = s;
    itn add=0, add2=0;
    int cnt = 0;
    /// first
    for(int i=1;i<s.size();i++){
        if(s[i] == s[i-1]){
            if(cnt) cnt++;
            else cnt=2;
        }else{
            add += cnt/2;
            cnt = 0;
        }
    }
    add += cnt/2;
            cnt = 0;
    /// second
    s += s;
    
    for(int i=0;i<s.size();i++){
        if(s[i] == s[i-1]){
            if(cnt) cnt++;
            else cnt=2;
        }else{
            //cout<<cnt<<endl;
            add2 += cnt/2;
            cnt = 0;
        }
    }
    add2 += cnt/2;
            cnt = 0;
    int add3 = 0;
    s += tmp;
    //cout<<s<<endl;
    for(int i=0;i<s.size();i++){
        if(s[i] == s[i-1]){
            if(cnt) cnt++;
            else cnt=2;
        }else{
            //cout<<cnt<<endl;
            add3 += cnt/2;
            cnt = 0;
        }
    }
    add3 += cnt/2;
            cnt = 0;
    //cout<<add3<<endl;
    int ans2 = INF;
    int sa = add2 - add, sa2 = add3 - add;
    //cout<<sa2<<endl;
    //cout<<add2<<' '<< add<<endl;
    int ans = add;
    //cout<<ans<<endl;
   
    ans += (k-1)*sa;
    if((k-1)%2 == 0){
        ans2 = add;
        ans2 += (k-1)/2 * sa2;
    }
    //cout<<ans<<' '<<ans2<<endl;
    cout<<min(ans, ans2)<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	vector<ll> v,v1;
	for(ll i=0;i<n;i++)
	{
		ll a,b;
		cin>>a>>b;
		v.push_back(a);
		v1.push_back(b);
	}
	sort(v.begin(),v.end());
	sort(v1.begin(),v1.end());
	reverse(v.begin(),v.end());
	if(n%2)
	{
		cout<<v1[n/2]-v[n/2]+1;
	}
	else
	{
		cout<<v1[n/2]+v1[(n/2)-1]-(v[n/2]+v[(n/2)-1])+1;
	}
	
}

Measured memory_bytes: 6668
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long long power(long long a, long long b,long long m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %m;
        a = a * a %m;
        b >>= 1;
    }
    return res;
}

vector<vector<int> >adj;
int vis[100005][2];
int ans[2];
int tot=0;
void dfs(int ver,int x)
{
    ans[x]++;
    vis[ver][x]=1;

    for(auto i:adj[ver])
    {
        if(vis[i][(x+1)%2]==0)
            dfs(i,(x+1)%2);
    }   
}


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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n,m;
    cin>>n>>m;
    adj.resize(n+1);
    int x,y;
    for(int i=0;i<m;i++)
    {
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    dfs(1,0);
    tot+=ans[0]*ans[1]-m;
    int res=0;
    for(int i=1;i<=n;i++)
    {
        if(vis[i][0]+vis[i][1]==2)
            res++;
    }    
    tot-=res*res;
    tot+=(res*(res-1))/2;
    cout<<tot;
    
} 
    


Measured memory_bytes: 12492
#include <iostream>

using namespace std;

int main()
{
    long long n ;
    cin>>n ;
    long long arr[n] ;
    for(long long i = 0 ; i < n ; ++i)
        cin>>arr[i] ;
    long long ans = -1e17+5 , MAX = -1e17+5;
    for(long long i = n-1 ; i >= 0 ; --i)
        ans = max(ans , MAX - arr[i]) , MAX = max(MAX , arr[i]);
    return cout<<ans<<"\n" , 0 ;
}



Measured memory_bytes: 4668
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

int main()
{
    int n;
    cin >> n;
    int a[n],b[n];
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    int ans = 0;
    for(int i = 0; i < n; i++){
        int tmp = 0;
        for(int j = 0; j <= i; j++){
            tmp += a[j];
        }
        for(int j = i; j < n; j++){
            tmp += b[j];
        }
        ans = max(ans,tmp);
    }
    cout << ans;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>

using namespace std;
using Int = long long;
typedef pair<int,int> Pi; typedef pair<Int,Int> Pl;
constexpr int mod = 1e9+7;
constexpr int INF32 = numeric_limits<int>::max();
constexpr Int INF64 = numeric_limits<Int>::max();
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rer(i,l,r) for(int(i)=(l); (i)<(r); ++(i))
#define rep(i,n) rer(i,0,n)
#define gnr(i,l,r) for(int (i)=(r)-1; (i)>=(l); --(i))
#define pri(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(i,n-1)cout<<a[i]<<' '; if(n)cout<<a[n-1]<<'\n';}
#define prip(p) cout<<(p).fi<<' '<<(p).se<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,m,_,x,y,q;
string s,sb;
bool ok;
char cf,cb;

int main(){
  cin.tie(nullptr); ios::sync_with_stdio(0);
  //cout<<fixed<<setprecision(20);
  
  double a,b,c,d,e,f;
  while(cin>>a>>b>>c>>d>>e>>f){
    double ay=(a*f-c*d)/(a*e-b*d),ax=(c-b*ay)/a;
    printf("%.3f %.3f\n",ax,ay);
  }
}


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

int main(){
	int n;	cin>>n;
	vector<string> S(n);
	for(int i=0;i<n;i++){
		cin>>S[i];
		sort(S[i].begin(), S[i].end());
	}
	vector<int> Alpha(26,0);
	for(int i=0;i<S[0].length();i++){
		Alpha[S[0][i]-'a']++;
	}

	for(int i=1; i<n; i++){
		vector<int> Beta(26,0);
		for(int j=0; j<S[i].length(); j++){
			Beta[S[i][j]-'a']++;
		}

		for(int j=0;j<26;j++){
			Alpha[j]=min(Alpha[j],Beta[j]);
		}
	}

//	for(int i=0;i<26;i++){
//		if(Alpha[i]){
//			printf("%c:%d\n",i+'a',Alpha[i]);
//		}
//	}
	string ans="";
	for(int i=0;i<26;i++){
		for(int j=0;j<Alpha[i];j++){
			ans.push_back('a'+i);
		}
	}

	cout<<ans<<endl;

	return 0;
}


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

int main(){
  int count=0;
  int N;
  cin>>N;
  vector<int>A(N+1);
  vector<int>B(N);
  vector<int>C(N-1);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  A[N]=0;
   for(int i=0;i<N;i++){
    cin>>B[i];
  }
   for(int i=0;i<N-1;i++){
    cin>>C[i];
  }
  for(int i=0;i<N;i++){
    count=count+B[A[i]-1];
      if(A[i]+1==A[i+1]){
        count=count+C[A[i]-1];
      }
  }
  cout<<count;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main {

    public static void main(String[] args) {

	final Scanner stdin = new Scanner(System.in);

	int m = 0;
	int sumNum = 0;
	int line = 0;

	while ( stdin.hasNextLine() ) {

	    final String[] input = stdin.nextLine().split( "," );
	    final int mpn = Integer.parseInt( input[0] );
	    final int num = Integer.parseInt( input[1] );
	    m += mpn * num;
	    sumNum += num;
	    line++;
	    
	}
	System.out.println( m );
	System.out.println( ( int )Math.round( ( double )sumNum / ( double )line ) );
    }
    
}

Measured memory_bytes: 17136
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#define EPS (1e-10)
#define PI 3.14159265358979323846264
using namespace std;


 
double rad(double d)
{
  return d*(PI/180.0);
}

int main()
{
  int m;
  while(cin >> m,m)
    {
      double v,areaA,areaB;
      areaA = areaB = 0;
      double ano = 360;
      for(int i=0;i<m-1;i++)
	{
	  cin >> v;
	  areaA += sin(rad(v));
	  ano -= v;
	}
      areaA += sin(rad(ano));
 
      cin >> m;
      ano = 360;
      for(int i=0;i<m-1;i++)
	{
	  cin >> v;
	  areaB += sin(rad(v));
	  ano -= v;
	}
      areaB += sin(rad(ano));
            

      if(fabs(areaA-areaB) < EPS)
	cout << 0 << endl;
      else if(areaA > areaB)
	cout << 1 << endl;
      else 
	cout << 2 << endl;
      
    }
  return 0;
}

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

#define debug(x) cout<<#x<<"="<<x<<endl
#define pii pair<int,int>
#define ll long long
#define pb push_back
#define mp make_pair

int n,a[100003];
map <int,int> m;

int main(){
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i];
		m[a[i]]++;
	}
	sort(a,a+n);
	for (int i=n-1;i>=0;i--){
		if (m[a[i]]<2) continue;
		m[a[i]]-=2;
		for (int j=i-1;j>=0;j--){
			if (m[a[j]]<2) continue;
			cout<<(ll)a[i]*a[j];
			return 0;
		}
	}
	cout<<0;
	return 0;
}

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

typedef long long ll;
typedef long double ld;

#define n1		      "\n"
#define B                     begin()
#define E                     end()
#define F                     first
#define S                     second
#define pb                    push_back
#define pf                    push_front
#define popb                  pop_back()
#define popf                  pop_front()

const int BIG=1e5+55;
const int BIGG=1e9+7;
const ll BIGGE=1e12+55;
const double SML=(1e-7);

using namespace std;

    int a[100][100];
    ll ans;

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

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin >>n >>m;
    for (int i=0; i<10; i++)
        for (int j=0; j<10; j++)
            cin >>a[i][j];
    floyd();
    for (int i=0; i<n; i++)
        for (int j=0; j<m; j++) {
            int x;
            cin >>x;
            if (x == 1 || x == -1)
                continue;
            ans += a[x][1];
        }
    cout <<ans <<n1;


    return 0;
}


Measured memory_bytes: 3576
#include <iostream>
#include <map>
#include <cstring>

using namespace std;

int main(int argc, char *argv[]) {
  int w, q;
  bool wall[100] = {false};
  map<int, int*> cats;
  while (true) {
    cin >> w >> q;
    if (w == 0 && q == 0)
      break;

    for (int i = 0; i < q; i++) {
      char c;
      cin >> c;
      if (c == 's') {
        int id, width;
        cin >> id >> width;
        bool slept = false;
        for (int j = 0; j < w; j++) {
          if (slept) {
            break;
          } else if (wall[j]) {
            continue;
          } else {
            for (int k = j; k < j+width; k++) {
              if (k == w || wall[k]) {
                slept = false;
                break;
              } else {
                slept = true;
              }
            }
            if (slept) {
              cout << j << endl;
              int *tmp = new int[2];
              tmp[0] = j;
              tmp[1] = j+width;
              cats.insert(pair<int, int*>(id, tmp));
              for (int k = j; k < j+width; k++)
                wall[k] = true;
              break;
            }
          }
        }
        if (!slept)
          cout << "impossible" << endl;
      } else {
        int id;
        cin >> id;
        for (int j = cats[id][0]; j < cats[id][1]; j++)
        wall[j] = false;
        cats.erase(id);
      }
    }
    cout << "END" << endl;
    memset(wall, false, sizeof(bool) * w);
    cats.clear();
  }
  return 0;
}

Measured memory_bytes: 1208
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int a1 = sc.nextInt();
		int a2 = sc.nextInt();
		int a3 = sc.nextInt();
		int cost = Math.abs(Math.max(Math.max(a1,a2),a3) - Math.min(Math.min(a1,a2),a3));

		System.out.println(cost);

	}
}

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

int main() {
	int n;
	cin >> n;
	vector<int> h(n), a(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		if (i == 0) a[i] = 1;
		else a[i] = h[i] - h[i - 1];
	}
	bool ok = true;
	int pos = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] > 0) pos++;
		else if (a[i] < -1) ok = false;
		else if (a[i] == -1) {
			if (pos == 0) ok = false;
			else pos = 0;
		}
	}

	if (ok) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>

using namespace std;

int  rank_by_mark(char c);
char mark_by_rank(int i);

int main()
{  
    int  n;
    char mark;
    int  rank;
    int  cards[4][13];
       
    for (int i = 0; i < 4; i++) {
         for (int j = 0; j < 13; j++) {
	      cards[i][j] = 0;
         }
    }      
     
    do {
        cin >> n;        
    } while (n > 52);
      
    for (int i = 0; i < n; i++) {   
         cin >> mark >> rank;                                         
         cards[rank_by_mark(mark)][rank - 1] = 1;
    }
        
    for (int i = 0; i < 4; i++) {
         for (int j = 0; j < 13; j++) {
	      if (cards[i][j] == 0) {
                  cout << mark_by_rank(i) << " " << j + 1 << endl;
              }
         }
    }
    
    return (0);
}

int rank_by_mark(char c)
{
    if (c == 'S') {
        return (0);
    } else if (c == 'H') {
        return (1);
    } else if (c == 'C') {
        return (2);
    } else if (c == 'D') {
        return (3);
    } else {
        exit(0);
    }
}

char mark_by_rank(int i)
{
     if (i == 0) {
         return ('S');
     } else if (i == 1) {
         return ('H');
     } else if (i == 2) {
         return ('C');
     } else if (i == 3) {
         return ('D');
     } else {
         exit(0);
     }
}

Measured memory_bytes: 1164
#include<stdio.h>
#include<stdlib.h>
int main()
{
    const int value = 753;
    const int MAX = 999;  
    long long s, a[10], i, result, dif = MAX;
    scanf("%lld", &s);
    for(i = 0; s != 0; i++)
    {
        a[i] = s % 10;
        s /= 10;
    }
    for(int j = 0; j <= i - 3; j++)
    {
        result = a[j] + a[j + 1] * 10 + a[j + 2] * 100;
        if(dif > abs(result - value))
        {
            dif = abs(result - value);
        }
    }
    printf("%d\n", dif);
    return 0;
}


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

int main(void){

    char ans[][10]={"AKIHABARA","KIHABARA","AKIHBARA","AKIHABRA","AKIHABAR","KIHBARA","KIHABRA",
                    "KIHABAR","AKIHRA","AKIHBAR","AKIHABR","AKIHBR","KIHABR","KIHBAR","KIHBRA","KIHBR"};


    char str[51];
    scanf("%s",str);

    for(int i=0;i<16;i++){
        if(strcmp(str,ans[i])==0) {
            printf("YES\n");
            return 0;
        }
    }

   printf("NO\n");
    

    return 0;
}

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

int main() {
  string c[2];
  cin >> c[0] >> c[1];
  int i;
  for (i = 0; i < 3; i++) {
    if (c[0].at(i) != c[1].at(2 - i)) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  int K,S,Z,sum=0,ans=0;
  cin >> K >> S;
  rep(X,0,K+1){
    rep(Y,0,K+1){
      Z = S - (X+Y);
      if(Z <= K && Z >= 0) ans++;
    }
  }
  cout << ans << endl;
}


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

/*Starry Sky Tree*/
/*Range Add Min(Max) Query*/
/*区間加算、区間Min,区間Max*/

class RMAQ{
public: 
  
  //遅延用の型  
  struct T{
    bool type; //0 - empty   , 1 - update
    int value;
    T():type(0),value(0){}
    T(bool type,int value):type(type),value(value){}
  };

  //比較可能な主データ型
  struct D{
    int value;
    D():value(0){} /*適切な値にする!!!!!!*/
    D(int value):value(value){}
    bool operator < (D a)const {return value < a.value;} //merge用
  };
  
  int n;
  vector<D> dat;
  vector<T> td;
  D returnD = D(0); // 範囲外の時に返す値。
  
  RMAQ(){n=-1;}
  RMAQ(int n_){
    n=1;
    while(n<n_)n*=2;
    td.resize(2*n-1,T());
    dat.resize(2*n-1,D());
  }
  
  D merge(D a,D b){return a.value + b.value;}
  
  void delay(int k,int len){
    if(td[k].type==0) return;
    int v = td[k].value;
    td[k].type = 0;
    td[k].value = 0;
    
    len /= 2;
    int l = k*2+1,r = k*2+2;
    dat[l].value = v * len; td[l].type = 1; td[l].value = v;
    dat[r].value = v * len; td[r].type = 1; td[r].value = v;
  }

  D update(int k,int x, int len){
    dat[k].value = x * len;
    td[k].type = 1;
    td[k].value = x;
    return dat[k];
  }
  
  //[a,b)の値をx加算　add(a,b,x)
  D query(int a,int b,int x,bool flg=true,int k=0,int l=0,int r=-1){
    if(r==-1) r=n, assert(a <= n && b <= n);
    if(r<=a||b<=l) return flg? dat[k]:returnD;
    if(a<=l&&r<=b) return flg? update(k, x, r - l):dat[k];
    
    delay(k, r - l);
    D vl = query(a,b,x,flg,k*2+1,l,(l+r)/2);
    D vr = query(a,b,x,flg,k*2+2,(l+r)/2,r);
    if(flg) dat[k] = merge(vl,vr);
    return merge(vl,vr);
  }
  
  //[a,b)の合計値を得る　find(a,b);
  int find(int a,int b){
    D res = query(a,b,0,false);
    return res.value;
  }
};


signed main(){
  int n,q;
  cin>>n>>q;
  
  RMAQ rmaq(n);
  while(q--){
    int cmd;
    cin>>cmd;
    if(cmd == 0){
      int s,t,x;
      cin>>s>>t>>x;
      rmaq.query(s,t+1,x);
    }
    if(cmd == 1){
      int s,t;
      cin>>s>>t;
      cout<<rmaq.find(s,t+1)<<endl;
    }
  }
  
  return 0;
}



Measured memory_bytes: 8928
from functools import reduce
from fractions import gcd

n = int(input())
a = list(map(int, input().split()))
A = list(set(a))
ans = [reduce(gcd, A)]

if len(A) == 1:
    print(A[0])
    exit()
for i in A:
    b = sorted(A)
    b.remove(i)
    if a.count(i) == 1:
        ans.append(reduce(gcd, b))

print(max(ans))


Measured memory_bytes: 89580
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if((a+b) > (c+d)){
    cout << "Left" <<  endl;
  }else if((a+b) == (c+d)){
    cout << "Balanced" << endl;
  }else{
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		long[] sum = new long[n + 1];
		long[] com = new long[n + 1];
		long[] subcom = new long[n + 1];

		int i;
		for(i = 0; i < n; i++) {
			a[i] = scan.nextInt();
			sum[a[i]]++;
		}
		for(i = 0; i < n + 1; i++) {
			if(sum[i] == 0 || sum[i] == 1)
				continue;
			subcom[i] = ((sum[i] - 2) * (sum[i] - 1)) / 2;
		}

		long total = 0;
		for(i = 0; i < n + 1; i++) {
			if(sum[i] == 0 || sum[i] == 1)
				continue;
			com[i] = ((sum[i] - 1) * sum[i]) / 2;
			total += com[i];
		}

		for(i = 0; i < n; i++) {
			System.out.println(total - com[a[i]] + subcom[a[i]]);
		}
	}
}

Measured memory_bytes: 103312
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
#include <fstream>
using namespace std;
typedef pair<long long,long long>p;
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
vector<long long> divisor(long long n) {
	vector< long long> ret;
	for (long long i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return (ret);
}
long long mod = 1e9 + 7;
struct LazySegmentTree {
private:
	int n;
	vector<int> node, lazy;
	vector<bool> lazyFlag;

public:
	LazySegmentTree(vector<int> v) {
		int sz = (int)v.size();
		n = 1; while (n < sz) n *= 2;
		node.resize(2 * n - 1);
		lazy.resize(2 * n - 1, INT_MAX);
		lazyFlag.resize(2 * n - 1, false);

		for (int i = 0; i<sz; i++) node[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; i--) node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
	}

	void lazyEvaluate(int k, int l, int r) {
		if (lazyFlag[k]) {
			node[k] = lazy[k];
			if (r - l > 1) {
				lazy[k * 2 + 1] = lazy[k * 2 + 2] = lazy[k];
				lazyFlag[k * 2 + 1] = lazyFlag[k * 2 + 2] = true;
			}
			lazyFlag[k] = false;
		}
	}

	void update(int a, int b, int x, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		lazyEvaluate(k, l, r);
		if (b <= l || r <= a) return;
		if (a <= l && r <= b) {
			lazy[k] = x;
			lazyFlag[k] = true;
			lazyEvaluate(k, l, r);
		}
		else {
			update(a, b, x, 2 * k + 1, l, (l + r) / 2);
			update(a, b, x, 2 * k + 2, (l + r) / 2, r);
			node[k] = min(node[2 * k + 1], node[2 * k + 2]);
		}
	}

	int find(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		lazyEvaluate(k, l, r);
		if (b <= l || r <= a) return INT_MAX;
		if (a <= l && r <= b) return node[k];
		int vl = find(a, b, 2 * k + 1, l, (l + r) / 2);
		int vr = find(a, b, 2 * k + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
};
typedef pair<int, p> pai;
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout <<fixed<< setprecision(16);
	string s;
	cin >> s;
	long long ans = 0;
	int acnt = 0;
	int bflag = 0;
	string ss = "";
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'B'&&s[i + 1] == 'C') {
			ss += 'X';
			i += 1;
		}
		else {
			ss += s[i];
		}
	}
	for (int i = 0; i < ss.length(); i++) {
		if (ss[i] == 'A') {
			acnt += 1;
		}
		else {
			if (ss[i] == 'X')ans += acnt;
			else {
				acnt = 0;
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 916
N = int(input())
A_B_C = []
for i in range(N):
    A_B_C.append(tuple(map(int, input().split())))

DP = [[0]*3 for i in range(N)]

DP[0][0] = A_B_C[0][0]
DP[0][1] = A_B_C[0][1]
DP[0][2] = A_B_C[0][2]
for i in range(1, N):
    for j in range(3):
        j_a = (j + 1) % 3
        j_b = (j + 2) % 3
        DP[i][j] = max(DP[i-1][j_a], DP[i-1][j_b]) + A_B_C[i][j]

print(max(DP[N-1][0], DP[N-1][1], DP[N-1][2]))

Measured memory_bytes: 76120
#include <stdio.h>

void swap(int *x, int *y);
void sort(int a[]);
int add(int a[]);

int main(void)
{
	int a1[10], a2[10];
	int i, j;
	
	for (i = 0; i < 10; i++){
		scanf("%d", &a1[i]);
	}
	for (i = 0; i < 10; i++){
		scanf("%d", &a2[i]);
	}
	
	sort(a1);
	sort(a2);
	
	printf("%d %d\n", add(a1), add(a2));
	
	return (0);
}

void sort(int a[])
{
	int i, j;
	int tmp;
	
	for (i = 0; i < 10; i++){
		for (j = 0; j <= 10; j++){
			if (a[i] > a[j]){
				swap(&a[i], &a[j]);
			}
		}
	}
}

int add(int a[])
{
	int ans;
	int i;
	
	ans = 0;
	
	for (i = 0; i < 3; i++){
		ans += a[i];
	}
	return (ans);
}
void swap(int *x, int *y)
{
	int tmp;
	tmp = *x;
	*x = *y;
	*y = tmp;
}

Measured memory_bytes: 596
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
using namespace std;

int main () {
    char b;
    cin>>b;
    if(b=='A')cout<<'T'<<endl;
    if(b=='T')cout<<'A'<<endl;
    if(b=='C')cout<<'G'<<endl;
    if(b=='G')cout<<'C'<<endl;
    return 0;
}

Measured memory_bytes: 256
a = [int(input()) for i in range(5)]
b = [int(str(i)[-1]) for i in a.copy()]
c = []
d = []

for i in b:
  if i == 0:
    c.append(0)
  else:
    c.append(10 - i)
print(sum(a) + sum(c) - max(c))

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;

int main(){
	while(1){
		int n;
		long road[10][10];
		scanf(" %d", &n);
		if(n==0) break;
		
		memset(road, -1, sizeof(road));
		for(int i=0; i<10; ++i) road[i][i]=0;
		 
		int city=0; //街の数
		for(int i=0; i<n; ++i){
			int a, b, c;
			scanf(" %d %d %d", &a, &b, &c);	
			road[a][b]=road[b][a]=c;
			if(city<a) city=a;
			if(city<b) city=b;
		}
		
		long ans[10]={0};	
		
		//各街を根としてbfs
		for(int i=0; i<=city; ++i){
			long cost[10]; //その街までの最小コスト
			for(int j=0; j<=city; ++j) cost[j]=1000000000; //とりあえず大きいので初期化
			
			queue<int> que;
			cost[i]=0;
			que.push(i);
			while( !que.empty() ){
				int v=que.front();
				que.pop();
				for(int j=0; j<10; ++j){
					if(v==j) continue;
					
					if(road[v][j]>=0 && cost[v]+road[v][j]<cost[j]){
						cost[j]=cost[v]+road[v][j];
						que.push(j);	
					}	
				}	
			}	
			/*
			printf("city %d to:\n", i);
			for(int j=0; j<=city; ++j) printf(" %d is %ld\n", j, cost[j]);
			*/
			for(int j=0; j<=city; ++j) ans[i]+=cost[j];
		}
		
		int a=0;
		for(int i=1; i<=city; ++i)
			if(ans[a]>ans[i]) a=i;	
			
		printf("%d %ld\n", a, ans[a]);
	}
}	

Measured memory_bytes: 1192
# しゃくとり法
# https://qiita.com/drken/items/ecd1a472d3a0e7db8dce
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_3_C&lang=jp

def main
  nums_len, q_len = ARGF.gets.split.map(&:to_i)

  nums = ARGF.gets.split.map(&:to_i)
  q_nums = ARGF.gets.split.map(&:to_i)

  q_nums.each do |q|
    ans = 0

    # 左端からスタート
    r = 0
    sum = 0
    0.upto(nums.length-1) do |l|
      # [left, right) の総和が q 以下となる最大の right を求める
      while r < nums.length && sum + nums[r] <= q
        sum += nums[r]
        r += 1
      end

      # この時点で r は(条件を満たす最大のidx)+1となっている。
      # ※r側を開区間と考えると、rは（条件を満たす最大のidx）になっている。
      # (r - l) が可能な組み合わせ数
      ans += r - l

      # leftを動かす準備
      if r == l
        # r と l が同じ位置の場合、rを動かす必要がある。
        # そして、sumはすでに0のはずなので減算しない
        r += 1
      else
        # leftが右に動くので減算しておく
        sum -= nums[l]
      end
    end

    puts ans
  end
end

if __FILE__ == $0
  main
end



Measured memory_bytes: 12856
#include<bits/stdc++.h>
using namespace std;
#define int  long long
#define tc(t)  int t; cin>>t; while(t--)
#define f(n)    for(int i=0;i<n;i++)
#define endl   "\n"
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 string user;
 cin>>user;
 int val=0;
 for(auto x:user)
 {
     if(x=='+') val++;
     else val--;


 }
 cout<<val<<endl;






}

Measured memory_bytes: 3656