akhauriyash/Code-Regression huggingface dataset:
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    int n, k, x, y;
    cin >> n >> k >> x >> y;

    cout << max(n-k, 0)*y + min(n,k)*x << endl;
}

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

int main() {
  int N,M;

  cin >> N >> M;
  vector<int> L(M);
  vector<int> R(M);

  for(int i=0;i<M;++i){
    cin >> L.at(i) >> R.at(i);
  }
  sort(L.begin(),L.end());
  sort(R.begin(),R.end());

  if(R.at(0)-L.at(M-1) >= 0){
    cout << R.at(0)-L.at(M-1)+1 << endl;
  }else{
    cout << 0 << endl;
  }
  return 0;
}


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

int x[100005];
int mo=1000000007;
int n;
int cache[100005][105][2];
int d;
string b;
int dp(int idx,int rem,int less)
{
    if(idx==n+1)
        return (rem==0);
    int ans=cache[idx][rem][less];
    if(ans!=-1)
        return  ans;
    ans=0;
    if(!less)
    {
        for(int i=0;i<=x[idx];i++)
        {
            ans+=dp(idx+1,(rem+i)%d,less|i<x[idx]);
        }
    }
    else
    {
        for(int i=0;i<=9;i++)
        {
            ans+=dp(idx+1,(rem+i)%d,1);
        }
    }
    ans%=mo;
    cache[idx][rem][less]=ans;
    return ans;
}
int f(string a)
{
    n=a.size();
    for(int i=1;i<=n;i++)
    {
        x[i]=(a[i-1]-'0');
    }
    memset(cache,-1,sizeof(cache));
    return dp(1,0,0);

}
int32_t main()
{
    cin>>b>>d;
    int ans=f(b);
    //cout<<ans<<" ";
    ans-=1;
    ans+=mo;
    ans%=mo;
    cout<<ans;
    return 0;

}

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

 long long int attack(long long int h)
 {
 if(h==1)
    return 1;

else
{

    long long int val=attack(h/2);
    return 2*val+1;

}
 }


 int main(){

 long long int h;

 cin>>h;
 cout<<attack(h)<<endl;


 return 0;



 }


Measured memory_bytes: 256
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int d;
	scanf("%d", &d);
	ll c[26];
	REP(i, 0, 26) scanf("%ld", &c[i]);
	ll s[d][26];
	REP(i, 0, d) REP(j, 0, 26) scanf("%ld", &s[i][j]);
	int t[d];
	REP(i, 0, d) scanf("%d", &t[i]);

	ll last[26];
	REP(i, 0, 26) last[i] = 0;

	ll score = 0;
	REP(i, 0, d){
		REP(j, 0, 26){
			if(j==t[i]-1){
				score += s[i][j];
				last[j] = i + 1;
			}
			score -= c[j] * (i+1 - last[j]);
		}
		printf("%ld\n", score);
	}
	return 0;
}



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

const int N = ((int)(1e6))+20;

int a,s,it = 0;
char tab[N];

int main(){
	cin>>s;
	while( cin>>tab[it] ) it++;
	for (int i = 0; i < it; i++){
		int num = int(tab[i]) - int('A');
		num+=s;
		num %= 26;
		cout<<char(int('A') + num);
	}	
}


Measured memory_bytes: 256
#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)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)
    {
        cin >> a.at(i);
    }
    ll ans = 0;
    rep(i, n)
    {
        rep2(j, i + 1, n)
        {
            rep2(k, j + 1, n)
            {
                if (a[i] != a[j] && a[j] != a[k] && a[k] != a[i])
                {
                    ll to = a[i] + a[j] + a[k];
                    ll ma = max({a[i], a[j], a[k]});
                    if (to > 2 * ma)
                    {
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
int n,m,a[SZ];
bool oo(int a,int b) {return (a&1)<(b&1);}
int main()
{
	scanf("%d%d",&n,&m); int o=0;
	for(int i=1;i<=m;++i)
		scanf("%d",a+i),o+=a[i]&1;
	if(o>2)
	{
		puts("Impossible");
		return 0;
	}
	sort(a+1,a+1+m,oo);
	reverse(a+1,a+1+m);
	if(m>1) swap(a[2],a[m]);
	for(int i=1;i<=m;++i) printf("%d ",a[i]);
	puts("");
	vector<int> vs;
	if(m>1)
	{
		vs.pb(a[1]-1); vs.pb(2);
		for(int i=2;i<m;++i) vs.pb(a[i]);
		vs.pb(a[m]-1);
	}
	else
	{
		vs.pb(a[1]-1); vs.pb(1);
	}
	vector<int> r;
	for(int i=0;i<vs.size();++i)
		if(vs[i]) r.pb(vs[i]);
	vs=r;
	printf("%d\n",int(r.size()));
	for(int i=0;i<r.size();++i) printf("%d ",r[i]);
	puts("");
}



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

int main(){
  vector<int> x(3);
  for(int i=0; i<3; i++){
    cin >> x.at(i);
  }
  sort(x.begin(), x.end());
  if(x.at(0)+x.at(1)==x.at(2)){
    cout << "Yes";
  }else{
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 3576
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#define PI acos(-1.0)
using namespace std;
const int N = 3005;
int dp[3050][3050];
int main() {
	string a,b;
	cin >> a >> b;
	for(int i=a.length()-1; i>=0; i--) {
		for(int j=b.length()-1; j>=0; j--) {
			if(a[i]==b[j]) {
				dp[i][j]=dp[i+1][j+1]+1;
			} else {
				dp[i][j]=max(dp[i+1][j],dp[i][j+1]);
			}
		}
	}
	int i,j;
	i = j = 0;
	while(i<a.length()&&j<b.length()) {
		if(a[i]==b[j]) {
			cout << a[i];
			i++;
			j++;
		} else if(dp[i][j]==dp[i+1][j]) {
			i++;
		} else {
			j++;
		}
	}
	return 0;
}

Measured memory_bytes: 39352
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;

int main()
{ 
  fast;
  string s;
  cin>>s;
  vector<ll> v;
 	ll big=0,small=0,bt=0,st=0;

 	for(ll i=0;i<=s.size();i++)
 	{
 		if(i==s.size())
 		{
 			if(bt>0)
 				v.pb(bt);
 			else v.pb(st);
 		}

 		else if(s[i]=='<')
 		{
 			if(bt>0)
 			{
 				v.pb(bt);
 				bt=0;
 			}
 			st++;
 		}
 		else
 		{
 			if(st>0)
 			{
 				v.pb(st);
 				st=0;
 			}
 			bt++;
 		}
 	}
 	ll start=0,end=0;

 	if(s[0]=='>')
 		start=1;
 	if(s[s.size()-1]=='>')
 		end=1;

 	ll cur=start,prev=-1;
 	ll ans=0;
 	for(ll i=0;i<v.size();i++)
 	{
 		if(cur==0)
 		{
 			ans=ans+ (v[i]*(v[i]-1))/2;
 			prev=v[i]-1;
 			cur=1;
 		}
 		else
 		{
 			ans+=max(prev+1,v[i]);
 			ans=ans+ (v[i]*(v[i]-1))/2;
 			cur=0;
 		}
 	}

 	if(end==0)
 		ans+=v[v.size()-1];

 	cout<<ans<<endl;

 
}


Measured memory_bytes: 3352
import math

def solve() :
    ri = raw_input()

    inarr = ri.split(' ')
    h = int(inarr[0])
    w = int(inarr[1])

    if h % 3 == 0 or w % 3 == 0 :
        return 0
    return min(min_diff(h,w), min_diff(w,h))

def min_diff(e1, e2) : #w,h or h,w
    score = e1
    x = e1/3
    s1 = x*e2
    s2 = (e1-x) * int(math.floor(e2/2))
    s3 = (e1 * e2) - s1 - s2
    score2 = max(abs(s1-s2), abs(s2-s3), abs(s3-s1))
    x = e1/3 + 1
    s1 = x*e2
    s2 = (e1-x) * int(math.floor(e2/2))
    s3 = (e1 * e2) - s1 - s2
    score3 = max(abs(s1-s2), abs(s2-s3), abs(s3-s1))    
    return min(score, score2, score3)

if __name__ == '__main__':
    print solve()

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

using namespace std;

int main() {

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

	int n;
	cin >> n;

	vector<vector<int>> dp(n + 1, vector<int>(3));

	for(int i = 1; i <= n; i++) {
		cin >> dp[i][0] >> dp[i][1] >> dp[i][2];
	}

	for(int i = 2; i <= n; i++) {
		dp[i][0] += max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] += max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] += max(dp[i-1][0], dp[i-1][1]);
	}

	cout << max(dp[n][0], max(dp[n][1], dp[n][2]));

	return 0;
}

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

typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int a, b;
    cin >> a >> b;
    if(a > b) cout << "safe";
    else cout << "unsafe";
    return 0;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N, M;
    cin >> N >> M;
    int s[M];
    char c[M];
    for(int i=0;i<M;i++){
        cin >> s[i] >> c[i];
        if(s[i] == 1 && c[i] == '0' && N != 1){
            cout << -1 << endl;
            return 0;
        }
    }

    char ans[N] = {};
    for(int i=0;i<N;i++){
        ans[i] = 'x';
    }

    for(int i=0;i<M;i++){
        if(ans[s[i]-1] == 'x'){
            ans[s[i]-1] = c[i];
        }else if(ans[s[i]-1] != c[i]){
            cout << -1 << endl;
            return 0;
        }
    }

    for(int i=0;i<N;i++){
        if(ans[i] != 'x'){
            cout << ans[i];
        }else if(i == 0 && N != 1){
            cout << 1;
        }else{
            cout << 0;
        }
        
    }

    cout << endl;

}

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

namespace ConsoleApp12
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] i = Console.ReadLine().Split(' ');
            int X = int.Parse(i[0]);
            int Y = int.Parse(i[1]);
            int Z = int.Parse(i[2]);
            int Yz = Y + Z;
            int N = X / Yz;
            if (Yz * N + Z > X)
            {
                N -= 1;
            }
            else;
            Console.WriteLine(N);

        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    int n,m,A[200001];
    cin>>n>>m;
    priority_queue<int> Q;
    rep(i,n) cin>>A[i],Q.push(A[i]);
    rep(i,m){
        int a=Q.top();
        a=a/2;
        Q.pop();
        Q.push(a);
    }
    ll ans=0;
    rep(i,n) ans+=Q.top(),Q.pop();
    cout<<ans;
}

Measured memory_bytes: 1148
n = int(input())
lst = [int(i) for i in input().split()]

if len(set(lst)) == 1:
    print('Yes')
    exit()

lst_c = sorted(lst)
for i in range(n):
    if lst[i] - lst_c[i] >= 2:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 14276
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll n, x, m;

ll order[1000009];
ll sum[1000009];

ll solve(ll n, ll x, ll m) {
    ll s = 0;
    ll loop_b = -1, loop_e = -1;
    for (ll i = 1; i <= n; i++) {
        if (order[x] != 0) {
            loop_b = order[x];
            loop_e = i;
            break;
        }
        s += x;
        order[x] = i;
        sum[i] = s;
        x = (x * x) % m;
    }
    ll ans = s;
    if (loop_b != -1) {
        ll cycle_len = loop_e - loop_b;
        ll a = (n - loop_e + 1) % cycle_len;
        ll cycle_sum = sum[loop_e - 1] - sum[loop_b - 1];
        ll cycle_num = ((n - loop_e + 1) / cycle_len);
        ans += cycle_sum * cycle_num + (sum[loop_b + a - 1] - sum[loop_b - 1]);
    }
    return ans;
}
ll _solve(ll n, ll x, ll m) {
    ll ans = 0;
    for (ll i = 1; i <= n; i++) {
        ans += x;
        x = (x * x) % m;
    }
    return ans;
}
int main() {
    cin >> n >> x >> m;
    printf("%lld\n", solve(n, x, m));
    return 0;
}

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

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

  if ( N[0] == N[1] && N[2] == N[1] || N[3] == N[1] && N[2] == N[1] ) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;

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

  int n, a;
  cin >> n;
  vector<int> A(n);
  for (int i = 1; i <= n; ++i) {
    cin >> a;
    A[i-1] = a - i;
  }
  sort(A.begin(), A.end());
  int b = A[n/2];
  long long res = 0;
  for (int i = 0; i < n; ++i) {
    res += abs(A[i]-b);
  }
  cout << res << endl;

  return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll X;
    ll Maxim=1;
    cin>>X;
    rep1(b, 40) reps(p, 2, 10){
        if(pow(b, p)<=X) Maxim=max(Maxim, (ll)pow(b, p));
    }
    cout<<Maxim<<endl;
    return 0;
}


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

int main(void)
{

	long long N,i,tmp,mul,ans=1e12;

	cin >> N;

	for(i=1;i*i<=N;i++)
	{
		if(N%i==0)
		{
			tmp=N/i;

			mul=(i-1)+(tmp-1);

			ans=min(ans,mul);

		}
		else
			continue;

	}

	cout << ans << endl;
}



Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <iostream>


using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		double x[4], y[4];
		for (int j = 0; j < 4; ++j)
			scanf("%lf %lf", x+j, y+j);

		double dx1 = x[1] - x[0];
		double dy1 = y[1] - y[0];
		double dx2 = x[3] - x[2];
		double dy2 = y[3] - y[2];
		if (dy1/dx1 == dy2/dx2)
			puts("YES");
		else
			puts("NO");
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef string::iterator state;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
map<char, int> mp;
string operators = "*-+";
ll ans = LONG_MIN;
ll one(state &itr);
ll two(state &itr);
ll three(state &itr);
ll number(state &itr);
ll one(state &itr) {
    ll now = two(itr);
    while(true) {
        //cerr << "one: " << *itr << endl;
        if(*itr == ')') {
            itr++;
            return now;
        }
        if(*itr == '=') return now;
        if(*itr == '-') {
            itr++;
            now -= two(itr);
            continue;
        }
        if(*itr == '+') {
            itr++;
            now += two(itr);
            continue;
        }
        if(*itr == '*') {
            itr++;
            now *= two(itr);
            continue;
        }
    }
}

ll two(state &itr) {
    ll now = three(itr);
    while(true) {
        //cerr << "tow: " << *itr << endl;
        if(mp[*itr] <= 1) {
            return now;
        }
        if(*itr == '-') {
            itr++;
            now -= three(itr);
            continue;
        }
        if(*itr == '+') {
            itr++;
            now += three(itr);
            continue;
        }
        if(*itr == '*') {
            itr++;
            now *= three(itr);
            continue;
        }
        return now;
    }
}

ll three(state &itr) {
    ll now = number(itr);
    while(true) {
        //cerr << "three: " << *itr << endl;
        //if(*itr == operators[0] || *itr == operators[1]) return now;
        if(mp[*itr] <= 2) return now;
        if(*itr == '-') {
            itr++;
            now -= number(itr);
            continue;
        }
        if(*itr == '+') {
            itr++;
            now += number(itr);
            continue;
        }
        if(*itr == '*') {
            itr++;
            now *= number(itr);
            continue;
        }
        return now;
    }
}

ll number(state &itr) {
    if(*itr == '(') {
        itr++;
        return one(itr);
    }
    ll now = 0;
    while(true) {
        //cerr << "number: " << *itr << endl;
        if(*itr < '0' || *itr > '9') return now;
        now *= 10;
        now += *itr - '0';
        itr++;
    }
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    S = S + "=";
    //sort(operators.begin(), operators.end());
    //do {
    for(mp['+'] = 1; mp['+'] <= 3; mp['+']++) {
        for(mp['-'] = 1; mp['-'] <= 3; mp['-']++) {
            for(mp['*'] = 1; mp['*'] <= 3; mp['*']++) {
                state itr = S.begin();
                ll now = one(itr);
                ans = max(ans, now);
            }
        }
    }
        //cerr << operators << " " << now << endl;
    //} while(next_permutation(operators.begin(), operators.end()));
    cout << ans << endl;
    return 0;
}



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

using namespace std;

long long n;
double ans[5005][5005], a[5005], kq;

int main() {
    cout << setprecision(10);
    for (int i = 0; i <= n / 2; i++)
        ans[0][i] = 1;
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        for (int j = 0; j <= n / 2; j++){
            ans[i][j] = ans[i - 1][j] * a[i] + ans[i - 1][j - 1] * (1 - a[i]);
        }
    }
    kq = 0;
    for (int i = 0; i <= n / 2; i++)
        kq += ans[n][i];
    cout << kq << endl;
}

Measured memory_bytes: 117760
#include<iostream>
#include<sstream>
#include<ios>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<string>
#include<numeric>
#include<set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using vi = vector<int>;
using vl = vector<long>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
using vpii = vector<pii>;
using vpll = vector<pll>;

int main(){
  long A, B;
  cin >> A >> B;

  if(A*B == 2) cout << 3 << endl;
  else if(A*B == 3) cout << 2 << endl;
  else cout << 1 << endl;
  
  return 0;
}

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

int main(){
	int n, j;
	cin >> n;
	getchar();
	char s[1001];
	for (int i = 0; i < n; i++) {
		//string s;
		//cin >> s;
		if (scanf("%1000[^\n]%*[^\n]", s) < 1) *s = '\0';
		getchar();
		for (j = 0; j < 1000-6; j++) {
			if (s[j + 6] == 0)
				break;
			if (s[j] == 'H'&&s[j + 1] == 'o'&&s[j + 2] == 's'&&s[j + 3] == 'h'&&s[j + 4] == 'i'&&s[j + 5] == 'n'&&s[j + 6] == 'o')
				s[j + 6] = 'a';
		}
		cout << s << endl;
		for (j += 5; j >= 0; j--) {
			s[j] = 0;
		}
	}
	

}


Measured memory_bytes: 3144
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
l = sorted(LIST())

ans = 0
for i in range(n-2):
    right = i + 2
    for j in range(i+1, n-1):
        left = j + 1
        while right < n-1 and l[right] < l[i] + l[j]:
            right += 1
        ans += right - left
        if l[right] < l[i] + l[j]:
            ans += 1
print(ans)

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

#define pb push_back
#define all(a) (a).begin(), (a).end()

using ll = long long;
using pii = pair<int, int>;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

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

#ifdef DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

void solve() {
}

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    ll n; cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
    	if (i % 3 == 0 || i % 5 == 0)
    		continue;
    	ans += i;
    }

    cout << ans << '\n';
}

Measured memory_bytes: 3652
def prime(n):
    a=[]
    while n%2 == 0:
        a.append(2)
        n //= 2
    f=3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
n=int(input())
r=prime(n)
R=map(str,r)
u=' '.join(R)
print("{}: {}".format(n,u))


Measured memory_bytes: 5596
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int n;
    cin >> n;
    map<string, int> m;
    int mx = -1;
    REP(i, n) {
        string tmp;
        cin >> tmp;
        if (m.find(tmp) == m.end()) {
            m[tmp] = 1;
        } else {
            m[tmp]++;
        }
        mx = max(mx, m[tmp]);
    }
    for (const auto& e: m) {
        if (e.S == mx) {
            cout << e.F << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 25216
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

/**
 * Water Rate
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int A, B, C, D, P;
			A = parseInt(line);
			B = parseInt(br.readLine());
			C = parseInt(br.readLine());
			D = parseInt(br.readLine());
			P = parseInt(br.readLine());
			if (P <= C) System.out.println(Math.min(P * A, B));
			else System.out.println(Math.min(P * A, B + (P - C) * D));
		}
	}
}

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

int main(){
    int n,ans=0,tmp=0;
    char s[110];
    scanf("%d",&n);
    scanf("%s",s);
    for (int i=0;i<n;i++) {
        tmp+=s[i]=='I'?1:-1;
        ans=max(ans,tmp);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <vector>
#include <string>
#include <cstdio>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ls x<<1
#define rs x<<1|1
#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define fun function
#define vi vector<int>
#define lowbit(x) x&(-x)
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);

using namespace std;

const int INF = 0x3f3f3f3f;
const int N=1e5+10;

int a[N],b[N];

int main() {
	IOS;
#ifdef xiaofan
	freopen("1.in","r",stdin);
	freopen("1.out","w",stdout);
#endif

	int n,m,k;
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=m;i++)cin>>b[i];
	int ans=INF;
	while(k--){
		int x,y,z;
		cin>>x>>y>>z;
		if(x>n||y>m)continue;
		ans=min(ans,a[x]+b[y]-z);
	}
	sort(a+1,a+1+n);
	sort(b+1,b+1+m);
	for(int i=1;i<=min(m,n);i++)
		ans=min(a[i]+b[i],ans);
	cout<<ans<<endl;




	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define put(x) cout << x << endl;
using namespace std;

string reverse(string x) {
    auto y = x;
    reverse(y.begin(), y.end());
    return y;
}

int main()
{
    string s;
    cin >> s;
    auto s1 = s.substr(0, (s.size() - 1) / 2);
    auto s2 = s.substr((s.size() + 3) / 2 - 1);
    yorn(s == reverse(s) && s1 == reverse(s1) && s2 == reverse(s2))
    return 0;
}

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

using namespace std;
const int MOD = 1000000007;

long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}

inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

long long modinv(long long a, long long m) {
    long long x, y;
    extGCD(a, m, x, y);
    return mod(x, m);
}

long long pow(long long b, long long e) {
  return e == 1 ? b : b * pow(b, e--);
}

int main(void) {
  int N; cin >> N;
  long long prmfct[1000000];
  int A[N];
  vector<pair<int, int>> prmftp;
  memset(prmfct, 0, sizeof(prmfct));
  
  for (int i = 0; i < N; i++) {
    prmftp.clear();
    int a; cin >> a; A[i] = a;
    int n = 0;
    if (a%2 == 0) {
      while (a%2 == 0) {
        a /= 2;
        n++;
      }
      prmftp.push_back(make_pair(2, n));
    }
    for (int j = 3; j*j <= A[i]; j++) {
      n = 0;
      if (a%j == 0) {
        while (a%j == 0) {
          a /= j;
          n++;
        }
        prmftp.push_back(make_pair(j, n));
      }
    }
    if (a != 0)
      prmftp.push_back(make_pair(a, 1));

    for (auto it = prmftp.begin(); it != prmftp.end(); it++) {
      if (prmfct[it->first] < it->second)
        prmfct[it->first] = it->second;
    }
  }

  long long lcm = 1;
  for (int i = 2; i < 1000000; i++) {
    if (prmfct[i] != 0) {
      lcm *= pow(i, prmfct[i]);
      lcm %= MOD;
    }
  }

  long long ans = 0;
  for (int i = 0; i < N; i++) {
    int a = modinv(A[i], MOD);
    a += a < 0 ? MOD : 0;
    ans += lcm * a;
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 8320
import sys
input = sys.stdin.readline
from collections import deque

S = input()[:-1]
Q = int(input())
que = []
acc = [0]

for i in range(Q):
    l = list(input().split())
    ty = int(l[0])
    
    if ty==1:
        acc.append(acc[-1]+1)
    else:
        acc.append(acc[-1]+0)
        
    if ty==1:
        continue
        
    f = int(l[1])
    que.append((i, f, l[2]))
    
ans = deque([])

if (acc[-1]-acc[0])%2==0:
    for i in range(len(S)):
        ans.append(S[i])
else:
    for i in range(len(S)-1, -1, -1):
        ans.append(S[i])

for i, f, c in que:
    cnt = acc[-1]-acc[i]
    
    if cnt%2==0:
        if f==1:
            ans.appendleft(c)
        else:
            ans.append(c)
    else:
        if f==1:
            ans.append(c)
        else:
            ans.appendleft(c)

ans = list(ans)
print(''.join(ans))

Measured memory_bytes: 108124
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	string s; cin >> s;

	int cnt = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'B') {
			cnt++;
		}
	}

	cnt--;

	map<int, int> m;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'B') {
			m[cnt--] = i;
		}
	}

	LL ans = 0;
	for (auto i : m) {
		ans += (s.length()-1 - (i.first) - i.second);
	}

	cout << ans << endl;
	

	return 0;
}

Measured memory_bytes: 9988
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc155_a.cpp
 * time   : Sat May  2 19:11:05 2020
 * quest  : A - Poor
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && b == c)
    cout << "No\n";
  else if (a == b || b == c || a == c)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String stra = input.readLine( );
		String strb = input.readLine( );
		String strc = input.readLine( );

		String[] list  = new String[3];
		list[0] = stra;
		list[1] = strb;
		list[2] = strc;

		int next = 0;
		String answer = "";
		while(list[0].length() >= 0 && list[1].length() >= 0 && list[2].length() >= 0){
			if(list[next].length() == 0){
				if(next == 0){
					answer = "A";
				}else if(next == 1){
					answer = "B";
				}else if(next == 2){
					answer = "C";
				}
				System.out.println(answer);
				break;
			}
			if(list[next].startsWith("a")){
				list[next] = list[next].substring(1);
				next = 0;
			}else if(list[next].startsWith("b")){
				list[next] = list[next].substring(1);
				next = 1;
			}else if(list[next].startsWith("c")){
				list[next] = list[next].substring(1);
				next = 2;
			}
		}
	}

}


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

using namespace std;

void solve() {
  string s;
  cin >> s;

  vector<vector<int>> dp(2, vector<int>(s.size() + 1, INT_MAX));
  dp[1][0] = 100000;
  dp[0][0] = 0;
  for (int i = 0; i < s.size(); ++i) {
    int num = s[s.size() - 1 - i] - '0';

    dp[0][i + 1] = min(dp[0][i] + num, dp[1][i] + num + 1);
    dp[1][i + 1] = min(dp[0][i] + (10 - num), dp[1][i] + (10 - num - 1));
  }

  auto coins = min(dp[0].back(), dp[1].back() + 1);
  cout << coins << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
}


Measured memory_bytes: 13084
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>

using namespace std;



int main() {
    

    int n,k;
    cin >> n >> k;
    long long ans = k;
    for (int i=1;i<n;i++){
        ans *= k-1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=111;
const int M=3*N;
int dp[N][N][M],a[N],b[N];
int main()
{
	int n,W;
	scanf("%d%d",&n,&W);
	for(int i=0;i<n;i++)
		scanf("%d%d",&a[i],&b[i]);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<=i;j++)
		{
			for(int h=0;h<=3*j;h++)
			{
				dp[i+1][j][h]=max(dp[i+1][j][h],dp[i][j][h]);
				dp[i+1][j+1][h+a[i]-a[0]]=max(dp[i+1][j+1][h+a[i]-a[0]],dp[i][j][h]+b[i]);
			}
		}
	}
	int ans=0;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=3*i;j++)
		{
			long long curW=(long long)a[0]*i+j;
			if(curW<=W)
				ans=max(ans,dp[n][i][j]);
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 12928
#include <cstdlib>
#include <iostream>


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

  int a, b, c;
  std::cin >> a >> b >> c;
  std::cout << (a + b == c || b + c == a || c + a == b ? "Yes" : "No") << std::endl;

  return EXIT_SUCCESS;
}


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

#define ll  long long
#define ull unsigned ll
#define LD long double

#define MP make_pair
#define BS binary_search
#define GCD __gcd
#define pb push_back
#define pp pop_back
#define ff first
#define ss second

#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define sz(a) (int)a.size()

int main(){
    int a,b;
    cin >> a >> b;
    int sum = a+b;
    puts((sum%3==0 || a%3==0 || b%3==0)?"Possible":"Impossible");
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = sc.nextInt();
		sc.close();
		int eat = 0;
		if (l > 0) {
			eat = l;
		} else if (l + n - 1 > 0) {
			eat = 0;
		} else {
			eat = l + n - 1;
		}
		int ans = 0;
		for (int i = 0; i < n; i++) {
			ans += l + i;
		}
		ans -= eat;
		System.out.println(ans);
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}
}


Measured memory_bytes: 23636
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
int main() {
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	cout << s1[0] << s2[1] << s3[2] << "\n";
}

Measured memory_bytes: 3536
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, XY):

    d = {}
    for i, j in combinations(range(N), r=2):
        xi, yi = XY[i]
        xj, yj = XY[j]
        d[(i, j)] = math.sqrt((xi-xj)**2 + (yi-yj)**2)

    ds = 0
    c = 0
    for p in permutations(range(N)):
        for k in range(1, N):
            i = min(p[k], p[k-1])
            j = max(p[k], p[k-1])
            ds += d[(i, j)]
        c += 1
    return ds/c


def main():
    N = read_int()
    XY = [read_int_n() for _ in range(N)]
    print(slv(N, XY))


if __name__ == '__main__':
    main()


Measured memory_bytes: 64872
#include <iostream>
#include <list>
#include <algorithm>
#include <iterator>
using namespace std;

int gcd(int a, int b){
	while(b){
		int r = a % b;
		a = b;
		b = r;
	}
	return a;
}

int main(){
	list<int> ls;
	list<int>::iterator it = ls.begin();

	int n, a, b, c;
	cin >> n >> a >> b >> c;
	a = gcd(a, b);
	if(n == 3) a = gcd(a, c);

	for(int i = 1; i * i <= a; ++i){
		if(a % i == 0){
			ls.insert(it, i);
			if(i * i < a) it = ls.insert(it, a / i);
		}
	}
	
	copy(ls.begin(), ls.end(), ostream_iterator<int>(cout, "\n"));
}

Measured memory_bytes: 1192
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

vector<ll> mods;
#define MOD_NUM 5

void setMods(){
  int cnt=0;
  ll val=MOD;
  while(cnt<MOD_NUM){
    bool ok=true;
    for(ll i=2;i*i<=val;i++){
      if(val%i==0){
        ok=false;
        break;
      }
    }

    if(ok){
      mods.push_back(val);
      cnt++;
    }

    val++;
  }
}

struct edge{
  int to;
  ll cost;
  int rev;
};

int N,M;
vector<int> A,B;
vector<ll> X;

vector<edge> g[100010];
pair<ll,ll> val[100010][MOD_NUM];
bool visited[100010];

void dfs(int now){
  for(int i=0;i<g[now].size();i++){
    edge &e=g[now][i];
    vector<pair<ll,ll>> nv(MOD_NUM,{0,0});
    for(int j=0;j<MOD_NUM;j++) nv[j]=val[now][j];

    if(e.rev){
      for(int j=0;j<MOD_NUM;j++) nv[j].second=nv[j].second*e.cost%mods[j];
    }else{
      for(int j=0;j<MOD_NUM;j++) nv[j].first=nv[j].first*e.cost%mods[j];
    }

    if(visited[e.to]){
      for(int j=0;j<MOD_NUM;j++){
        ll a=val[e.to][j].first*nv[j].second%mods[j];
        ll b=val[e.to][j].second*nv[j].first%mods[j];

        if(a!=b){
          cout<<"No"<<endl;
          exit(0);
        }
      }
    }else{
      visited[e.to]=1;
      for(int j=0;j<MOD_NUM;j++) val[e.to][j]=nv[j];
      dfs(e.to);
    }

  }
}

int main(){
  cin>>N>>M;
  A.resize(M);
  B.resize(M);
  X.resize(M);
  rep(i,M) cin>>A[i]>>B[i]>>X[i];

  setMods();

  rep(i,M){
    A[i]--;
    B[i]--;
    g[A[i]].push_back(edge{B[i],X[i],0});
    g[B[i]].push_back(edge{A[i],X[i],1});
  }

  for(int i=0;i<N;i++){
    if(visited[i]) continue;
    visited[i]=1;
    for(int j=0;j<MOD_NUM;j++) val[i][j]=mkp(1,1);
    dfs(i);
  }

  cout<<"Yes"<<endl;

  return 0;
}



Measured memory_bytes: 36808
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long A, B, C;
	cin >> A >> B >> C;
	long long a = A / 2, b = B / 2, c = C / 2;
	long long Num1, Num2, Num3;
	Num1 = abs((A - a) * B * C - a * B * C);
	Num2 = abs(A * (B - b) * C - A * b * C);
	Num3 = abs(A * B * (C - c) - A * B * c);
	long long ans = min({ Num1,Num2, Num3 });
	cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? (-(a)) : (a))

typedef long long ll;

using namespace std;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll N, K;

	scanf("%lld %lld", &N, &K);
	printf("%lld\n", min({ ABS(N - K*(N / K)), ABS(N - K*(N / K + 1)), ABS(N - K*(N / K - 1)) }));

	return 0;
}

Measured memory_bytes: 256
import java.io.*;
class Main{
    public static void main(String[] args) throws IOException
    {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String str = br.readLine();
	String[] strAry = str.split(" ");
	int a = Integer.parseInt(strAry[0]);
	int b = Integer.parseInt(strAry[1]);
	int c = Integer.parseInt(strAry[2]);
	int count = 0;
	for(int i=a;i<=b;i++)
	    if(c%i==0) count++;
	System.out.println(count);
    }
}

Measured memory_bytes: 24500
#include<iostream>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<cmath>
using namespace std;

int main() {
	double a, b, c;
	cin >> a >> b >> c;
	double PI = acos(-1);
	double crad = c * PI / 180;

	double S = a * b*sin(crad) / 2;
	double h, d, L;
	

	printf("%.5f\n", S);
	printf("%.5f\n", sqrt(a*a+b*b-2*a*b*cos(crad))+a+b);
	printf("%.5f\n", b*sin(crad));

	return 0;

}



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

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  vector<int> l(Q), r(Q);
  for(int i = 0; i < Q; i++) {
    cin >> l[i] >> r[i];
  }

  vector<int> cnt(N+1, 0);
  for(int i = 0; i < N; i++) {
    if(S[i] == 'A' && S[i+1] == 'C') {
      cnt[i+1] = cnt[i] + 1;
    }
    else {
      cnt[i+1] = cnt[i];
    }
  }
  cout << endl;

  for(int i = 0; i < Q; i++) {
    cout << cnt[r[i]-1] - cnt[l[i]-1] << endl;
  }

  return 0;
}


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

int main() {

    int n;
    cin >> n;
    vector<int> vec1(n),vec2(n);
    
    for(int i = 0; i < n ; i++){
        cin >> vec1.at(i);
        vec2.at(n-i-1) = vec1.at(i);
    }
    
    cout << vec2.at(0);
    
    for(int i = 1; i < n ; i++){
        cout << " " << vec2.at(i);
    }
    
    cout << endl;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    int K;
    std::cin >> K;

    int even = K / 2;
    int odd = 0;
    if (K % 2 == 0) {
        odd = K / 2;
    } else {
        odd = K / 2 + 1;
    }

    std::cout << even * odd << std::endl; 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int r;
	cin >> r;
	cout << r * r << endl;
	
	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SZ(x) (int)(x).size()
#define mset(a,x) memset(a,x,sizeof(a))
#define dbg(x) cout<<#x<<": "<<(x)<<"\n"
#define pb push_back
#define mp make_pair

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int m = n-1;

    ll tot = 0;
    rep(mask, 1<<m){
        ll sum = 0, cur = 0;
        rep(i,n){
            if(mask & (1<<(i-1))) {
                sum += cur;
                cur = 0;
            }
            cur = cur * 10 + (s[i] - '0');
        }
        sum += cur;
        tot += sum;
    }

    cout << tot << endl;

    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
ary = []
ans = "Yes"
n.times do
  ary << gets.strip
end
ary.each_with_index do |i, k|
  if ary.count(i) == 2
    ans = "No"
  else 
    if ary[k+1]
      i[(i.length-1)] != ary[(k+1)][0] ? ans = "No" : next
    end
  end
end

puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;

template<class T>bool chmax(T &a, const T &b) { if( a < b ) { a = b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) { if( b < a ) { a = b; return 1; } return 0;}

#ifdef LOCAL
#define eprintf(...) printf(__VA_ARGS__)
#else
#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) 		( ((a) + ((b) - 1) ) / b)
#define SET_ZERO(a)	 		( memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a,b)	( memset((a), b, sizeof(a)))

const int N_MAX = 1010*101;

int count32bit(unsigned int v) {
	unsigned int count = (v & 0x55555555) + ((v >> 1) & 0x55555555);
	count = (count & 0x33333333) + ((count >> 2) & 0x33333333);
	count = (count & 0x0f0f0f0f) + ((count >> 4) & 0x0f0f0f0f);
	count = (count & 0x00ff00ff) + ((count >> 8) & 0x00ff00ff);
	return (count & 0x0000ffff) + ((count >> 16) & 0x0000ffff);
}

int main() {
	int N, C;
	scanf("%d %d", &N, &C);
	unsigned int time[(N_MAX+1)*2];
	SET_ZERO(time);
	for (int i = 0; i < N; i++) {
		int s, t, c;
		scanf("%d %d %d", &s, &t, &c);
		time[s*2-1] |= 1 << (c-1);
		time[t*2] |= 1 << (c-1);
	}
	
	int max = 0;
	unsigned int state = 0;
	for (int i = 0; i < (N_MAX+1)*2; i++) {
		state = state ^ time[i];
		chmax(max, count32bit(state));
	}
	printf("%d\n", max);
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(){
  int height[300], weight[300];
  int i = 0, j = 0, count = 0, l = 0;

  for(i=1;i<=300;i++){
    scanf("%d %d", &height[i], &weight[i]);
    if(height[i]==0&&weight[i]==0) break;
    count++;
  }

  for(l=1;l<=count;l++){
    for(i=1;i<=height[l];i++){
      for(j=1;j<=weight[l];j++){
        if(i%2==0){
          if(j%2==0){
            printf("#");
          }else{
            printf(".");
          }
        }else{
          if(j%2==0){
            printf(".");
          }else{
            printf("#");
          }
        }
      }
      printf("\n");
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 572