akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int m, k;
    cin >> m >> k;
    if (k>=1<<m) {
        cout << "-1" << endl;
        return 0;
    }
    if (m==0) {
        cout << "0 0" << endl;
        return 0;
    }
    if (m==1) {
        if (k==1) {
            cout << "-1" << endl;
            return 0;
        }
        cout << "0 0 1 1" << endl;
        return 0;
    }
    rep(i, 1<<m) {
        if (i==k) continue;
        cout << i << " ";
    }
    cout << k << " ";
    for (int i=(1<<m)-1; i>=0; i--) {
        if (i==k) continue;
        cout << i << " ";
    }
    cout << k << endl;

    return 0;
}


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

using namespace std;

void fastio() {
	cin.tie(nullptr);
	cin.sync_with_stdio(false);
}

using LL = long long;
using LD = long double;

const LL MOD = 1e9+7;
const LL INF = LLONG_MAX;
const LL N = 1e6+1;

#define F first
#define S second

int main() {
	fastio();
	
	LL x;
	cin >> x;
	cout << (1^x) << "\n";
}

Measured memory_bytes: 3608
N,A,B = map(int,input().split())
if (A-B)%2==0:
  print((B-A)//2)
  exit()
else:
  p = N - A
  q = B - 1
  r = A - 1
  s = N - B
  if p < q:
    print(s + 1 + (p-s-1)//2)
  elif p >= q:
    print(r + 1 + (q-r-1)//2)

Measured memory_bytes: 3064
'''
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineering College

'''
from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd 
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]

def bo(i):
    return ord(i)-ord('a')

file = 0

def solve():
    



    # for _ in range(ii()):

    n=ii()
    a=li()
    a.sort(reverse=True)
    if(n==1):
        print(0)
        exit(0)
    ans=a[0]
    k=n-2
    for i in range(1,n):
        if(k==0):
            break
        if(k==1):
            ans+=a[i]
            k-=1
        else:
            ans+=2*a[i]
            k-=2
    print(ans)










  
















if __name__ =="__main__":

    if(file):

        if path.exists('input1.txt'):
            sys.stdin=open('input1.txt', 'r')
            sys.stdout=open('output1.txt','w')
        else:
            input=sys.stdin.readline
    solve()

Measured memory_bytes: 103304
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

alias Pair = Tuple!(int, "a", int, "b");

void main() {
    string n;
    scan(n);
    n.map!(ch => ch == '1' ? "9" : "1").joiner.writeln;
}






void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


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

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

  vector<int> masu(N);
  for (int i = 0; i < N; i++) {
    cin >> masu.at(i);
  }

  int res = 0;
  for (int i = 1; i < N+1; i++) {
    int a = masu.at(i-1);
    if (i % 2 == 1 && a % 2 == 1) {
      res++;
    }
  }
  cout << res << endl;
}


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


int main(void) {
	int h, w;
	cin >> h >> w;
	vector<string> a(h);
	for (int i = 0; i < h; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < h; i++) {
		int tmp = 0;
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '.')
				tmp++;	
		}
		if (tmp == w) {
            /*
			for (int k = i; k < h - 1; k++) {
				a[k] = a[k + i];
			}
            */
			a.erase(a.begin() + i);
			i--;
			h--;
		}
	}
	for (int i = 0; i < w; i++) {
		int tmp = 0;
		for (int j = 0; j < h; j++) {
			if (a[j][i] == '.') {
				tmp++;
			}
		}
		if (tmp == h) {
			for (int k = 0; k < h; k++) {
				for (int l = i; l < w - 1; l++) {
					a[k][l] = a[k][l + 1];
				}
              	a[k].pop_back();
            }
            w--;
            i--;
		}
	}
    //cout << endl;
	for (int i = 0; i < h; i++) {
		cout << a[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    lint N,K;
    cin >> N >> K;
    cout << (lint)pow(K-1,N-1)*K << endl;
}

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

int main(){
    int i,no=0,counter=0;
    string w,t;

    cin >> w;
    while(cin >> t){
        if(t == "END_OF_TEXT") break;
        for(i=0;i<t.size();i++){
            // ここをcctypeのisupperで判定してたらずっとWAだった．．
            if(t[i] >= 'A' && t[i] <= 'Z') t[i] += ('a' - 'A');
            if(w[i] != t[i]){
                no = 1;
                break;
            }
        }
        if(i == w.size() && no == 0){
            counter++;
        }
        no = 0;
    }
    cout << counter << endl;
    return 0;
}


Measured memory_bytes: 3172
n,m,k=map(int, input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

#Aの累積和
cumA = [0]*(n+1)
for i in range(n):
    cumA[i+1] = cumA[i] + A[i]
#Bの累積和
cumB = [0]*(m+1)
for i in range(m):
    cumB[i+1] = cumB[i] + B[i]

ans = 0
j = m

for i in range(n+1):
    if cumA[i]>k: #Ai>kであれば、どのようにjを選んでもAi+Bj<=kとなることはない
        break
    while cumB[j] > k-cumA[i] and j>0: #各iについて Bj <= k - Aiを満たす最大のjを求める 
        j -= 1
    ans = max(ans,i+j)
print(ans) 

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;

#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_LARGE = 1000000100;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

void Main()
{
	int n,a,b;
	cin >> n >> a >> b;
	cout << min(a*n,b) << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 256
/*Allah Vorosha*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define n_p next_permutation
#define p_p prev_permutation
#define in insert
#define rev reverse
#define pf push_front
#define pob pop_back
#define uniq(v)         v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define all(x) (x).begin(),(x).end()
#define pof pop_front
#define ios ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define scn scanf
#define prt printf
#define rep(i, a, n) for(int i = a; i < n; i++)
#define mod 1000000007
#define yes cout << "YES\n"
#define no cout << "NO\n";
#define take for(auto &it : a) cin >> it;
#define out cout << a << "\n";
#define l_b lower_bound
#define u_b upper_bound
#define Max 100005
template<typename T> T mymax(T x, T y) {
    return (x > y ? x : y);
}

using namespace std;

const int N = 1e5 + 5;

long long be(long long x,long long y){
    long long res=1;
    while(y){
        if(y&1){
            res*=x;
            res%=mod;
        }
        x*=x;
        x%=mod;
        y>>=1;
    }
    return res;
}

void solve() {
    auto cnt = [&](ll a)
    {
        int c = 0;
        while(a) {
            a /= 10;
            c++;
        }
        return c;
    };
    ll n;
    cin >> n;
    int mn = 1e8;
    for(ll i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ll b = n / i;
            int p = max(cnt(i), cnt(b));
            mn = min(mn, p);
        }
    }
    cout << mn;
}

int main() {

    solve();
    return 0;
}


Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;    
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    int r = scanf("%d", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    int r = scanf("%lld", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, double i)
{
    printf("%.20f", i);
    return my;
}

constexpr char BR = '\n';


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

int main()
{
    int N;
    io >> N;
    vi A(N);
    for (int i = 0; i < N; i++)
        io >> A[i];
    
    ll ans = 0;
    int curA = A[0];
    for (int i = 1; i < N; i++)
    {
        if (curA > A[i])
        {
            ans += curA - A[i];
        }
        else
        {
            curA = A[i];
        }
    }
    
    io << ans << BR;
}

Measured memory_bytes: 4052
# encoding: utf-8
N = int(input())
TA = [list(map(int, input().split())) for i in range(N)]

for i in range(1, N):
    Tprev, Aprev = TA[i - 1]
    Ti, Ai = TA[i]
    # skip
    if Ti >= Tprev and Ai >= Aprev: continue
    # process
    if (Tprev / Ti) > (Aprev / Ai): rate = -(-Tprev // Ti)
    else: rate = -(-Aprev // Ai)
    # print("#", i, rate)
    TA[i][0] = Ti * rate
    TA[i][1] = Ai * rate

print(sum(TA[-1]))

Measured memory_bytes: 3188
c=0
while True:
    x,y=map(int,input().split())
    if x==0 and y==0:
        break
    
    if x<y:
        x,y=y,x
    
    while True:
        if y==0:
            break
        
        x=x%y
        x,y=y,x
        c+=1
        
    print(x,c)
    c=0


Measured memory_bytes: 5604
import sys

input = sys.stdin.readline

n, q= map(int, input().split())

S = input()
S = S.replace('\n','')
s_list = list(S)

l = [0 for i in range(q)]
r = [0 for i in range(q)]
for i in range(q):
    l[i], r[i] = map(int, input().split())

ac_sum_list = [0 for i in range(len(s_list))]
tmp = ""
ac_sum = 0
for i,s in enumerate(s_list):
    if tmp + s == "AC":
        ac_sum += 1
    ac_sum_list[i] = ac_sum
    tmp = s


for i in range(q):
    l_index = l[i]
    r_index = r[i]
    l_ac = ac_sum_list[l_index-1]
    r_ac = ac_sum_list[r_index-1]
    print(r_ac - l_ac)

Measured memory_bytes: 19920
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
using namespace std;
#define MAX 2147483647
long aray[400002];
int n;

int right(int k){
  return 2*k+2;
}
int left(int k){
  return 2*k+1;
}
int parent(int k){
  return (k-1)/2;
}
long query(int a,int b,int k,int l,int r){
  long res;
  //if (n==1)res = aray[0];
  if(r<=a || b<=l)res = MAX;
  else if(a<=l && r<=b)res = aray[k];
  else res = min(query(a,b,left(k),l,(l+r)/2),query(a,b,right(k),(l+r)/2,r));
  return res;
}
long findmin(int a,int b){
    return query(a,b,0,0,n);
}
void update(int k,long x){
  k = k+n-1;
  aray[k] =x;
  while(k>0){
    k=parent(k);
    aray[k]=min(aray[left(k)],aray[right(k)]);
  }
}
int main(){
  int com,q,x,y,p=2,i=0;
  cin>>n>>q;
  while(n>pow(p,i))i++;
  n = pow(p,i);
  p = n*2;
  for(i=0;i<p;i++)aray[i]=MAX;
  for(i=0;i<q;i++){
    cin>>com>>x>>y;
    if(!com)update(x,y);
    else cout<<findmin(x,y+1)<<endl;
  }
  //cout<<"---------------"<<endl;
  //for(i=0;i<p-1;i++)cout<<aray[i]<<endl;
  return 0;
}



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

using namespace std;

#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, a, b) for (int i = a; i < b; i++)
#define MP(a, b) make_pair(a, b)

int main()
{
	int res;
	cin >> res;
	cout << res/3 << endl;
	return 0;
}


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

int main() {
	ios_base::sync_with_stdio( false );

	string S;
	cin >> S;

	string p = "ACGT";
	int result = 0;

	for( int i = 0; i < S.size(); ++i ) {
		int x = S.size() - i;

		for( int j = i; j < S.size(); ++j ) {
			if( p.find_first_of( S[j] ) == string::npos ) {
				x = j - i;
				break;
			}
		}

		if( x > result ) { result = x; }
	}

	cout << result << endl;

	return 0;
}


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

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<int> h(N + 2);
	for (int i = 0; i < N; i++) cin >> h[i];

	vector<int> dp(N + 2, INF);
	dp[0] = 0;
	for (int i = 0; i < N; i++) {

		dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
		dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
	}

	cout << dp[N - 1];

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	string str;
	cin>>str;
	int ans = 0;
	int n = str.size();
	int ac = 0;
	for(int i=0;i<n-1;i++){
		if( str[i] == 'A' ){
			ac ++ ;
		}
		else if ( str[i] == 'B' && str[i+1] == 'C' ){
			ans += ac;
			i++;
		}
		else{
			ac = 0;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 644
#include<iostream>
#include<map>

using namespace std;

int main()
{
    map <int,int> mp;
    int n,i;
    int flag=0;
    
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>mp[i];
    }
    for(i=0;i<n;i++)
    {
        if(mp[i]%2==0)
        {
            if(mp[i]%3==0||mp[i]%5==0)
            {
                continue;
            }
            else
            {
                flag=1;
                break;
            }
        }
    }
    if(flag)
    {
        cout<<"DENIED"<<endl;
    }
    else
    {
        cout<<"APPROVED"<<endl;
    }
    return 0;
}







Measured memory_bytes: 256
def main():
    n = int(input())
    s1 = input()
    s2 = input()
    mod = 10**9 + 7
    h = "h"
    v = "v"
    d = ""
    i = 0
    while i < n:
        if s1[i] == s2[i]:
            d += v
        else:
            d += h
            i += 1
        i += 1
    c = 3 + 3 * (d[0] == h)
    for i in range(len(d) - 1):
        if d[i] == v:
            c = c * 2 % mod
        else:
            if d[i + 1] == h:
                c = c * 3 % mod
    print(c)

if __name__ == '__main__':
    main()

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

using namespace std;
typedef long long ll;

#define rep(i , j , n) for(long long i = j ; i <= n ; i++)
const ll N = 123456;

int b[N];
int c[N];
vector < ll > ans[N];
int cnt[N];

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

    int n , m;
    cin >> n >> m;

    rep(i , 1 , n) cin >> c[i] >> b[i];

    rep(i , 1 , n) {
        ans[c[i]].push_back(b[i]);
    }

    multiset < ll > available;

    int res = 0;

    for(int i = m - 1 ; i >= 0 ; i--) {
        for(ll x : ans[m - i]) {
            available.insert(x);
        }
        if(!available.empty()) {
            res += *available.rbegin();
            available.erase(prev(available.end()));
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 9728
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String x = sc.next();
		String y = sc.next();
		
		int ans = x.compareTo(y);
		if (ans > 0) {
			System.out.println(">");
		} else if (ans >= 0) {
			System.out.println("=");
		} else {
			System.out.println("<");
		}
	}
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll A,B,K;
  cin>>A>>B>>K;
  if(K<=A){
    cout<<A-K<<" "<<B<<endl; 
  }
  else{
    cout<<0<<" "<<max((ll)0,B+A-K)<<endl; 
  }
}


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

int main(){
  int H,W,h,w;
  cin >> H >> W>> h >> w;
  int ans = (H-h)*(W-w);
  
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);
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 (a > b) { a = b; return 1; } return 0; }

int N;
string S;

bool solve(vb &isS) {
	FOR(i, 2, N + 1) {
		if (isS[i - 1]) {
			if (S[i - 1] == 'o') {
				isS[i] = isS[i - 2];
			}
			else isS[i] = !isS[i - 2];
		}
		else {
			if (S[i - 1]  == 'o')isS[i] = !isS[i - 2];
			else isS[i] = isS[i - 2];
		}
	}
	if (isS[0] == isS[N]) {
		REP(i, N)if ((isS[(i + N - 1) % N] ^ isS[(i + 1) % N]) != ((S[i] == 'o') ^ (isS[i])))
			return false;
		return true;
	}
	return false;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	cin >> S;
	vb isS(N + 1);
	vvb loop({ {true,true},{true,false},{false,true},{false,false} });
	REP(i, 4) {
		isS[0] = loop[i][0];
		isS[1] = loop[i][1];
		if (solve(isS)) {
			REP(i, N) {
				cout << (isS[i]?'S':'W');
			}
			cout << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 592
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <iomanip>
 
using namespace std;
 
typedef long long ll;
typedef pair <long long, long long> pll;
 
ll mod = 998244353;
 
int main(){
  ios_base::sync_with_stdio(false);
  ll n;
  cin >> n;
  cout << n + n*n + n*n*n;
}

Measured memory_bytes: 3652
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd
import sys
#input = sys.stdin.readline

import copy
"""
from collections import *
N,A=map(int,input().split())
X=list(map(int,input().split()))
G=2501
dp=[[0 for i in range((N+1)*G)] for n in range(N)]

X[0]

dp[0][G+X[0]]=1

for n in range(1,N):

    for i in range(len(dp[0])):
        if (X[n]+G)>=0:
            if dp[n-1][i-(X[n]+G)]:
                dp[n][i]=dp[n-1][i-(X[n]+G)]+dp[n-1][i]
            else:
                dp[n][i]=dp[n-1][i]
        else:
            dp[n][i]=dp[n-1][i]
    dp[n][G+X[n]]+=1
    #print([(dp[n][i],i//G,i%G,i%G//(i//G),i) for i in range(len(dp[0])) if dp[n][i]])

print(sum([dp[-1][i] for i in range(len(dp[0])) if i//G and (i%G)%(i//G)==0 and (i%G)//(i//G)==A]))


Measured memory_bytes: 134992
#include<stdio.h>
#include<string.h>
int main(void){
    char S[20],T[20];
    scanf("%s %s",S,T);
    for(int i=0;i<strlen(S);i++){
        if(S[i]!=T[i]){
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;
}


Measured memory_bytes: 1724
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    long[] a=new long[n];
    for(int i=0;i<n-1;i++)a[sc.nextInt()-1]++;
    for(int i=0;i<n;i++)System.out.println(a[i]);
    
  }
}


Measured memory_bytes: 72020
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define ms(s,x) memset(s,x,sizeof(s))
#define pb push_back
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;

const double PI = acos(-1.0);
const double eps = 1e-8;
const ll MOD = 1e9+7;
const int MAXN = 1e5+5;

int main()
{
    int a[5];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);
    if ((a[0] == a[1] && a[0] != a[2]) || (a[1] == a[2] && a[0] != a[1]))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var nums = ReadIntArray();
            var n = nums[0];
            var m = nums[1];
            var a = ReadIntArray().Select(x => new Price(x));
            var set = new SortedSet<Price>(a);
            for (int i = 0; i < m; i++)
            {
                var max = set.Max;
                set.Remove(max);
                max.Discount();
                set.Add(max);
            }
            var result = set.Sum(x => (long)x.Value);
            Console.WriteLine(result);
            ReadString();
        }

        public static string ReadString()
        {
            return Console.ReadLine();
        }

        public static string[] ReadStringArray()
        {
            return ReadString().Split(' ');
        }

        public static int[] ReadIntArray()
        {
            return ReadStringArray().Select(x => int.Parse(x)).ToArray();

        }

        public static int ReadInt()
        {
            return int.Parse(ReadString());
        }
    }

    class Price : IComparable<Price>
    {
        public int Value { get; private set; }
        public int Id = NewId();

        private static int _prevId;
        static int NewId()
        {
            return ++_prevId;
        }


        public Price(int value)
        {
            Value = value;
        }

        public void Discount()
        {
            Value /= 2;
        }

        public int CompareTo(Price other)
        {
            var result = Value.CompareTo(other.Value);
            if (result == 0)
            {
                return Id.CompareTo(other.Id);
            }
            else
            {
                return result;
            }
        }
    }
}


Measured memory_bytes: 35292
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

void solve() {
    ll a,b,c,n;
    string s, t;
    ll ans;
    string text;
    ll sum = 0;

    cin  >> n;

    ll d[100];
    rep(i,n) {
        ll a;
        cin >> a;
        d[i] = a;
    }

    rep(i, n-1){
        Rep(j, i+1, n){
            sum += d[i] * d[j];
        }
    }

    std::cout << sum << endl; 
    // std::cout << text << endl; 
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    solve();
    // stop
        return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

struct move_coin{int from_y, from_x, to_y, to_x;};

std::vector<move_coin> ans;
int a[500][500];

void move(int from_y, int from_x, int to_y, int to_x){
  if(a[from_y][from_x]%2==0) return;
  move_coin m;
  m.from_y = from_y+1, m.from_x = from_x+1, m.to_y = to_y+1, m.to_x = to_x+1;
  ans.push_back(m);
  a[from_y][from_x]--;
  a[to_y][to_x]++;
}

int main(){
  int h,w;
  cin >> h >> w;
  REP(i,h)REP(j,w){
    cin >> a[i][j];
  }
  REP(i,h){
    if(i%2==0){
      REP(j,w-1) move(i,j,i,j+1);
      if(i!=h-1) move(i,w-1,i+1,w-1);
    }else{
      REP(j,w-1) move(i,w-j-1,i,w-j-2);
      if(i!=h-1) move(i,0,i+1,0);
    }
  }
  cout << ans.size() << endl;
  for(auto m : ans){
    printf("%d %d %d %d\n", m.from_y, m.from_x, m.to_y, m.to_x);
  }
  return 0;
}


Measured memory_bytes: 5104
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

string s[2222];
P p[2222][2222];
bool u[2222][2222];
int d[2222][2222],c[4][2222][2222];
int n,m;
void dfs(int xx,int yy, P q) {
  u[xx][yy]=1;
  rep(i,4) {
    int x=xx+dx[i],y=yy+dy[i];
    if(!check(n,m,x,y)||s[x][y]=='0'||q==P(x,y)||u[x][y]) continue;
    p[x][y]=P(xx,yy);
    dfs(x,y,P(xx,yy));
  }
}

void Main() {
  int q;
  cin >> n >> m >> q;
  rep(i,n) R s[i];
  rep(i,n)rep(j,m) p[i][j]=P(-2,-2);
  rep(i,n)rep(j,m) {
    if(!u[i][j]&&s[i][j]=='1') {
      d[i+1][j+1]++;
      dfs(i,j,P(-1,-1));
    }
  }
  rep(i,n)rep(j,m+1)d[i+1][j]+=d[i][j];
  rep(i,n+1)rep(j,m)d[i][j+1]+=d[i][j];
  rep(i,n)rep(j,m) {
    if(s[i][j]=='1'&&p[i][j]==P(i-1,j)) c[0][i][j+1]++;
  }
  rep(i,n)rep(j,m) {
    if(s[i][j]=='1'&&p[i][j]==P(i+1,j)) c[1][i][j+1]++;
  }
  rep(i,n)rep(j,m) {
    if(s[i][j]=='1'&&p[i][j]==P(i,j-1)) c[2][i+1][j]++;
  }
  rep(i,n)rep(j,m) {
    if(s[i][j]=='1'&&p[i][j]==P(i,j+1)) c[3][i+1][j]++;
  }
  rep(i,n+1)rep(j,m+1) {
    c[0][i][j+1]+=c[0][i][j];
    c[1][i][j+1]+=c[1][i][j];
    c[2][i+1][j]+=c[2][i][j];
    c[3][i+1][j]+=c[3][i][j];
  }
  while(q--) {
    ll x1,y1,x2,y2,cnt=0;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--,y1--,x2--,y2--;
    cnt+=c[0][x1][y2+1]-c[0][x1][y1];
    cnt+=c[1][x2][y2+1]-c[1][x2][y1];
    cnt+=c[2][x2+1][y1]-c[2][x1][y1];
    cnt+=c[3][x2+1][y2]-c[3][x1][y2];
    ll ans=d[x2+1][y2+1]-d[x2+1][y1]-d[x1][y2+1]+d[x1][y1];
    pr(ans+cnt);
  }
}

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


Measured memory_bytes: 145024
//love yjl forever
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int INF=0x3f3f3f3f;
ll n;
int main()
{
/*	freopen("","r",stdin);
	freopen("","w",stdout);*/
	int i;
	cin>>n;
	ll x=n/500;
	n=n-x*500;
	ll y=n/5;
	
	cout<<x*1000+y*5<<endl;
}

Measured memory_bytes: 256
import sys
a = []
for _ in range(3):
    a_ = list(map(int, input().split()))
    a.append(a_)
n = int(input())
b = []
for i in range(n):
    b_ = int(input())
    b.append(b_)
d = [[0]*3 for _ in range(3)]
for i in range(3):
    for j in range(3):
        for k in b:
            if k == a[i][j]:
                d[i][j] = 1
                break
for i in range(3):
    if d[i][0] == 1 and d[i][1] == 1 and d[i][2] == 1:
        print("Yes")
        sys.exit()
    elif d[0][i] == 1 and d[1][i] == 1 and d[2][i] == 1:
        print("Yes")
        sys.exit()
if d[0][0] == 1 and d[1][1] == 1 and d[2][2] == 1:
    print("Yes")
    sys.exit()
elif d[2][0] == 1 and d[1][1] == 1 and d[0][2] == 1:
    print("Yes")
    sys.exit()
print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;
char c[10][10];

signed main(){
	int h, w;
    cin >> h >> w;
    rep(i, 0, h){
        rep(j, 0, w){
            cin >> c[i][j];
        }
        c[i][w] = '.';
    }
    bool f = true;
    int x = 0;
    rep(i, 0, h){
        rep(j, x, w + 1){
            if(c[i][j] == '#'){
                c[i][j] = '.';
            }else{
                x = j - 1;
                break;
            }
        }
    }
    rep(i, 0, h) rep(j, 0, w) if(c[i][j] == '#') f = false;
    if(f) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N;
  cin >> N;
  for(int i=1;;++i){
	int sum = 0;
	for(int d=1;d<=i;++d){
	  if(i % d == 0)
		++sum;
	}
	if(sum == N){
	  cout << i << endl;
	  break;
	}
  }

  return 0;
}



Measured memory_bytes: 3132
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <deque>
using namespace std;
typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);	
	int n, m; cin >> n >> m;
	vector<pair<int, int>> v;
	for (int i = 0; i < m; i++) {
		int x, y; 
		cin >> x >> y;
		v.push_back({ x,y });
	}
	int x, y;
	if (n == 1)x = 0, y = 9;
	else if (n == 2)x = 10, y = 99;
	else if (n == 3)x = 100, y = 999;

	for (int i = 0; i <= 1000; i++) {
		if (x <= i && i <= y) {
			vector<int> tmp;
			int t = i;
			while (t > 0) {
				tmp.push_back(t % 10); t /= 10;
			}
			if (tmp.empty())tmp.push_back(0);
			bool f = false;
			for (int j = 0; j < m; j++) {
				if (tmp[n - v[j].first] != v[j].second) {
					f = true; break;
				}
			}
			if (!f) {
				cout << i << '\n'; return 0;
			}
		}
	}
	cout << -1 << '\n';



}




Measured memory_bytes: 256
s = input().strip()
max_l = 0
for i in range(len(s)):
    for j in range(i, len(s)):
        if set(s[i:j+1]).issubset({'A', 'C', 'G', 'T'}):
            max_l = max(max_l, j+1 - i)

print(max_l)

Measured memory_bytes: 3060
#include<stdio.h>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<math.h>
#include<algorithm>
using namespace std;

#define INF 987654321
#define ll long long

string s;
vector<int> v[2];
int dp[16001][2]; //토글링
int X, Y;

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

	cin >> s;
	cin >> X >> Y;

	int cnt = 0, ty = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == 'F') cnt++;
		else
		{
			v[ty].push_back(cnt);
			cnt = 0;
			ty = 1 - ty;
		}
	}
	if (cnt) v[ty].push_back(cnt);

	//i = 0 예외 처리: 로봇은 처음에 오른쪽을 보고 있다.
	dp[8000 + v[0][0]][1] = 2;
	for (int i = 1; i < v[0].size(); i++)
	{
		for (int j = 0; j < 16001; j++)
		{
			if (dp[j][i % 2] == i + 1)
			{
				if (j + v[0][i] <= 16001)
					dp[j + v[0][i]][1 - i % 2] = i + 2;
				if (j - v[0][i] >= 0)
					dp[j - v[0][i]][1 - i % 2] = i + 2;
			}
		}
	}

	if (dp[X+8000][v[0].size() % 2] != v[0].size() + 1)
	{
		cout << "No";
		return 0;
	}

	for (int j = 0; j < 16001; j++)
		dp[j][0] = dp[j][1] = 0;

	dp[8000][0] = 1;
	for (int i = 0; i < v[1].size(); i++)
	{
		for (int j = 0; j < 16001; j++)
		{
			if (dp[j][i % 2] == i + 1)
			{
				if (j + v[1][i] <= 16001)
				{
					dp[j + v[1][i]][1 - i % 2] = i + 2;
				}
				if (j - v[1][i] >= 0)
					dp[j - v[1][i]][1 - i % 2] = i + 2;
			}
		}
	}

	if (dp[Y+8000][v[1].size() % 2] != v[1].size() + 1)
	{
		cout << "No";
		return 0;
	}
	
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 512
def cmb(n,r,mod):
  if r<0 or r>n:
    return 0
  r=min(r,n-r)
  return g1[n]*g2[r]*g2[n-r]%mod

n,m=map(int,input().split())
mod=10**9+7

g1=[1,1]
g2=[1,1]
inverse=[0,1]
 
for i in range(2,m+2):
  g1.append((g1[-1]*i)%mod)
  inverse.append((-inverse[mod%i]*(mod//i))%mod)
  g2.append((g2[-1]*inverse[-1])%mod)

f=[0,1]
for i in range(2,n+2):
  f.append(f[-1]*i%mod)

x=[1]
for i in range(m-n+1,m+1):
  x.append(x[-1]*i%mod)
x.reverse()
ans=0
for i in range(len(x)):
  if i%2==1:
    ans-=cmb(n,i,mod)*x[i]
  else:
    ans+=cmb(n,i,mod)*x[i]
  ans%=mod
print((ans*f[n]*cmb(m,n,mod))%mod)

Measured memory_bytes: 166716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int x,y,a,b,c;
    int t;
    cin >> x >> y >> a >> b >> c;
    priority_queue<pair<int, int>> q;
    for(int i=0;i<a;i++){
        cin >> t;
        q.push({t,0});
    }
    for(int i=0;i<b;i++){
        cin >> t;
        q.push({t,1});
    }
    for(int i=0;i<c;i++){
        cin >> t;
        q.push({t,2});
    }

    ll cnt[] = {0,0,0};
    ll ans = 0;
    while(x+y > cnt[0] + cnt[1] + cnt[2]){
        int v, k;
        tie(v,k) = q.top();
        q.pop();
        if(k == 0 && cnt[0] >= x) continue;
        if(k == 1 && cnt[1] >= y) continue;
        ans += v;
        cnt[k]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6384
a, b = map(int, input().split())

if(a > 0):
    print("Positive")
elif(a < 0 and b >= 0):
    print("Zero")
elif(a < 0 and b < 0):
    if((abs(a-b)+1)%2 == 0):
        print("Positive")
    else:
        print("Negative")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
    int n,q;
    string s;
    cin>>n>>s>>q;
    set<int>x[26];
    for(int i=0;i<s.length();i++)
    {
        x[s[i]-'a'].insert(i);
    }
    for(int i=0;i<q;i++)
    {
        int iq;
        cin>>iq;
        if(iq==1)
        {
            int p;
            char c;
            cin>>p>>c;
            x[s[p-1]-'a'].erase(p-1);
            x[c-'a'].insert(p-1); 
            s[p-1]=c;
        }
        else
        {
            int l,r;
            cin>>l>>r;
            int ans=0;
            for(int i=0;i<26;i++)
            {
                auto it=x[i].lower_bound(l-1);
                if(it!=x[i].end() && *it<r)
                {
                    ans++;
                }
            }
            cout<<ans<<'\n';
        }
    }
   return 0;
}    

Measured memory_bytes: 24220
#include<stdio.h>

long long ab(long long a){
	if(a<0)return -a;
	return a;
}

int main(){
	long long N,i;
	scanf("%lld",&N);
	long long A[N+2];
	long long sum[N+2];
	A[0]=A[N+1]=sum[0]=0;
	for(i=1;i<=N+1;i++){
		if(i<=N)scanf("%lld",&A[i]);
		sum[i]=sum[i-1]+ab(A[i]-A[i-1]);
	}
	
	for(i=1;i<=N;i++){
		long long ans=sum[i-1]+sum[N+1]-sum[i+1]+ab(A[i+1]-A[i-1]);
		printf("%lld\n",ans);
	}
	
	return 0;
}

Measured memory_bytes: 2688
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner s = new Scanner(System.in);
  
    int n = s.nextInt();
  
    while( n > 0){
        int max_p = 0;
        int max_d = 0;
      
        for(int i=0; i<n; ++i){
            int p = s.nextInt();
            int d1 = s.nextInt();
            int d2 = s.nextInt();
            if( max_d < d1 + d2 ){
                max_d = d1 + d2;
                max_p = p;
            }
        }
      
        System.out.println(max_p +" "+ max_d);
      
        n = s.nextInt();
    }
  }
}


Measured memory_bytes: 160668
// #define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
using ll = long long;
using P = pair<int, int>;
using V = vector<int>;
using VV = vector<V>;

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;
}
//~ int A = (1<<2) | (1<<3) | (1<<5) | (1<<7);
//~ for (int bit=A; ; bit=(bit-1)&A){
//~ if (!bit) break;
//~ }
int next_combination(int sub) {
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}
//~ int n=5;
//~ int k=3; // nCkの組み合わせ、ただしk=0には対応してない
//~ int bit=(1<<k)-1; // 1000 -> 0111
//~ for(; bit < (1<<n); bit=nex_combination(bit){
//~ }
bool isPrime(int a) {
    if (a == 2) return true;
    if (a <= 1 || a % 2 == 0) return false;

    for (int i = 3; i * i <= a; i += 2) {
        if (a % i == 0) return false;
    }
    return true;
}
//~ vector<int> a = {1, 14, 32, 51, 51, 51, 243, 419, 750, 910};
vector<int> aaa;
// index が条件を満たすかどうか
bool isOK(int index, int key) {
    if (aaa[index] >= key)
        return true;
    else
        return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
    int ng = -1;  //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok =
        (int)aaa
            .size();  // 「index =
                      // a.size()-1」が条件を満たさないこともあるので、初期値は
                      // a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key))
            ok = mid;
        else
            ng = mid;
    }
    return ok;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//~ int v[100100];
//~ int INF = 1 << 30;
//~ vector<vector<int>> dp(310, vector<int>(310));
//~ ll dp[110][100100];
//~ vector<int> dp(100100, 0));

//~ int seen[110];
//~ int ans[110][2];
//~ ll MOD = 1e9 + 7;

void memo() {
    int n = 100;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
        a[i]--;
    }

    vector<int> ans(n);
    iota(ans.begin(), ans.end(), 0);
    sort(ans.begin(), ans.end(), [&](int i, int j) { return a[i] < a[j]; });

    double t1 = 0.1;
    cout << fixed << setprecision(6) << t1 << endl;
}

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

    int cnt = 0;
    ll ans = 0;
    rep(i, (int)s.size()) {
        if (s[i] == 'W') {
            ans += (i - cnt);
            cnt++;
        }
    }

    // 2+3+3+4

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3744
# -*- coding: utf-8 -*-

import math
import itertools

# 入力
N = int(input())
list = []
for i in range(N) :
  a, b = map(int, input().split())
  list.append([a,b])

  
#for i in range(len(list)) :
  #print (str(list[i][0]) + " " + str(list[i][1]))

di = 0.0
S = 0.0
for v in itertools.permutations(list):
  #print (v)
  for ni in range(N-1) :
    
    if ni < N-1 :
      xi = v[ni][0]
      yi = v[ni][1]
      xj = v[ni+1][0]
      yj = v[ni+1][1]
    else :
      xi = v[ni][0]
      yi = v[ni][1]
      xj = v[0][0]
      yj = v[0][1]
      
    #print (xi, xj, yi, yj)
    #print ("xi-xj**2 " + str((xi - xj)**2) )
    #print str(((xi - xj)**2 + (yi - yj)**2) ** (1/2))
    di = math.sqrt((xi - xj)**2 + (yi - yj)**2)
    #print (di)
    S += di
    
print (S/math.factorial(N))
#print (math.factorial(N))

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

int main(){
  int d, n;
  cin >> d >> n;
  
  int num = pow(100, d);
  vector<int> ans;
  for (int i=1 ; ; i++){
    if (i%num == 0 && i%(num*100) != 0){
      ans.push_back(i);
      if (ans.size() == n){
        cout << i << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 3852
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,B,S=0;cin>>N;
  vector<int>A(N),C(N-1);
  for(int i=0;i<N;i++)cin>>A.at(i);
  for(int i=0;i<N;i++){cin>>B;S+=B;}
  for(int i=0;i<N-1;i++)cin>>C.at(i);
  for(int i=0;i<N-1;i++)if(A.at(i+1)-A.at(i)==1)S+=C.at(A.at(i)-1);
  cout<<S<<endl;
}

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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int a, b;
    cin >> a >> b;

    if(a%2!=0 && b%2==0)
        cout << (a+b)/2+1 << endl;
    else if(a%2==0 && b%2!=0)
        cout << (a+b)/2+1 << endl;
    else
        cout << (a+b)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
fn main() {
    let (p, q, r) = {
        let s = {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).unwrap();
            s.trim_right().to_owned()
        };
        let mut integers = s.split_whitespace();
        let p: i32 = integers.next().unwrap().parse().unwrap();
        let q: i32 = integers.next().unwrap().parse().unwrap();
        let r: i32 = integers.next().unwrap().parse().unwrap();
        (p, q, r)
    };
    let answer = std::cmp::min(p+q, q+r);
    let answer = std::cmp::min(answer, p+r);
    println!("{}", answer);
}


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

int main() {
    int a, b, c, k;
    vector<int>  arr;
    cin >> a >> b >> c;
    cin >> k;
    arr.push_back(a);
    arr.push_back(b);
    arr.push_back(c);
    sort(arr.begin(), arr.end());
    for(int i = 0; k > i; i++) {
        arr[2] = arr[2]*2;
    }
    cout << arr[0] + arr[1] + arr[2];
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n = int(input())

w = list(map(int, input().split()))
ans = 100000000000000
for i in range(n-1):
    aa = w[:i+1]
    bb = w[i+1:]
    ans = min(ans, abs(sum(bb)-sum(aa)))

print(ans)




Measured memory_bytes: 2940
#include <algorithm>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <tuple>
#include <bitset>
#include <unordered_map>
using namespace std;
typedef long long ll;
int main() {
    ios::sync_with_stdio(false);

    vector<int> fib(50);
    fib[0] = fib[1] = 1;
    for (int i=2; i<50; ++i) {
        fib[i] = fib[i-1] + fib[i-2];
    }

    int n;
    cin >> n;
    cout << fib[n] << endl;

    return 0;
}

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

const int m=1000000000;

int main(){
  ll s;
  cin >> s;
  int a=(s-1)/m+1;
  int b=m-(s-1)%m-1;
  
  if(s==1e18) cout << 0 << ' ' << 0 << ' ' << m <<  ' ' << 0 << ' ' << 0 << ' ' << m;
  else cout << 0 << ' ' << 0 << ' ' << m <<  ' ' << 1 << ' ' << b << ' ' << a;
  return 0;
}

Measured memory_bytes: 3640