akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout<<setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define lint long long
#define FOR(i,a,b) for(lint i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009

typedef pair<int, int> P;

lint ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
	int n; cin>>n;
	string s; cin>>s;
	int ans = n;
	REP(i,n-1){
		if(s[i]==s[i+1]) ans--;
	}
	cout<<ans<<endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  int N_ab= 26;
  vector<int> freq_common(N_ab,INT_MAX);
  for(int i=0; i<n; i++){
    string str;
    cin >> str;

    vector<int> freq(N_ab,0);
    for(int j=0; j<str.size(); j++){
      int c_id= str.at(j)-'a';
      freq.at(c_id)++;
    }
    for(int j=0; j<N_ab; j++){
      if( freq_common.at(j) > freq.at(j) ){
        freq_common.at(j)= freq.at(j);
      }
    }
  }

  for(int j=0; j<N_ab; j++){
    for(int k=0; k<freq_common.at(j); k++){
      char c= 'a'+j;
      cout << c;
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
import java.awt.*;
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			Polygon poly = new Polygon();
			for (int j = 0; j < 3; j++) {
				int x = sc.nextInt();
				int y = sc.nextInt();
				poly.addPoint(x, y);
			}
			boolean k = poly.contains(sc.nextInt(), sc.nextInt());
			boolean s = poly.contains(sc.nextInt(), sc.nextInt());
			System.out.println(k ^ s ? "OK" : "NG");
		}
	}
}

Measured memory_bytes: 63668
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

#define error(x) cout << #x << " = " << x << endl

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int N = 1e5 + 20;
int n, a[N], last;
ll sum[N];

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

	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];

	sort(a, a + n);
	for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + a[i];

	for (int i = 0; i < n; i++)
		if (2 * sum[i] < a[i]) last = i;

	cout << n - last << '\n';
}


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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n, k;
	cin >> n >> k;
	if (n == 0)
		cout << 0;
	else if (k == 1)
		cout << 0;
	else
	{
		ll r = n % k;
		cout << min(r, abs(r - k));
	}
	return 0;
}


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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; i++)
#define repn(i, st, ed) for(ll i=st; i<=ed; i++)
#define repb(i, ed, st) for(ll i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1e5 + 10;
const ll INF = 1LL << 60;

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



// Main Code

ll s[2010], t[2010];
ll ans[2010][2010];
int main()
{
	int n, m;
	cin>>n>>m;
	repn(i, 1, n) cin>>s[i];
	repn(i, 1, m) cin>>t[i];
	repn(i, 1, n)
	{
		repn(j, 1, m)
		{
			ans[i][j] = (ans[i-1][j] + ans[i][j-1]);
			if(s[i] != t[j]) ans[i][j] -= ans[i-1][j-1];
			if(s[i] == t[j]) ans[i][j]++;
			if(ans[i][j] < M) ans[i][j] += M;
			ans[i][j] %= M;
		}
	}
	cout<<ans[n][m]+1<<endl;
}


Measured memory_bytes: 31744
n, c, k = map(int, input().split())
T = sorted(int(input()) for _ in range(n))

counter = 1
start = -1
wating_num = 0
for t in T:
  if start < 0:
    start = t
  if t - start > k or wating_num + 1 > c:
    counter += 1
    wating_num = 0
    start = t
  wating_num += 1
print(counter)

Measured memory_bytes: 13244
x=int(input())
saidai=0
beki=0

for i in range(1,x+1):
    for j in range(2,int(10)):
        if x>=i**j>saidai:
            saidai=i**j
            #print(i,j)
        if saidai>x:
            break
    if saidai>x:
        break
print(saidai)

Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int n, h[100000], c[100000];
int abs(int a)
{
    return (a > 0) ? a : (-a);
}
int main()
{
    //freopen("FROG1.inp", "r", stdin);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    c[0] = 0;
    c[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; i++)
    {
        c[i] = min(c[i-1] + abs(h[i] - h[i-1]), c[i-2] + abs(h[i] - h[i-2]));
    }
    cout << c[n-1];
    return 0;
}


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

int main(){
    int N, K;
    cin >> N >> K;
    int t;
    long long d;
    vector<pair<long long, int> > pairs(N);
    rep(i, N){
        cin >> t >> d;
        pairs[i] = make_pair(d, t);
    }
    sort(pairs.begin(), pairs.end());
    set<int> s;
    int x = 0;
    long long sum = 0;
    long long M[K+1];
    fill_n(M, K+1, 0);
    priority_queue<long long , vector<long long>, greater<long long> > used;
    rep(i, K){
        int j = (N-1) - i;
        sum += pairs[j].first;
        if(!s.count(pairs[j].second)){
            s.insert(pairs[j].second);
            x++;
        }
        else{
            used.push(pairs[j].first);
        }
    }
    M[x] = sum;
    int j = N-K-1;
    int i = x;
    while(!used.empty()&& j >= 0){
        long long m = used.top();
        used.pop();
        while(j >= 0){
            if(!s.count(pairs[j].second)){
                s.insert(pairs[j].second);
                M[i+1] = M[i] - m + pairs[j].first;
                j--;
                break;
            }
            else j--;
        }
        i++;
    }
    priority_queue<long long> que;
    for(long long a = x; a <= i; a++){
        que.push(M[a] + a*a);
    }
    cout << que.top() << endl;
}

Measured memory_bytes: 5884
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define rn return
#define fi first
#define se second
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;


int main(){
    int N;
    cin >> N;
    int ans = 0;
    FOR(i,1,10){
        int a = N/i;
        if (a<10 && a*i == N){
            ans = 1;
        }
    }
    
    if (ans){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
    rn 0;
}



Measured memory_bytes: 256
x, y = gets.strip.split.map(&:to_i)

def group(i)
  return :c if i == 2
  return :a if [1, 3, 5, 7, 8, 10, 12].include?(i)
  return :b
end

puts group(x) ==  group(y) ? 'Yes' : 'No'

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

int main(){
    string s,t;
    cin>>s>>t;
    
    int cnt=0;
    size_t l=s.length();
    rep(i,l){
        if(s[i]!=t[i]) cnt++;
    }
    
    cout<<cnt<<"\n";
    return 0;
}

Measured memory_bytes: 3916
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#define N 200020
#define mod 1000000007
using namespace std;
int n,m;
int a[N];
long long dp[N],tot[N];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)if(i==1||a[i]!=a[i-1])a[++m]=a[i];
	dp[0]=1;
	for(int i=1;i<=m;i++)
	{
		tot[a[i]]+=dp[i-1],tot[a[i]]%=mod;
		dp[i]+=tot[a[i]],dp[i]%=mod;
	}
	printf("%lld\n",dp[m]);
}

Measured memory_bytes: 4096
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int a; cin >> a;
	vector<int> v;
	for(int i = 2; i < 100; i++){
		if (pow(i,2)> 1000){
			break;
		}
		int count = 2;
		bool b = false;
		while(true){
			v.push_back(pow(i,count));
			if (pow(i,count) > 1000){
				b = true;
				break;
			}
			count++;
		}
	}
	sort(v.rbegin(), v.rend());
	rep(i, v.size()){
		if (a >= v[i]){
			cout << v[i] << endl;
			return 0;
		}
	}
	cout << 1 << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;
import java.lang.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    if (x >= 30) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

  }

}


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

#define ll              long long int
#define pb              push_back
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define fast_io         ios_base::sync_with_stdio(false); cin.tie(NULL);

double dp[305][305][305];

double findAns(int &n, int one, int two, int three){

    if(one <0 or two<0 or three<0){
        return 0;
    }

	if(one == 0 and two == 0 and three == 0){
		return 0;
	}

    if(dp[one][two][three] > -0.9){
        return dp[one][two][three];
    }

	double ans;
	ans = n +   (one * findAns(n, one - 1, two, three)) + 
				(two * findAns(n, one + 1, two - 1, three)) +
				(three * findAns(n, one, two + 1, three-1)); 

	ans = (ans/(one + two + three));

    dp[one][two][three] = ans;
	return ans;
}


int main(){

    int n;
    cin >> n;
    int val;

    int one=0, two=0, three=0;

    for(int i=0; i<n; i++){
    	cin >> val;
    	if(val == 1)
    		one++;
    	else if(val == 2)
    		two++;
    	else if(val == 3)
    		three++;
    }

    memset(dp, -1, sizeof(dp));
    double ans = findAns(n, one, two, three);
    cout<< ps(ans, 15)<<"\n";
    
	return 0;
}


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

if m==1:
    print(1)
    exit()

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
l=factorization(m)
ans=1
for p,b in l:
    com1=1
    com2=1
    for i in range(b):
        com1*=(b+n-1-i)
        com2*=(1+i)
    ans*=(com1//com2)%mod


print(ans%mod)


Measured memory_bytes: 38512
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using static System.Math;
using System.Text.RegularExpressions;

namespace CsharpSpiral {
    partial class Program {
        static void Main(string[] args) {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }
        public void Solve(ConsoleInput cin) {
            var n = cin.ReadInt;
            var A = cin.ReadLongArray(n);
            Console.WriteLine(string.Format("{0} {1} {2}", A.Min(), A.Max(), A.Sum()));
        }
    }

    static class ExtendClass {
        public static void Swap<T>(this T[] X, int i, int j) {
            T tmp = X[i];
            X[i] = X[j];
            X[j] = tmp;
        }
        public static string Join<T>(this T[] X, string separator = " ") => string.Join(separator, X);
        public static S[] Clone<S>(this S[] src) where S : struct {
            var res = new S[src.Length];
            Array.Copy(src, res, src.Length);
            return res;
        }
    }

    class ConsoleInput {
        private readonly TextReader _stream;
        private readonly char _separator = ' ';
        private readonly Queue<string> inputStream;
        public ConsoleInput(TextReader stream, char separator = ' ') {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read {
            get {
                if(inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for(int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) {
            var ret = new string[N];
            for(long i = 0; i < N; ++i)
                ret[i] = Read;
            return ret;
        }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
    }
}



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

int main(){
  int N, L; // Nこのりんご
  cin >> N >> L;

  vector<int> taste_1(N);
  int min = 0;
  for(int i = 0; i < N; i++){
    taste_1.at(i) = L + i;
    if(abs(taste_1.at(i)) < abs(taste_1.at(min))){
      min = i;
    }
  }

  int ap_taste = 0;
  for(int j = 0; j < N; j++){
    if(j != min){
      ap_taste += taste_1.at(j);
    }
  }
  
    cout << ap_taste << endl;
}

Measured memory_bytes: 256
# coding: utf-8
i = False
while True:
    line = input().rstrip().split()
    H = int(line[0])
    W = int(line[1])
    if H == 0 and W == 0:
        print("\n",end="")
        break
    if i:
        print("\n",end="")
    for i in range(H):
        for j in range(W):
            if (i + j) % 2 == 0:
                print("#",end="")
            else:
                print(".",end="")
        print("\n",end="")
    i =True


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

int main()
{
    int n, k;
    std::cin >> n >> k;

    const long long mod = 1000000007;

    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    long long p = 0;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i; j < n; j++) {
            if (a[i] > a[j]) {
                p++;
                p %= mod;
            }
        }
    }

    long long q = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (a[i] > a[j]) {
                q++;
                q %= mod;
            }
        }
    }

    long long ans1 = (long long)k * p % mod;
    long long ans2 = (long long)k * (k - 1) / 2 % mod;
    ans2 *= q;
    ans2 %= mod;
    long long ans = ans1 + ans2;
    ans %= mod;
    std::cout << ans << std::endl;
    return 0;
}


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

int debug = 1;

int main(){
    int n;
    string st;
    cin >>n>>st;
    int ans=0;
    for(int i=0;i<n-2;i++){
        if(st[i]=='A'&&st[i+1]=='B'&&st[i+2]=='C'){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

void countingSort(int);

int A[2000001],B[20000001],C[10001],n=0;

int main(){

	int i,j,t;

	scanf("%d",&n);

	for(i=0 ; i<n ; i++){
		scanf("%d",&A[i]);

		if(t<A[i])t=A[i];

	}

	countingSort(t);

	for(i=1; i<=n-1 ;i++){
			printf("%d ",B[i]);
	}
	  printf("%d",B[i]);
	  printf("\n");
		

		return 0;
	}

	void countingSort(int k){

		int i,j;

		for(i=0 ; i<=k;i++){
			C[i]=0;
		}

		for(j=0 ; j<n ; j++){
			C[A[j]] = C[A[j]]+1;
		}

		for(i=0 ; i<=k ; i++){
			C[i] = C[i]+C[i-1];
		}

		

		for(j=n-1 ; j>=0 ; j--){
			B[C[A[j]]] = A[j];
			C[A[j]] = C[A[j]]-1;
}
}

Measured memory_bytes: 16948
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//int[] array = new int[2000000];
		long n = sc.nextLong();
		long k = sc.nextLong();
		while(true) {
			long x=n/k;
			long y=n%k;
			if(x==0)
				break;
			else
				n=y;
		}
		long z = Math.abs(n-k);
		if(z<n)
			System.out.println(z);
		else
			System.out.println(n);
	}
}

Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int main(){
    int H,W,i,j;
    while(1){
        cin >> H >> W;
        if(H == 0 && W == 0)break;
        i=0;
        j=0;
        while(i < H){
            for(j = 0; j < W; j++){
                if(i==0 || i==H-1 || j==0 || j==W-1){
                    cout << '#';
                }
                else{
                    cout << '.';
                }
            }
            cout << endl;
            i++;   
        }
        cout <<endl;
    }
}


Measured memory_bytes: 3104
#include <stdio.h>

int main() {
	long long a, b, x;

	scanf("%lld%lld%lld", &a, &b, &x);
	printf("%lld\n", b / x + 1 - (a == 0 ? 0 : (a - 1) / x + 1));
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	string s; cin >> s;
	if(s[0]=='7' || s[1]=='7' || s[2]=='7') puts("Yes");
	else puts("No");
}


Measured memory_bytes: 3624
fun main(args : Array<String>) {
    val S = readLine()!!
    val result = IntArray(S.length, { 0 })

    val spots = mutableListOf<Pair<Int, Int>>()

    var prev = ' '
    S.forEachIndexed { index, c ->
        if (c == 'L' && prev == 'R') {
            spots.add(Pair(index - 1, index))
        }

        prev = c
    }

    (0 until S.length).forEach { i->
        if (S[i] == 'R')  {
            val index = lowerBound(spots, i)
            val spot = spots[index]
            val distance = spot.first - i
            if (distance % 2 == 0) {
                result[spot.first]++
            } else {
                result[spot.second]++
            }
        } else {
            val index = lowerBound(spots, i)
            val spot = spots[index - 1]
            val distance = i - spot.second
            if (distance % 2 == 0) {
                result[spot.second]++
            } else {
                result[spot.first]++
            }
        }
    }
    result.forEach {
        print(it)
        print(' ')
    }
}
fun lowerBound(sortedList: List<Pair<Int, Int>>, key: Int) : Int {
    var ng = - 1 // left
    var ok = sortedList.size  // right

    fun isOk(mid: Int) : Boolean {
        return sortedList.get(mid).first >= key
    }

    while (Math.abs(ok - ng) > 1) {
        var mid = (ok + ng) / 2
        if (isOk(mid)) {
            ok = mid
        } else {
            ng = mid
        }
    }
    return ok
}

Measured memory_bytes: 49008
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef long long ll;
typedef long double ld;

void solve() {
    ll n, a, b, c;
    cin >> n >> a >> b >> c;
    vector<string> s(n);
    for(ll i = 0; i < n; i++) cin >> s[i];
    string ans = "";
    for(ll i = 0; i < n; i++) {
        if(s[i] == "AB") {
            if(a > b) {a--; b++; ans += "B";}
            else if(b > a) {a++; b--; ans += "A";}
            else {
                if(i < n - 1 && s[i + 1] == "AC") {a++; b--; ans += "A";}
                else if(i < n - 1 && s[i + 1] == "BC") {a--; b++; ans += "B";}
                else {a--; b++; ans += "B";}
            }
        }
        if(s[i] == "AC") {
            if(a > c) {a--; c++; ans += "C";}
            else if(c > a) {a++; c--; ans += "A";}
            else {
                if(i < n - 1 && s[i + 1] == "AB") {a++; c--; ans += "A";}
                else if(i < n - 1 && s[i + 1] == "BC") {a--; c++; ans += "C";}
                else {a--; c++; ans += "C";}
            }
        }
        if(s[i] == "BC") {
            if(b > c) {b--; c++; ans += "C";}
            else if(c > b) {b++; c--; ans += "B";}
            else {
                if(i < n - 1 && s[i + 1] == "AC") {c++; b--; ans += "C";}
                else if(i < n - 1 && s[i + 1] == "AB") {c--; b++; ans += "B";}
                else {c--; b++; ans += "B";}
            }
        }
        if(a < 0 || b < 0 || c < 0) {cout << "No"; return;}
    }
    cout << "Yes\n";
    for(ll i = 0; i < ans.size(); i++) cout << ans[i] << "\n";
}    

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

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

#define ll long long

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

    int x; cin >> x;
    if (x == 1) cout << 0 << endl;
    else cout << 1 << endl;

    return 0;
}

Measured memory_bytes: 3604
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll mod=1e9+7;

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main()
{
    ll n;
    cin >> n;
    ll ans=0;
    vector<ll> p=divisor(n);
    vector<ll> q=divisor(n-1);
    ans+=q.size()-1;
    for(auto x:p){
        if(x==1) continue;
        ll m=n;
        while(m%x==0){
            m/=x;
        }
        if(m%x==1){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 384
def main():

    k = int(input())
    a = [0] * (10 ** 6 + 1)
    a[0] = 7 % k
    if a[0] == 0:
        print(1)
        exit()
    for i in range(1, k + 1):
        a[i] = (a[i - 1] * 10 + 7) % k
        if a[i] == 0:
            print(i + 1)
            exit()
    print(-1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 48344
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<long long> > vvll;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define INF 5000000000000000LL
#define MOD 1000000007
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define p_q priority_queue

#define FOR(i, a, b) for (int i=(a); i<=(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 200005
ll n;
ll x[MN];
ll ps[MN];
ll c; //x in problem!

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n >> c;
    FOR(i, 1, n){
        cin >> x[n+1-i];
        //ps[i] = ps[i-1]+x[i];
    }
    FOR(i, 1, n){
        ps[i] = ps[i-1]+x[i];
        //cout << ps[i] << " ";
    }
    //cout << "\n";

    ll ans = INF;

    FOR(i, 1, n){
        ll cm = 5;

        ll ca = 0;
        for(ll j=i; j<=n+i; j+=i){
            ll sm = ps[min(j, n)]-ps[j-i];

            ca += sm*cm;
            //cm+=2;
            if(j != i) cm += 2;
            if(ca > INF) ca = INF;
        }

        ca += c*(ll)(i+n);
        if(ca > INF) ca = INF;

        //cout << i << " " << ca << "\n";

        ans = min(ans, ca);
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 3328
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int as[n];
  for (int i = 0; i < n; i++) {
    cin >> as[i];
  }
  for (int i = n - 1; i > 0; i--) {
    cout << as[i] << " ";
  }
  cout << as[0] << endl;
  return 0;
}


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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

int main(){
    int M, D;
    cin >> M >> D;
    int cnt = 0;
    for(int i = 4; M >= i; i++)for(int j = 22; D >= j; j++){
        if(j % 10 >= 2 && j / 10 >= 2)if(i == (j / 10) * (j % 10)) cnt++;
    }
    print(cnt);
}



Measured memory_bytes: 256
#pragma warning(disable: 4996)

#include <iostream>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <vector>
#include <bitset>
#include <numeric>
#include <string>
#include <set>
#include <tuple>
#include <utility>
#include <regex>
#include <deque>
#include <map>
#include <queue>
using namespace std;

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; ++i) cin >> p[i];
	int cnt = 0;
	int min_n = 1e9;
	for (int i = 0; i < n; ++i) {
		min_n = min(min_n, p[i]);
		if (min_n >= p[i]) ++cnt;
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
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 dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

ll beki(int a, int n){
    if(n == 0) return 1;
    ll ans = beki(a, n / 2);
    ans = ans * ans;
    if(n % 2 == 1) ans = ans * a;
    return ans;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    
    ll N,M;cin>>N>>M;
    vl A(M); vin(A);
    ll ma = 0;
    rep(i,M) ma += A[i];
    if(ma > N) dame
    else{
        cout << N - ma << endl;
    }

}

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

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

typedef long long ll;
const ll mod = 1e9+7;

const ll INF = 1e18 + 7;
ll sum(int i,int j,int * a){
	ll res = 0;
	for(auto k = i;k<=j;++k)
		res += a[k];
	return res;
}
int main(int argc, const char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;

	int n,i,j,k;
	cin>>n;
	int a[n];
	for(i=0;i<n;++i)
		cin>>a[i];

	ll dp[n][n];

	for(i=n-1;i>=0;--i){
		for(j=i;j<n;++j){
			if(i == j)
				dp[i][j] = 0;
			else{
				dp[i][j] = INF;
				ll s = sum(i,j,a);
				for(k=i;k<j;++k){
					dp[i][j] = min(dp[i][j],dp[i][k] + dp[k+1][j] + s);
				}
			}
		}
	}
    cout<<dp[0][n-1]<<"\n";
#ifndef LOCAL_DEFINE
    cerr << "Time elapsed: "<< 1e1 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif // LOCAL_DEFINE
    return 0;
}

Measured memory_bytes: 1536
#include<stdio.h>
using namespace std;

int main() {
	int n; scanf("%d", &n);
	int c = 0;
	while (n--) {
		int d; scanf("%d", &d);
		for (int i = 1; i*i <= d; i++)if ((d - i) % (2 * i + 1) == 0)goto g;
		c++; g:;
	}
	printf("%d\n", c);
}

Measured memory_bytes: 2664
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from scipy.sparse.csgraph import floyd_warshall
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush, heapify
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n = inp()
    a = inpl()
    dic = defaultdict(int)
    ans = sum(a)
    for i in range(n):
        dic[a[i]] += 1
    q = inp()
    for _ in range(q):
        b,c = inpm()
        ans += dic[b]*(c-b)
        dic[c] += dic[b]
        dic[b] = 0
        print(ans)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 94764
#include<bits/stdc++.h>
using namespace std;
long long aa;bool bb;char ch;
long long scan()
{
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	ch=='-'?(bb=1,aa=0):(bb=0,aa=ch-48);
	while(ch=getchar(),(ch>='0'&&ch<='9'))
		aa=aa*10+ch-48;
	return (bb?(-aa):(aa));
}
struct cmp1
{
	bool operator()(long long a,long long b){
		return a>b;
	}
};
priority_queue<long long,vector<long long>,cmp1> h1;
struct cmp2
{
	bool operator()(long long a,long long b){
		return a<b;
	}
};
priority_queue<long long,vector<long long>,cmp2> h2;
long long ans,a[300010],sum1[300010],sum2[300010];
int n;
long long Max(long long u,long long v){return u>v?u:v;}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=3*n;++i)
	{
		scanf("%lld",&a[i]);
	}
	for(int i=1;i<=n;++i)
	{
		h1.push(a[i]);
		sum1[i]=sum1[i-1]+a[i];
	}
	for(int i=n+1;i<=n*2;++i)
	{
		h1.push(a[i]);
		sum1[i]=sum1[i-1]+a[i];
		sum1[i]-=h1.top();
		h1.pop();
	}
	for(int i=n*3;i>n*2;--i)
	{
		h2.push(a[i]);
		sum2[i]=sum2[i+1]+a[i];
	}
	for(int i=n*2;i;--i)
	{
		h2.push(a[i]);
		sum2[i]=sum2[i+1]+a[i];
		sum2[i]-=h2.top();
		h2.pop();
	}
	ans=sum1[n]-sum2[n+1];
	for(int i=n+1;i<=n*2;++i)
		ans=Max(ans,sum1[i]-sum2[i+1]);
	cout<<ans<<endl;
}

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


#define M 1000000007
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define mod 998244353
#define sz(v) (int)(v).size()

#define pii pair<int, int>
#define vi vector<int>
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

ll add(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a+b)%M;
	return (p+M)%M;
}

ll mul(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a*b)%M;
	return (p+M)%M;
}


int main()
{
	fastio;
	ll i,j,n,k,c,pre[200010]={0},suf[200010]={0};
	cin>>n>>k>>c;
	string str;
	cin>>str;
	str = " "+str;
	for(i=1;i<=n;i++)
	{
		pre[i]=1;
		if((str[i]!='x')&&(i>c))
			pre[i]=max(pre[i],pre[i-c-1]+1);
		pre[i]=max(pre[i],pre[i-1]);
	}
	for(i=n;i>0;i--)
	{
		suf[i]=1;
		if((str[i]!='x')&&(i+c+1<=n+1))
			suf[i]=max(suf[i],suf[i+c+1]+1);
		suf[i]=max(suf[i],suf[i+1]);	
	}
	if(c==0)
	{
		ll cnt=0;
		for(i=1;i<=n;i++)
		{
			if(str[i]=='o')
				cnt++;
		}
		if(cnt==k)
		{
			for(i=1;i<=n;i++)
			{
				if(str[i]=='o')
					cout<<i<<endl;
			}
		}
		return 0;
	}
	// for(i=1;i<=n;i++)
	// 	cout<<pre[i]<<" ";
	// cout<<endl;
	// for(i=1;i<=n;i++)
	// 	cout<<suf[i]<<" ";
	// cout<<endl;
	ll sum[200010]={0};
	j=0;
	for(i=1;i<=n;)
	{
		if(j!=n+1)		
			j++;
		else
			i++;
		if(j-i+1>c)
			i++;
		ll val = pre[i-1]+suf[j+1];
		// if(i==1)
		// 	cout<<val<<endl;
		if(val>=k)
		{
			sum[i]++;
			sum[j+1]--;
		}
	}
	ll cur=0;
	for(i=1;i<=n;i++)
	{
		cur+=sum[i];
		if(cur==0)
			cout<<i<<endl;
	}
	// cout<<endl;
    return 0;
}




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

int main() {
    int N;
    cin >> N;
    int i = 0;
    int multiplier = pow(2, i);

    while(multiplier <= N) {
        i++;
        multiplier = pow(2,i);
    }
    cout << multiplier/2 << endl;
}

Measured memory_bytes: 4100
#include<iostream>
#include<numeric>
#include<vector>
using namespace std;

long long int gcd(long long int x, long long int y){
    long long int r = x % y;
    while(r != 0){
        x = y;
        y = r;
        r = x % y;
    }
    return y;
}

int main(){
    long long int n;
    cin >> n;
    vector<long long int> t(n);
    for(long long int i = 0 ; i < n ; i++){
        cin >> t[i];
    }
    for(long long int i = 0 ; i < n-1 ; i++){
        t[i+1] = t[i] / gcd(t[i], t[i+1]) * t[i+1];
    }
    cout << t[n-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF=1e9,MOD=1e9+7,LINF=1e18;
struct E{int to,di;};
typedef pair<int,int> P;
/*
ダイクストラそれぞれ回してds[i]:sからの最短距離、dt[i]:tからの最短距離を作ってやる
各点へのs,tからの行き方が何通りあるかはdpで求められる(それぞれdps[i],dpt[i])
早い順にやってあげれば良さそう
ちょうど最短距離の半分の時に被るのが何通りかを数え上げて引いてやればいい
つまり？
その道を通るのが何通りかを調べてやれば終わり？
だから、
int sum_time=ds[t];
int ans=dps[t]*dps[t];
for(auto u,v,d edge){
  if(dps[u]<=sum_time/2<=dps[v])ans-=dps[u]*dpt[v];
}
*/
/*
なんでWAが出るのか　考察が間違っているのかな
最短経路の２乗-ぶつかるやつって考え方はあってると思う
最短経路がいつくあるかは流石に数えられている？各点へのそれが求められているから大丈夫なはず
そーとしてあるから足し損ねとかもなさそう
ぶつかるやつの数え損ね、数え過ぎがある？
点でぶつかるならその点はちょうど中間に位置していないといけない
つまりその点に辿りつくのにどっちから言ってもsum_time/2
この時削られるのは　あー分かったかも？
*/
int ds[123456],dt[123456],dps[123456],dpt[123456];

signed main(){
  int N,M,s,t;cin>>N>>M>>s>>t;s--;t--;
  vector<E> edge[N];
  for(int i=0;i<M;i++){
    int u,v,d;cin>>u>>v>>d;u--;v--;
    edge[u].push_back({v,d});
    edge[v].push_back({u,d});
  }
  for(int i=0;i<123456;i++)ds[i]=dt[i]=LINF;
  ds[s]=dt[t]=0;
  priority_queue<P,vector<P>,greater<P>> que;
  que.push(P(0,s));
  while(que.size()){
    P p=que.top();que.pop();
    int d=p.first,u=p.second;
    if(ds[u]<d)continue;
    for(auto q:edge[u]){
      if(ds[q.to]>ds[u]+q.di){
        ds[q.to]=ds[u]+q.di;
        que.push(P(ds[q.to],q.to));
      }
    }
  }
  que.push(P(0,t));
  while(que.size()){
    P p=que.top();que.pop();
    int d=p.first,u=p.second;
    if(dt[u]<d)continue;
    for(auto q:edge[u]){
      if(dt[q.to]>dt[u]+q.di){
        dt[q.to]=dt[u]+q.di;
        que.push(P(dt[q.to],q.to));
      }
    }
  }
  int sum_time=ds[t];
  vector<P> w(N);
  for(int i=0;i<N;i++)w[i]=P(ds[i],i);
  sort(w.begin(),w.end());
  dps[s]=1;
  for(int i=0;i<N;i++){
    int a=w[i].second;
    for(auto p:edge[a])
      if(ds[a]+p.di==ds[p.to])
        dps[p.to]+=dps[a],dps[p.to]%=MOD;
  }
  for(int i=0;i<N;i++)w[i]=P(dt[i],i);
  sort(w.begin(),w.end());
  dpt[t]=1;
  for(int i=0;i<N;i++){
    int a=w[i].second;
    for(auto p:edge[a])
      if(dt[a]+p.di==dt[p.to])
        dpt[p.to]+=dpt[a],dpt[p.to]%=MOD;
  }
  assert(dps[t]==dpt[s]);
  int ans=(dps[t]*dpt[s])%MOD;
  //cout<<ans<<endl;
  /*
  for(int i=0;i<N;i++)cout<<ds[i]<<" ";cout<<endl;
  for(int i=0;i<N;i++)cout<<dt[i]<<" ";cout<<endl;
  for(int i=0;i<N;i++)cout<<dps[i]<<" ";cout<<endl;
  for(int i=0;i<N;i++)cout<<dpt[i]<<" ";cout<<endl;
  */
  for(int i=0;i<N;i++){
    if(ds[i]*2==sum_time&&dt[i]*2==sum_time){
      int a=(dps[i]*dpt[i])%MOD;
      ans-=(a*a)%MOD;
      ans+=MOD;ans%=MOD;
      assert(ans>=0&&ans<MOD);
      continue;
    }
    for(auto p:edge[i]){
      if(ds[i]*2<sum_time&&ds[p.to]*2>sum_time&&dt[p.to]+ds[i]+p.di==sum_time){
        //cout<<i<<" "<<p.to<<endl
        int a=(dps[i]*dpt[p.to])%MOD;
        ans-=(a*a)%MOD;
        ans+=MOD;ans%=MOD;
        assert(ans>=0&&ans<MOD);
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 19456
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

void read();
template<typename First, typename... Rest> void read(First& first, Rest&... rest);
void write();
template<typename First, typename... Rest> void write(First first, Rest... rest);
template<typename T> void write_vec(vector<T>& v, char divider);

int main(){
    int n;
    read(n);
    vector<int> v(n);
    for(int i = 0; i < n; i++){
        read(v[i]);
    }
    map<int, int> mp1;
    map<int, int> mp2;
    for(int i = 0; i < n; i++){
        if(i & 1){
            mp1[v[i]]++;
        }
        else{
            mp2[v[i]]++;
        }
    }
    priority_queue<pair<int, int>> q1;
    for(auto i = mp1.begin(); i != mp1.end(); i++){
        if(i->second) q1.push(make_pair(i->second, i->first));
    }
    priority_queue<pair<int, int>> q2;
    for(auto i = mp2.begin(); i != mp2.end(); i++){
        if(i->second) q2.push(make_pair(i->second, i->first));
    }
    int ans = 0;
    if(q1.top().second != q2.top().second) {
        ans = n - (q1.top().first + q2.top().first);
    }
    else{
        int m1 = q1.top().first;
        int m2 = q2.top().first;
        q1.pop();
        q2.pop();
        int m12 = (q1.empty())? 0 : q1.top().first;
        int m22 = (q2.empty())? 0 : q2.top().first;
        ans = n - max(m12 + m2, m22 + m1);
    }
    write(ans);
    return 0;
}

//配列以外の入力を受け取る
void read(){

}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
    cin >> first;
    read(rest...);
}
//
//配列以外を出力する
void write(){

}
template<typename First, typename... Rest>
void write(First first, Rest... rest){
    cout << first << " ";
    write(rest...);
}
//
//配列を区切って出力する
template<typename T>
void write_vec(vector<T>& v, char divider){
    for(size_t i = 0; i < v.size(); i++){
        cout << v[i] << divider;
    }
}
//

Measured memory_bytes: 6520
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

int main() {
    long n, m, l;
    cin >> n >> m >> l;
    vector<vector<long>> a(n, vector<long>(m));
    for (long i = 0; i < n; i++){
        for (long j = 0; j < m; j++){
            cin >> a[i] [j];
        }
    }
    vector<vector<long>> b(m, vector<long>(l));
    for (long i = 0; i < m; i++){
        for (long j = 0; j < l; j++){
            cin >> b[i] [j];
        }
    }

    vector<vector<long>> c(n, vector<long>(l));
    for (long i = 0; i < n; i++) {
        for (long j = 0; j < l; j++) {
            for (long k = 0; k < m; k++) {
                c[i][j] += a[i][k] * b[k][j];
            }
        }
    }

    for (long i = 0; i < n; i++) {
        for (long j = 0; j < l - 1; j++) {
            cout << c[i][j] << " ";
        }
        cout << c[i][l - 1] << endl;
    }
}


Measured memory_bytes: 3368
MOD = 10**9+7


def make_cmb_table(n):
    fact = [1]
    for i in range(1, n+1):
        fact.append(fact[i-1] * i % MOD)

    ifact = [0] * (n+1)
    ifact[n] = pow(fact[n], MOD-2, MOD)
    for i in range(n, 0, -1):
        ifact[i-1] = ifact[i] * i % MOD
    return (fact, ifact)


def cmb(n, r, table):
    if r > n:
        return 0
    return table[0][n] * table[1][n - r] * table[1][r] % MOD


def main():
    n, k = map(int, input().split())
    k = min(k, n-1)
    table = make_cmb_table(n)
    ans = 0
    for i in range(k+1):
        ans += cmb(n, i, table) * cmb((n-i-1)+i, i, table) % MOD
        ans %= MOD
    print(ans)


main()


Measured memory_bytes: 54256
// 通分して
// package main

// import "fmt"

// func main() {
// 	var n int
// 	fmt.Scan(&n)
// 	a := make([]float64, n)
// 	for i := 0; i < n; i++ {
// 		fmt.Scan(&a[i])
// 	}

// 	x := 1.0 // 分母
// 	for _, aa := range a {
// 		x *= aa
// 	}

// 	y := 0.0 // 分子
// 	for _, aa := range a {
// 		y += x / aa
// 	}

// 	ans := x / y
// 	fmt.Println(ans)
// }

// ------------------------
// ナイーブに
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	x := 0.0 // 分母
	for _, aa := range a {
		x += 1 / aa
	}

	ans := 1 / x
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
#define N 300001
int mod=1000000007;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
void solve()
{
    int n; cin>>n;
    cout<<n+n*n+n*n*n;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test; test=1; //cin>>test;
    int x=1;
    while(test--)
    {
        //cout<<"Case #"<<x++<<": ";
        solve();
    }
    return 0;
}


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

using namespace std;

int main(){
  string S;
  cin >> S;
  
  int v[4];
  for(int i=0; i<4; i++) v[i] = (int)(S[i]-'0');
  
  int bit=0;
  for(bit=0; bit < (1<<3); bit++){
    int val = v[0];
    for(int i=0; i<3; i++){
      if (bit & (1<<i)) val += v[i+1];
      else val -= v[i+1];
    }
    if(val == 7) break;
  }
  
  char ope[3];
  for(int i=0; i<3; i++){
    ope[i] = (bit & (1<<i)) ? '+' : '-';
  }
  
  printf("%d%c%d%c%d%c%d=7", v[0], ope[0], v[1], ope[1], v[2], ope[2], v[3]); 
  
  return 0; 
}

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

using namespace std;

#define li          long
#define ll          long long
#define ull         unsigned long long
#define ff          first
#define ss          second
#define pii         pair<int,int>
#define pli         pair<li,li>
#define pll         pair<ll,ll>
#define pb          push_back
#define fo(i,k,n)   for(int i = k;i<n; i++)
#define ro(i,k,n)   for(int i = k; i>=n; i--)
#define tc          int t;cin>>t;while(t--)
#define all(v)      v.begin(),v.end()
#define inf         INT_MAX
#define ninf        INT_MIN
#define W(x)        cout<<x<<endl
#define WW(x,y)     cout<<x<<' '<<y<<endl;
#define in(x)       cin>>x
#define v(x)        vector<x>
#define int         long long
#define ar(x,y)     array<x,y>
const ll mod1 = 99844353;
const ll mod2 = 1e9+7;
/* template <class T>
using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; */

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

template<class T>
T power(T a,T b){
    T res = (T)1;
    while(b>0){
        if(b&1)res = res*a;
        b>>=1;
        a*=a;
    }
    return res;
}

struct dsu{
  unordered_map<int,int> pr,sz;
  dsu(){
    (this->pr).clear();
    (this->sz).clear();
  }
  void make(int x){
    pr[x] = x;
    sz[x] = 1;
  }
  int getpar(int x){
    if(pr[x] == x)return x;
    return pr[x] = getpar(pr[x]);
  }
  void merge(int x,int y){
    x = getpar(x);
    y = getpar(y);
    if(sz[x]<sz[y])swap(x,y);
    pr[y] = x;
    sz[x]+=sz[y];
    sz[y] = 0;
  }
};

void solve(){
  int x;
  cin>>x;
  int z = 2;
  while((z*180)%x!=0)z+=2;
  cout<<(z*180)/x<<"\n";
}

signed main(){
    fastio();
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	string s;
	cin>>s;
	int a = (s[0]-48)*10+(s[1]-48);
	int b = (s[2]-48)*10+(s[3]-48);
	if( (a<=12&&a>0) && (b<=12&&b>0) ){
		cout<<"AMBIGUOUS\n";
	}
	else if( !(a<=12&&a>0) && (b<=12&&b>0) ){
		cout<<"YYMM\n";
	}
	else if( (a<=12&&a>0) && !(b<=12&&b>0) ){
		cout<<"MMYY\n";
	}
	else{
		cout<<"NA\n";
	}
}

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
using namespace std;

int main() {
	int a, b, c,cnt=1;
	cin >> a >> b >> c;
	if (a != b)
	{
		cnt++;
	}
	if (a != c && b != c)
	{
		cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256