akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
using namespace std;
typedef long long LL;
const int N = 21;
const int MAXS = (1 << N) + 5;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

char g[MAXS];
int n, k, S;
int lg2[MAXS], ch[MAXS][2], dp[N][MAXS];

void init() {
	read(n); read(k);
	S = (1 << (n + 1));
	lg2[0] = -1;
	for (int i = 1; i < S; ++i) {
		lg2[i] = lg2[i >> 1] + 1;
	}
	for (int i = 0; i <= n; ++i) {
		scanf("%s", g);
		int len = (1 << i);
		for (int j = 0; j < len; ++j) {
			dp[i][j ^ len] = (g[j] == '1');
		}
	}
}

void solve() {
	for (int s = 2; s < S; ++s) {
		if ((s >> (lg2[s] - 1)) & 1) {
			ch[s][1] = s ^ (1 << lg2[s]);
			ch[s][0] = ch[ch[s][1]][0];
		} else {
			ch[s][0] = s ^ (3 << (lg2[s] - 1));
			ch[s][1] = ch[ch[s][0]][1];
		}
	}
	for (int i = n; i >= 1; --i) {
		for (int s = (1 << i); s < S; ++s) {
			int x = dp[i][s];
			if (!x) continue;
			int ss = (s >> i), t = (s & ((1 << i) - 1)) ^ (1 << i);
			dp[0][ss] += x;
			if (ch[t][0]) {
				int v = ch[t][0];
				dp[lg2[v]][(((ss << 1) ^ 1) << lg2[v]) ^ v] += x;
			}
			if (ch[t][1]) {
				int v = ch[t][1];
				dp[lg2[v]][((ss << 1) << lg2[v]) ^ v] += x;
			}
		}
	}
	int ans = 1;
	for (int s = S - 1; s > 1; --s) {
		if (dp[0][s] >= k && lg2[s] >= lg2[ans]) {
			ans = s;
		}
	}
	int p = n;
	while (!((ans >> p) & 1)) {
		--p;
	}
	while (p--) {
		putchar(((ans >> p) & 1) + '0');
	}
	puts("");
}

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


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

int main() { 
    int n, ans = 1e9;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i) cin >> a[i];
    sort(a.begin(), a.end());
    for(int i = 1; i <= a[n-1]; ++i) {
        int t = 0;
        for(int j = 0; j < n; ++j) {
            t += (i-a[j])*(i-a[j]);
            
        }
        ans = min(ans, t);
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
int main(void){
    int n;
    while(cin>>n,n){
        valarray<int> field(0,441);
        int cur=220;
        rep(i,n){
            int x,y; cin>>x>>y;
            field[x+(20-y)*21]=1;
        }
        int m; cin>>m;
        rep(i,m){
            char c; int d;
            cin>>c>>d;
            vi vl={-21,1,-1,21};
            rep(j,d){
                cur+=vl[((string)"NEWS").find(c)];
                field[cur]=0;
            }
        }
        cout<<(field.sum()==0?"Yes":"No")<<endl;
    }
}

Measured memory_bytes: 3160
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main(void){
    //x1, y1, x2, y2 （実数）なので double 型を使う
    double x1,y1, x2, y2;
    cin >> x1 >> y1;
    cin >> x2 >> y2;
    double d = pow(x1-x2, 2) + pow(y1-y2, 2);
    cout << fixed << setprecision(5) << sqrt(d);
    cout << endl; 
}


Measured memory_bytes: 3244
#include "bits/stdc++.h"
using namespace std;

static const int MOD = 1000000007;

long long fact(long long a) {
        if (a == 1) return 1;
        return a * fact(a - 1) % MOD;
}

int main() {
        long long n, m;
        cin >> n >> m;
        if (abs(n - m) > 1) { 
                cout << 0 << endl;
                return 0;
        }
        if (n < m) swap(n, m);
        long long ans = 1;
        if (n == m) {
                ans *= 2;
                ans = ans * fact(n) % MOD;
                ans = ans * fact(m) % MOD;
        } else {
                ans = ans * fact(n) % MOD;
                ans = ans * fact(m) % MOD;
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 1792
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define qmin(x,y) (x=min(x,y))
#define qmax(x,y) (x=max(x,y))
#define mp(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline int read(){
	int ans=0,fh=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') fh=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
		ans=ans*10+ch-'0',ch=getchar();
	return ans*fh;
}
int n,m,d;
int main(){
//	freopen("nh.in","r",stdin);
//	freopen("zhy.out","w",stdout);
	n=read(),m=read(),d=read();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			int x=i+j+m,y=i-j+m;
			if((x/d)&1){
				if((y/d)&1) printf("R");
				else printf("Y");
			}
			else{
				if((y/d)&1) printf("G");
				else printf("B");
			}
		}
		printf("\n");
	}
	return 0;
}














Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
	int A[100][100], b[101][1] = { 0 }, n, m, i, j, output[101][1] = { 0 };
	scanf("%d %d", &n, &m);
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			scanf("%d", &A[i][j]);
		}
	}

	for (i = 0; i < m; i++)
	{
		scanf("%d", &b[i][1]);
	}

	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			output[i][1] += A[i][j] * b[j][1];
		}
	}
	for (i = 0; i < n; i++)
	{
		printf("%d\n", output[i][1]);
	}
	return 0;
}


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

ll n;
const ll MAXN = 2e5 + 10;

ll a[MAXN], cnt[MAXN], res = 0;

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

    cin >> n;
    for(ll i = 1; i <= n; ++i) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    for(ll i = 1; i <= n; ++i) {
        res += cnt[i] * (cnt[i] - 1) / 2;
    }
    for(ll i = 1; i <= n; ++i) {
        cout << res - cnt[a[i]] + 1 << "\n";
    }

    return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int cnt = 0;
    for (int i = 0; i <= a; i++){
        int a_sum = 500 * i;
        for (int j = 0; j <= b; j++){
            int b_sum = 100 * j;
            for (int k = 0; k <= c; k++){
                int c_sum = 50 * k;
                if ((a_sum + b_sum + c_sum) == x){
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
}

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

int main() {
  int d , n;
  cin >> d >> n;
  if ( d == 0 ) {
    if ( n!= 100) {
    cout << n << endl;
    }else cout << 101 << endl;
    return 0 ;
  }else if ( d == 1 ){
    if ( n!=100){
    cout << n*100 << endl;
    }else cout << 10100 <<endl;
    return 0;    
  }else if ( d==2){
    if ( n!= 100){
    cout << n*10000 << endl;
    }else cout << 1010000 << endl;
  }
}

Measured memory_bytes: 3656
#include<cstdio>
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a%3==0||b%3==0||(a+b)%3==0){
		printf("Possible\n");
	}else{
		printf("Impossible\n");
	}
	return 0;
}

Measured memory_bytes: 128
import copy
ym,xm=map(int,input().split())
ym-=1
xm-=1
field=[]
for i in range(ym+1):
  field.append(list(input()))
ans=copy.deepcopy(field)
def check(x,y):
  ret=0
  chx=[0]
  chy=[0]
  if x!=0:
    chx.append(-1)
  if x!=xm:
    chx.append(1)
  if y!=0:
    chy.append(-1)
  if y!=ym:
    chy.append(1)
  for px in chx:
    for py in chy:
      if px==0 and py==0:
        continue
      if field[y+py][x+px]=="#":
        ret+=1
  return ret

for x in range(xm+1):
  for y in range(ym+1):
    if field[y][x]=="#":
      continue
    ans[y][x]=check(x,y)

for i in ans:
  for j in i:
    print(j,end="")
  print()

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

using namespace std;
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define ll long long
#define lson node<<1
#define rson (node<<1)+1

const int maxn=3e6+10;
const ll mod=1e9+7;
const double pi=acos(-1);

ll qpow(ll a,ll n)
{
    ll b=1;
    while(n)
    {
        if(n&1)
            b=(b*a)%mod;
        a=a*a%mod;
        n>>=1;
    }
    return b;
}

ll ji[maxn];
void init()
{
    ji[0]=1;
    for(int i=1;i<maxn;i++)
        ji[i]=ji[i-1]*i%mod;
}

ll c(ll a,ll n)
{
    return ji[n]*qpow(ji[a],mod-2)%mod*qpow(ji[n-a],mod-2)%mod;
}

int main()
{
    init();
    ll n;
    string s;
    cin>>n>>s;
    ll len=s.length();
    ll k=len+n;
    ll ans=0;
    for(int i=1;i<=k-len+1;i++)
    {
        ans=(ans+qpow(26,i-1)*qpow(25,k-i-len+1)%mod*c(len-1,k-i)%mod)%mod;
    }
    cout<<ans;
    return 0;
}



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

using namespace std;

char field[110][110];
int used[110][110];

void f(int y, int x) {
    if (field[y][x] == '.') {
        printf("%d %d\n", x, y);
        return;
    }
    if (used[y][x]) {
        puts("LOOP");
        return;
    }

    used[y][x] = 1;
    switch (field[y][x]) {
        case '>': f(y, x + 1); break;
        case 'v': f(y + 1, x); break;
        case '<': f(y, x - 1); break;
        case '^': f(y - 1, x); break;
    }
}

int main(void) {
    int H, W;
    while (scanf("%d %d", &H, &W), H) {
        for (int i = 0; i < H; i++) {
            scanf("%s", field[i]);
            for (int j = 0; j < W; j++)
                used[i][j] = 0;
        }
        
        f(0, 0);
    }
}


Measured memory_bytes: 3196
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int Z = scan.nextInt();
        int W = scan.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = scan.nextInt();
        }
        if (N == 1) {
            System.out.println(Math.abs(a[N-1]-W));
            return;
        }
        long answer = Math.max(Math.abs(a[N-1]-W),Math.abs(a[N-1]-a[N-2]));
        System.out.println(answer);
    }
}


Measured memory_bytes: 26032
import java.util.Scanner;
import java.util.*;

public class Main{
	
	public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	Stack<Integer> moveSeq = new Stack<Integer>();
	while(scan.hasNext()){
		
		int i = scan.nextInt();
		if(i == 0){
			System.out.println(moveSeq.pop());
				
			} else {
				moveSeq.push(i);
		}
	}
	

	
}

}



Measured memory_bytes: 26312
def main():
    day = input()
    days = {'SUN': 7, 'MON': 6, 'TUE': 5, 'WED': 4, 'THU': 3, 'FRI': 2, 'SAT': 1}
    print(days[day])


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
s=input()
n=len(s)
c0=0
c1=0
for i in range(n):
    if i%2 >0:
        if s[i]!='1':
            c0+=1
        else:
            c1+=1
    else:
        if s[i]!='0':
            c0+=1
        else:
            c1+=1
print(min(c0,c1))

Measured memory_bytes: 3188
#include <iostream>
#include <set>
using namespace std;
int main(){
    int n; cin>>n;
    set<int> st;
    for(int i = 0; i < n; ++i){
        int a; cin >> a;
        st.insert(a);
    }
    if(st.size()==n) puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 12916
#include <bits/stdc++.h>
using namespace std;
//repetition
//------------------------------------------
#define FOR(i, p, b) for (int i = (p); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \<< " " << __FILE__ << endl;

int main() {
    int N, K, total = 0;
    cin >> N >> K;

    int i = 0;
    int x[N] = {0};
    REP(i, N) {
        cin >> x[i];
    }
    i = 0;
    REP(i, N) {
        if (x[i] >= K) {
            if (x[i] >= x[i] - K) {
                total += (x[i] - K) * 2;
            } else {
                total += x[i] * 2;
            }
        } else {
            if (x[i] >= K - x[i]) {
                total += (K - x[i]) * 2;
            } else {
                total += x[i] * 2;
            }
        }
    }
    cout << total << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(ll i=0;i<n;++i)
#define END(x) (*(x.end()-1))
#define INF INT_MAX / 2

using namespace std;
typedef long long ll;


template<typename T>
T gcd(T a, T b){
   if (a%b == 0){
       return(b);
   }
   else{
       return(gcd(b, a%b));
   }
}

template<typename T>
T lcm(T a,T b){
    return a/gcd(a,b)*b;
}

int main(void){
    ll n;
    cin>>n;
    vector<ll>p(n);
    rep(i,n){
        cin>>p[i];
    }
    ll ans=0;
    rep(i,n){
        if(p[i]-1==i){
            ++ans;
            ++i;
        }
    }
    cout<<ans;
}
/*

*/


Measured memory_bytes: 3960
#include <iostream>

using namespace std;

int main(void) {
	int N,a,b=1;
	cin >> N;
	int h[20];
	
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}

	a = h[0];

	for (int i = 1; i < N; i++) {
		
		if (h[i] >= a) {
			a = h[i];
			b++;
		}
	}
	cout << b;

	return 0;

	
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
const int N = 2e5+10;
const int mod = 1e9+7;
int a[] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;
int main()
{
    cin >> k;
    cout << a[k] << endl;
}

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

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    if(a%2==0 || b%2==0 || c%2==0)cout << 0 << endl;
    else{
        ll ans = min({a*b, b*c, c*a});
        cout << ans << endl;
    }
    
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
#define INF 1e18
signed main(){
    int h,w;
    cin>>h>>w;
    int ans=INF;
    if(h==2&&w==2){
        ans=1;
    }
    for(int i=1;i<=h-2;i++){
        int a=i*w,b=((h-i)/2)*w,c=((h-i+1)/2)*w;
        ans=min(ans,max(a,max(b,c))-min(a,min(b,c)));
        b=(h-i)*(w/2),c=(h-i)*((w+1)/2);
        ans=min(ans,max(a,max(b,c))-min(a,min(b,c)));
    }
    swap(h,w);
    for(int i=1;i<=h-2;i++){
        int a=i*w,b=((h-i)/2)*w,c=((h-i+1)/2)*w;
        ans=min(ans,max(a,max(b,c))-min(a,min(b,c)));
        b=(h-i)*(w/2),c=(h-i)*((w+1)/2);
        ans=min(ans,max(a,max(b,c))-min(a,min(b,c)));
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    string s,t;
    std::cin >> s;
    std::cin >> t;
    ll ns,nt;
    ns = s.length();
    nt = t.length();
    
    vector<vector<int>> alin(26);
    
    for (int i = 0; i < ns; i++) {
        int x = s[i]-'a';
        alin[x].push_back(i);
    }
    ll now = -1;
    ll res = 0;
    for (int i = 0; i < nt; i++) {
        int x = t[i]-'a';
        if(alin[x].empty()){
            std::cout << -1 << std::endl;
            return 0;
        }
        auto inde = distance(alin[x].begin(),upper_bound(alin[x].begin(),alin[x].end(),now));
        if(inde == alin[x].size() ){
            res++;
            now = alin[x][0];
        }else{
            now = alin[x][inde];
        }
    }
    std::cout << res*ns+now+1 << std::endl;
}


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

int main()
{
  int x;
  cin >> x;
  int i, k;
  int ans = 1;
  for(i = 2; i <= x; i++)
  {
    k = i * i;
    while(k <= x)
    {
      if(k > ans)
      {
        ans = k;
      }
      k *= i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define INF (1<<20)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

map<string, int> m;

int main() {
	int n;
	cin >> n;
	char inp[8];

	rep(i, n) {
		string word;
		scanf("%s", inp);
		cin >> word;

		if (inp[0] == 'i') {
			m[word] = 1;
		}
		else {
			if (m.find(word) != m.end()) cout << "yes" << endl;
			else cout << "no" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 36572
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

map<long long int, long long int> prime_factor(long long int n) {
    map<long long int, long long int> ret;
    for (long long int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1) ret[n] = 1;
    return ret;
}

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

    int div = 1000000007;

    map<ll, ll> primes;
    for (int i = 1; i <= N; i++) {
        map<ll, ll> tmp = prime_factor(i);
        for (auto a : tmp) {
            primes[a.first] += a.second;
        }
    }

    ll output = 1;
    for (auto p : primes) {
        // cout << p.first << " " << p.second << endl;
        output *= (p.second + 1) % div;
        output %= div;
    }
    cout << output << endl;

    return 0;
}


Measured memory_bytes: 3556
#include <stdio.h>
#include <stdlib.h>
#define a_element 2001
#define FALSE 0
#define TRUE 1

int n,A[a_element];
  
int consider(int m, int i){
  if(m==0)return TRUE;
  if(i>=n)return FALSE;
  int flag= consider(m, i+1) || consider(m-A[i], i+1);
  return flag;
}

int main(){
  int m[a_element];
  int q,i;
  int flag = FALSE;

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

  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&m[i]);
  }

  for(i=0; i<q; i++){
    flag = consider(m[i],0);
    if(flag == TRUE) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}



Measured memory_bytes: 2104
#include <iostream>


using namespace std;


using ll = long long;


int main()
{
    ll N, M;
    cin >> N >> M;

    if (N == 1 && M == 1) {
        cout << 1 << endl;
        return 0;
    }

    if (N == 1) {
        cout << M - 2 << endl;
        return 0;
    } else if (M == 1) {
        cout << N - 2 << endl;
        return 0;
    }

    cout << (M - 2) * (N - 2) << endl;
}


Measured memory_bytes: 256
from fractions import gcd
import math
a, b = map(int, input().split())

def devisors(value):
    if value == 1:
        return [1]
    devisors = []
    root = int(math.sqrt(value))
    for a in range(1, root+1):
        if a == root and a * a == value:
            devisors.append(root)
            continue
        if value % a == 0:
            devisors.append(a)
            devisors.append(value // a)
    return devisors

def prime_devisors(value):
    ret_devisors = []
    devs = devisors(value)
    for devisor in devs:
        prime_flag = True
        root = int(math.sqrt(devisor))
        for a in range(2, root + 1):
            if devisor % a == 0:
                prime_flag = False
                break
        if prime_flag and devisor != 1:
            ret_devisors.append(devisor)
    return ret_devisors


if __name__ == "__main__":
    val = gcd(a, b)
    primes = prime_devisors(val)
    if len(primes) == 0: #公約数が1しかない場合
        print(1)
    else:
        print(1 + len(primes))

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

int main() {
    int a, b;
    cin >> a >> b;

    int price = -1;
    bool ret = true;

    for (int i = 0; i <= 1500; i++){
        if ((int)(i * 0.08) == a && (int)(i * 0.1) == b){
            price = i;
            break;
        }
    }

    cout << price << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

bool B[100100];
int main(){
    string S;
    cin >> S;
    int N = S.length();
    REP(i,N){
        char c = S[i];
        if(c == 'B') B[i] = true;
    }

    bool isblack = B[0];
    ll ans = 0;
    for(int i = 1; i < N; i++){
        if(B[i] != isblack) {
            ans++;
            isblack = B[i];
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <map>

using namespace std;

int main() {
    int N;
    cin >> N;
    map<int, int> mp;
    for(int n=0; n<N; n++) {
        int A;
        cin >> A;
        mp[A]++;
    }
    
    int ans=mp.size();
    int cnte=0;
    for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
        if(itr->second%2==0) {
            cnte++;
        }
    }
    
    if(cnte%2!=0) {
        ans--;
    }
    
    cout << ans << endl;
    

    return 0;
    
}

Measured memory_bytes: 4992
//                      Aman Raj  - AmanRaj1608
#include<bits/stdc++.h>
using namespace std;
#define ll                        long long
#define vi                        vector<ll int>
#define pb                        emplace_back
#define rep(i,a,b)                for(int i = a; i<b; ++i)
#define rrep(i,a,b)               for(int i = a; i>=b; --i)
#define p(a)                      cout << a << "\n";
#define p2(a,b)                   cout << a << " " << b << "\n";
#define fast_io                   ios_base::sync_with_stdio(false);cin.tie(NULL);
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://

int32_t main() {
	fast_io;
    ll tt = 1;
	// cin >> tt;
    while(tt--) {
        ll n,k;
		cin >> n >> k;
		vector<int> h(n);
		rep(i,0,n)	cin >> h[i];

		vector<int> dp(n,INT_MAX);
		dp[0] = 0;
		rep(i,0,n) {
			rep(j,1,k+1) {
				if(i-j<0 || i-j>n)	break;
				dp[i] = min(dp[i], abs(h[i]-h[i-j]) + dp[i-j]);
			}
		}
		p(dp[n-1])
    }
    return 0;
}
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://


Measured memory_bytes: 1024
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;

using namespace std;

ll gcd(ll a, ll b) {
    if(b == 0) return a;
    return gcd(b,a%b);
}

vector<long> pp;
void preparePrime( long maxp )
{
    long i;
    vector<long> a(maxp+1);
    for(i=2; i<=maxp; i++) {
        long k=i+i;
        while(k<=maxp) {
            a[k]=1;
            k+=i;
        }
    }
    for(i=2; i<=maxp; i++) {
        if(a[i]==0) pp.push_back( i );
    }
    return;
}

void decompositPrime( ll a, vector<pair<ll,ll> >& vv )
{
    preparePrime( (long)sqrt((double)a) );

    long i;
    for(i=0; i<(long)pp.size(); i++) {
        long count = 0;
        while(a % pp[i] == 0 ) {
            a /= pp[i];
            count ++;
        }
        if(count>0) vv.push_back( make_pair( pp[i], count ) );
        if (a==1) break;
    }
    if(a>1) {
        vv.push_back( make_pair( a, 1 ) );
    }

    return;
}

vector<long> zz;

void dfs( long i, const long siz, const pair<ll,ll>* vv, ll curr)
{
    if(i==siz) {
        if(curr>0) {
            //printf("%lld ", curr);
            zz.push_back(curr);
        }
        return;
    }
 
    long k;
    ll tmp=1;
    for(k=0; k<=vv[i].second; k++) {
        if(k>0) tmp*= vv[i].first;
        dfs(i+1, siz, vv, curr*tmp);
    }
    return;
}

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);
    vector<long> a(n);
    long i;
    for(i=0; i<n; i++) {
        scanf("%ld", &a[i]);
    }

    ll val0=a[1];
    for(i=2; i<n; i++) {
        val0 = gcd(val0, a[i]);
    }

    vector<pair<ll,ll> > vv;
    decompositPrime( a[0], vv );

    long siz=(long)vv.size();
 
    dfs(0, siz, &(vv[0]), 1);

    sort(zz.begin(), zz.end());
    ll curr=INF;
    for(i=zz.size()-1; i>=0; i--) {
        curr = zz[i];
        long k;
        long cnt=0;
        for(k=0; k<n; k++) {
            if(a[k] % curr != 0) cnt++;
            if(cnt>1) break;
        }
        if(cnt<=1) {
            break;
        }
    }
    printf("%ld\n", MAX(curr,val0));

    return 0;
}


Measured memory_bytes: 1280
using System;

namespace AizuOnlineJudgement.ITP1_3_B
{
	public static class Program
	{
		public static void Main (string[] args)
		{
			int i = 0, x;
			while ((x = int.Parse (Console.ReadLine ())) > 0) {
				Console.WriteLine ("Case " + ++i + ": " + x);
			}
		}
	}
}



Measured memory_bytes: 9384
// Created by sz
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int k;
    cin >> k;
    queue<ll> q;
    for (int i = 1; i < 10; i++){
        q.push(i);
    }
    
    int cnt= 0;
    while (1) {
        ll cur = q.front();
        q.pop();
        cnt++;
        if(cnt == k){
            cout << cur << "\n";
            return 0;
        }
        
        if(cur%10 > 0 &&q.size() + cnt < k){
            q.push(cur*10 + cur%10 -1);
        }
        if(q.size() + cnt < k)
        q.push(cur*10 + cur%10);
        if(cur%10<9 &&q.size() + cnt < k){
            q.push(cur*10 + cur%10 + 1);
        }
    }
    
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define MAXN 100010
using namespace std;
typedef long long LL;
const LL mod = 1e9+7;
int a[MAXN], p1[MAXN], p2[MAXN];
LL inv[MAXN];
LL fac[MAXN];
LL Com(int n,int m){
    return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
void init(){
    inv[0]=fac[0]=1;
    inv[1]=1;
    for(int i=1;i<MAXN;i++){
        fac[i]=fac[i-1]*i%mod;
    }
    inv[1]=1;
    for(int i=2;i<MAXN;i++){
        inv[i]=(LL)(mod-mod/i)*inv[mod%i]%mod;
    }
    inv[0]=1;
    for(int i=1;i<MAXN;i++){
        inv[i]=inv[i-1]*inv[i]%mod;
    }
}
int main() {
//    freopen("out.txt", "w", stdout);
    init();
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n+1; ++i) {
        scanf("%d", &a[i]);
        p2[a[i]] = i;
    }
    for (int i = n; i >= 0; --i) p1[a[i]] = i;
    int tot;
    for (int i = 1; i <= n; ++i) if (p2[i] - p1[i]) {
        tot = p1[i] + n - p2[i];
        break;
    }
//    printf("%d\n", tot);
    for (int i = 1; i <= n+1; ++i) {
        LL ans = Com(n+1, i);
        if (tot >= i-1) ans = (ans + mod - Com(tot, i-1)) % mod;
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 3968
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(n-1):
    if p[i] == i+1:
        tmp = p[i]
        p[i] = p[i+1]
        p[i+1] = tmp
        ans += 1

if p[-1] == n:
    tmp = p[-1]
    p[-1] = p[-2]
    p[-2] = tmp
    ans += 1

print(ans)


Measured memory_bytes: 20620
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
typedef pair<int, int > Pii;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
#define pb push_back
#define rs resize 
#define rep(i, a, b) for(int i=(a); i<(b); i++)
const long long int mod = 1e9 + 7;
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define COUT(a) cout << a << endl



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

    cout << max(0,A-B*2) << endl;

}


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

int f[N],n,tot;
vector<int>to[N];

inline int read()
{
	int ans=0,f=1;char c=getchar();
	while(c>'9'||c<'0') {if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') ans=(ans<<1)+(ans<<3)+(c^48),c=getchar();
	return ans*f;
}

void dfs(int x,int ga,int va,int gb,int fa)
{
	if(x>ga)va=ga,ga=x,gb=0,++f[x];
	else
	{
		if(fa==ga)gb=x;
		if(x>va)va=0;
		if(x<=va)++f[ga];else ++f[gb];
	}
	for(auto v:to[x]) if(v!=fa) dfs(v,ga,va,gb,x);
}

void dfs2(int x,int fa)
{
	f[x]+=f[fa];
	for(auto v:to[x]) if(v!=fa) dfs2(v,x);
}
int main()
{
	n=read();
	int x,y;
	for(int i=1;i<n;++i)
		x=read(),y=read(),to[x].push_back(y),to[y].push_back(x);
	dfs(1,0,0,0,0);dfs2(1,0);
	for(int i=2;i<=n;++i)printf("%d ",f[i]-1);
}


Measured memory_bytes: 28928
#include<bits/stdc++.h>
#include<iomanip>
#define fastIO  std::ios::sync_with_stdio(false);cin.tie(NULL)
#define endl "\n"
#define rep(i, l, r) for (long long i = (l); i < (r); i++)
#define repb(i, r, l) for (long long i = (r); i > (l); i--)
#define ll long long
#define pb push_back
#define SZ(x) ((int) (x).size())
 
using namespace std;
 
typedef vector<long long> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef long long int lli;
typedef long double ld;
typedef unsigned long long ull; 
const int MAX_CHAR=256;
 


bool palin(string s){
    string s1=s;
    reverse(s.begin(),s.end());
    return s==s1;
}

ll exp(lli b,lli e){
    ll sum=1;
    b=b%1000000007;
    while(e!=0){
        if(e&1) sum=(sum* b)%1000000007;
        e=e>>1;
        b=(b*b)%1000000007;
    }
    return sum;
}

bool sam(string s){
    for(int i=1;i<s.length();i++){
        if(s[i]!=s[i-1])    return false;
    }
    return true;
}

int k;

bool bool_comp(vector<ll>& v1,vector<ll>& v2){
    if(abs(v1[1]-v2[1])<abs(v1[0]-v2[0]))   return v1[1]<v2[1];
    return v1[0]<v2[0];
}
bool bool_comp1(vector<ll>& v1,vector<ll>& v2){
    
    return v1[1]<v2[1];
}
bool bool_comp2(vector<ll>& v1,vector<ll>& v2){
    
    return v1[0]<v2[0];
}

int main(){
	fastIO;
	ll x,k,d,z;
	cin>>x>>k>>d;
	x=abs(x);
	ll a=x,b=a;
	if(x/d>k){cout<<x-k*d;}
	else{
	    a=x-x/d*d;k-=x/d;
	    if(k%2==0){cout<<a;}
	    else {cout<<abs(a-d);}
	}
// 	while(k--){
// 	    if(abs(b)>abs(a)){
// 	        a=b;
// 	        b=b+d;
// 	    }
// 	    else{
// 	        a=b;
// 	        b-=d;
// 	    }
// 	}
// 	cout<<abs(b);
}
// static int a=20; 
// void xyz() 
// { 
// 	printf("%d, ", a); 
// 	a = 100; 
// } 
// int main() 
// { 
// 	printf("%d, ", a); 
// 	{ 
// 		static int a = 10; 
// 		printf("%d, \n", a); 
// 		xyz(); 
// 	} 
// 	printf("%d", a); 
// } 

Measured memory_bytes: 3648
#include<iostream>
#include<stdio.h>
using namespace std;
long long N;
int main()
{
	while (scanf("%lld", &N) != EOF)
	{
		long long  h, n, t1, t2;
		bool flag = 0;
		for (h = 1; h <= 3500; h++) 
		{
			for (n = 1; n <= 3500; n++)
			{
				t1 = N*h*n;
				t2 = 4 * h*n - n*N - h*N;
				if (t1 > 0 && t2 > 0 && t1%t2 == 0)
				{
					printf("%lld %lld %lld\n", h, n, t1 / t2);
					flag = 1;
					break;
				}
			}
			if (flag)
				break;
		}
	}
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    int p[n + 1];
    rep(i, n) cin >> p[i];
    p[n] = 0;

    int ans = 0;
    rep(i, n) {
        if (p[i] == i + 1) {
            if (p[i + 1] == i + 2) i++;
            ans++;
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::setprecision(15);}}fIO;
template<typename T> using V = std::vector<T>;
template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; }
/*-*/

int main() {
	int x;
	std::cin >> x;
	print(x^1);
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <string>
#include <set>
using namespace std;

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

    vector<string> words(n);
    for (auto& i : words) {
        cin >> i;
    }

    set<string> memo;
    bool isValid = true;
    memo.insert(words.back());
    for (size_t i=0; i < words.size()-1; i++) {
        const auto& word = words[i];
        if (memo.find(word) != memo.end()) {
            isValid = false;
            break;
        }
        memo.insert(word);
        if (words[i].back() != words[i + 1].front()) {
            isValid = false;
            break;
        }
    }
    cout << (isValid ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,i,j,k,count=0,x;
    scanf("%d",&a);
    for(i=1;i<a+1;i++)
    {
        for(j=1;j<a+1;j++)
        {
            for(k=1;k<a+1;k++)
            {
                x=__gcd(i,j);
                x=__gcd(x,k);
                count=count+x;
            }
        }
    }
    printf("%d",count);
}



Measured memory_bytes: 3840
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int S = sc.nextInt();
		int h = S / 3600;
		int m = (S % 3600)/60;
		int s = S % 60;

		System.out.println(h + ":" + m + ":" + s);
	}

}



Measured memory_bytes: 26340
n = int(input())
s = []
t = []
for i in range(n):
    s1,t1 = map(str, input().split())
    t1 = int(t1)
    s.append(s1)
    t.append(t1)
x = str(input())
flag = 0
ans = 0
for i in range(n):

    if flag:
        ans += t[i]

    if s[i]==x:
        flag = 1
print(ans)
    


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int a[N];
    rep(i, N) cin >> a[i];

    int max = abs(a[0]);
    int index = 0;
    rep(i, N-1) {
        if (max < abs(a[i+1])) {
            max = abs(a[i+1]);
            index = i+1;
        }
    }
    cout << N*2-1 << endl;
    rep(i, N) cout << index+1 << " " << i+1 << endl;
    if(a[index] < 0) {
        for(int i = N; i > 1; i--) {
            cout << i << " " << i-1 << endl;
        }
    } else {
        rep(i, N-1) {
            cout << i+1 << " " << i+2 << endl;
        }        
    }



    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <set>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define sz(x) int(x.size())

typedef long long ll;

using namespace std;

static const int MAX = 100001;

/******* c++14 don't include *******/

template<typename T>
T gcd(T a, T b){if( b == 0)return a; return gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){return a*b/gcd(a,b); }

/*******                      *******/

int main(int argc, const char * argv[]) {
    // input from txt
    
    /////////
    //write//
    /////////
    
    
    pair<int, int> p = make_pair(0, 0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    rep(i, n){
        int c = s[i];
        if('A' <= c && c <= 'M'){
            p.second++;
        }
        else if('N' <= c&& c <='Z'){
            p.second--;
        }
        else if('a' <= c&& c <= 'm'){
            p.first++;
        }
        else p.first--;
    }
    
    int res_n = 0;
    string res;
    while(p.first!=0 || p.second != 0){
        res_n++;
        if(p.first>0){
            p.first--;
            res+='a';
        }
        else if(p.first<0){
            p.first++;
            res+='n';
        }
        else if(p.second>0){
            p.second--;
            res+='A';
        }
        else{
            p.second++;
            res+='N';
        }
    }
    
    cout << res_n << endl;
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 3340
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

ll d1[300100],d2[300100];

ll mult(ll n,ll m){//n^m%modを求める
    if(m==1){
        return n%mod;
    }else if(m%2==0){//オーバーフロー防止のためにn^(m/2)*n^(m/2)を考える
        ll t=mult(n,m/2);
        return (t*t)%mod;
    }else{//奇数の時はn^(m-1)*nを考える
        ll t=mult(n,m-1);
        return (t*n)%mod;
    }
}

void make_table(ll N){
	for(ll i=0;i<=N;i++){
		if(i==0){
			d1[i]=1;
			d2[i]=1;
		}else{
			d1[i]=(i*d1[i-1])%mod;
			d2[i]=mult(d1[i],mod-2);
		}
	}
}

template <class T>
T comb_mod_2(T n,T k){
    return (((d1[n]*d2[n-k])%mod)*d2[k])%mod;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    make_table(200000);
    ll n,a,b,c;
    cin>>n>>a>>b>>c;
    ll ans=0;
    ll x=mult(a+b,mod-2);
    rep(i,n){
      ll cnt,cnt1=1,cnt2=1;
      cnt1*=mult(a,n);
      cnt1*=mult(x,n);
      cnt1%=mod;
      if(i!=0){
        cnt1*=mult(b,i);
        cnt1%=mod;
        cnt1*=mult(x,i);
        cnt1%=mod;
      }
      cnt2*=mult(b,n);
      cnt2*=mult(x,n);
      cnt2%=mod;
      if(i!=0){
        cnt2*=mult(a,i);
        cnt2%=mod;
        cnt2*=mult(x,i);
        cnt2%=mod;
      }
      cnt=(cnt1+cnt2)%mod;
      cnt*=comb_mod_2(n+i-1,n-1);
      cnt%=mod;
      cnt*=(n+i);
      cnt%=mod;
      ans+=cnt;
      ans%=mod;
    }
    ans*=(100*x)%mod;
    ans%=mod;
    cout<<ans<<endl;
}

Measured memory_bytes: 3840
using System;
using System.Linq;
using System.Collections.Generic;

public class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        List<String> shiritori = new List<string>();
        shiritori.Add(Console.ReadLine());
        string last = shiritori[0].Substring(shiritori[0].Length - 1, 1);
        string tmp;
        for (int i = 0; i < n - 1; i++)
        {
            tmp = Console.ReadLine();
            if (shiritori.Contains(tmp))
            {
                Console.WriteLine("No");
                return;
            }

            if (last.Equals(tmp.Substring(0, 1)))
            {
                shiritori.Add(tmp);
                last = tmp.Substring(tmp.Length - 1, 1);
            }
            else
            {
                Console.WriteLine("No");
                return;
            }
        }
        Console.WriteLine("Yes");
    }
}

Measured memory_bytes: 13148
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
c = LS2()

# 最終形は、R…RW…W

w = [0]*N  # i番目までにある'W'の個数
r = [0]*N  # i番目までにある'R'の個数
for i in range(N):
    if i == 0:
        if c[i] == 'W':
            w[i] = 1
        else:
            r[i] = 1
    else:
        if c[i] == 'W':
            w[i] = w[i-1]+1
            r[i] = r[i-1]
        else:
            w[i] = w[i-1]
            r[i] = r[i-1]+1

b = r[-1]  # 'R'の個数

if b == 0:
    print(0)
    exit()

print(min(max(w[i],b-r[i]) for i in range(N)))  # 境界がi番目


Measured memory_bytes: 86156
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int d;
  cin>>d;

  vector<ll> p(26);
  rep(i,26) {
    cin>>p[i];
  }


  vector<vector<ll>> q(d,vector<ll>(26));
  rep(i,d) {
    rep(j,26) {
      cin>>q[i][j];
    }
  }

  ll pre=0;
  vector<int> r(26,0);
  rep(i,d-5){
    ll ans=-INF;
    ll memo;
    rep(j,26){
      ll sum=pre;
      auto last=r;
      sum+=q[i][j];
      last[j]=i+1;
      rep(k,26){
        sum-=5*p[k]*(i+1-last[k]);
      }
      if(sum>ans) {
        memo=j;
        chmax(ans,sum);
      }
    }
    cout << memo+1 << endl;
    pre=ans;
    r[memo]=i+1;
  }

  ll answer=-INF;
  ll A,B,C,D,E;
  vector<int> zen(5);
  rep(i,26){
    rep(j,26){
      rep(k,26){
        rep(l,26){
          rep(m,26){
            zen[0]=i;
            zen[1]=j;
            zen[2]=k;
            zen[3]=l;
            zen[4]=m;

            ll sum=0;
            auto last=r;
            rep(n,5){
              sum+=q[d-5+n][zen[n]];
              last[zen[n]]=d-5+n+1;
              rep(o,26){
                sum-=p[o]*(d-5+n+1-last[o]);
              }
            }

            if(sum>answer) {
              A=zen[0];
              B=zen[1];
              C=zen[2];
              D=zen[3];
              E=zen[4];
            }
            chmax(answer,sum);

          }
        }
      }
    }
  }

  cout << A+1 << endl;
  cout << B+1 << endl;
  cout << C+1 << endl;
  cout << D+1 << endl;
  cout << E+1 << endl;
  
}

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

def keta(n):
    s=0
    while(n>0):
        s+=n%10
        n=n//10
    return s

ans=0
for i in range(a,n+1):
    if(a<=keta(i)&keta(i)<=b):
        ans+=i

print(ans)

Measured memory_bytes: 40048
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#include <time.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
 
using namespace std;



int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    int i;
    int cnt=0;
    for(i=0; i<n; i++) {
        int tmp;
        scanf("%d", &tmp);
        if(tmp%2) cnt++;
    }
    if(cnt%2) {
        printf("NO\n");
    }
    else {
        printf("YES\n");
    }

    return 0;
}


Measured memory_bytes: 128
#coding:utf-8
#1_9_A
size = int(input())
heap = list(map(int, input().split()))

for i in range(size):
    print("node {}: key = {}, ".format(i+1, heap[i]), end="")
    if i != 0:
        print("parent key = {}, ".format(heap[(i+1)//2 - 1]), end="")
    if (i+1)*2 <= size:
        print("left key = {}, ".format(heap[(i+1)*2 - 1]), end="")
    if (i+1)*2 + 1 <= size:
        print("right key = {}, ".format(heap[(i+1)*2]), end="")
    print()

Measured memory_bytes: 7684
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<=0&&b>=0)printf("Zero");
	else if(a>0)printf("Positive");
	else if(a<0&&((min(b,-1)-a+1)%2)==0)printf("Positive");
	else printf("Negative");
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll h,w;
char s[1010][1010];
ll ans[1010][1010];
ll que[10000010];
ll quecnt;
ll d4[]={0,1,0,-1,0};
int main(){
	scanf("%lld%lld",&h,&w);
	rep(i,0,h)scanf(" %s",s+i);
	rep(i,0,h)rep(j,0,w)if(s[i][j]=='#'){
		que[quecnt++]=i*w+j;
		ans[i][j]=1;
	}
	for(int id=0;id<quecnt;id++){
		int i=que[id]/w;
		int j=que[id]%w;
		rep(k,0,4){
			int ii=i+d4[k];
			int jj=j+d4[k+1];
			if(0<=ii&&ii<h&&0<=jj&&jj<w){
				if(ans[ii][jj]==0){
					que[quecnt++]=ii*w+jj;
					ans[ii][jj]=ans[i][j]+1;
				}
			}
		}
	}
	ll a=0;
	rep(i,0,h)rep(j,0,w)a=max(a,ans[i][j]);
	printf("%lld",a-1);
}

Measured memory_bytes: 18560
#include <iostream>

using namespace std;
const int N = 1e6+10;
int q[N];
int main(){
	int n;
	cin >> n;
	int cnt=0;
	for (int i=1;i<=n;i++){
		scanf("%d",&q[i]);
		if (i%2==1 && q[i]%2==1)
			cnt++;
	}
	cout << cnt << endl;



	return 0;
}

Measured memory_bytes: 3760
n = int(input())
h = list(map(int,input().split()))
INF = 10**4 * 10**5
dp = [INF]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
    dp[i] = min(dp[i],dp[i-1]+abs(h[i-1]-h[i]))
    dp[i] = min(dp[i],dp[i-2]+abs(h[i-2]-h[i]))
print(dp[-1])

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

int main() {
	int a, b;
	double d, r, f;
	cin >> a >> b;
	d = a / b;
	r = a % b;
	f = 1.0 * a / b;
	printf("%.0lf ", d);
	printf("%.0lf ", r);	
	printf("%.5lf\n", f);
}


Measured memory_bytes: 3188
#include <stdio.h>
#include <algorithm>

const int N = 2e5 + 10;

char s[N];

int main() {
  int n, a, b, c, d;
  scanf("%d %d %d %d %d %s", &n, &a, &b, &c, &d, s);
  int t = 5;
  while (t--) {
    s[n] = '#';
    n++;
  }
  s[n] = '\0';
  a--; b--; c--; d--;
  s[a] = 'A';
  s[b] = 'B';
  if (c < d) {
    std::swap(c, d);
    std::swap(a, b);
  }
  while (a != c) {
    if (a + 1 == c || a + 2 == c) {
      s[a] = '.';
      s[c] = '#';
      break;
    }
    if (s[a + 1] == '#' && s[a + 2] == '#') {
      puts("No");
      return 0;
    }
    if (s[a + 1] == '.') {
      s[a] = '.';
      s[a + 1] = 'A';
      a += 1;
      continue;
    }
    if (s[a + 2] == '.') {
      s[a] = '.';
      s[a + 2] = 'A';
      a += 2;
      continue;
    }
    if (s[a + 1] == 'B') {
      if (b == d) {
        puts("No");
        return 0;
      }
      if (s[a + 3] == '.') {
        s[a + 1] = '.';
        s[a + 3] = 'B';
        b += 2;
      } else {
        puts("No");
        return 0;
      }
    }
    if (s[a + 2] == 'B') {
      if (b == d) {
        puts("No");
        return 0;
      }
      if (s[a + 3] =='.' || s[a + 4] == '.') {
        if (s[a + 3] == '.') {
          s[a + 2] = '.';
          s[a + 3] = 'B';
          b++;
        } else {
          s[a + 2] = '.';
          s[a + 4] = 'B';
          b += 2;
        }
      } else {
        puts("No");
        return 0;
      }
    }
  }
  while (b != d) {
    if (b + 1 == d || b + 2 == d) {
      s[b] = '.';
      s[d] = '#';
      break;
    }
    if (s[b + 1] == '#' && s[b + 2] == '#') {
      puts("No");
      return 0;
    }
    if (s[b + 1] == '.') {
      b++;
      continue;
    }
    if (s[b + 2] == '.') {
      b += 2;
      continue;
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 384