akhauriyash/Code-Regression huggingface dataset:
n = int(input())
v = list(map(int, input().split()))

v0 = v[::2]
v1 = v[1::2]

d0 = dict()
for x in v0:
    d0[x] = d0.get(x, 0) + 1

d1 = dict()
for x in v1:
    d1[x] = d1.get(x, 0) + 1

L0 = [(k, v) for k, v in d0.items()]
L0 = sorted(L0, key=lambda x: x[1], reverse=True)

L1 = [(k, v) for k, v in d1.items()]
L1 = sorted(L1, key=lambda x: x[1], reverse=True)

half_n = n // 2
ans = -1
if L0[0][0] != L1[0][0]:
    ans = (half_n - L0[0][1]) + (half_n - L1[0][1])
else:
    if len(L0) > 1 and len(L1) > 1:
        if L0[1][1] >= L1[1][1]:
            ans = (half_n - L0[1][1]) + (half_n - L1[0][1])
        else:
            ans = (half_n - L0[0][1]) + (half_n - L1[1][1])
    else:
        if len(L0) == 1 and len(L1) > 1:
            ans = (half_n - L1[1][1])
        elif len(L0) > 1 and len(L1) == 1:
            ans = (half_n - L1[0][1])
        else:
            ans = (half_n)
print(ans)

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

int main(){
    int a, b, k;
    cin >> a >> b >> k;
    for (int i = min(a,b); i >= 1; --i){
        if(a % i == 0 && b % i == 0) {
            --k;
        }
        if (k == 0){
            cout << i << endl;
            exit(0);
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
using namespace std;
using ll = long long;


int main() {
	int n, d; cin >> n >> d;
	vector<vector<int>> x(n, vector<int>(d));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) cin >> x[i][j];
	}
	auto f = [&](int i, int j) {
		int ret = 0;
		for (int t = 0; t < d; t++) {
			ret += (x[i][t] - x[j][t])*(x[i][t] - x[j][t]);
		}
		return ret;
	};
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			int dis = f(i, j);
			for (int k = 1; k <= dis; k++) {
				if (k*k > dis) break;
				if (k*k == dis) ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <utility>
using namespace std;

#define PrintLn(X) cout << X << endl
#define Loop(n) for(int loop_ = n; loop_; --loop_)
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define For(i, a, b) for(int i = a; i < (int)(b); ++i)

int main(void)
{
	int N, x;
	cin >> N >> x;
	int a[200000];
	
	Rep(i, 2 * N - 1){
		a[i] = i + 1;
	}
	if(x != 1 && x != 2 * N - 1){
		PrintLn("Yes");
		if(x < N){
			swap(a[x - 0], a[N - 0]);
			swap(a[x - 1], a[N - 1]);
			swap(a[x - 2], a[N - 2]);
		}else{
			swap(a[x - 2], a[N - 2]);
			swap(a[x - 1], a[N - 1]);
			swap(a[x - 0], a[N - 0]);
		}
		Rep(i, 2 * N - 1) PrintLn(a[i]);
	}else{
		PrintLn("No");
	}
	return 0;
}


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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int gcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int n,k,ans=0;
  cin>>n>>k;
  vector<int> v(n);
  rep(i,n) cin>>v[i];
  sort(v.begin(),v.end(),greater<int>());
  rep(i,k){
    ans+=v[i];
  }
  cout<<ans<<endl;
}
///////////////////////////

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
	public static void main(String[]$){

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		String S = sc.next();

		S = S.substring(0,K-1) + S.substring(K-1,K).toLowerCase() + S.substring(K,S.length());

		System.out.println(S);
	}
}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn=1e5+100;
const int mod=1e9+7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n;
ld T, A;
ld best=100000, id;
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin>>n>>T>>A;
    for(int i=0; i<n; i++)
    {
        ld a;
        cin>>a;
        if(abs(T-a*0.006-A) < best)
        {
            best=abs(T-a*0.006-A);
            id=i+1;
        }
    }
    cout<<id;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  int n;
  cin>>n;
  int mx = 0;
  for(int i = 0; i * i <= n; i++)
  {
    mx = i;
  }
  cout << mx * mx << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

	double money = 100000;
	int n;

	cin >> n;

	for (int i = 1; i <= n; i++) {
		//???????????????
		money *= 1.05;
		//1000??????????????°?????????
		double miman = money - ((int)(money*0.001)) * 1000.0;
		if (miman > 0) {
			money = money - miman + 1000.0;
		}
	}

	cout << (int)money << endl;

	return 0;

}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

template <class T> class MultiArray2
{
    public:
        T* _a;
        int _w;
        int _h;
        MultiArray2(int w, int h, bool clr = false)
        {
            _w = w; _h = h;
            _a = new T[_w * _h];
            if(clr) memzero();
        }

        void memzero()
        {
            memset(_a, 0, _w * _h * sizeof(T));
        }

        ~MultiArray2()
        {
            delete _a;
        }

        T* operator[](int i)
        {
            return _a + (i * _h);
        }

        void print()
        {
            for( int j = 0; j < _h; j++ )
            {
                for( int i = 0; i < _w; i++ )
                {
                    cout << (*this)[i][j] << " ";
                }
                cout << endl;
            }
        }
};

int main()
{
    int n;
    cin >> n;
    int *e2 = new int[n];
    int *e5 = new int[n];
    rep(i, n)
    {
        string s;
        cin >> s;

        bool isShosu = false;
        _LL ans = 0;
        _LL p10 = 1000000000;

        rep(j, s.length())
        {
            if( s[j] == '.' )
            {
                ans = ans * p10;
                isShosu = true;
            }
            else
            {
                if( !isShosu )
                {
                    ans = ans * 10 + (s[j] - '0');
                }
                else
                {
                    p10 /= 10;
                    ans = ans + p10 * (s[j] - '0'); 
                }
            }
        }

        if( !isShosu ) ans = ans * p10;

        //2, 5の約数を求める
        e2[i] = 0;
        e5[i] = 0;

        while( ans % 5 == 0 )
        {
            ans /= 5;
            e5[i]++;
        }
        while( ans % 2 == 0 )
        {
            ans /= 2;
            e2[i]++;
        }
    }

    MultiArray2<_LL> count(19, 19, true);
    rep(i, n) count[min(e2[i], 18)][min(e5[i], 18)]++;
    _LL ans = 0;
    rep(k2, 19)
    {
        rep(k5, 19)
        {
            _LL c1 = count[k2][k5];
            if( c1 == 0 ) continue;
            for( _LL l2 = 18 - k2; l2 < 19; l2++ )
            {
                for( _LL l5 = 18 - k5; l5 < 19; l5++ )
                {
                    _LL c2 = count[l2][l5];
                    if( c2 == 0 ) continue;
                    if( k2 == l2 && k5 == l5 ) c2--;
                    ans += c1 * c2;
                }
            }
        }
    }
    ans /= 2;
    cout << ans;
}

Measured memory_bytes: 5168
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

s = 0

for i in range(n):
    s += b[a[i]-1]
    if i == n-1:
        continue
    elif a[i] + 1 == a[i+1]:
        s += c[a[i]-1]
    
print(s)

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


int main(){
    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        int x=i;
        if(x%3==0){
            cout << " " << i;
            continue;
        }
        while(x!=0){
            if(x%10==3){
                cout << " " << i;
                break;
            }
            x/=10;
        }



    }
    cout << endl;
}
	
	





Measured memory_bytes: 3092
list1=input().split(' ')
N=int(list1[0])
K=int(list1[1])
Q=int(list1[2])
listQ=[]
for i in range(Q):
    listQ.append(int(input()))
listScores=[K for i in range(N)]
sum=0
for i in listQ:
    sum=sum+1
    listScores[i-1]=listScores[i-1]+1
for i in listScores:
    i=i-sum
    if i>0:
        print('Yes')
    elif i<=0:
        print('No')


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

int main(){
    int nedan = 700;
    char S1, S2, S3;
    cin >> S1 >> S2 >> S3;

    if(S1 == 'o')nedan += 100;
    if(S2 == 'o')nedan += 100;
    if(S3 == 'o')nedan += 100;
    cout << nedan << endl;
    return 0;
}

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

int main() {
   string S;
   cin >> S;
   int count=0;
   int n = S.size()/2;
   string a = S.substr(0, n);
   reverse(S.begin(), S.end());
   string b = S.substr(0, n);

   for(int i=0; i<n; i++) {
      if(a[i] != b[i]) count++;
   }
   cout << count << endl;
}

Measured memory_bytes: 3600
#include<iostream>
#include<map>
#include<set>
#include<vector>
using namespace std;
int N;
long mod=1e9+7;
int dp[2][1<<20];
int sx;
long cnt;
vector<int>G[1<<20];
int s[500050];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		int a;cin>>a;sx^=a;
		s[i+1]=s[i];
		if(sx)G[sx].push_back(i);
		else
		{
			cnt++;
			s[i+1]++;
		}
	}
	s[N+1]=s[N];
	for(int i=1;i<1<<20;i++)
	{
		dp[0][i]=1;
		if(G[i].empty())continue;
		int p=G[i][0];
		G[i].push_back(N);
		for(int j=1;j<G[i].size();j++)
		{
			long k=s[G[i][j]+1]-s[p+1];
			dp[1][i]=(dp[1][i]+dp[0][i])%mod;
			dp[0][i]=(dp[0][i]+k*dp[1][i]%mod)%mod;
			p=G[i][j];
		}
	}
	if(sx)cout<<dp[0][sx]<<endl;
	else
	{
		long ans=1;
		for(int i=1;i<cnt;i++)ans=ans*2%mod;
		for(int i=1;i<1<<20;i++)
		{
			ans=(ans+dp[1][i])%mod;
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 43904
import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    private static String solve(Scanner scanner) {
        boolean ret = solveInner(scanner);
        return ret ? "POSSIBLE" : "IMPOSSIBLE";
    }

    private static boolean solveInner(Scanner scanner) {
        String line = scanner.nextLine();
        int N = Integer.parseInt(line.split(" ")[0]);
        int M = Integer.parseInt(line.split(" ")[1]);
        HashMap<Integer, HashSet<Integer>> islandToIslands = new HashMap<>();

        for (int i = 0; i < M; i ++) {
            line = scanner.nextLine();
            String[] split = line.split(" ");
            int a = Integer.parseInt(split[0]);
            int b = Integer.parseInt(split[1]);

            HashSet<Integer> set = islandToIslands.getOrDefault(a, new HashSet<>());
            set.add(b);
            islandToIslands.put(a, set);
        }

        HashSet<Integer> neighbors = islandToIslands.getOrDefault(1, new HashSet<>());
        for (Integer n: neighbors) {
            HashSet<Integer> set = islandToIslands.get(n);
            if (set == null) continue;
            if (set.contains(N)) return true;
        }

        return false;
    }

    public static void main(String[] args) {
//        tests();

        Scanner scanner = new Scanner(System.in);
        System.out.println(solve(scanner));
    }

    private static String ex1 = "3 2\n" +
            "1 2\n" +
            "2 3";
    private static String ex2 = "4 3\n" +
            "1 2\n" +
            "2 3\n" +
            "3 4";
    private static String ex3 = "100000 1\n" +
            "1 99999";
    private static String ex4 = "5 5\n" +
            "1 3\n" +
            "4 5\n" +
            "2 3\n" +
            "2 4\n" +
            "1 4";

    private static void tests() {
        System.out.println(solve(new Scanner(testCaseToInputStream(ex1))));
        System.out.println(solve(new Scanner(testCaseToInputStream(ex2))));
        System.out.println(solve(new Scanner(testCaseToInputStream(ex3))));
        System.out.println(solve(new Scanner(testCaseToInputStream(ex4))));
    }

    private static ByteArrayInputStream testCaseToInputStream(String ex) {
        try {
            return new ByteArrayInputStream(ex.getBytes("utf-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            throw new RuntimeException();
        }
    }

    private static int[] lineTointNums(String line) {
        String[] numStrs = line.split(" ");
        int[] nums = new int[numStrs.length];
        for (int i = 0; i < nums.length; i ++) {
            nums[i] = Integer.parseInt(numStrs[i]);
        }
        return nums;
    }
}


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

#define ll long long
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (ll)1000000007
#define f first
#define s second
#define debug1(x) cerr<<x<<"\n"
#define debug2(x,y) cerr<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<"\n"
#define nl cerr<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cerr<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define mxn 100005

ll dp[101][mxn];
int a[mxn],n,k;

ll solve(int i,int k){
if(k<0)return 0LL;
if(k==0||i==n+1)return 1LL;
ll &ans=dp[i][k];
if(ans!=-1)return ans;
int rem=min(k,a[i]);
ans=(solve(i+1,k)-solve(i+1,k-rem-1)+mod)%mod;
ans=(ans+solve(i,k-1))%mod;
return ans;
}

int main(){
sp;
memset(dp,-1,sizeof dp);
cin>>n>>k;
for(int i=1; i<=n; ++i)cin>>a[i];
ll ans=(solve(1,k)-solve(1,k-1)+mod)%mod;
cout<<ans;
return 0;}


Measured memory_bytes: 85376
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n;
    cin >> n;
    map<string,int> mp;
    rep(i,n){
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        if(mp.find(s) == mp.end()){
            mp[s] = 1;
        }else{
            mp[s]++;
        }
    }

    ll ans = 0;
    for(auto i = mp.begin(); i != mp.end(); i++){
        int num = i->second;
        ans += (ll)num*(num-1)/2;
    }

    cout << ans << endl;
    return 0;

}

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define PII pair<int,int>
#define INF LONG_MAX
#define ull unsigned long long
#define long long long
#define PIL pair<long,int>
#define M 1000000007
#define endl "\n"

void fastIO() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

}


void findFactor(int el,unordered_set<int> &f,bool *flag){
    for(int i = 2;i*i<=el;i++){
        if(el%i==0){
            if(el/i==i){
                if(f.find(i)==f.end()){
                    f.insert(i);
                }else{
                    *flag = true;
                    return;
                }
            }else{
                if(f.find(i)!=f.end() || f.find(el/i)!=f.end()){
                    *flag = true;
                    return ;
                }else{
                    f.insert(i);
                  
                    f.insert(el/i);
                }    
            }
        }
    }
}
bool pairWise(int ar[],int n){
    unordered_set<int> factors;
    bool flag = false;
    for(int i=0;i<n;i++){
        if(ar[i]==1)
            continue;
        if(factors.find(ar[i])!=factors.end())
            return false;
        findFactor(ar[i],factors,&flag);  
        factors.insert(ar[i]);
        if(flag==true){
            return false;
        }
    }
    return true;
}

int main()
{
	fastIO();
    int n;
    cin>>n;
    int ar[n];
    for(int i=0;i<n;i++){
        cin>>ar[i];
    }
    int allgcd =ar[0] ;
    for(int i= 1;i<n;i++){
        allgcd = __gcd(allgcd,ar[i]);
    }
    
    
    if(allgcd !=1 ){
        cout<<"not coprime";
        
    }else {
        if(pairWise(ar,n)){
            cout<<"pairwise coprime";
        
        }else{
            cout<<"setwise coprime";
        }
    }
  
    
}



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

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

const string YES = "Yes";
const string NO = "No";

void solve(ll a, ll b, ll c) {
  bool pred = a+b+c == 2*max({a,b,c});
  cout << (pred ? YES : NO) << endl;
}

int main() {
  ll a;
  cin >> a;
  ll b;
  cin >> b;
  ll c;
  cin >> c;
  solve(a, b, c);
  return 0;
}


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

typedef long long ll;

#define PB push_back
#define MP make_pair

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
    ll a, b, c, d, e; cin >> a >> b >> c >> d >> e;
    if (a == 0) cout << 1 << "\n";
    if (b == 0) cout << 2 << "\n";
    if (c == 0) cout << 3 << "\n";
    if (d == 0) cout << 4 << "\n";
    if (e == 0) cout << 5 << "\n";
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* print new lines
*/



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

int Harmony(int *A, int *B)
{
    if(*A>*B)
    {
        for(int i=(*B);i<(*A);i++)
        {
            if((i-(*B))==((*A)-i))
                return i;
        }
        goto label;
    }

    else if(*A<*B)
    {
        for(int i=(*A);i<(*B);i++)
        {
            if((i-(*A))==((*B)-i))
                return i;
        }
        goto label;
    }

    else
    {   label:
        return 0;
    }


}

int main()
{

    int A,B;
    int K;
    scanf("%d %d",&A,&B);
    K=Harmony(&A,&B);
    if(K!=0)
        printf("%d",K);
    else
        printf("IMPOSSIBLE");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#define ll long long
#define pb push_back
#define f first
#define s second
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
const int N = 10005;
int a[N];


int solve(){
    int n; cin >> n;
    ll now;
    for(ll i = 1; i <= 100; i++){
        for(ll j = 1; j <= 100; j++){
            for(ll k = 1; k <= 100; k++){
                now = i * i + j * j + k * k + i * j + i * k + k * j;
                if(now <= 10000)a[now]++;
            }
        }
    }
    for(int i = 1; i <= n; i++){
        cout << a[i] << endl;
    }
    return 0;
}

int main(){
    fast;
    solve();
    return 0;
}



Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
const int N = 1e6+6;
const ll mod = 1e9+7;
int a[222];
int b[1222];
int c[1222];
void solve(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n-1;i++){
        cin>>c[i];
    }
    int ans = b[a[0]-1];
    for(int i=1;i<n;i++){
        ans+=b[a[i]-1];
        if(a[i]==a[i-1]+1)ans+=c[a[i-1]-1];
    }

    cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--)solve();
	return 0;
}


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

int main()
{
    int n,m,x,temp;
    cin>>n>>m>>x;
    int arr[n+1];
    for(int &x:arr)
        x=0;
    for(int i=0;i<m;i++)
    {   cin>>temp;
        arr[temp]++;}
    int s1=0,s2=0;
    for(int i=0;i<x;i++)
        s1+=arr[i];
    for(int i=x+1;i<n+1;i++)
        s2+=arr[i];
    if(s1>s2)
        swap(s1,s2);
    cout<<s1;



}

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

//?????????????????¢?????????
double dist(double x1,double y1,double x2,double y2){
	return (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
}
//??????
double dot_product(double x1,double y1,double x2,double y2){
	return x1*x2+y1*y2;
}
int main(){
	double x1,y1,x2,y2,xq,yq;
	while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf",&x1,&y1,&x2,&y2,&xq,&yq)){
		double xr,yr,k,xs,ys;
		k=dot_product(x2-x1,y2-y1,xq-x1,yq-y1)/dist(x2,y2,x1,y1);
		//s?????§?¨?
		xs=x1+k*(x2-x1);
		ys=y1+k*(y2-y1);
		//r?????§?¨?
		xr=2*xs-xq;
		yr=2*ys-yq;
		printf("%.6lf %.6lf\n",xr,yr);
	}
}

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

int main() {
	int n, l;
	cin >> n >> l;
	string list[n];
	for(int i=0; i<n; ++i) {
		cin >> list[i];
	}
	sort(list, list+n);
	for(auto v : list) {
		cout << v;
	}
	cout << endl;
}

Measured memory_bytes: 256
class PreallocatedQueue:
    def __init__(self, n, init_val):
        self.queue = [init_val] * n #根にサイズを負の値で格納する。
        self.l = 0
        self.r = 0
        self.n = n
        self.init_val = init_val
        self.count = 0

    def append(self, val):
        if self.count == self.n:
            if self.r == 0:
                self.queue = self.queue + [self.init_val] * self.n
            else:
                self.queue = self.queue[self.l:] + self.queue[:self.r] + [self.init_val] * self.n
                self.l = 0
            self.r = self.n
            self.n *= 2
        self.queue[self.r] = val
        self.r = (self.r + 1) % self.n
        self.count += 1

    def popleft(self):
        if self.count == 0:
            raise IndexError('popleft from empty queue')
        val = self.queue[self.l]
        self.l = (self.l + 1) % self.n
        self.count -= 1
        return val

    def pop(self):
        if self.count == 0:
            raise IndexError('pop from empty queue')
        val = self.queue[self.r - 1]
        self.r = (self.r - 1) % self.n
        self.count -= 1
        return val
    
    def size(self):
        return self.count
    
    def __bool__(self):
        return self.count != 0

def fast_bellman_ford(n, s, graph, edge_n, init_val): #どう？
    d = [init_val] * n
    d[s] = 0
    q = PreallocatedQueue(edge_n, 0)
    q.append(s)
    checker = [-1] * n
    for i in range(n):
        m = q.count
        for _ in range(m):
            vf = q.popleft()
            for vt, w in graph[vf]:
                if d[vt] > d[vf] + w:
                    d[vt] = d[vf] + w
                    if checker[vt] < i:
                        q.append(vt)
                        checker[vt] = i
        if not q:
            break
    if q: #閉路の存在
        minus_inf = -float('inf')
        i += 1
        while q:
            m = q.count
            for _ in range(m):
                vf = q.popleft()
                for vt, w in graph[vf]:
                    if d[vt] > d[vf] + w:
                        d[vt] = minus_inf
                        if checker[vt] < i:
                            q.append(vt)
                            checker[vt] = i
            i += 1
    return d

n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(m):
    a, b, w = map(int, input().split())
    graph[a-1].append((b-1, -w))
d = fast_bellman_ford(n, 0, graph, 2 * m, float('inf'))
print(-d[-1] if d[-1] != -float('inf') else 'inf')


Measured memory_bytes: 74924
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int first = sc.nextInt();
        int second = sc.nextInt();
        int mod_fist = first%2019;
        int mod_second = second%2019;
        int ans = 2018;
        if (first+2020<=second) {
            ans = 0;
        }
        for (int i=mod_fist; i<=mod_second; i++) {
            for (int j=i+1; j<=mod_second; j++) {
                ans = Math.min(ans, (i*j)%2019);
            }
        }
        System.out.println(ans);
    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}
void _main();
int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); return 0;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<29;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<59; 

void _main(){
  int N; scanf("%d",&N);
  using vd = vector<double>;
  vd x(N),y(N),ans(N);
  rep(i,N) scanf("%lf %lf",&x[i],&y[i]);
  int sample = 1e6;
  rep(k,sample){
    double xx,yy;
    if(N>=40){
      xx = 1e12 * cos(2*PI*double(k)/double(sample));
      yy = 1e12 * sin(2*PI*double(k)/double(sample));
    }else{
      xx = 1e10 * cos(2*PI*double(k)/double(sample));
      yy = 1e10 * sin(2*PI*double(k)/double(sample));

    }
    double mi = 1e31;
    int arg = -1;
    rep(i,N) if(chmin(mi,(xx-x[i])*(xx-x[i])+(yy-y[i])*(yy-y[i]))) arg=i;
    ans[arg] += double(1)/double(sample);
  }
  rep(i,N) printf("%.8lf\n",ans[i]);
} 

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

int main() {
string s;
cin >> s;
string ans ="No";
if(s[2]==s[3]&&s[4]==s[5])
{ans = "Yes";}

cout << ans <<endl;



}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

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

using namespace std;


int main(){
    
    int N;
    cin >> N;
    
    vector<int> H(N+1);
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }
    H[N] = 1000000001;
    
    int ans = 0;
    int ansn = 0;
    
    int now = 0;
    while (now < N-1) {
        ansn = 0;
        
        int nex = now+1;
        
        while (H[nex-1] >= H[nex]) {
            ansn += 1;
            if (nex == N-1) {
                break;
                
            }
            nex += 1;
        }
        if (ans < ansn) {
            ans = ansn;
        }
        
        now = nex;
        
    }
    
    cout << ans << endl;
    
    
    
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<iterator>
#include<string>
#include<sstream>
#include <unordered_map>
#include<cmath>
using namespace std;
#define ll long long
int __gcd(int a,int b){return b==0 ? a : __gcd(b,a%b);}
ll __gcd(ll a,ll b){return b==0 ? a : __gcd(b,a%b);}

const int maxn=2e5+5;
ll a[maxn],b[maxn],suma[maxn],sumb[maxn];
int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int _=1;
    while(_--){
        int n,m,k; cin>>n>>m>>k;
        for(int i=1;i<=n;++i) cin>>a[i],suma[i]=suma[i-1]+a[i];
        for(int i=1;i<=m;++i) cin>>b[i],sumb[i]=sumb[i-1]+b[i];
        int ans=0;
        for(int i=0;i<=n;++i){
            if(suma[i]>k) break;
            int tem=i,temk=k-suma[i];
            tem+=upper_bound(sumb+1,sumb+m+1,temk)-sumb-1;
            ans=max(ans,tem);
        }
        cout<<ans<<"\n";
    }
}

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

int main() {
	int a, b, h, m;
	cin >> a >> b >> h >> m;
	cout << fixed << setprecision(15);
	double_t x = 30 * h - 5.5 * m;
	if (x >= 180)x = 360 - x;
	double_t pi = 3.141592653589793;
	double_t ans = a * a + b * b - 2 * a * b * cos(pi * x / 180);
	ans = sqrt(ans);
	cout << ans << endl;

}

Measured memory_bytes: 4188
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

const int INF = (int)1e9;

struct RMQ{
  typedef long long Type;
  int segn2;
  Type inf;
  vector<pair<int,Type> > data;

  RMQ(int n){
    inf = (long long)1e18;
    segn2 = 1;
    while(segn2 < n) segn2*=2;

    data.assign(segn2*2,make_pair(0,-inf));
  }

  int query(){
    return data[0].first;
  }
  
  void set(int k,Type x){
    int K= k + segn2-1;
    data[K] = make_pair(k,x);

    while(K>0){
      K = (K-1)/2;
      if(data[K*2+1].second < data[K*2+2].second)
	data[K] = data[K*2+2];
      else
	data[K] = data[K*2+1];
    }

  }
};
  

int main(){
  int n,r,l;
  int d,t=0,x,bt;
  long long ans[100010] = {0};
  int memo[100010] ={0};
  
  scanf("%d%d%d",&n,&r,&l);

  RMQ rmq(n+1);

  for(int i=1;i<=n;i++){
    rmq.set(i,0);
  }

  t = 0;
  
  for(int i=0;i<r;i++){
    bt = t;
    scanf("%d%d%d",&d,&t,&x);

    ans[rmq.query()] += (t-bt);

    memo[d] += x;
    rmq.set(d,memo[d]);
  }

  ans[rmq.query()] += (l-t);

  int ans_max=-(int)1e18,ans_i;

  for(int i=1;i<=n;i++){
    if(ans_max < ans[i]){
      ans_max = ans[i];
      ans_i = i;
    }
  }

  cout << ans_i << endl;
  
  return 0;
}

Measured memory_bytes: 6220
from itertools import product

n, m = map(int, input().split())
s = [list(map(lambda x:int(x)-1,input().split()))[1:] for _ in range(m)]
p = list(map(int,input().split()))


count = 0
for i in product([0,1], repeat=n):
    i = list(i)
    on = True
    for j in range(m):
        score = 0
        for k in s[j]:
            if i[k] == 1:
                score += 1
        if score % 2 == p[j]:
            continue

        else:
            on = False
            break

    if on:
        count += 1

print(count)

Measured memory_bytes: 41328
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val a = sc.nextInt()
    val b = sc.nextInt()
    println((b - 1 + a - 1 - 1) / (a - 1))
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 31388
S = input()
ma = 0
ma_ = 0
for c in S:
    if c == 'A' or c == 'C' or c == 'G' or c == 'T':
        ma_ += 1
    else:
        ma = max(ma, ma_)
        ma_ = 0
ma = max(ma, ma_)
print(ma)




Measured memory_bytes: 9048
import sys
input = sys.stdin.readline

N,X,M=map(int,input().split())
LIST=[X]
SET={X}

a=X

while True:
    if a*a%M in SET:
        break
    else:
        a=a*a%M
        LIST.append(a)
        SET.add(a)

l=LIST.index(a*a%M)
LEN=len(LIST)

if N<=LEN:
    print(sum(LIST[:N]))
else:
    ANS=sum(LIST[:l])
    N-=l
    LIST=LIST[l:]
    S=sum(LIST)

    r,q=divmod(N,len(LIST))

    print(ANS+S*r+sum(LIST[:q]))
    



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

if a <= 0 and b >= 0:
    print("Zero")
    exit()

if a > 0:
    print("Positive")
    exit()
    
res = min(0,b) - min(0,a) + 1

if res%2 == 0:
    print("Positive")
else:
    print("Negative")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m,x;
  cin >> n >> m >> x;
  vector<int> gate(m);
  for(int i=0; i<m;i++){
    cin >> gate.at(i);
  }
  int count_gate=0;
  for(int i=0;gate.at(i)<x;i++){
	count_gate++;
  }
  if(count_gate <= m /2){
    cout << count_gate <<endl;
    return 0;
  }
	else{cout << m - count_gate << endl;}
}

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

const int N = 3;
int main() {
    string s;
    cin >> s;

    string r = "No";
    for (int i=1; i < N; i++) {
        if (s[i-1] != s[i]) {
            r = "Yes";
            break;
        }
    }
    cout << r << endl;
    return 0;
}


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

typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;

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

    int a, b, c;
    cin >> a >> b >> c;
    cout << max(0, c - a + b) << '\n';

    return 0;
}

Measured memory_bytes: 256
N, W = map(int, input().split())
dp = [[0]*(W+1) for i in range(N+1)]
for i in range(N):
    w, v = map(int, input().split())
    for j in range(W+1):
        if w + j <= W:
            dp[i+1][j+w] = max(dp[i][j+w], dp[i][j]+v)
            dp[i+1][j] = max(dp[i][j], dp[i+1][j])
        else:
            dp[i+1][j] = max(dp[i][j], dp[i+1][j])

print(max(dp[N]))


Measured memory_bytes: 121708
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    for (int i = 1; i < 10; i++) {
      for (int j = 1; j < 10; j++) {
        if (i * j == n) {
          System.out.println("Yes");
          return;
        }
      }
    }
    System.out.println("No");
  }
}


Measured memory_bytes: 22868
loop do
    n = gets.to_i
    break if n == 0
    a = gets.split
    p = [-Float::INFINITY, Float::INFINITY]
    a.each_with_index do |aa,i|
        if aa == "x"
            if i < a.size - 1 && a[i+1] == "x"
                p = [Float::INFINITY, -Float::INFINITY]
                break
            end
            if i == 0
                p[1] = a[1].to_i - 1
            elsif i < a.size - 1
                if i % 2 == 1
                    p[0] = [[a[i-1].to_i, a[i+1].to_i].max + 1, p[0]].max
                else
                    p[1] = [[a[i-1].to_i, a[i+1].to_i].min - 1, p[1]].min
                end
            else
                if i % 2 == 1
                    p[0] = [a[i-1].to_i + 1, p[0]].max
                else
                    p[1] = [a[i-1].to_i - 1, p[1]].min
                end
            end
        else
            if i < a.size - 1 && a[i+1] != "x"
                if i % 2 == 1 && aa.to_i < a[i+1].to_i ||  i % 2 == 0 && aa.to_i > a[i+1].to_i
                    p = [Float::INFINITY, -Float::INFINITY]
                    break
                end
            end
        end
    end
    if p[0] == p[1]
        puts p[0]
    elsif p[0] > p[1]
        puts "none"
    else
        puts "ambiguous"
    end
end

Measured memory_bytes: 6168
import os
import sys

import numpy as np
from scipy.optimize import fmin

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N = int(sys.stdin.readline())
X, Y, D = list(zip(*[sys.stdin.readline().rstrip().split() for _ in range(N)]))
X = np.array(X, dtype=int)
Y = np.array(Y, dtype=int)
D = np.array(D)

Rmin = min(list(X[D == 'R']) + [INF])
Rmax = max(list(X[D == 'R']) + [-INF])
Lmin = min(list(X[D == 'L']) + [INF])
Lmax = max(list(X[D == 'L']) + [-INF])
Umin = min(list(Y[D == 'U']) + [INF])
Umax = max(list(Y[D == 'U']) + [-INF])
Dmin = min(list(Y[D == 'D']) + [INF])
Dmax = max(list(Y[D == 'D']) + [-INF])

Xmin = min(list(X[(D == 'U') | (D == 'D')]) + [INF])
Xmax = max(list(X[(D == 'U') | (D == 'D')]) + [-INF])
Ymin = min(list(Y[(D == 'R') | (D == 'L')]) + [INF])
Ymax = max(list(Y[(D == 'R') | (D == 'L')]) + [-INF])


def cost(t):
    if t < 0:
        return -t + 10 ** 18
    xl = min(Xmin, Lmin - t, Rmin + t)
    xr = max(Xmax, Lmax - t, Rmax + t)
    yb = min(Ymin, Dmin - t, Umin + t)
    yt = max(Ymax, Dmax - t, Umax + t)
    return (xr - xl) * (yt - yb)


x, = fmin(cost, x0=100000, ftol=10 ** -10, disp=False)
print('{:.10f}'.format(cost(x)))


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

int main()
{
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if (s.at(0) == s.at(1) && s.at(2) == s.at(3) && s.at(1) != s.at(2))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

int main(){
  int f[13] = {-1,1,3,1,2,1,2,1,1,2,1,2,1};
  int x,y;
  
  scanf(" %d %d",&x,&y);
  if(f[x] == f[y]){
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}


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

int main() {
  vector<int> i(3);
  for (auto &e : i) cin >> e;

  bool f1, f2, s;
  f1 = f2 = s = false;
  for (auto e : i) {
    if (e == 5) {
      if (f1) {
        f2 = true;
      } else {
        f1 = true;
      }
    }
    if (e == 7) s = true;
  }

  if (f1 && f2 && s)
    puts("YES");
  else
    puts("NO");
}

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

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

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

  int ans = 1001001001;
  for (int i = -100; i <= 100; i++) {
    int cost = 0;
    for (int j = 0; j < N; j++) {
      cost += pow((A.at(j)- i), 2);
    }
    ans = min(ans, cost);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<3;i++){
        if(s[i]=='a')
            ans+=1;
        if(s[i]=='b')
            ans+=10;
        if(s[i]=='c')
            ans+=100;
    }
    if(ans==111)
        puts("Yes\n");
    else puts("No\n");
 }



Measured memory_bytes: 256
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from heapq import heappop,heappush
import time
import sys
readline = sys.stdin.readline
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
#main
s=input()
print("x"*len(s))

Measured memory_bytes: 7652
n=int(input())

A=list(map(int,input().split()))

A.sort()

lis=[0 for i in range(10**6)]

for i in A:
    if lis[i-1]==0:
        lis[i-1]=1
        j=2
        while i*j<=10**6:
            lis[i*j-1]=-1
            j+=1
    elif lis[i-1]==1:
        lis[i-1]=-2

cnt=0
for i in A:
    if lis[i-1]==1:
        cnt+=1

print(cnt)

Measured memory_bytes: 164796
#include<cstdio>
using namespace std;

int n, a, b, c, x, y[100];

int main() {
  while (1) {
    scanf("%d%d%d%d%d", &n, &a, &b, &c, &x);
    if (n == 0) break;
    for (int i = 0; i < n; i++) scanf("%d", &y[i]);
    bool end = false;
    int now = x, i, j;
    for (i = 0, j = 0; i < 10000; i++) {
      while (now != y[j]) {
        now = (now * a + b) % c;
        i++;
        if (i > 10000) break;
      }
      if (i > 10000) break;
      now = (now * a + b) % c;
      j++;
      if (j == n) {
        end = true;
        break;
      }
    }
    if (end) printf("%d\n", i);
    else printf("-1\n");
  }
}



Measured memory_bytes: 2556
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
using namespace std;
typedef long long ll;
int main(){
  int a,b;
  cin >> a >> b;

  if(1 <= a && a <= 9 && 1 <= b && b <= 9)cout << a * b << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s,t;
long long ans,ls,ll,hh,p,h1,h2;
long long tt;
int main()
{
	cin>>s>>p;
	ls=s.size();
	if(ls==1)
	{
		cout<<p/2;
		return 0;
	}
	for(int i=1;i<ls;i++)
	if(s[i]!=s[i-1])
	{
		tt=i;
		break;
	}
	if(tt==0)
	{
		cout<<ls*p/2;
		return 0;
	}
	t=s+s;
	hh=1;
	for(int i=tt+1;i<tt+ls;i++)
	{
		if(t[i]==t[i-1])
		hh++;
		else
		{
			ans+=hh/2;
			hh=1;
		}
	}
	ans+=hh/2;
	ans=ans*p;
	h1=1;
	h2=1;
	for(int i=1;s[i]==s[i-1];i++)
	h1++;
	for(int i=ls-2;s[i]==s[i+1];i--)
	h2++;
	if((h1+h2)/2!=h1/2+h2/2&&s[0]==s[ls-1])
	ans--;
	cout<<ans;
	return 0;
}

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

int main(){
	int n,m;
	int i,j;
	int A[100][100],B[100],C[100]={0};
 	
	cin>>n>>m;
 	
 	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cin>>A[i][j];
		}
 	}
	for(j=0;j<m;j++){
		cin>>B[j];
	}
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			C[i] += A[i][j] * B[j];
		}
	}
	for(i=0;i<n;i++){
		cout<<C[i]<<endl;
	}
  	return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define ll long long
#define MAX 10000000
#define M 1000000007
#define PI 2 * acos(0.0)
#define set_zero(arr) memset(arr,0,sizeof(arr))
#define fast_io  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std; 
int main(){
   fast_io
   ll n,w;
   cin>>n>>w;
   ll a[n],b[n];
   for(ll i = 0;i<n;i++){
      cin>>a[i];
      cin>>b[i];
   }
   ll dp[n+1][w+1];
   for(ll i = 0;i<=n;i++){
      for(ll j = 0;j<=w;j++){
         if(i == 0 || j == 0){
            dp[i][j] = 0;
         }
         else{
            if(a[i-1] <= j){
                dp[i][j] = max(b[i-1] + dp[i-1][j - a[i-1]] , dp[i-1][j] );
            }
            else{
               dp[i][j] = dp[i-1][j];
            }
         }
      }
   }
   cout<<dp[n][w]<<endl;
   return 0;
}

Measured memory_bytes: 82412