akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n, x; cin >> n >> x;
	int ans = 1;
	int d = 0;
	rep(i, 1, n)
	{
		int l; cin >> l;
		d += l;
		if (d <= x)++ans;
	}
	cout << ans << endl;
}

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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(0)





void solve() {

	string s;
	cin >> s;
	int cnt = 0;
	for(int i = 0; i < s.length() / 2; i++) {
		if(s[i] != s[s.length() - 1 - i]) {
			cnt++;
		}
	}
	cout << cnt;
	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	fix;
	solve();

	return 0;
}

Measured memory_bytes: 3644
import java.util.*;
         
    class Main{
        public static void main(String[] args) {
            
            try(Scanner sc = new Scanner(System.in)){
                int r = Integer.parseInt(sc.next());
                double pi = Math.PI;
     
                System.out.println(2 * (double)r * pi);
     
            }catch(Exception e){
                e.printStackTrace();
            }        
        }
    }

Measured memory_bytes: 35908
#!/usr/bin/env python3

n, m = map(int, input().split())
p = []
s = []
for i in range(m):
    t1, t2 = input().split()
    p.append(int(t1)-1)
    s.append(t2)

# 問題iがACしているかどうかを覚えておく配列
ac = [0 for _ in range(n)]
# 問題iがWAしている回数
pena = [0 for _ in range(n)]

# ac[], pena[]を作る。
for i in range(m):
    if ac[p[i]] == 1:
        continue # XXX
    if s[i] == 'AC':
        ac[p[i]] = 1 
    else:
        pena[p[i]] += 1

AC=0
PENA=0
for i in range(n):
    AC += ac[i]
    if ac[i] == 1:
        PENA += pena[i]

print("%d %d" % (AC,PENA))


Measured memory_bytes: 14924
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
#include <map>
#include <algorithm>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=410;
struct Tile{
	const static int D=4;
	int a[D];
	inline Tile nxt(){
		return (Tile){a[1],a[2],a[3],a[0]};
	}
	inline friend bool operator < (const Tile &a,const Tile &b){
		for(int i=0;i<4;i++){
			if(a.a[i]!=b.a[i])return a.a[i]<b.a[i];
		}
		return false;
	}
}tile[N];
map<Tile,int>m;
inline void add(Tile x,int v){
	for(int i=0;i<Tile::D;i++,x=x.nxt()){
		m[x]+=v;
	}
}
inline bool vis(Tile x){
	return m.find(x)!=m.end();
}
int main(){
	int n=ni;
	for(int i=1;i<=n;i++){
		tile[i]=(Tile){ni,ni,ni,ni};
		add(tile[i],1);
	}
	lint ans=0;
	for(int i=1;i<=n;i++){
		add(tile[i],-1);
		int *a=tile[i].a;
		for(int j=i+1;j<=n;j++){
			int *b=tile[j].a;
			add(tile[j],-1);
			for(int d=0;d<4;d++){
				tile[j]=tile[j].nxt();
				Tile f1=(Tile){a[1],a[0],b[0],b[3]};
				Tile f2=(Tile){a[2],a[1],b[3],b[2]};
				Tile f3=(Tile){a[3],a[2],b[2],b[1]};
				Tile f4=(Tile){a[0],a[3],b[1],b[0]};
				if(!(vis(f1)&&vis(f2)&&vis(f3)&&vis(f4)))continue;
				lint tmp=1;
				tmp*=m[f1],add(f1,-1);
				tmp*=m[f2],add(f2,-1);
				tmp*=m[f3],add(f3,-1);
				tmp*=m[f4];
				add(f1,1),add(f2,1),add(f3,1);
				ans+=tmp;
			}
			add(tile[j],1);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >>n;
  long long int t[n],a[n];
  long long int tt=1,aa=1;
  for(int i=0;i<n;i++){
    cin >>t[i] >>a[i];
    long long int ttt,aaa;
    if(tt%t[i]==0)ttt=tt/t[i];
    else ttt=tt/t[i]+1;
    if(aa%a[i]==0)aaa=aa/a[i];
    else aaa=aa/a[i]+1;
    long long int n=max(ttt,aaa);
    tt=n*t[i];
    aa=n*a[i];
  }
  cout << tt+aa <<endl;
  
}


Measured memory_bytes: 256
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();  
        int A = r.i();
        int B = r.i();
        int C = r.i();
        int X = r.i();
        int ans = 0;
        for(int a = 0; a <= A; a++){
            for(int b = 0; b <= B; b++){
                for(int c = 0; c <= C; c++){
                    int sum = a*500+b*100+c*50;
                    if(sum == X)
                        ans++;
                }
            }
        }        
        println(ans);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int Int(String s){
            return Integer.parseInt(s);
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
    }
}

Measured memory_bytes: 21332
process.stdin.resume();
process.stdin.setEncoding('utf8');


function Main(input) {
    var inputs = input.split("\n");
    
    var A = inputs[1].split(" ").map(e => parseInt(e)).sort((a, b) => a - b);
    
    var Alice = 0, Bob = 0;
    
    for (var i = 0; i < parseInt(inputs[0]); i++) {
        if (i % 2 === 0) {
            Alice += A.pop();
        } else {
            Bob += A.pop();  
        }
    }
    
    console.log(Alice - Bob);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 9676
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int M, D;
    cin >> M >> D;

    int cnt = 0;

    for (int m = 1; m <= M; m++) {
        for (int d = 1; d <= D; d++) {
            int d1 = d % 10;
            int d10 = d / 10;

            if (d1 >= 2 && d10 >= 2 && d1 * d10 == m) {
                cnt++;
            }
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int main()
{
	int N,D;
	scanf("%d %d",&D,&N);
	if(D<=8 && N<=8)
		printf("Yay!\n");
	else
		printf(":(\n");
		
	return 0;
 } 
 
 

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

int roman2int(const char c)
{
  if (c == 'I')
    return 1;
  else if (c == 'V')
    return 5;
  else if (c == 'X')
    return 10;
  else if (c == 'L')
    return 50;
  else if (c == 'C')
    return 100;
  else if (c == 'D')
    return 500;
  else
    return 1000;
}

int main()
{
  string s;
  while (cin >> s) {
    int ans = 0;
    for (unsigned int i = 0; i < s.size()-1; ++i) {
      if (roman2int(s[i]) < roman2int(s[i+1]))
	ans -= roman2int(s[i]);
      else
	ans += roman2int(s[i]);
    }
    cout << ans+roman2int(s[s.size()-1]) << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

long count(long m , long a ,long b){
    long x;
    if(a==0 && b==0)
    return 0;
    else{
        x=m/(a+b);
        m=m%(a+b);
    }
    if(a>m)
    return (x*a+m);
    else
    return (x*a+a);
}

int main()
{
    long n,a,b;
    cin >> n >> a >> b;
    cout << count(n,a,b) ;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>

int main()
{
    while (true) {
        int a, b, c, d, e, f;
        std::cin >> a >> b >> c >> d >> e >> f;
        if (std::cin.eof()) break;
        double denom = a * e - b * d;
        double x = (c * e - b * f) / denom, y = (a * f - c * d) / denom;
        std::cout << std::fixed << std::setprecision(3) << floor(1000.0 * x + 0.5) / 1000.0
            << " " << floor(1000.0 * y + 0.5) / 1000.0 << std::endl;
    }
}

Measured memory_bytes: 1236
#include <stdio.h>

int main(void)
{
	int num, cnt = 0;
	int i, j, k, l;

	while( scanf("%d", &num) != EOF){
		for(i = 0; i < 10; i++){
			for(j = 0; j < 10; j++){
				for(k = 0; k < 10; k++){
					for(l = 0; l < 10; l++){
						if(i + j + k + l == num){
							cnt++;
						}
					}
				}
			}
		}
		printf("%d\n", cnt);
		cnt = 0;
	}

	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
	long long x,y=100,i=0;
	scanf("%lld",&x);
	while(1) {
		y*=1.01;
		(long long)y;
		i++;
		if(y>=x) break;
	}
	printf("%lld",i);
	return 0;
} 

Measured memory_bytes: 1692
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
public class Main {
    public static void main(String[]args) {
        FastScanner sc=new FastScanner();
        PrintWriter pw=new PrintWriter(System.out);
        int n=sc.nextInt(),k=sc.nextInt();
        int left=0,right=n;
        long lsum=0,rsum=0,ans=0;
        for(int i=0;i<n+1;i++){
            lsum+=left;rsum+=right;
            if(i>=k-1){
                ans+=rsum-lsum+1;
                ans%=1000000007;
            }
            left++;right--;
        }
        System.out.println(ans);
    }
}

//高速入力コピペ
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 32760
m = 1000000007
 
factorials = [1]
 
for i in range(1,1000001):
    factorials.append((factorials[-1]*i) % m)
 
n = int(input())
 
if n == 1:
    print(0)
else:
    temp = pow(10,n,m) - (2*pow(9,n,m) - pow(8,n,m))
    print(temp % m)

Measured memory_bytes: 48576
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String s = String.valueOf(n);
        if (s.charAt(0) == '7' || s.charAt(1) == '7' ||  s.charAt(2) == '7') {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35780
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <cstring>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

using namespace std;

const int N_MAX = 1000000;
int dp[N_MAX];


int fib(int n, int* dp){
  if(n==0) dp[n] = 1;
  if(n==1) dp[n] = 1;

  if(dp[n] >= 0) return dp[n];
  else dp[n] = fib(n-2, dp) + fib(n-1, dp);
  return dp[n];
}

int main(){
  int n;
  cin >> n;
  memset(dp, -1, N_MAX * sizeof(dp[0]));
  cout << fib(n, dp) << endl;
  return 0;
}



Measured memory_bytes: 6996
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  int r, g, b, n, ans = 0;
  cin >> r >> g >> b >> n;
  for (int i = 0; i * r <= n; ++i) {
    for (int j = 0; i * r + j * g <= n; ++j) {
      if ((n - i * r - j * g) % b == 0) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    string s, t;
    cin>>s>>t;
    if((t.size()-s.size())!=1){
        cout<<"No";
        return 0;
    }
    int n=s.size();
    for(int i=0; i<n; i++){
        if(s[i]!=t[i]){
            cout<<"No";
            return 0;
        }
    }
    if(int(t[n])<97 || int(t[n])>122){
        cout<<"No";
        return 0;
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
   
#define pb push_back
#define ll long long
#define f first
#define s second
#define ld long double
#define fa fflush(stdout); 

using namespace std;
void data() {
    #ifdef NURS
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif
} 
const int N = 5e5 + 100;
const ll mod = 1e9 + 7;
 
int main ()
{
	data();
	int r;
	cin >> r;
	cout << r * r * 3;
}     
//JUDGE_ID: 295965SY
//Tis I

Measured memory_bytes: 3584
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;
int main(void){
    // Your code here!
    string s;
    int l;
    int s_int[10];
    long long sum;
    long long ans = 0;
    cin >> s;
    l = s.length();
    for(int i = 0; i < l; i++){
        s_int[i] = int(s[i]-'0');
    }
    for(int i = 0; i < pow(2,l-1); i++){
        int k = i;
        int cnt = 0;
        sum = s_int[l-1];
        for(int j = l-2; j >= 0; j--){
            if(k % 2 == 0){
                cnt++;
            }else{
                cnt = 0;
            }
            
            sum += s_int[j] * pow(10,cnt);
            k /= 2;
        }
        ans += sum;
    }
    cout << ans;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    S = input().split()
    A = int(S[0])
    B = int(S[1])
    C = int(S[2])
    K = int(S[-1])

    if K <= A:
        print(K)
    elif K > A:
        if A + B >= K:
            print(A)
        elif A + B < K:
            print(2*A+B-K)

Measured memory_bytes: 9196
local a = {}
a[1], a[2], a[3] = io.read("*n", "*n", "*n")
local min = math.min(math.min(a[1], a[2]), a[3])
local max = math.max(math.max(a[1], a[2]), a[3])
local mincnt = -1
for tgt = min, max do
  local cnt = 0
  for i = 1, 3 do
    if(a[i] < tgt) then
      if((tgt - a[i]) % 2 == 0) then
        cnt = cnt + (tgt - a[i]) // 2
      else
        cnt = cnt + (tgt - a[i]) // 2 + 2
      end
    elseif(tgt < a[i]) then
      cnt = cnt + a[i] - tgt
    end
  end
  if(tgt == min) then mincnt = cnt else mincnt = math.min(mincnt, cnt) end
end
print(mincnt)


Measured memory_bytes: 256
def resolve():
    '''
    code here
    '''
    N = int(input())
    A_list = [int(item) for item in input().split()]

    is_zero = False
    is_over = False
    res = 1

    for item in A_list:
        if item == 0:
            is_zero = True
            break

    if is_zero:
        print(0)
    else:
        for item in A_list:
            res *= item

            if res > 10 ** 18:
                is_over = True
                break
        else:
            print(res)

        if is_over:
            print(-1)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 21484
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
#pragma GCC optimize("O3")
using namespace std;

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

set<int> cr[26];
char s[500000 + 5];

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n,q;
	scanf("%d %s %d",&n,s,&q); 
	rep(i,0,n)cr[s[i] - 'a'].insert(i);
	while(q--){
		int t;
		scanf(" %d",&t);
		if(t == 1){
			int i;
			char c;
			scanf(" %d %c",&i,&c);
			--i;
			cr[s[i]-'a'].erase(i);
			cr[c-'a'].insert(i);
			s[i] = c;
		}
		else{
			int l,r;
			scanf(" %d %d",&l,&r);
			--l,--r;
			int cnt = 0;
			rep(i,0,26){
				auto it = cr[i].lower_bound(l);
				if(it != cr[i].end() && (*it) <= r)++cnt;
			}
			printf("%d\n",cnt);
		}
	}
}


Measured memory_bytes: 24192
#coding:utf-8
k, n = map(int,input().split())
a = input().split()
a.append(str(int(a[0]) + k))
distance = []
for i in range(n):
    preh, nexh = int(a[i]),int(a[i+1])
    d = abs(nexh - preh)
    distance.append(d)
b = abs(k - max(distance))
print("{}".format(b))

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

#define all(x) x.begin(),x.end()
#define fi first
#define sd second
#define lson (nd<<1)
#define rson (nd+nd+1)
#define PB push_back
#define mid (l+r>>1)
#define MP make_pair
#define SZ(x) (int)x.size()

using namespace std;

typedef long long LL;

typedef vector<int> VI;

typedef pair<int,int> PII;

inline int read(){
    int res=0, f=1;char ch=getchar();
    while(ch<'0'|ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){res=res*10+ch-'0';ch=getchar();}
    return res*f;
}

const int MAXN = 200'005;

const int MOD = 1000000007;

void addmod(int& a, int b){a+=b;if(a>=MOD)a-=MOD;}
int mulmod(int a, int b){return 1ll*a*b%MOD;}

template<typename T>
void chmin(T a, T b){if(a>b)a=b;}

template<typename T>
void chmax(T a, T b){if(b>a)a=b;}

int cnt[5005];

int main(){
    int n=read();
    LL ans=0;

    for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            int t=__gcd(i,j);
            ++cnt[t];
        }
    }

    for(int i=1;i<=n;++i){
        for(int j=1;j<=5000;++j){
            if(cnt[j]){
                ans+=1ll*cnt[j]*__gcd(j,i);
            }
        }
    }

    cout<<ans;

    return 0;
}


Measured memory_bytes: 3656
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
int main() {
	ll n;
	cin >> n;
	ll count = 1;
	for (int i = 0; i <= pow(n, 0.5); i++) {
		if (i > 0) {
			if (n % i == 0) {
				count = i;
			}
		}
	}
	cout << count + n / count - 2 << endl;
}

Measured memory_bytes: 4044
n, x, m = map(int,input().split())
ans = x
num = 0
l = [0]*m
lis = [-1]*m
l[0] = x
lis[x] = num
for i in range(1,n):
    x = (x*x)%m
    num += 1
    if lis[x]!=-1:
        a = (n-i)//(i-lis[x])
        b = (n-i)%(i-lis[x])
        ans += a * sum(l[lis[x]:i])
        for j in range(lis[x],lis[x]+b):
            ans += l[j]
        break
    l[i] = x
    lis[x] = i
    ans += x
print(ans)

Measured memory_bytes: 13936
#include <vector>
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;


int main(){
    int K;
    cin >> K;
    int sum=0;
/*
    for(int i=1; i!=K-1; i++){
        for(int j=i+1; j!=K;j++){
            for(int k=j+1; k!=K+1; k++){
             sum += __gcd(__gcd(j,k),i); 
            }
        }
    }
*/
    for(int i=1; i!=K+1; i++){
        for(int j=1; j!=K+1;j++){
            for(int k=1; k!=K+1; k++){
             sum += __gcd(__gcd(j,k),i); 
            }
        }
    }
    cout << sum << endl;
    return 0;
}

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

int main (){
	int a, b, x, y;
	x = 0;
	y = 0;
	while(cin >> a >> b && ( a != 0 || b != 0 )){
		
		if (a <= b){
			x = a;
			y = b;
		}
		else {
			x = b;
			y = a;
		}
		cout << x << " "<< y << endl;
	}
	return 0;
}



Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
int main(){

   string a;
   string b;
   cin>>a;
   cin>>b;
   int s=0;
   for(int i=0,j=0;i<a.size();i++,j++){
       if(a[i]==b[j]){
         s++;



       }


   }
   cout<<s<<endl;




}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
typedef long long LL;
typedef long double Lf;
#define in (void)scanf
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
//#define Rep(i,a,n)for(LL i=(LL)(a);i<(LL)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define Repp(i,l,r,k)for(int i=(int)(l);i<(int)(r);i+=(int)(k))
//#define Repp(i,l,r,k)for(LL i=(LL)(l);i<(LL)(r);i+=(LL)(k))
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))
#define MOD 1000000007//998244353,1000000007,1000000009,4999999999999997
int upi(const void* a, const void* b) { return*(int*)a<*(int*)b ? -1 : *(int*)a> * (int*)b ? 1 : 0; }
int downi(const void* a, const void* b) { return*(int*)a<*(int*)b ? 1 : *(int*)a> * (int*)b ? -1 : 0; }
void sortupi(int* a, int n) { qsort(a, n, sizeof(int), upi); } //1,2,3,4,...
void sortdowni(int* a, int n) { qsort(a, n, sizeof(int), downi); }
int upLL(const void* a, const void* b) { return*(LL*)a<*(LL*)b ? -1 : *(LL*)a> * (LL*)b ? 1 : 0; }
int downLL(const void* a, const void* b) { return*(LL*)a<*(LL*)b ? 1 : *(LL*)a> * (LL*)b ? -1 : 0; }
void sortupLL(LL* a, int n) { qsort(a, n, sizeof(LL), upLL); }
void sortdownLL(LL* a, int n) { qsort(a, n, sizeof(LL), downLL); }
int cmp_char(const void* a, const void* b) { return *(char*)a - *(char*)b; } // a,b,c,d
int cmp_str(const void* a, const void* b) { return strcmp(*(const char**)a, *(const char**)b); } // aaa,aab
LL gcd(LL p, LL q) { while (q) { LL t = p % q; p = q; q = t; }return p; }
LL modpow(LL a,LL n,int m){LL x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invmodpow(b,p)modpow(b,p-2,p)// a/b≡a*b^{-1}(mod p)...return b^{-1}(mod p)
//typedef struct fac { LL n, exp; }F;
//LL fact(LL n,F*a){LL x=n,i,j,c=0;for(i=2;i*i<=x;i++){for(j=1;x%i==0;j++)x/=i;if(j>1){a[c].n=i;a[c++].exp=j-1;}}if(x-1){a[c].n=x;a[c++].exp=1;}return c;}
LL nibtan(LL* a,LL n,LL x){LL p=0,q=n/2,r=n-1;while(r-p>1){if(x>=a[q])p=q;if(x<=a[q])r=q;q=(p+r)/2;}return a[p]==x?p:r;}
//snippet

#define N 300009

void run(void) {
	int x;
	in("%d", &x);
	printf(x ? "0" : "1");	
}

int main(void) {
	int test = 1;
//	in("%d", &test);
	while (test--) {
		run();
		fflush(stdout);
	}
	return 0;
}

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

int main(){
  int k;
  cin >> k;
  if(k%2==0||k%5==0){
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  ll r = 7;
  while(1){
    ans++;
    ll tmp = r%k;
    r = tmp;
    if(r==0)break;
    else{
      r *= 10;
      r += 7;
      continue;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3660
#include <stdio.h>

int main(){
  int a,b,c,d;

  scanf("%d %d %d %d",&a,&b,&c,&d);
  
  while(1){
    c -= b;
    if(c <= 0){
      printf("Yes\n");
      break;
    }
    a -= d;
    if(a <= 0){
      printf("No\n");
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 1648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5;
ll n,x,len,p[N];
pair<ll,ll> a[N],b[N];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n;
    for(ll i=0;i<n;i++)cin>>a[i].first,a[i].second=i;
    for(ll i=0;i<n;i++)cin>>b[i].first,b[i].second=i;
    sort(a,a+n);sort(b,b+n);
    for(ll i=0;i<n;i++)if(a[i].first>b[i].first)return cout<<"No" , 0;
    for(ll i=0;i<n-1;i++)if(a[i+1].first<=b[i].first)return cout<<"Yes" , 0;
    for(ll i=0;i<n;i++)p[a[i].second]=b[i].second;
    do{
        x=p[x];
        len++;
    }while(x);
    cout<<(len==n?"No":"Yes");
}

Measured memory_bytes: 4224
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main{
	Scanner s=new Scanner(System.in);

	void solve(){
		System.out.println(s.next().replaceAll(".","x"));
	}

	public static void main(String[] A){
		new Main().solve();
	}

	int gInt(){
		return Integer.parseInt(s.next());
	}
	long gLong(){
		return Long.parseLong(s.next());
	}
	double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,this::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,this::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,this::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return Range.rep(i);
	}
	Range rep(int f,int t,int d){
		return Range.rep(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream REP(int v){
		return IntStream.range(0,v);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(this::gInt).limit(n);
	}
	LongStream LONGS(int n){
		return LongStream.generate(this::gLong).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}

class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int			t;
	Supplier<T>	supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}

}

class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

	Range(int from,int to,int d){
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}
	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}
}

Measured memory_bytes: 22612
S = input()
f = int(S[:2])
s = int(S[2:])
t1 = False
t2 = False
if(f > 0 and f < 13):
    t1 = True
if(s > 0 and s < 13):
    t2 = True
if(t1 == True):
    if(t2 == True):print('AMBIGUOUS')
    else:print('MMYY')
else:
    if(t2 == True):print('YYMM')
    else:print('NA')


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

const int MAX_N = 1e5 + 5;

int arr [MAX_N];

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

  int n;
  cin >> n;

  int ans = 0;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    ans += abs(arr[i] - arr[i - 1]);
  }
  ans += abs(0 - arr[n]);

  for (int i = 1; i <= n; i++) {
    cout << ans - abs(arr[i] - arr[i + 1]) - abs(arr[i] - arr[i - 1]) + abs(arr[i + 1] - arr[i - 1]) << '\n';
  }
}


Measured memory_bytes: 1664
(defun prime-factorization (n)
  (let ((ans '()))
    (labels ((divide (m i c)
		     (unless (zerop (rem m i))
		       (return-from divide (values m (cons i c))))
		     (divide (/ m i) i (1+ c)))
	     (take-apart (m i)
			 (when (= m 1)
			   (return-from take-apart ans))

			 (when (< (sqrt m) i)
			   (return-from take-apart
			     (setf ans (append ans (list (cons m 1))))))

			 (if (zerop (rem m i))
			    (multiple-value-bind (m2 part) (divide m i 0)
			      (setf ans (append ans (list part)))
			      (take-apart m2 (1+ i)))
			    (take-apart m (1+ i)))))
      (take-apart n 2)
      ans)))

(defun caddi2018c ()
  (let* ((n (read)) (p (read)))
    (reduce #'*
	    (mapcar (lambda (x) (expt (car x) (floor (cdr x) n)))
		    (prime-factorization p)))))

(format t "~a~%" (caddi2018c))

Measured memory_bytes: 16224
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define ff first
#define ss second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl "\n"
inline ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2, m);
    p = (p * p) % m;
    if (n % 2)
        return (p * a) % m;
    else
        return p;
}
const ll MOD = 1e9 + 7;
const int N = int(3e5) + 999;
#define int long long int
#define inf 1e18

int dp[405][405];
int ans = 0;
int arr[405];

int sum(int l, int r)
{
    int x = 0;
    for (int i = l; i <= r; i++)
        x += arr[i];
    return x;
}

int32_t main()
{
    IOS;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> arr[i];

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
            if (i == j)
                dp[i][i] = 0;
            else
                dp[i][j] = inf;
    }

    for (int l = n - 1; l >= 0; --l)
    {
        for (int r = l; r < n; r++)
        {
            if (l == r)
                continue;

            int s = sum(l, r);
            for (int i = l; i < r; i++)
            {
                dp[l][r] = min(dp[l][r], dp[l][i] + dp[i + 1][r] + s);
            }
        }
    }

    cout << dp[0][n - 1];
    return 0;
}

Measured memory_bytes: 1536
#include<cstdio>
using namespace std;
int cale(int x){
	int sum=0;
	while(x){
		sum+=x%10;
		x=x/10;
	}
	return sum;
}
int main(){
	int n;
	scanf("%d",&n);
	int msum=1e9+7;
	for(int i=1;i<=n/2;i++){
		msum=(msum>cale(i)+cale(n-i))?(cale(i)+cale(n-i)):msum;
	}
	printf("%d\n",msum);
	return 0;
}

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

using namespace std;

#define  N 5005

int dp[N][N];
const int MOD = 1e9 + 7;

void relax(int &x, int y) {
    y %= MOD;
    x += y;
    if (x >= MOD) x -= MOD;
}

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int m = s.size();
    dp[0][0] = 1;

    for (int i = 0; i < N - 1; i++) {
        for (int j = 0; j < N; j++) {

            //backspace
            if (j == 0) relax(dp[i + 1][0], dp[i][0]);
            else relax(dp[i + 1][j - 1], dp[i][j] * 2);

            relax(dp[i + 1][j + 1], dp[i][j]);
        }
    }
    cout << dp[n][m] << endl;

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef qwerty
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif


    int T = 1;
    //cin >> T;
    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 98176
# 32bitのMod一つでRollingHashを行った場合、
# 10**5個程度のHashを生成するだけでも
# 半分以上の確率でどこかのHashが衝突していることが分かります


# 小文字アルファベットの時のbese
base = 27  # alphabet


def getnum(x):
    return ord(x) - ord("a") + 1


# rolling hash実装

# 必要な定数
# mod = 1<<61-1としたときの高速余り計算
m30 = (1 << 30) - 1
m31 = (1 << 31) - 1
m61 = (1 << 61) - 1
mod = m61
positive_delta = m61 ** 4

# 高速化された計算
def mul(a, b):
    au = a >> 31
    ad = a & m31  # 余りを取ることが&演算でできる
    bu = b >> 31
    bd = b & m31
    mid = ad * bu + au * bd
    midu = mid >> 30
    midd = mid & m30
    return calcmod(au * bu * 2 + midu + (midd << 31) + ad * bd)


def calcmod(a):
    au = a >> 61
    ad = a & m61
    res = au + ad
    if res >= m61:
        res -= m61
    return res


# s:string
def rollinghash(s):
    num = len(s)
    res = [0] * (num + 1)
    pow_base = [1] * (num + 1)
    for i in range(num):
        res[i + 1] = calcmod(mul(res[i], base) + getnum(s[i]))
        pow_base[i + 1] = calcmod(mul(pow_base[i], base))
    return res, pow_base


def search(left, right, rh):
    return calcmod(rh[right] - mul(rh[left], pow_base[right - left]) + positive_delta)


n = int(input())
s = input()
rh, pow_base = rollinghash(s)

ng = n
ok = 0


def hantei(x, rh):
    kumi = {}
    for i in range(n - x + 1):
        temp = search(i, i + x, rh)
        if temp in kumi:
            pre_idx = kumi[temp]
            if i - pre_idx >= x:
                # print("pair", i, pre_idx, "delta", x)
                return True
        else:
            kumi[temp] = i
    # print(x, kumi)
    return False


while ng - ok > 1:
    mid = (ng + ok) // 2
    if hantei(mid, rh):
        ok = mid
    else:
        ng = mid
    # print(ok, ng)

print(ok)


Measured memory_bytes: 10296
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
typedef long long LL;
#define rep(i,n) for(LL i=0; i<(LL)(n); i++)

//qsort
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

//比較
int max(int a, int b){
	if (a>b) return a;
	else return b;
}

int min(int a,int b) {
	if(a>b) return b;
	else return a;
}

LL ans( LL n,LL xx){
	if(n == -1){
		return 0;
	}
	return (n/xx)+1;
}

//main関数
int main(){
	LL aa,bb,xx;
	scanf("%lld %lld %lld",&aa,&bb,&xx);
	
	printf("%lld\n",ans(bb,xx)-ans(aa-1,xx));
}







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

void solve() 
{
    int n;cin>>n;
    map<string,int>mp;
    mp["AC"]=0;
    mp["WA"]=0;
    mp["TLE"]=0;
    mp["RE"]=0;
    string s;REP(i,n){
        cin>>s;
        mp[s]++;
    }
    cout<<"AC"<<" x "<<mp["AC"]<<endl;
    cout<<"WA"<<" x "<<mp["WA"]<<endl;
    cout<<"TLE"<<" x "<<mp["TLE"]<<endl;
    cout<<"RE"<<" x "<<mp["RE"]<<endl;
}

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

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define ll long long
#define fir first
#define sed second
#define i64 int64_t
#define ui64 uint64_t
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define kpair pair<int, pair<int,int>
#define lwb lower_bound
#define upb upper_bound
const int mod = 1e9+7;
const int maxn = 1e5;

using namespace std;
ifstream fi("");
ofstream fo("");
ll n;
ll a[100000];
ll c[100001];
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    c[1]= abs(a[1]-a[0]);
    for(int i=2;i<n;i++) c[i]= min(c[i-1]+abs(a[i]-a[i-1]),c[i-2]+abs(a[i]-a[i-2]) );
    cout<<c[n-1];
}






Measured memory_bytes: 1792
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
sumlist = [0 for i in range(N+1)]
for i in range(1,N+1):
    sumlist[i] += sumlist[i-1]+A[i-1]
Ac = Counter(sumlist)
ans = 0
for i in Ac.values():
    ans += (i*(i-1))//2
print(ans)

Measured memory_bytes: 40960
#include <bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < n; i++)
#define REPR(i,n) for(int i = n; i >= 0; i--)
#define FOR(i,m, n) for(int i = m-1; i < n; i++)
#define INF 2000000000
#define ALL(v) v.begin(), v.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
//vector<vector<要素の型>> 変数名(要素数1, vector<要素の型>(要素数2, 初期値))
//vector<intなど> 変数名(要素数,初期値)
using namespace std;
typedef long long ll;
int main(){
    int n,v;
  	int v_max=100100;
  	int n_max=110;
    ll w,w_max;
    cin>>n>>w_max;
    ll dp[n_max][v_max];
  	REP(i,n_max){
    REP(j,v_max){
    dp[i][j]=INF;}}
    dp[0][0]=0;
    REP(i,n){
        cin>>w>>v;
        for(int j=0;j<v_max;j++) {
          if(j>=v) dp[i+1][j]=min(dp[i][j],dp[i][j-v]+w);
         else dp[i+1][j]=dp[i][j];}
      //REP(j,v_max+1) cout<<"dp["<<i+1<<"]["<<j<<"]="<<dp[i+1][j]<<endl;
    }
  	//REP(j,v_max+1) if(dp[n][j]!=INF) cout<<"dp["<<n<<"]["<<j<<"]="<<dp[n][j]<<endl;
    //ll max=0;
    REPR(i,v_max-1){
        if(dp[n][i]<=w_max) {
          cout<<i<<endl;
          break;
                            }
    }
}


Measured memory_bytes: 86272
#include <bits/stdc++.h>
using namespace std;
int main () {
    int N;
    cin >> N;
    set<string> x;
    for (int i = 0; i < N; i++) {
        string S;
        cin >> S;
        x.insert(S);
    }
    if (x.size() == 3) puts("Three");
    else puts("Four");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const long long INF = 1001001001;
const long long MOD = 1000000007;
const double EPS = 1e-10;

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

    int n;
    while(cin>>n&&n){
        int k[n];
        int cnt_o=0,cnt_z=0;
        for(int i=0;i<n;i++){
            cin>>k[i];
            if(k[i]==1)cnt_o++;
            if(k[i]==0)cnt_z++;
        }
        if(cnt_o+cnt_z==n){
            cout<<"NA"<<endl;
            continue;
        }
        cout<<(n-(cnt_z))+1<<endl;
    }
}


Measured memory_bytes: 3156
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: usize = itr.next().unwrap().parse().unwrap();
    let b: usize = itr.next().unwrap().parse().unwrap();
    let c: usize = itr.next().unwrap().parse().unwrap();
    let s: Vec<&str> = (0..n).map(|_| itr.next().unwrap()).collect();

    let mut now = (a, b, c);
    let mut ans = Vec::new();
    for i in 0..n {
        if s[i] == "AB" {
            if now.0 == 0 && now.1 == 0 {
                println!("No",);
                return;
            } else if now.0 == 0 {
                now.0 += 1;
                now.1 -= 1;
                ans.push('A');
            } else if now.1 == 0 {
                now.0 -= 1;
                now.1 += 1;
                ans.push('B');
            } else {
                if i != n - 1 && s[i + 1] == "BC" {
                    now.0 -= 1;
                    now.1 += 1;
                    ans.push('B');
                } else {
                    now.0 += 1;
                    now.1 -= 1;
                    ans.push('A');
                }
            }
        } else if s[i] == "BC" {
            if now.2 == 0 && now.1 == 0 {
                println!("No",);
                return;
            } else if now.2 == 0 {
                now.2 += 1;
                now.1 -= 1;
                ans.push('C');
            } else if now.1 == 0 {
                now.2 -= 1;
                now.1 += 1;
                ans.push('B');
            } else {
                if i != n - 1 && s[i + 1] == "AB" {
                    now.2 -= 1;
                    now.1 += 1;
                    ans.push('B');
                } else {
                    now.2 += 1;
                    now.1 -= 1;
                    ans.push('C');
                }
            }
        } else {
            if now.0 == 0 && now.2 == 0 {
                println!("No",);
                return;
            } else if now.0 == 0 {
                now.0 += 1;
                now.2 -= 1;
                ans.push('A');
            } else if now.2 == 0 {
                now.0 -= 1;
                now.2 += 1;
                ans.push('C');
            } else {
                if i != n - 1 && s[i + 1] == "BC" {
                    now.0 -= 1;
                    now.2 += 1;
                    ans.push('C');
                } else {
                    now.0 += 1;
                    now.2 -= 1;
                    ans.push('A');
                }
            }
        }
    }

    let mut out = Vec::new();
    writeln!(out, "Yes").ok();
    for i in 0..n {
        writeln!(out, "{}", ans[i]).ok();
    }
    stdout().write_all(&out).unwrap();
}


Measured memory_bytes: 4584
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
const int inf=1e18;

int32_t main()
{
	#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	#endif
	int n,m,x;
	cin>>n>>m;
	vector<int> dp(4100, inf);
	vector<int> a(m),b(m),c(m);
	for(int i=0;i<m;i++)
	{
		cin>>a[i]>>b[i];
		for(int j=0;j<b[i];j++)
		{
			cin>>x;x--;
			c[i]|=(1<<x);
		}
	}
	dp[0]=0;
	for(int i=0;i<m;i++)
	{
		for(int mask=0;mask<(1<<n);mask++)
		{
			dp[mask|c[i]]=min(dp[mask|c[i]], dp[mask]+a[i]);
		}
	}
	if(dp[(1<<n)-1]==inf)cout<<-1;
	else cout<<dp[(1<<n)-1];
	
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef vector<pair<int,int>> vpii;

int N;
vpii blue;
int flag[210][210];

int main() {
    cin >> N;
    blue.resize(N);
    for (int i = 0; i < N; i++) {
        int tempx, tempy;
        scanf("%d%d", &tempx, &tempy);
        flag[tempy][tempx] = 1;
    }
    for (int i = 0; i < N; i++) {
        int tempx, tempy;
        scanf("%d%d", &tempx, &tempy);
        blue[i] = make_pair(tempy, tempx);
    }
    sort(blue.begin(), blue.end());
    int count = 0; 
    for (int i = 0; i < N; i++) {
        pair<int,int> b = blue[i];
        int x = -1, y = -1;
        for (int j = 0; j < b.second; j++) {
            for (int k = 0; k < b.first; k++) {
                if (flag[k][j]) x = j, y = k;
            }
        }
        if (x != -1) {
            flag[y][x] = 0;
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <cmath>

std::vector<int> onesIndex(int n) {
	std::vector<int> ret;

	for (int k = 0; n != 0; ++k) {
		if (n % 2 == 1) {
			ret.push_back(k);
		}
		n = n / 2;
	}

	return ret;
}

int main() {
	int h, w, k;
	std::cin >> h >> w >> k;
	std::vector<std::vector<char>> grid;
	std::vector<int> rowSum(h);
	std::vector<int> heightSum(w);
	int t = 0;
	for (int i = 0; i < h; ++i) {
		std::string s;
		std::cin >> s;
		std::vector<char> v;
		for (int j = 0; j < w; ++j) {
			v.push_back(s[j]);
			if (s[j] == '#') {
				rowSum[i] += 1;
				heightSum[j] += 1;
				t += 1;
			}
		}
		grid.push_back(v);
	}

	int num = 0;
	for (int i = 0; i < std::pow(2,h); ++i) {
		for (int j = 0; j < std::pow(2,w); ++j) {
			int sum = 0;
			for (auto y : onesIndex(i)) {
				for (auto x : onesIndex(j)) {
					if (grid[y][x] == '#') {
						sum -= 1;
					}
				}
				sum += rowSum[y];
			}
			for (auto x : onesIndex(j)) {
				sum += heightSum[x];
			}

			if (t - sum == k) {
				num += 1;
			}
		}
	}

	std::cout << num;
}


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

string replace(string s)
{
	string ans = "";
	for(long long int i = 0 ; i < (s.length()-1) ; i++)
	{
		if(s.substr(i,2) == "BC") 
		{
			ans+="D";
			i++;
		}
		else
		{
			ans += s[i];		
		}
	}
	return ans;
}

int main()
{	
	string s;
	cin>>s;
	long long int count = 0 ;
	long long int ans = 0;
	string temp = replace(s);
	long long int n = temp.length();
	for(long long int i = 0 ; i < n ; i++)
	{
		if(temp[i] == 'A') 
		{	
			count++;
		}
		else if(temp[i] == 'D') 
		{
			ans += count;
		}
		else 
		{
			count = 0;
		}
	} 
	cout<<ans<<endl;
}

Measured memory_bytes: 1028
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
//#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
using namespace std;

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

    ll a,b,c,n,maxi=0,f=0,mini=INF;
    ll sum=0;
    string str,sub;
    ll h,w;
    ll m,k;
    cin>>n;
    vector<ll> v(n);
    rep(i,n) cin>>v[i];
    ll bigf=0;
    ll smaf=0;
    for(ll i=1;i<n;i++){
        if(v[i-1]<v[i]){
            if(smaf==1){
                smaf=0;
                sum++;
                //bigf=1;
            }else{
                bigf=1;
            }
        }else if(v[i-1]>v[i]){
            if(bigf==1){
                bigf=0;
                sum++;
                //smaf=1;
            }else{
                smaf=1;
            }
        }
    }
    sum++;
    cout<<sum<<endl;
    return 0;
}


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

int main()
{
    int N;
    string S, T;
    cin >> N >> S >> T;
    string A;

    for (int i = 0; i < N; i++)
    {
        A += S.at(i);
        A += T.at(i);
    }

    cout << A;
    
}

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

using namespace std;

#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)

const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    llong n, k;
    cin >> n >> k;
    llong ans = k * pow(k - 1, n - 1);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
n = int(input())
alist = list(map(int, input().split(" ")))

alist.sort(reverse=True)

if n%2 == 0:
  result = alist[0] + 2*sum(alist[1:int(n/2)])
  print(result)
elif n%2 == 1:
  result = alist[0] + 2*sum(alist[1:int(n//2)]) + alist[n//2]
  print(result)

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

const int maxn = 1e6+7;
int t,n,m;
vector<int> sieve,cnt,primes;

void precal(){
	sieve = cnt = vector<int>(maxn,0);
	for (int i=2; i<maxn; i++){
		if (sieve[i] == 0){
			primes.push_back(i);
			for (int j=i; j<maxn; j+= i){
				sieve[j] = i;
			}
		}
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n;
	precal();
	int x,maxf;
	for (int i=0; i<n; i++){
		cin >> x;
		while (x > 1){
			maxf = sieve[x];
			++cnt[maxf];
			while (x % maxf == 0) x/=maxf;
		}
	}
	
	int state = 0;
	for (int i=0, s=primes.size(); i<s; i++){
		int now = primes[i];
		if (cnt[now] >= n) state = 2;
		else if (cnt[now] >= 2){
			state = 1;
		}
		
		if (state == 2) break;
	}
	
	if (state == 0) cout << "pairwise coprime" << endl;
	else if (state == 1) cout << "setwise coprime" << endl;
	else cout << "not coprime" << endl; 
	return 0;
}


Measured memory_bytes: 11696