akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N,M,ans=0;
	cin >> N >> M;
	vector<vector<int>> s(M);
	vector<int> p(M);
	for(int i=0;i<M;i++){
		int k;
		cin >> k;
		for(int j=0;j<k;j++){
			int ss;
			cin >> ss;
			ss--;
			s[i].push_back(ss);
		}
	}
	for(auto &i:p)cin >> i;
	
	for(int i=0;i<pow(2,N);i++){
		int bit=i;
		vector<int> swi(N);
		for(int j=0;j<N;j++){
			swi[j]=bit%2;
			bit/=2;
		}
		vector<int> count(M,0);
		for(int j=0;j<M;j++){
			for(auto k:s[j])if(swi[k]==1)count[j]++;
		}
		bool flag=true;
		for(int j=0;j<M;j++)if(count[j]%2!=p[j])flag=false;
		if(flag)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(){
  char s[100010],ss[100020]={};
  char a[][10]={"eraser","erase","dreamer","dream"};
  char b[5][10]={};
  int i,j,k,l;
  scanf("%s",s);
  for(l=0;s[l];l++);
  for(i=0;i<l;i++)ss[i]=s[l-i-1];
  for(i=0;i<4;i++){
    for(l=0;a[i][l];l++);
    for(j=0;j<l;j++)b[i][j]=a[i][l-j-1];
  }
  //printf("%s\n",ss);
  //for(i=0;i<4;i++)printf("%s\n",b[i]);
  for(i=0;ss[i];i+=k){//printf("%d\n",i);return 0;
    for(j=0;j<4;j++){
      for(k=0;b[j][k];k++){
	if(ss[i+k]-b[j][k])break;
      }
      if(b[j][k]==0)break;
    }
    if(j==4){
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  return 0;
}
    
    


Measured memory_bytes: 384
/*
Dont BLUNDER
*/
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize ("-ffloat-store")
#pragma GCC optimization ("unroll-loops")
//for n2 loops
#include<bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;


 */
#define d long double
#define int long long
#define pii pair<int,int>
#define pb push_back
#define endl '\n'
#define pi acos(-1)

#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
int const mod = 998244353;
int const mod1 = 1000000007;
#define l first
#define r second
int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define haha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// * Using PBDS *
/*typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
               os; */



int modexp(int x, int n) {
	if (n == 0) {
		return 1;
	}
	else if (n & 1) {
		return (modexp((x * x) % mod, n / 2) % mod * x % mod) % mod;
	}
	else {
		return (modexp((x * x) % mod, n / 2) % mod);
	}
}

int modinv(int n)
{
	return modexp(n, mod - 2);
}

int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}
bool comp(pii a, pii b) {
	return a.second < b.second;

}
struct hash_pair {

	size_t operator()(const pair<int, int>& p) const
	{

		return ((  p.second ^ p.first) << 32);
	}
};



signed main()
{
	haha
// #ifndef ONLINE_JUDGE

// 	freopen("inp.txt", "r", stdin);

// 	freopen("out1.txt", "w", stdout);
// #endif
	int n;
	cin >> n;
	int arr[n];
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	sort(arr, arr + n);
	int c = 0;
	for (int i = 0; i < n - 2; i++) {
		for (int j = i + 1; j < n - 1; j++) {
			for (int k = j + 1; k < n; k++) {
				if (arr[i] != arr[j] && arr[j] != arr[k]) {
					if (arr[i] + arr[j] > arr[k])
						c++;
				}
			}
		}
	}
	cout << c;
















}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <vector>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (n); i++)
 
using namespace std;
 
int main()
{
    string s;cin >> s;
  	if(s[1] == 'B')cout << "ARC" << endl;
  	else cout << "ABC" << endl;
    return 0;
}

Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharp_AtCoder
{


    class Program
    {
        

        static void Main(string[] args)
        {
            int[] p = new int[3];
            bool[] p_b = new bool[3];
            p[0] = int.Parse(Console.ReadLine()) - 1;
            p[1] = int.Parse(Console.ReadLine()) - 1;

            for(int i = 0; i < 2; i++)
            {
                p_b[p[i]] = true;
            }

            for(int i = 0; i < 3; i++)
            {
                if (!p_b[i])
                {
                    Console.WriteLine(i + 1);
                    return;
                }
            }

        }
    }
}


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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> a(N+1);
    for (int i = 1; i <= N; i++) cin >> a[i];
    vector<vector<bool>> dp1(N+2, vector<bool>(K+1, false));
    dp1[0][0] = true;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= K; j++) {
            if (dp1[i-1][j]) {
                dp1[i][j] = true;
                dp1[i][min(K, j+a[i])] = true;
            }
        }
    }
    
    int ans = 0;
    set<int> s;
    s.insert(0);
    for (int i = N; i >= 1; i--) {
        bool check = true;
        for (int j = 0; j <= K; j++) {
            if (!dp1[i-1][j]) continue;
            auto it = s.lower_bound(K-j-a[i]);
            if (it != s.end() && (*it) < K-j) {
                check = false;
                break;
            }
        }
        if (check) ans++;
        vector<int> nxt;
        auto it2 = s.begin();
        while (it2 != s.end()){
            nxt.push_back(min(K, (*it2)+a[i]));
            it2++;
        }
        for (int n : nxt) s.insert(n);
    }
    cout << ans << endl;
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vl vector<long>
#define P pair<int,int>
using namespace std;

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


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

int N, M;
vector<vector<int>> graph, d;

void Dijsktra(int s) {
  vector<int> color(N + 1), p(N + 1, -1);
  d[s][s] = 0;

  while (true) {
    int min_cost = 1000000000, u;
    for (int i = 1; i <= N; i++) if (color[i] != 2 && d[s][i] < min_cost) min_cost = d[s][i], u = i;
    if (min_cost == 1000000000) break;
    color[u] = 2;
    for (int v = 1; v <= N; v++) {
      if (color[v] != 2 && graph[u][v] != -1)
        if (d[s][u] + graph[u][v] < d[s][v]) d[s][v] = d[s][u] + graph[u][v], p[v] = u, color[v] = 1;
    }
  }
}

int main() {
  cin >> N >> M;
  graph.resize(N + 1, vector<int>(N + 1, -1));
  vector<int> a(M + 1), b(M + 1), c(M + 1);
  for (int i = 1; i <= M; i++) cin >> a[i] >> b[i] >> c[i];
  for (int i = 1; i <= M; i++) graph[a[i]][b[i]] = c[i], graph[b[i]][a[i]] = c[i];
  d.resize(N + 1, vector<int>(N + 1, 1000000000));
  for (int i = 1; i <= N; i++) Dijsktra(i);
  int ans = M;
  for (int i = 1; i <= M; i++) {
    bool flag = false;
    for (int s = 1; s <= N; s++) if (d[s][a[i]] + c[i] == d[s][b[i]]) flag = true;
    if (flag) ans--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	string a;
	cin>>a;
	if(a[0]==a[2])
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		String in = stdIn.nextLine();
		int ix = stdIn.nextInt();
		String inC = in.substring(0);
		boolean c1 = check1(inC,ix);
		boolean c2 = check2(in,ix);
		
		if(c1 && c2) {
			System.out.println("U");
		}
		else if(c1) {
			System.out.println("M");
		}
		else if(c2) {
			System.out.println("L");
		}
		else {
			System.out.println("I");
		}
	}
	static boolean check1(String a, int b) {
		int id = 0;
		for(int i = 0; i < a.length(); i++) {
			
			
			if(a.charAt(i) == '+') {
				id = i+1;
			}
			if(a.charAt(i) == '*') {
				int o1 = Integer.parseInt(a.substring(id, i));
				int id2 = 0;
				for(int j = i+1; j < a.length(); j++) {
					if(a.charAt(j) == '+' || a.charAt(j) == '*' ) {
						id2 = j;
						break;
					}
					if(j == a.length()-1) {
						id2 = j+1;
						break;
					}
				}
				int o2 = Integer.parseInt(a.substring(i+1,id2));
				String tmp = a.substring(0,id);
				tmp += (o1 * o2);
				tmp += a.substring(id2,a.length());
				a = tmp;
				i = -1;
			}
		}
		for(int i = 0; i < a.length(); i++) {

			if(a.charAt(i) == '+') {
				int o1 = Integer.parseInt(a.substring(0,i));
				for(int j = i+1; j < a.length(); j++) {
					
					if(a.charAt(j) == '+') {
						int o2 = Integer.parseInt(a.substring(i+1,j));
						o1 += o2;
						String tmp = String.valueOf(o1);
						tmp += a.substring(j,a.length());
						a = tmp;
						i = -1;
						break;
					}
					if(j == a.length()-1) {
						int o2 = Integer.parseInt(a.substring(i+1,j+1));
						o1 += o2;
						String tmp = String.valueOf(o1);
						tmp += a.substring(j+1,a.length());
						a = tmp;
						i = -1;
						break;
					}
				}
			}
		}
		
		if(Integer.parseInt(a) == b) return true;
		return false;
		
	}
	static boolean check2(String a, int b) {
		for(int i = 0; i < a.length(); i++) {
			if(a.charAt(i) == '*' || a.charAt(i) == '+') {
				boolean x = false;
				if(a.charAt(i) == '*') {
					x = true;
				}
				int o1 = Integer.parseInt(a.substring(0, i));
				for(int j = i+1; j < a.length(); j++) {
					if(a.charAt(j) == '*' || a.charAt(j) == '+') {
						int o2 = Integer.parseInt(a.substring(i+1,j));
						if(x) {
							String tmp = String.valueOf((o1 * o2)) + a.substring(j);
							a = tmp;
						}
						else {
							String tmp = String.valueOf((o1 + o2)) + a.substring(j);
							a = tmp;
						}
						i = -1;
						break;
					}
					if(j == a.length()-1) {
						int o2 = Integer.parseInt(a.substring(i+1,j+1));
						if(x) {
							String tmp = String.valueOf((o1 * o2)) + a.substring(j+1);
							a = tmp;
						}
						else {
							String tmp = String.valueOf((o1 + o2)) + a.substring(j+1);
							a = tmp;
						}
						i = -1;
						break;
					}
				}
			}
		}
		if(Integer.parseInt(a) == b) {
			return true;
		}
		return false;
	}
}

Measured memory_bytes: 17360
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

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

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  s=S()
  t=S()

  for i in range(len(s)-len(t)+1)[::-1]:
    x=s[i:i+len(t)]
    f=True
    for j in range(len(t)):
      if x[j]==t[j] or x[j]=='?':
        pass
      else:
        f=False

    if f:
      # 後ろから合致する場所は置き換え
      # 残りの '?' 部は 'a' に置き換え
      print(str(s[:i]+t+s[i+len(t):]).replace('?','a'))
      exit()

  print('UNRESTORABLE')

main()
# print(main())


Measured memory_bytes: 5420
#include <bits/stdc++.h>
#include <array>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
using namespace std;
template <typename T> istream & operator >> (istream & is, vector<T> & vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;
using VI = vector<int>;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}

int main() {
	int x; CI x;
	if (x == 3 or x == 5 or x == 7) { CO "YES" EN; }
	else CO "NO" EN;
}


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

const int64_t MOD = 998244353;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = fact[1] = 1;
    for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
}

void create_seq_inv_mod(int num){
    seq_inv[0] = seq_inv[1] = 1;
    for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
}

void create_fact_inv_mod(int num){
    fact_inv[0] = fact_inv[1] = 1;
    for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    const int M = 1e6;
    vector<int64_t> sum(M+1);
    for(int a : A) add(sum[a], a);
    for(int i=1; i<=M; i++) for(int j=2*i; j<=M; j+=i) add(sum[i], sum[j]);

    vector<int64_t> W(M+1);
    for(int i=1; i<=M; i++){
        add(W[i], inv_mod(i));
        for(int j=2*i; j<=M; j+=i) add(W[j], MOD - W[i]);
    }

    int64_t ans = 0;
    for(int i=1; i<=M; i++){
        int64_t res = sum[i] * sum[i] % MOD * W[i] % MOD;
        add(ans, res);
    }

    for(int64_t a : A) add(ans, MOD - a);
    mul(ans, inv_mod(2));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 16640
import sys
sys.setrecursionlimit(10 ** 7)

n, q = map(int,input().split())
tree = [list(map(int,input().split())) for _ in range(n-1)]
score = [list(map(int,input().split())) for _ in range(q)]

graph = [[] for _ in range(n+1)]
for t in tree:
    graph[t[0]].append(t[1])
    graph[t[1]].append(t[0])
#print(graph)
#[[], [2], [1, 3, 4], [2], [2]]

value = [0]*(n+1)
for s in score:
    value[s[0]] += s[1]

#print(value)
# [0, 100, 10, 1, 0]

q = [(1,0)]
while q:
    target,parent = q.pop()
    value[target] += value[parent]
    for t in graph[target]:
        if t == parent:
            continue
        else:
            q.append((t,target))

v = value[1:]
print(*v)

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

using namespace std ;

#define inf 0x3f3f3f3f
#define ll long long

ll n , s ;

ll f( ll b , ll n )
{
	return n < b ? n : f( b , n / b ) + n % b ;
}

int main()
{
	scanf( "%lld%lld" , &n , &s ) ;
	if( s > n ) return puts( "-1" ) , 0 ;
	if( s == n ) return printf( "%lld\n" , n + 1 ) , 0 ;
	ll m = sqrt( n ) + 1 ;
	for( ll i = 2 ; i <= m ; i ++ )
	{
		if( f( i , n ) == s )
			return printf( "%lld" , i ) , 0 ;
	}
	ll ans = 1e11 ;
	n -= s ;
	for( ll i = 1 ; i * i <= n ; i ++ )
	{
		if( n % i == 0 )
		{
			ll b = n / i + 1;
			if( f ( b , n + s ) ==  s ) ans = min ( ans , b ) ;
		}
	}
	printf( "%lld\n" , ans != 1e11 ? ans : -1 ) ;
	return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a[123456],co;
int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=1;i<n;i++){
        if(a[i]<=a[(i-1)])co++;
    }
    co++;
    cout<<co<<endl<<n<<endl;
}



Measured memory_bytes: 3512
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
from bisect import bisect_left, bisect_right
#======================================================#
def main():
    n = II()
    aa = MII(); bb = MII(); cc = MII()
    aa.sort();  bb.sort();  cc.sort()
    cnt = 0
    for b in bb:
        a = bisect_left(aa, b)
        c = bisect_right(cc, b)
        cnt += (a)*(n-c)
    print(cnt)



if __name__ == '__main__':
    main()

Measured memory_bytes: 22720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(long long i=s;i<n;i++)
#define mod 1000000007
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 2e18
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main()
{
          string s,t;
          cin>>s>>t;
          cout<<t<<s<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

typedef long long ll;
int n, k;

double func(int v){
    if (v >= k) return 1;
    return 0.5 * func(2 * v);
}

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

    double ans = 0.0;

    for(int i = 1; i <= n; ++i){
        if (i >= k) ans += 1.0 / n;
        else{
            ans += 1.0 / n * func(i);
        }
    }

    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;

int main(){

    int n; cin >> n;

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

    vector<vector<int>> vdivisor;
    vector<int> vempty;
    for(int i=0; i<n+1; i++){
        vdivisor.push_back(vempty);
    }

    for(int i=1; i<n+1; i++){
        int sqrti = sqrt(i);
        // cout << sqrti << endl;
        for(int j=1; j<=sqrti; j++){
            // cout << i << " " << j << endl;
            if(i % j == 0){
                vdivisor[i].push_back(j);
            }
        }
        int nd = vdivisor[i].size();
        if(sqrti*sqrti != i){
            for(int j=nd-1; j>=0; j--){
                vdivisor[i].push_back(i / vdivisor[i][j]);
            }
        }
        else{
            for(int j=nd-2; j>=0; j--){
                vdivisor[i].push_back(i / vdivisor[i][j]);
            }
        }
    }

    // for(int i=0; i<vdivisor[n].size(); i++){
    //     cout << vdivisor[n][i] << " " << endl;
    // }

    int m = 0;
    vector<int> ans;

    for(int i=n-1; i>=0; i--){
        int nd = vdivisor[i+1].size();
        if((i+1) > n/2){
            if(a[i] == 1){
                b[i] = 1;
                m++;
                ans.push_back(i+1);
                // cout << i+1 << " ";
                for(int j=0; j<nd; j++){
                    c[vdivisor[i+1][j]-1]++;
                    // cout << vdivisor[i+1][j] << " ";
                }
                // cout << endl;
            }
        }
        else{
            // cout << i+1 << " " << c[i] << endl;
            if(c[i]%2 != a[i]){
                b[i] = 1;
                m++;
                ans.push_back(i+1);
                for(int j=0; j<nd; j++){
                    c[vdivisor[i+1][j]-1]++;
                }
            }
        }
    }

    // for(int i=0; i<n; i++){
    //     cout << b[i] << endl;
    // }

    cout << m << endl;
    for(int i=0; i<ans.size(); i++){
        cout << ans[i] << " ";
    }

    return 0;
}

Measured memory_bytes: 24556
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <cstdio>
#include <math.h>
#include <utility>
#include <list>
#include <functional>
#include <queue>
using namespace std;

#define ll long long
#define vecint vector<int>
#define Pii pair<int, int>

#define REP(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define print(a) cout << a << endl

#define MOD 1000000007
#define NIL -1

int N,M;
int ans[50];

void solve(){
    rep(i,M){
        int x,y;
        cin>>x>>y;
        ans[x-1]++;ans[y-1]++;
    }
    rep(i,N){
        print(ans[i]);
    }
    return;
}



int main(){
    cin>>N>>M;
    solve();
    return 0;
}


Measured memory_bytes: 256
import numpy as np
ary=[]
ary_=[]
num=[]
for i in range(3):
    lst=input().split()
    ary.append(lst)
n=int(input())
for i in range(n):
    num.append(input())

for i in range(3):
    for j in range(3):
        for k in num:
            if ary[i][j]==k:
                ary[i][j]=0

for i in range(3):
    if set(ary[i])=={0}:
        print('Yes')
        exit()
    elif ary[0][i]==0 and ary[0][i]==ary[1][i] and ary[2][i]==ary[0][i]:
        print('Yes')
        exit()
if ary[0][0]==0 and ary[1][1]==ary[0][0] and ary[2][2]==ary[0][0]:
    print('Yes')
    
elif ary[2][0]==0 and ary[2][0]==ary[1][1] and ary[1][1]==ary[0][2]:
    print('Yes')
else:
    print('No')


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

int main() {
int n,m;
cin>>n;
cin>>m;
int a[m];
for(int i=0;i<m;i++){
cin>>a[i];	
}
int sum =0;
int j=0;
while(j<m){
	sum+=a[j];
	j++;
}
int diff = n-sum;
if(diff<0) diff = -1;
cout<<diff;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i<(n);i++)
#define fore(i,a) for(auto &i:a)
#define debug(a,b) cout << "debug : " << a << " , "<< b << endl
using ll=long long;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
const ll INF=1LL<<60;
const ll mod=1E9+7;

int main(){
  int n,m;
  cin >> n >> m;
  int aa,b;
  vector<vll> a(n+1,vll());
  rep(i,m){
    cin >> aa >> b;
    a[aa].push_back(b);
    a[b].push_back(aa);
  }
  queue<int>q;q.push(1);
  vector<int>ans(n+1,mod);
  int cnt=n;
  while(!q.empty()){
    int u=q.front();q.pop();
    rep(i,a[u].size()){
      int p=a[u][i];
      if(ans[p]==mod){
	cnt--;
	ans[p]=u;
	q.push(p);
      }
    }
  }

  if(cnt!=0)cout << "No" << endl;
  else {
    cout << "Yes" << endl;
    rrep(i,2,n+1)cout << ans[i] << endl;
  }
}



Measured memory_bytes: 12312
#include <cstdio>
#include <cstring>
#include <queue>
#include <utility>

#define fir first
#define sec second

using namespace std;

typedef pair<int,int> mp;
typedef pair<int,mp> mmp;


typedef struct{
	int x,y;
}pos;

int h,w,n;
char map[1005][1005]={};
int gone[1005][1005];

pos dir[4]={ {0,1},{1,0},{0,-1},{-1,0} };

int main(void){
	scanf("%d%d%d", &h, &w, &n);
	pos ms;
	char read[1005];
	for(int y=0;y<h;y++){
		scanf("%s",read);
		for(int x=0;x<w;x++){

			map[x][y]=read[x];

			if(map[x][y]=='S'){
				ms.x=x; ms.y=y;
			}
		}
	}

	int r=0;
	for(int k=1;k<=n;k++){

		memset(gone,0,sizeof(gone));
		queue<mmp> que;
		
		que.push(make_pair( 0,make_pair( ms.x,ms.y )));

		while(true){
			mmp ma=que.front();
			que.pop();

			if( map[ma.sec.fir][ma.sec.sec] == ('0'+k) ){
				ms.x=ma.sec.fir;
				ms.y=ma.sec.sec;
				r+=ma.fir;
				break;
			}
			for(int i=0;i<4;i++){
				int nx = ma.sec.fir + dir[i].x;
				int ny = ma.sec.sec + dir[i].y;

				if(!(nx<0 || nx>=w || ny<0 || ny>=h || map[nx][ny]=='X' || gone[nx][ny]==1)){
					que.push( make_pair(ma.fir+1, make_pair(nx, ny)) );
					gone[nx][ny]=1;
				}
			}
		}
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 5988
#include<stdio.h>
int min(int a,int b)
{
    return ((a>b)?b:a);
}

int main(void)
{
    int n,i,b[101]={0},a[101]={0};
    long long int sum = 0;
    scanf("%d",&n);
    for(i=0;i<n-1;i++)
    {
        scanf("%d",&b[i]);
    }
    for(i=0;i<n-1;i++)
        sum+=min(b[i],b[i+1]);
    printf("%lld\n",sum+b[n-2]+b[0]);
    return 0;
}


Measured memory_bytes: 128
H, W = map(int, input().split())
Ss = [input() for _ in range(H)]

# 行の入れ替えパターンを生成する（中央付近から埋めていく）
def dfs(iR):
    # 全て埋まったら、判定に移る
    if iR < 0:
        return check()

    # 未使用の行を検索する
    iF = flgs.index(False)
    Rs[iR] = iF - offset
    flgs[iF] = True

    # ペアの相手を決めて、次のペア生成に移る
    ans = False
    for iF2, flg in enumerate(flgs):
        if not flg:
            Rs[H - 1 - iR] = iF2 - offset
            flgs[iF2] = True
            ans = ans or dfs(iR - 1)
            flgs[iF2] = False

    flgs[iF] = False

    return ans


# 与えられた行の入れ替えパターンに対して、列の入れ替えのみで点対称にできるかを判定する
def check():

    Ts = [Ss[R] for R in Rs]
    Ts = list(map(list, zip(*Ts)))

    # (W+1)/2列目を使用可能かどうか
    if W % 2: flgCenter = True
    else: flgCenter = False

    # 各列に対して、処理を行う
    Used = [False] * W
    for j, T in enumerate(Ts):
        if Used[j]: continue
        for j2, T2 in enumerate(Ts[j + 1:], j + 1):
            # 上下反転したような未使用の列が存在するならば、次の列へ
            if not Used[j2] and T[::-1] == T2:
                Used[j2] = True
                break
        else:
            # 自身が上下対称、かつ、(W+1)/2列目を使用可能ならば、次の列へ
            if T[::-1] == T and flgCenter == True:
                flgCenter = False
            else:
                # この入れ替えパターンでは不可能と判定
                return False

    return True


if H % 2:
    # Hが奇数ならば、先頭にダミーを付加
    flgs = [False] * (H + 1)
    offset = 1
else:
    flgs = [False] * H
    offset = 0

Rs = [-1] * H
if dfs((H - 1) // 2):
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll n,l;
	cin>>n>>l;
	ll sum=0,a[1100]={},ans=1e9;
	for(int i=0;i<n;i++){
		a[i]=l+i;
		sum+=l+i;
		ll num=abs(a[i]);
		if(num<abs(ans))ans=a[i];
	}
	cout<<sum-ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct kk{
int id;
int ac;
int wa;
vector<int> p;//譬ク蝠城。後↓蟇セ縺吶ｋ繝壹リ繝ォ繝?ぅ
vector<bool>acs;
int psum;
};
//
kk ans[105];
int main(){
	int T,P,R;
	while(cin>>T>>P>>R&&(T+P+R)!=0){//T繝√?繝??P蝠?R蛟九?繝ュ繧ー
	for(int i=0;i<105;i++){
	ans[i].p.resize(180);
	ans[i].acs.resize(190);
	for(int j=0;j<103;j++)ans[i].p[j]=0,ans[i].acs[j]=0;
	ans[i].id=i;
	}

	for(int i=0;i<R;i++){
	int a,b,c;//id,蝠城。景d,邨碁℃譎る俣
	string d;//繝。繝?そ繝シ繧ク
	cin>>a>>b>>c>>d;
	if(d=="WRONG"){
	ans[a].p[b]++;
	}
	else if(d=="CORRECT"){
	ans[a].ac++;
	ans[a].acs[b]=true;
	ans[a].p[b]=ans[a].p[b]*1200+c;
	}
	}
	for(int i=1;i<=T;i++){
		int sum=0;
		for(int j=0;j<=P;j++)if(ans[i].acs[j])sum+=ans[i].p[j];
		ans[i].psum=sum;
	}

	//for(int i=1;i<=T;i++)cout<<ans[i].id<<" "<<ans[i].ac<<" "<<ans[i].psum<<endl;
	for(int i=1;i<=T;i++){
		for(int j=i+1;j<=T;j++){
			if(ans[i].ac<ans[j].ac)swap(ans[i],ans[j]);//蜿ウ縺ョ縺サ縺?′蠑キ縺代ｌ縺ーswap
			else if(ans[i].ac==ans[j].ac){

				if(ans[i].psum>ans[j].psum)swap(ans[i],ans[j]);
				if(ans[i].psum==ans[j].psum&&ans[i].id>ans[j].id)swap(ans[i],ans[j]);
			}
		}
	}
	for(int i=1;i<=T;i++){
	cout<<ans[i].id<<" "<<ans[i].ac<<" "<<ans[i].psum<<endl;
	}
		for(int i=0;i<=104;i++){ans[i].p.clear();ans[i].acs.clear();ans[i].psum=0;ans[i].ac=0;ans[i].wa=0;ans[i].id=0;}
	}
		return 0;
}

Measured memory_bytes: 1328
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <string>
#include <sstream>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<ll> VL;

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

  int X, Y;
  cin >> X >> Y;

  int ans = 0;
  if (X > Y) {
    ans = X;
    X -= 1;
  } else {
    ans = Y;
    Y -= 1;
  }
  if (X > Y) {
    ans += X;
    X -= 1;
  } else {
    ans += Y;
    Y -= 1;
  }

  cout << ans << endl;

}

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

const int nax = 1e5 + 5;
vector<int> edge[nax];
int con[nax];
int dist[nax];
bool visited[nax];

void dfs(int a) {
  assert(!visited[a]);
  visited[a] = true;

  for (int b : edge[a]) {
    dist[b] = max(dist[a] + 1, dist[b]);
    --con[b];
    if (con[b] == 0) {
      dfs(b);
    }
  }
}

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

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    edge[a].push_back(b);
    ++con[b];
  }

  for (int i = 1; i <= n; i++) {
    if (!visited[i] && con[i] == 0) {
      dfs(i);
    }
  }

  int ans;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, dist[i]);
  }
  cout << ans << endl;
}


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

#define fs first
#define sc second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define pb emplace_back

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

int main() {
	int n;
	
	while (cin >> n, n) {
		bool f[101][101] = {false};
		rep(i, n) {
			int m = in();
			rep(j, m) {
				f[i][in()] = true;
			}
		}

		vi a, l;
		
		int k = in();
		rep(i, k) l.pb(in());

		rep(i, n) {
			bool beet = true;
			rep(j, l.size()) {
				if (!f[i][l[j]]) beet = false;
			}
			if (beet) a.pb(i + 1);
		}

		cout << (a.size() == 1 ? a[0] : -1) << endl;
	}
}

Measured memory_bytes: 3116
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>
#include <math.h>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

#define pi 3.141592653589793
#define mod 1000000007

char name[5] = { 'M' ,'A' , 'R' ,'C' ,'H' };
llint possible[5] = {0,0,0,0,0};

int count = 0;

int func(int x,int n) {
	if (n == 1)return x;
	return x * func(x - 1,n-1);
}

int f(int x) {
	if (x == 0)return 1;
	return x * f(x - 1);
}

int main() {
	int n;
	cin >> n;
	vector<string>s(n);
	vector<int>memo(n);
	for (int i = 0; i < n; i++)cin >> s[i];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 5; j++) {
			if (s[i][0] == name[j]) {
				possible[j]++;
			}
		}
	}
	int people = 0;
	for (int i = 0; i < 5; i++) {
		if (possible[i] > 0) {
			people++;
		}
	}
	if (people < 3) {
		cout << 0 << endl;
		return 0;
	}

	llint res = 0;

	for (int i = 0; i < 5; i++) {
		for (int j = 0; j < 5; j++) {
			if (j <= i)continue;
			for (int k = 0; k < 5; k++) {
				if (k <= j)continue;
				res += possible[i]* possible[j] *possible[k];
			}
		}
	}

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
int gcd(int a, int b)
{
	if (a == 0)
		return b;
	if (b == 0)
		return a;
	int r = a%b;
	while (r != 0)
	{
		a = b;
		b = r;
		r = a%b;
	}
	return b;
}
int L[100001], R[100001], M[100001];
int main()
{
	vector<int> a;
	int n, x;
	cin >> n;
	a.push_back(0);
	for (int i = 1; i <= n; i++)
	{
		cin >> x;
		a.push_back(x);
	}
	if (n == 2)
		cout << (a[1] > a[2] ? a[1] : a[2]) << "\n";
	else
	{
		L[1] = 0;
		R[n + 1] = 0;
		for (int i = 1; i <= n-1; i++)
			L[i + 1] = gcd(L[i], a[i]);
		for (int i = n; i >= 1; i--)
			R[i] = gcd(R[i + 1], a[i]);
		for (int i = 1; i <= n; i++)
			M[i] = gcd(L[i], R[i+1]);
		int max = 0;
		for (int i = 1; i <= n; i++)
		{
			if (M[i] > max)
				max = M[i];
		}
		cout << max << "\n";
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 1912
require 'pp'
require 'prime'

n = gets.chomp!.to_i
MOD = 10 ** 9 + 7
memo = { }
1.upto(n) do |i|
    Prime.prime_division(i).each do |num, cnt|
        memo[num] ||= 0
        memo[num] += cnt
    end
end

ans = 1
memo.each do |num, cnt|
    ans = (ans * (cnt + 1)) % MOD
end

puts ans


Measured memory_bytes: 2428
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <string.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main()
{
ll ans,n,k,temp;

cin >> n>>k;
vector<ll> syu(100002,0);
vector<ll> nokori;
ll dp[n]={};
rep(i,n){
    ll t,d;
    cin >>t>>d;
    if(syu[t]>d)nokori.push_back(d);
    else{nokori.push_back(syu[t]);syu[t]=d;}
}
sort(syu.rbegin(), syu.rend());
sort(nokori.rbegin(), nokori.rend());
ans=syu[0]+1;
rep(i,k-1){
    ans+=nokori[i];
}
temp=ans;
//cout << temp << endl;
rep(i,k-1){
    if(syu[i+1]==0)break;
    temp=temp+syu[i+1]-nokori[k-i-2]+(i+2)*(i+2)-(i+1)*(i+1);
    //cout << temp << endl;
    if(temp>ans)ans=temp;
}
/* for (int i = 0; i < n; ++i) {
    cout << syu[i] << " ";
}cout  << endl;
for (int i = 0; i < n; ++i) {
    cout << nokori[i] << " ";
}cout  << endl; */
cout << ans << endl;
return 0;
}





Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll K=1000000007;
 
int main (){    
    int N;
    cin>>N;
    vector<int> P(N);
    int Ans=0;
    ll Min=K;
    for(int i=0; i<N;i ++){
        cin>>P[i];
        if(i==0){
            Ans ++;
            Min=P[0];
            continue;
        }
        if(P[i]<Min){
            Ans ++;
            Min=P[i];
        }
    }
  cout<<Ans;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VL = vector<LL>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define FILL(a, b) memset(a, b, sizeof(a))

void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    m1 += h1 * 60;
    m2 += h2 * 60;
    cout << max(0, m2 - m1 - k) << "\n";
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,i,c,d;
    scanf("%d%d",&a,&b);
   if(a==0)
   {
       if(b!=100)
      printf("%d\n",b);
      else
        printf("101\n");
   }
   else if(a==1)
   {
        if(b!=100)
       printf("%d\n",b*100);
        else
        printf("10100\n");
   }
   else if(a==2)
   {
       if(b!=100)
       printf("%d\n",b*10000);
        else
        printf("1010000\n");
   }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N;
    cin >> N;
    set<int> st;
    rep(i,N){
        int a;
        cin >> a;
        st.insert(a);
    }
    if(st.size()==N)cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

int main(){
	int N;
	cin >> N;
	vector<int> W(N);
	vector<int> sum(N+1,0);
	for(int i=0;i<N;i++){
		int w;
		cin >> w;
		W[i]=w;
		sum[i+1]=sum[i]+w;
	}
	int ans=999999999;
	for(int i=0;i<N;i++){
		ans=min(ans,abs(sum[N]-sum[i]*2));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;  
int a[5]={0};
int main()  
{  
    int n;  
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        string s;
        cin>>s;
        if(s[0]=='A') a[1]++;
        if(s[0]=='W') a[2]++;
        if(s[0]=='T') a[3]++;
        if(s[0]=='R') a[4]++;
    }
    cout<<"AC x "<<a[1]<<endl;
    cout<<"WA x "<<a[2]<<endl;
    cout<<"TLE x "<<a[3]<<endl;
    cout<<"RE x "<<a[4]<<endl;
    return 0;  
}  


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] input = new int[N];
		int res = 0;
		for (int i = 0; i < N; i++) {
			input[i] = sc.nextInt();
			while (true) {
				if (input[i] % 2 == 0) {
					input[i] /= 2;
					res++;
				} else {
					break;
				}
			}
		}
		System.out.print(res);
	}
}


Measured memory_bytes: 34720
S=input()
N=len(S)
A=[0]
B=[0]
C=[0]
X=[0]
for i in range(N):
  A.append(A[i])
  B.append(B[i])
  C.append(C[i])
  X.append(X[i])
  if S[i]=='A':
    A[-1]+=1
  elif S[i]=='B':
    B[-1]+=1
  elif S[i]=='C':
    C[-1]+=1
  else:
    X[-1]+=1
P=0
mod=10**9+7
for i in range(N):
  if S[i]=='B':
    P=(P+pow(3,X[N],mod)*A[i]*(C[N]-C[i+1]))%mod
    if X[i]:
      P=(P+pow(3,X[N]-1,mod)*X[i]*(C[N]-C[i+1]))%mod
    if X[N]-X[i+1]:
      P=(P+pow(3,X[N]-1,mod)*A[i]*(X[N]-X[i+1]))%mod
    if X[i] and X[N]-X[i+1]:
      P=(P+pow(3,X[N]-2,mod)*X[i]*(X[N]-X[i+1]))%mod
  if S[i]=='?':
    P=(P+pow(3,X[N]-1,mod)*A[i]*(C[N]-C[i+1]))%mod
    if X[i]:
      P=(P+pow(3,X[N]-2,mod)*X[i]*(C[N]-C[i+1]))%mod
    if X[N]-X[i+1]:
      P=(P+pow(3,X[N]-2,mod)*A[i]*(X[N]-X[i+1]))%mod
    if X[i] and X[N]-X[i+1]:
      P=(P+pow(3,X[N]-3,mod)*X[i]*(X[N]-X[i+1]))%mod
print(P)

Measured memory_bytes: 107800
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
long long a[1001][1001]={0};
int main(){
int i,j,c,s,l;
char cl[2001],sl[2001];
scanf("%s %s",sl,cl);
s=strlen(sl);
c=strlen(cl);
for(i=0;i<=s;i++)a[i][0]=1;
for(i=1;i<=s;i++){
for(j=0;j<c;j++){
a[i][j+1]=a[i-1][j+1]%1000000007;
if(sl[i-1]==cl[j]){
a[i][j+1]=(a[i-1][j+1]+a[i-1][j])%1000000007;
}
}
}
cout<<a[s][c]<<endl;
return 0;
}

Measured memory_bytes: 10980
#include<iostream>
#include<stdio.h>

using namespace std;

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

  for(int i=0;i<n;i++){
    int ans=0;
    for(int j=0;j<m;j++){
      ans+=(a[i][j]*b[j]);
    }
      cout<<ans<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <queue>
#include <set>

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

using namespace std;

int dp[2005][2005];

string solve(string str) {
    rep(i,2005)rep(j,2005)dp[i][j] = 0;
    string rev = str;
    reverse(rev.begin(), rev.end());
    
    for (int i = 1; i <= str.size(); i++) {
        int si = i - 1;
        for (int j = 1; j <= str.size(); j++) {
            int sj = j - 1;
            if (si + sj >= str.size())break;
            if (si + sj == str.size() - 1) {
                dp[i][j] = dp[i-1][j-1] + 1;
            } else {
                if (str[si] == rev[sj])dp[i][j] = dp[i-1][j-1] + 2;
            }
            dp[i][j] = max(dp[i][j], max(dp[i-1][j], dp[i][j-1]));
        }
    }

    string ans;
    int ansMax = 0;
    int index = 0;
    
    rep(i, str.size() + 1) {
        if (ansMax < dp[i][str.size() + 1 - i]) {
            index = i;
            ansMax = dp[i][str.size() + 1 - i];
        }
    }

    int pi = index, pj = str.size() + 1 - index;
    if (ansMax % 2 == 1) {
        ansMax--;
        ans = str[pi-1];
        pi--, pj--;
    }
    
    while(pi > 0 && pj > 0) {
        while(pi > 0 && dp[pi-1][pj] == dp[pi][pj])pi--;
        while(pj > 0 && dp[pi][pj-1] == dp[pi][pj])pj--;
        if (pi == 0 || pj == 0)break;
        ans = str[pi-1] + ans + str[pi-1];
        pi--,pj--;
    }

    return ans;
}

int main() {
    string str;
    while(cin >> str) {
        cout << solve(str) << endl;
    }
    return 0;
}

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

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1];
    auto P = N.iota.map!(_ => readln.split.map!(to!long).array).array;
    P.sort!((a, b) => a[0] < b[0]);
    long ans = -1;

    foreach (i; 0..N) {
        long[] Y = [P[i][1]];
        foreach (j; i+1..N) {
            Y ~= P[j][1];
            if (Y.length < K) continue;
            Y.sort();
            foreach (k; 0..Y.length.to!int-K+1) {
                if (ans == -1)
                    ans = (P[j][0] - P[i][0]) * (Y[k+K-1] - Y[k]);
                else
                    ans = min(ans, (P[j][0] - P[i][0]) * (Y[k+K-1] - Y[k]));
            }
        }
    }

    ans.writeln;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace testing
{
    class Program
    {

        static void Main(string[] args)
        {
            //int[] d = Console.ReadLine().Split().Select(int.Parse).ToArray();
            string a = Console.ReadLine();
            if (a == "SAT") Console.WriteLine("1");
            if (a == "FRI") Console.WriteLine("2");
            if (a == "THU") Console.WriteLine("3");
            if (a == "WED") Console.WriteLine("4");
            if (a == "TUE") Console.WriteLine("5");
            if (a == "MON") Console.WriteLine("6");
            if (a == "SUN") Console.WriteLine("7");
        }
    }
}


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

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

Measured memory_bytes: 256
N = gets.to_i
C, S, F= readlines.map{|l| l.split.map(&:to_i)}.transpose

def go(t, i)
  u = (t + F[i] - 1) / F[i] * F[i]
  u = S[i] if S[i] > u
  i == N - 2 ? u + C[i] : go(u + C[i], i + 1)
end

(0 ... N - 1).each{|i| puts go(0, i)}
puts 0

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

string sentence;
typedef string::const_iterator State;

int parse(State &it){
  int ret = 0;
  while(isdigit(*it)){
    ret = ret * 10;
    ret = ret + *it - '0';
    it++;
  }
  return ret;
}

int main(void){
  int sum = 0;
  while(cin >> sentence){
    for(State it = sentence.begin(); it != sentence.end(); it++){
      if(isdigit(*it)){
        sum += parse(it);
        it--;
      }
    }
  }
  cout << sum <<endl;
  return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define LL long long
#define mp make_pair
#define next tipa_next
#define hash tipa_hash
#define ll long long
const int INF = 1000LL*1000*1000;
const int base = 1000 * 1000 * 1000;
map<LL , int> m;
int main()
{
    LL n , p;
    cin >> n >> p;
    LL ans = 1;
    for(LL i = 2; i * i <= p; i++)
    {
        while(p % i == 0)
        {
            m[i]++;
            p /= i;
        }
    }
    if(p != 1)
    {
        m[p]++;
    }
    for(auto x : m)
    {
        int cnt = x.second / n;
        for(int i = 0; i < cnt; i++)
            ans *= x.first;
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    int N;
    cin >> N;
    vector<string> data(N);
    for (int i = 0; i < N; i++) {
        cin >> data[i];
    }
    vi count(26, 0);
    int n = data[0].size();
    for (int i = 0; i < n; i++) {
        int num = data[0][i] - 'a';
        count[num]++;
    }
    for (string s : data) {
        vi ansa(26,0);
        int a = s.size();
        for (int i = 0; i < a; i++) {
            int num = s[i] - 'a';
            ansa[num]++;
        }
        for (int i = 0; i < 26; i++) {
            count[i] = min(count[i], ansa[i]);
        }
    }
    string ans = "";
    for (int i = 0; i < 26; i++) {
        for (int j = 0; j < count[i]; j++) {
            char c = 'a' + i;
            ans.push_back(c);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
import java.util.*;

public class Main{
  public static void main(String args[]) {
    Scanner in  = new Scanner(System.in);
    String str  = in.next();
    int rnum    = in.nextInt();
    String pstr = "";

    for(int i = 0; i < rnum; i++){
      String order = in.next();
      int start    = in.nextInt();
      int end      = in.nextInt();
      if(order.equals("print")){
        pstr = str.substring(start,end+1);
        System.out.println(pstr);
      } else if(order.equals("reverse")){
        pstr = str.substring(start,end+1);
        StringBuffer sb = new StringBuffer(pstr);
        sb = sb.reverse();
        pstr = str.substring(0,start);
        pstr += sb.toString();
        pstr += str.substring(end+1,str.length());
        str = pstr;
        // System.out.println(str);
        //
      } else if(order.equals("replace")){
        String re = in.next();
        pstr  = str.substring(0,start);
        pstr += re;
        pstr += str.substring(end+1,str.length());
        str = pstr;
        // System.out.println(str);
        //
      }
    }
  }
}



Measured memory_bytes: 30244
#include<cstdio>
int main(){
    int k,s,ans=0,x,y,z;
    scanf("%d%d",&k,&s);
    for(x=0;x<=k;x++){
        for(y=0;y<=k;y++){
            z=s-x-y;
            if(0<=z && z<=k)ans++;
        }
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
let scan1 f = stdin.ReadLine() |> f
let scanVecV f n = [| for i in 1..n -> stdin.ReadLine() |> f |]

let n = scan1 int
let xs = scanVecV string n

let isUniq str = xs |> Array.filter ((=) str) |> Array.length |> (=) 1

let isOK str1 str2 =
  (Seq.last str1) = (Seq.head str2) && (isUniq str1) && (isUniq str2)

xs
|> Seq.pairwise
|> Seq.forall (fun (x1,x2) -> isOK x1 x2)
|> fun b -> if b then "Yes" else "No"
|> printfn "%s"


Measured memory_bytes: 14300