akhauriyash/Code-Regression huggingface dataset:
# include <iostream>
# include <cstdlib>
using namespace std;


int main () {
    bool ans = true;
    int c[3][3];
    for ( int i = 0; i < 3; i++){
        for ( int j = 0; j < 3; j++) {
            cin >> c[i][j];
        }
    }
    
    
    for ( int i = 1; i < 3; i++){
        int da = c[i][0] - c[i-1][0];
        for ( int j = 1; j < 3; j++){
            if ( da != c[i][j] - c[i-1][j] ){
                ans = false;
            }
        }
    }
    
    for ( int j = 1; j < 3; j++){
        int db = c[0][j] - c[0][j-1];
        for ( int i = 1; i < 3; i++){
            if ( db != c[i][j] - c[i][j-1] ){
                ans = false;
            }
        }
    }
    
    if ( ans == true ) {
        cout << "Yes";
    } else {
        cout << "No";
    }
}

Measured memory_bytes: 256
N = int(input()) - 1
keta = 1
cumsum = 0
oldcumsum = 0
while True:
  cumsum += 26 ** keta
  if cumsum > N:
    break
  else:
    oldcumsum = cumsum
  keta += 1

N -= oldcumsum
#N -= 1
#print(keta)

name = ''
for k in range(1,keta+1):
  ch_n = N // (26 ** (keta - k))
  ch = chr(ord('a') + ch_n)
  name += ch
  N -= ch_n * (26 ** (keta - k))
print(name)

Measured memory_bytes: 9048
#include<stdio.h>
int main(){
    int a, b, c;
    int d;
    scanf("%d %d %d", &a, &b, &c);
    if(a>b){
        d=a;
        a=b;
        b=d;
    }
    if(b>c){
    d=b;
    b=c;
    c=d;
    }
    if(a>b){
    d=a;
    a=b;
    b=d;
    }
    printf("%d %d %d\n", a, b, c);
    return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <cstring>
#define int long long
using namespace std;
int *val;
int *wt;

int knapsck(int n, int w){
    int dp[2][w+1];
    for (int i=0; i<=n; i++){
        for (int j = 0; j <= w; j++){
            // Base Case ...
            if(i==0 || j == 0){
                dp[i%2][j] = 0ll; 
                continue;
            }
            if(wt[i-1]>j)
                dp[i%2][j] = dp[(i-1+2)%2][j];
            else{
                dp[i%2][j] = max( 
                                dp[ (i-1+2)%2 ][j] , 
                                val[i-1] + dp[ (i-1+2)%2 ][ j - wt[i-1] ] );
            }
        }
    }
    return dp[n%2][w]; 
}

signed main() {
    signed n, w;
    scanf("%d %d",&n,&w);
    val = new int[n];
    wt = new int[n];
    
    for (int i=0;i<n; i++)
    scanf("%lld %lld", wt+i, val+i);
    printf("%lld",knapsck(n, w));
     
    return 0;
}

Measured memory_bytes: 5260
import collections

n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))

d_c = collections.Counter(d)
t_c = collections.Counter(t)

ans = 'YES'
for e in t_c.items():
    diff, cnt = e[0], e[1]
    if d_c[diff]:
        if d_c[diff] < cnt:
            ans = 'NO'
            break
    else:
        ans = 'NO'
        break
    
print(ans)

Measured memory_bytes: 57056
n,m = map(int,input().split())
dp = [0 for i in range(n+2)]
for i in range(m):
    a,b = map(int,input().split())
    if a > b:a,b = b,a
    dp[a] += 1
    dp[b+1] -= 1
ios = [0 for i in range(n+3)]
for i in range(len(dp)):
    ios[i+1] = ios[i] + dp[i]
ans = 0
for i in range(len(ios)):
    if ios[i] == m:
        ans += 1
print(ans)


Measured memory_bytes: 51360
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string.h>
typedef long long ll;
#define MAX(x, y)	(((x) > (y))? (x) : (y))
#define MIN(x, y)	(((x) < (y))? (x) : (y))
#define ABS(x)		(((x) < 0)? (-1*(x)) : (x))
#define REPI(x,y)	for (int i=(x);i<(y);i++)
#define REPJ(x,y)	for (int j=(x);j<(y);j++)
#define MEMCLR(X)	memset((X),0,sizeof((X)))

using namespace std;
typedef pair<int, int> Point;
typedef vector<vector<Point>> Graph;

int i,j,a,b,c,d,N;
char s[10];

int main() {
	cin >> N;
	
	a = N/1000;
	b = (N%1000)/100;
	c = (N%100)/10;
	d = N%10;
	
	s[0] = '0' + a;
	s[2] = '0' + b;
	s[4] = '0' + c;
	s[6] = '0' + d;
	s[7] = '=';
	s[8] = '7';
	s[9] = 0;
	
	if ((a+b+c+d)==7) {
		s[1] = '+';
		s[3] = '+';
		s[5] = '+';
	} else if ((a+b+c-d)==7) {
		s[1] = '+';
		s[3] = '+';
		s[5] = '-';
	}  else if ((a+b-c+d)==7) {
		s[1] = '+';
		s[3] = '-';
		s[5] = '+';
	}  else if ((a+b-c-d)==7) {
		s[1] = '+';
		s[3] = '-';
		s[5] = '-';
	}  else if ((a-b+c+d)==7) {
		s[1] = '-';
		s[3] = '+';
		s[5] = '+';
	}  else if ((a-b+c-d)==7) {
		s[1] = '-';
		s[3] = '+';
		s[5] = '-';
	}  else if ((a-b-c+d)==7) {
		s[1] = '-';
		s[3] = '-';
		s[5] = '+';
	}  else if ((a-b-c-d)==7) {
		s[1] = '-';
		s[3] = '-';
		s[5] = '-';
	}
	cout << s;
	
	return 0;
}


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

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

using namespace std;
using lint=long long;

const long long INF=1LL<<61;

lint a[6],d;
map<lint,lint> memo;

lint dfs(lint n){
	if(n==1) return d;

	if(memo.count(n)>0) return memo[n];

	lint res=INF;
	if(n<res/d) res=d*n;
	for(int x:{2,3,5}){
		lint next=n/x;
		if(1<=next && next<n) res=min(res,a[x]+d*(n-next*x)+dfs(next));
		next=(n+x-1)/x;
		if(1<=next && next<n) res=min(res,a[x]+d*(next*x-n)+dfs(next));
	}
	return memo[n]=res;
}

void solve(){
	lint n; cin>>n>>a[2]>>a[3]>>a[5]>>d;
	memo.clear();
	cout<<dfs(n)<<'\n';
}

int main(){
	int q; scanf("%d",&q); rep(_,q) solve();
	return 0;
}


Measured memory_bytes: 4512
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;

int main(){
    ll k; cin >> k;
    vector<ll> a(50);
    for(int i=0;i<50;i++){
        a[i]=i+k/50;
    }
    for(int i=0;i<50;i++){
        if(i<k%50){
            a[i]+=51-k%50;
        }
        else{
            a[i]-=k%50;
        }
    }
    cout << 50 << endl;
    for(int i=0;i<50;i++){
        cout << a[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 256
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r;
    cin >> r;
    cout << r * r * 3 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	string a,b;
	int num=0;
	cin>>a>>b;
	for(int i=0;i<3;i++){
		if(a[i]==b[i])num++;
	}
	cout<<num<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 1000000

int prime[MAX + 5] = {0};
int ans[MAX + 5] = {0};
int s[MAX + 5] = {0};
int init() {
    ans[0] = ans[1] = 1;
    for (int i = 2; i <= MAX; i++) {
        if (!ans[i]) {
            prime[++prime[0]] = i;
            s[i] = s[i - 1] + 1;
        } else {
            s[i] = s[i - 1];
        }
        for (int j = 1; j <= MAX; j++) {
            if (i * prime[j] > MAX) break;
            ans[i * prime[j]] = 1;
            if (i % prime[j] == 0) {
                break;
            }
        }
    }
    return 0;
}

int main() {
    int n;
    init();
    while (~scanf("%d", &n)) {
        printf("%d\n", s[n]);
    }
    return 0;
}



Measured memory_bytes: 9816
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - When I hit my pocket...
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

int main() {
  int k, a, b;
  scanf("%d%d%d", &k, &a, &b);

  if (a + 2 >= b || k + 1 <= a) printf("%d\n", k + 1);
  else {
    int c = k - (a - 1);
    printf("%lld\n", a + (ll)(b - a) * (c / 2) + (c & 1));
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using Graph = vector<vector<int>>;


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll modinv(ll a, ll m){
    ll b = m, u = 1, v = 0;
    while(b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if(u < 0) u += m;
    cout << u << endl;
    return u;
}

ll paty_counter(ll level, ll x){
    ll size = pow(2, level+2) - 3;
    ll pmi = pow(2, level) - 1;
    if(x == 0){
        return 0;
    }else if(level == 0){    
        return 1;
    }else{
        if(x <= (size - 1)/2){
            return paty_counter(level-1, x-1);
        }else{
            return pmi + 1 + paty_counter(level-1, x - pow(2, level+1) + 3 - 2);
        }
    }

}
 
int main() {
    ll n,k,q;
    cin >> n >> k >> q;
    vector<ll> a(q);
    REP(i, q){
        cin >> a[i];
    }

    vector<ll> point(n, k-q);
    REP(i, q){
        point[a[i]-1] += 1;
    }
    REP(i, n){
        if(point[i] > 0){
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}



Measured memory_bytes: 4788
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
ll mod=1E9+7;
 
#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)
 
ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
ld id(){ ld x; cin >> x; return x; }
void oi(ll x){ cout << x; }
void od(ld x){ cout << fixed << setprecision(10) << x; }
void os(string x){ cout << x; }
void oe(){ cout << endl; }
void oie(ll x){ oi(x); oe(); }
void ode(ld x){ od(x); oe(); }
void ose(string x){ os(x); oe(); }

bool memo[1123456];

int main(){
    ll N=ii();
    map<ll,ll> m;
    REP(i,0,N){
        m[ii()]++;
    }
    ll ret=0;
    for(auto [a,b] : m){
        if(memo[a]){
            continue;
        }
        if(b==1){
            ret++;
        }
        for(ll i = a; i < 1123456; i += a){
            memo[i]=true;
        }
    }
    oie(ret);

    return 0;
}

Measured memory_bytes: 17196
function Main(input) {
  	input = input.split("\n");
  	i = 0;
  	x = [];
	counter = 0;
  	N =1000000;
    D = 0;
   for(i=0;i<=N;i++){
      	num = input[i].split(/\s+/);
      	littleX = [];
		if(i==0){
          N = num[0];
          D = num[1];
        }else{
        	for(j=0;j<D;j++){
	          littleX.push(num[j]);
        	}
            x.push(littleX);
        }

     	//console.log("i= "+i+"N:" + N + ",D:"+D + ",littleX:" + littleX);
    }

  	for(i=0;i<N;i++){
      	for(k=i+1;k<N;k++){
	      	//console.log("check "+i+"to"+k);
          	//console.log(x[i]);
          	//console.log(x[k]);
          	sum = 0;
          	for(j=0;j<D;j++){
            	sum+= Math.abs((x[i][j] - x[k][j])*(x[i][j] - x[k][j]));
            }
          	//console.log(sum);
          	//console.log(Math.sqrt(sum));
          	//console.log(Number.isInteger(Math.sqrt(sum)));
          	if(Number.isInteger(Math.sqrt(sum)) === true){
            	counter++;
            }
        }
    }
  	console.log(counter);
  	
}Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
n=int(input())
l=list(map(int,input().split()))
cnt=[0 for i in range(n+1)]
mod=10**9+7
fact=[1]*(n+2)
inv=[1]*(n+2)
for i in range(2,n+2):
    fact[i]=i*fact[i-1]%mod
inv[-1]=pow(fact[-1],mod-2,mod)
for i in range(n+1,1,-1):
    inv[i-1]=inv[i]*i%mod
def comb(x,y):return fact[x]*inv[y]%mod*inv[x-y]%mod if x>=y>=0 else 0
for i in range(n+1):
    if cnt[l[i]]:
        r=cnt[l[i]]+n-i;break
    cnt[l[i]]+=i
else:r=n-cnt[l[0]]
for i in range(1,n+2):
    print((comb(n+1,i)-comb(r,i-1))%mod)

Measured memory_bytes: 20452
#include <iostream>
#include <math.h>
#include <string>
using namespace std;

int main()
{
  string s;
  cin >> s;
  if (s.at(0) == 'A' && s.at(1) == 'A' && s.at(2) == 'A')
  {
    cout << "No" << endl;
    return 0;
  }
  if (s.at(0) == 'B' && s.at(1) == 'B' && s.at(2) == 'B')
  {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
public class Main {


  private static void solve() {
    int n = ni();
    int s = 0;
    int m = n;
    while (n > 0) {
      s += n % 10;
      n /= 10;
    }
    System.out.println(m % s == 0 ? "Yes" : "No");
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
string alp="abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    vector<int> t(N),v(N),T(N+1);
    rep(i,N){
        cin >> t[i];
    }
    rep(i,N){
        cin >> v[i];
    }
    T[0]=0;
    rep(i,N){
        T[i+1]=T[i]+t[i];
    }
    rep(i,N){
        T[i+1]*=2;
    }
    vector<double> ms(T[N]+1,100000);
    rep(i,N){
        for (int j=T[i];j<=T[i+1];j++){
            ms[j]=min(ms[j],(double)v[i]);
        }
    }
    ms[T[N]]=0;
    for (int i=T[N]-1;i>=0;i--){
        ms[i]=min(ms[i+1]+0.5,ms[i]);
    }
    ms[0]=0;
    for (int i=1;i<=T[N];i++){
        ms[i]=min(ms[i-1]+0.5,ms[i]);
    }
    double ans=0;
    for (int i=1;i<T[N];i++){
        ans+=ms[i];
    }
    ans/=2.0;
    cout << fixed << setprecision(6);
    cout << ans << endl;
}

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

const int combination_max=500000+1000;
const int combination_modulo=1000000007;
vector<int64_t> factorials(combination_max);
vector<int64_t> factorials_inv(combination_max);
vector<int64_t> inverse(combination_max);
int combination_mod(int n, int k);
int permutation_mod(int n, int k);
int prepare_combination_mod();

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

	prepare_combination_mod();
	int64_t c=0;
	for (int i=0;i<=n;++i)
	{
		int64_t cc=(int64_t)permutation_mod(m-i,n-i)*combination_mod(n,i);
		// fprintf(stderr,"%d_C_%d: %d\n",n,i,combination_mod(n,i));
		// fprintf(stderr,"%d_P_%d: %d\n",m-i,n-i,permutation_mod(m-i,n-i));
		cc%=combination_modulo;
		// fprintf(stderr,"\tcc: %lld\n",cc);
		if ((i&1)==0)
		{
			c+=cc;
			c%=combination_modulo;
		}
		else
		{
			c-=cc;
			if (c<0)
			{
				// fprintf(stderr,"\tunderflow happened: %d\n",c);
				c+=combination_modulo;
			}
		}
		// fprintf(stderr,"total(%d): %lld\n",i,c);
	}
	c*=permutation_mod(m,n);
	// fprintf(stderr,"%d_P_%d: %d\n",m,n,permutation_mod(m,n));
	c%=combination_modulo;
	cout << c << endl;
}




int prepare_combination_mod()
{
	factorials[0]=1;
	factorials[1]=1;
	factorials_inv[0]=1;
	factorials_inv[1]=1;
	inverse[1]=1;
	for (int i=2;i<combination_max;++i)
	{
		factorials[i]=factorials[i-1]*i%combination_modulo;
		inverse[i]=combination_modulo - inverse[combination_modulo%i]*(combination_modulo/i)%combination_modulo;
		factorials_inv[i]=factorials_inv[i-1]*inverse[i]%combination_modulo;
	}
	return 0;
}

int combination_mod(int n, int k)
{
	return factorials[n]*(factorials_inv[k]*factorials_inv[n-k]%combination_modulo)%combination_modulo;
}

int permutation_mod(int n, int k)
{
	return (factorials[n]*factorials_inv[n-k])%combination_modulo;
}




Measured memory_bytes: 15036
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;

int main(){
  int a[4];
  rep(i,4) scanf("%d",&a[i]);

  int res=0;
  rep(i,a[0]){
    if(i>=a[1]) res+=a[3];
    else res+=a[2];
  }
  printf("%d\n",res);


  return 0;

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
 
using namespace std;
  
int main() {
	long long pw[11]; pw[0] = 1;
	for (int i = 1; i <= 10; ++i) pw[i] = 1ll * pw[i - 1] * 10;
	int num = 0;
	for (int i = 1 ; i <= 10; ++i)   {
		cout << "? " << pw[i] << "\n";
		cout.flush();
		char c; cin >> c;
		if(c == 'N') {
			num = i;
			break;
		}
	}
	
	if(num == 0) {
		for(int i = 1; i <= 10; ++i) {
			cout << "? " << pw[i] - 1 << "\n";
			cout.flush();
			char c; cin >> c;
			if(c == 'Y') {
				cout << "! " << pw[i - 1] << "\n";
				cout.flush(); exit(0);
			}
		}
	}
	
	long long l = pw[num - 1], r = pw[num] - 1;
	
	while(l < r)   {
		long long mid = (l + r) >> 1;
		cout << "? " << mid * 10 << "\n";
		cout.flush();
		char c; cin >> c;
		if(c == 'Y') r = mid;
		else l = mid + 1;
	}
	cout << "! " << l << "\n";
	cout.flush();
}

Measured memory_bytes: 596
#include <iostream>

using namespace std;
bool st[200];
int main()
{
    int x,n,t;
    cin>>x>>n;
    int ans=x,root=0;
    for(int i=1;i<=n;i++){
        cin>>t;st[t]=true;
    }
    for(int i=1;i<=199;++i){
        if(st[i])continue;
        if(ans>abs(i-x)){
            ans=abs(i-x);
            root=i;
        }
    }
    cout<<root<<endl;
}

Measured memory_bytes: 3628
iipt=lambda:int(input())
miipt=lambda:map(int,input().split(" "))
o=[0]*112345
e=[0]*112345
n=iipt()
A=miipt()
for i,a in enumerate(A):
    if i%2:
        o[a]+=1
    else:
        e[a]+=1
om=-1,0
om2=-1,0
em=-1,0
em2=-1,0
for i,v in enumerate(o):
    if v>=om[1]:
        om2=om
        om=i,v
    elif v>=om2[1]:
        om2=i,v
for i,v in enumerate(e):
    if v>=em[1]:
        em2=em
        em=i,v
    elif v>=em2[1]:
        em2=i,v
if om[0]==em[0]:
    print(min(n-om2[1]-em[1],n-om[1]-em2[1]))
else:
    print(n-om[1]-em[1])


Measured memory_bytes: 12408
# coding: utf-8
# Your code here!

h,w= list(map(int,input().split()))	
B = []
for _ in range(h):
    B.append([int(i) for i in input().split()])

def hh(j):
    return j//w

def ww(j):
    if j//w%2==0:
        return j%w
    else:
        return w-1-j%w

ans = []
for i in range(h*w-1):
#    print(hh(i),ww(i))
    if B[hh(i)][ww(i)]%2 ==1:
        B[hh(i)][ww(i)]-=1
        B[hh(i+1)][ww(i+1)]+=1
        ans.append([hh(i)+1,ww(i)+1,hh(i+1)+1,ww(i+1)+1])

print(len(ans))
for a in ans:
#    for i in a:
#        print(i,end=" ")
#    print()
    print(a[0],a[1],a[2],a[3])

#print(B)






Measured memory_bytes: 30112
import java.util.*;
public class Main {
    static long MOD = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long w = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        List<Long> factorial = new ArrayList<>();
        factorial.add(1L);
        List<Long> inverse = new ArrayList<>();
        inverse.add(1L);
        for (int i = 1; i <= h + w - 2; i++) {
            factorial.add(factorial.get(i - 1) * i % MOD);
            inverse.add(pow(factorial.get(i), MOD - 2) % MOD);
        }
        long ans = 0;
        for (int i = (int) b; i < w; i++) {
            long tmp1 = combine(h - a - 1 + i, i, factorial, inverse);
            long tmp2 = combine(a - 1 + w - i - 1, a - 1, factorial, inverse);
            ans += tmp1 * tmp2;
            ans %= MOD;
        }
        System.out.println(ans);
    }

    public static long pow(long x, long n) {
        long ans = 1;
        while (n > 0) {
            if ((n & 1) == 1) {
                ans = ans * x % MOD;
            }
            x = x * x % MOD;
            n >>= 1;
        }
        return ans;
    }

    public static long combine(long n, long k, List<Long> factorial, List<Long> inverse) {
        return factorial.get((int) n) * inverse.get((int) k) % MOD * inverse.get((int) n - (int) k)
            % MOD;
    }
}


Measured memory_bytes: 51284
#include<bits/stdc++.h>
//#include <iostream>
//#include <iomanip>
//#include <vector>
//#include <cmath>
//#include <algorithm>
using namespace std;


#define F first
#define PB push_back
#define MP make_pair

typedef unsigned long long ll;

ll p = pow(10, 9) + 7;





int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s, t;
    cin >> s >> t;

    vector<vector<int> > dp(s.length() + 1, vector<int>(t.length() + 1));
    vector<vector<pair<int, int> > > last(s.length() + 1, vector<pair<int, int > >(t.length() + 1));
    s = '1' + s;
    t = '2' + t;
    for(int i = 1; i <= s.length() - 1; i++)
    {
        for(int j = 1; j <= t.length() - 1; j++)
        {
            if(s[i] == t[j])
            {
                dp[i][j] = dp[i - 1][j - 1] + 1;
                last[i][j].first = i - 1;
                last[i][j].second = j - 1;

            } else{
                if(dp[i - 1][j] > dp[i][j - 1])
                {
                    dp[i][j] = dp[i - 1][j];
                    last[i][j].first = i - 1;
                    last[i][j].second = j;
                } else{
                    dp[i][j] = dp[i][j - 1];
                    last[i][j].first = i;
                    last[i][j].second = j - 1;
                }

            }
        }
    }



    string ans ="";
    int p1 = s.length() - 1;
    int p2 = t.length() - 1;
//
//    for(int i = 0; i < last.size(); i++)
//    {
//        for(int j = 0; j < last[i].size(); j++)
//        {
//            cout << "{" << last[i][j].first << ", " << last[i][j].second << "} ";
//        }
//        cout << endl;
//    }
    while(p1 != 0 && p2 != 0)
    {
//        cout << p1 << " " << p2 << endl;
        if(last[p1][p2].first == p1 - 1 && last[p1][p2].second == p2 - 1)
        {
            ans += s[p1];
        }
        int temp = p1;
        p1 =last[p1][p2].first;
        p2 = last[temp][p2].second;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;

}

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

ll lcm(ll x, ll y){
    if(x == 0 || y == 0)
        return 0;
    return (x * y / __gcd(x, y));
}
 
int main(){
    ll A, B;
    cin >> A >> B;

    cout << lcm(A, B) << endl;

}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n = int(input())
s = input()

num = int(s, 2) # 元の2進数を数字に
opc = s.count('1') # 元の2進数のpopcount

# ±1したpopcountで余りを求めておく
if opc > 1:
    num1 = num % (opc - 1)
else:
    num1 = 0
num0 = num % (opc + 1)

for i in range(n):
    if s[i] == '1':
        if opc == 1:
            print(0)
            continue
        tmp = (num1 - pow(2, n - 1 - i, opc - 1)) % (opc - 1)
    else:
        tmp = (num0 + pow(2, n - 1 - i, opc + 1)) % (opc + 1)

    # binで2進数にしてpopcount求める
    ans = 1
    while tmp > 0:
        tmp %= bin(tmp).count('1')
        ans += 1
    print(ans)


Measured memory_bytes: 9516
#include <bits/stdc++.h>
const int MOD = 1e9 + 7, N = 40, L = 17;
int n, x, y, z, f[ N + 1 ][ 1 << L ];
int main( )
{
 std::ios::sync_with_stdio( false );
 std::cin >> n >> x >> y >> z;
 int mx = ( 1 << ( x + y + z ) ) - 1, ans = 1, haiku = ( ( 1 << ( x + y + z ) ) >> 1 ) | ( ( 1 << ( y + z ) ) >> 1 ) | ( ( 1 << z ) >> 1 );
 f[ 0 ][ 0 ] = 1;
 for( int i = 0; i < n; ++i, ans = ans * 10LL % MOD ) for( int s = 0; s <= mx; ++s )
 {
  if( !f[ i ][ s ] )
   continue;
  for( int j = 1; j <= 10; ++j )
  {
   int trs = ( s << j | ( 1 << j >> 1 ) ) & mx;
   if( ( trs & haiku ) ^ haiku )
    f[ i + 1 ][ trs ] = ( f[ i + 1 ][ trs ] + f[ i ][ s ] ) % MOD;
   }
 }
 int sub = 0;
 for( int i = 0; i <= mx; ++i )
  sub = ( sub + f[ n ][ i ] ) % MOD;
 std::cout << ( ans - sub + MOD ) % MOD;
 return 0;
}

Measured memory_bytes: 22260
<?php

$nx = explode(' ', trim(fgets(STDIN)));
$n = $nx[0];
$x = $nx[1];
$l = explode(' ', trim(fgets(STDIN)));

$b = 0;
$c = 1;
for($i=0; $i<$n; $i++){
  $b += $l[$i];
  if ($b <= $x) {
    $c++;
  } else {
 	break;
  }
}

echo $c;

?>

Measured memory_bytes: 4604
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;

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

  int N;
  cin >> N;
  cout << (N+1)/2 << endl;
}

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 NumberFormatException, IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] tmpArray = br.readLine().split(" ");

		long a = Long.parseLong(tmpArray[0]);
		long b = Long.parseLong(tmpArray[1]);
		long c= Long.parseLong(tmpArray[2]);
		long k = Long.parseLong(tmpArray[3]);

		long result = 0;
		if(k % 2 == 1){
			result = b - a;
		}
		else {
			result = a - b;
		}

		System.out.println(result);
	}

}


Measured memory_bytes: 23124
# solve problem
def solve(n, m, targets, games):
    counter = [0 for i in range(n+1)]

    for i in range(m):
        for j in range(n):
            if games[i][j] == targets[i]:
                counter[j+1] += 1
            else:
                counter[targets[i]] += 1

    return counter


# main function
if __name__ == '__main__':
    n = int(input())
    m = int(input())
    tmp_targets = input().split()

    targets = []
    for i in range(m):
        targets.append(int(tmp_targets[i]))

    games = [[0 for i in range(n)] for j in range(m)]
    tmp_games = []
    for i in range(m):
        tmp_games = input().split()
        for j in range(n):
            games[i][j] = int(tmp_games[j])

    results = solve(n, m, targets, games)
    for i in range(1, n+1, 1):
        print(results[i])

Measured memory_bytes: 7748
s = list(str(input()))
k = int(input())
for i in range(len(s)):
    if s[i] != "a":
        num = 26-(ord(s[i])-ord("a"))
        if k >= num:
            k -= num
            s[i] = "a"
s[-1] = chr(ord("a")+((ord(s[i])-ord("a")+k)%26))
print("".join(s))

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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const lint inv = MOD - 2;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

int main(){
    int n;
    cin >> n;
    vector<int> a(n+2);
    a[0] = 0;
    a[n+1] = 0;
    REP(i, 1, n+1){
        cin >> a[i];
    }
    int ans = 0;
    rep(i, n+1){
        ans += abs(a[i+1] - a[i]);
    }
    REP(i, 1, n+1){
        cout << ans - abs(a[i-1] - a[i]) - abs(a[i] - a[i+1]) + abs(a[i+1] - a[i-1]) << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

	ll k;cin>>k;
	vector<ll> a(k),mi(k+1),ma(k+1);
	mi[k]=(2);ma[k]=(2);
	for(int i=0;i<k;i++) cin>>a[i];
	for(int i=k-1;i>=0;i--){
		if(ma[i+1]<a[i]){
			cout<<-1<<endl;
			//cout<<i<<" "<<a[i]<<" "<<mi[i+1]<<" "<<ma[i+1]<<endl;
			return 0;
		} 
		else{
			ma[i] = (ma[i+1]/a[i])*a[i]+a[i]-1;
			mi[i] = ((mi[i+1]-1)/a[i]+1)*a[i];
			if(ma[i]<mi[i]){
				cout<<-1<<endl;
				return 0;
			}
		}
	}
	cout<<mi[0]<<" "<<ma[0]<<endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
    int limit = 2*(1000000);
    char str1[limit];
    cin >> str1;
    char str2[limit];
    cin >> str2;
    int answer = 0;
    int size_ = strlen(str1);
    for (int i = 0; i < size_; i++)
    {
        if (str1[i] != str2[i])
        {
            answer++;
        }
        else
       {
            continue;
       }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 4020
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 10000000007; //10^9+7

int main(){
  string s;
  cin>>s;
  int ans=0;
  REP(i,s.size())if(s[i]=='1')ans++;
  print(ans);
}

Measured memory_bytes: 256
import std.stdio;
import std.string, std.conv, std.array, std.algorithm;
import std.uni, std.math, std.container, std.typecons;
import core.bitop, std.datetime, std.range;

void main(){
    auto rd = readln.split.to!(int[]);
    auto n = rd[0], q = rd[1];
    auto ds = new int[][](n, 1);
    auto n2s = iota(n).array;

    foreach(i ; 0 .. n){
        ds[i][0] = i;
    }

    foreach(lp ; 0 .. q){
        rd = readln.split.to!(int[]);
        auto c = rd[0], x = rd[1], y = rd[2];

        if(c == 0){
            merge(ds, n2s, x, y);
        } else{
            writeln(n2s[x] == n2s[y] ? 1 : 0);
        }
    }

}

void merge(int[][] ds, int[] n2s, int x, int y){
    auto u = n2s[x];
    auto v = n2s[y];

    if(u == v) return;

    if(ds[u].length > ds[v].length) swap(u, v);

    ds[v] ~= ds[u];
    foreach(z ; ds[u]){
        n2s[z] = v;
    }
    delete ds[u];
}

Measured memory_bytes: 11076
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int a[26];
int main()
{	
	
	int a, b; cin >> a >> b;
	if (a == b || abs(a - b) == 1)
		cout << "Yay!";
	else
		cout << ":(";
}

Measured memory_bytes: 3100
N = int(input())
pt, px, py = 0, 0, 0
for i in range(N):
    t, x, y = map(int, input().split())
    a = abs(x - px) + abs(y - py)
    b = t - pt
    if b < a or (a - b) % 2 != 0:
        print("No")
        exit()
    pt, px, py = t, x, y
print("Yes")

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

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

using namespace std;
using ll=long long;
const ll INF = 100000000;

int main() {
    int h, w, k;
    cin >> h >> w >> k;

    char c[6][6];
    int sum = 0;
    int row_sum[6] = {}, colum_sum[6] = {};
    rep(i, h) {
        rep(j, w) {
            cin >> c[i][j];
            if (c[i][j] == '#') {
                sum++;
                row_sum[i]++;
                colum_sum[j]++;
            }
        }
    }
    int res = 0;
    int cnt;
    for (int i = 0; i < 1 << h; ++i) {
        for (int j = 0; j < 1 << w; ++j) {
            cnt = sum;
            vector<int> q;
            for (int k = 0; k < h; ++k) {
                if ((i >> k & 1) == 1) {
                    cnt -= row_sum[k];
                    q.push_back(k);
                }
            }
            for (int k = 0; k < w; ++k) {
                if ((j >> k & 1) == 1) {
                    cnt -= colum_sum[k];
                    for (int l = 0; l < q.size(); ++l) {
                        if (c[q[l]][k] == '#') {
                            cnt++;
                        }
                    }
                }
            }
            if (cnt == k) {
                res++;
            }
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define maxn 200050
using namespace std;
typedef long long LL;

int n;
int a[maxn];

int ans;

int N;
map<int,int> mp;
vector<int> G[maxn];

int d[maxn];
int cnt[maxn];

void join(int i,int j)
{
    ++d[i],++d[j];
    G[i].push_back(j);
    G[j].push_back(i);
}

void init()
{
    scanf("%d",&n);
    for (int i=0;i<n;++i)
        scanf("%d",&a[i]);
    sort(a,a+n);
    for (int i=0,j=0;i<n;i=j)
    {
        while (j<n&&a[i]==a[j])    ++j;
        cnt[mp[a[i]]=++N]=j-i;
    }
    for (auto p:mp)
        for (int b=0;b<31;++b)
        {
            LL c=(1LL<<b)-p.first;
            if (p.first<=c)   continue;
            if (mp.count(c))
                join(p.second,mp[c]);
        }
}

bool vis[maxn];

queue<int> q;

void solve()
{
    for (int i=1;i<=N;++i)
        if (d[i]==1)
            q.push(i);
    while (!q.empty())
    {
        int i=q.front();    q.pop();
        for (auto j:G[i])
        {
            int c=min(cnt[i],cnt[j]);
            ans+=c;
            cnt[i]-=c;
            cnt[j]-=c;
            if (--d[j]==1)
                q.push(j);
        }
    }
    for (int b=0;b<31;++b)
        if (mp.count(1<<b))
            ans+=cnt[mp[1<<b]]/2;
    printf("%d\n",ans);
}

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

Measured memory_bytes: 22528
from operator import itemgetter
N, H = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=itemgetter(1, 0), reverse=True)
A, B = zip(*AB)
maxa = 0
for i, a in enumerate(A):
    if maxa <= a:
        maxa = a
        argmaxa = i
s = 0
cnt = 0
for i, b in enumerate(B):
    if i != argmaxa:
        if maxa < b:
            s += b
            cnt += 1
            if s >= H:
                print(cnt)
                exit()
s += B[argmaxa]
cnt += 1

if s >= H:
    print(cnt)
else:
    print((H-s-1)//maxa+1+cnt)


Measured memory_bytes: 36068
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

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

        Map<String, Integer> map = new HashMap<>();
        for (String s : w) {
            if (map.containsKey(s)) {
                map.put(s, map.get(s) + 1);
                continue;
            }
            map.put(s, 1);
        }

        for (String key: map.keySet()) {
            if (map.get(key) % 2 == 1) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }

}


Measured memory_bytes: 22612
from collections import Counter

n = int(input())
v_list = list(map(int, input().split()))

v_odd = v_list[0::2]
v_even = v_list[1::2]

c_odd = Counter(v_odd).most_common(2)
c_even = Counter(v_even).most_common(2)

if c_odd[0][0] == c_even[0][0]:
    if len(c_odd) > 1 and len(c_even) > 1:
        if c_odd[1][1] > c_even[1][1]:
            print(len(v_odd) - c_odd[1][1] + len(v_even) - c_even[0][1])
            exit()
        else:
            print(len(v_odd) - c_odd[0][1] + len(v_even) - c_even[1][1])
            exit()
    elif len(c_odd) >= 2:
        print(len(v_odd) - c_odd[1][1] + len(v_even) - c_even[0][1])
        exit()
    elif len(c_even) >= 2:
        print(len(v_odd) - c_odd[0][1] + len(v_even) - c_even[1][1])
        exit()
    else:
        print(len(v_even))
        exit()

print(len(v_odd) - c_odd[0][1] + len(v_even) - c_even[0][1])

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



int main() {
    int N;
    cin>>N;
    vector<double> p(N);
    rep(i,N){
        cin>>p.at(i);
    }
    vector<vector<double>> dp(N,vector<double>(N+1));
    dp.at(0).at(0)=1-p.at(0);
    dp.at(0).at(1)=p.at(0);
    rep(i,N-1){
        rep(j,i+2){
            dp.at(i+1).at(j)+=dp.at(i).at(j)*(1-p.at(i+1));
            dp.at(i+1).at(j+1)+=dp.at(i).at(j)*p.at(i+1);
        }
    }
    double ans=0;
    for(int j=(N+1)/2;j<=N;j++){
        ans+=dp.at(N-1).at(j);
    }
    cout << fixed << setprecision(10);
    cout<<ans<<endl;
}

Measured memory_bytes: 70656
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

ll a[100100],b[100100],s=0ll;
vector<ll> v;

int main(void){
	int n,i,ans=0;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a[i];
		s += a[i];
	}
	for(i=0; i<n; ++i){
		cin >> b[i];
		s -= b[i];
	}
	if(s<0ll){
		cout << "-1" << endl;
		return 0;
	}
	s = 0ll;
	for(i=0; i<n; ++i){
		if(a[i]<b[i]){
			++ans;
			s += b[i]-a[i];
		}else if(a[i]>b[i]){
			v.push_back(a[i]-b[i]);
		}
	}
	sort(v.begin(),v.end(),greater<ll>());
	i = 0;
	while(s>0ll){
		s -= v[i];
		++ans;
		++i;
	}
	cout << ans << endl;
	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pii> vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vector<pair<ll,ll> > > vvpll;
typedef vector<bool> vb;
typedef map<int,int> mii;
typedef map<char,int> mci;
typedef map<ll,ll> mll;

#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) x.begin() , x.end()
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define F first
#define S second
#define left (node << 1)
#define right (node << 1) + 1
// #define mod 998244353
#define mod 1000000007 

#define trace1(x)                       cerr<<#x<<": "<<x<<endl
#define trace2(x, y)                    cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)                 cerr<<#x<<": " <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(x, y, z , t)             cerr<<#x<<": " <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#t<<": "<<t<<endl
#define trace5(x, y, z , t , u)         cerr<<#x<<": " <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#t<<": "<<t<<" | "<<#u<<": "<<u<<endl
#define trace6(x, y, z , t , u , v)     cerr<<#x<<": " <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#t<<": "<<t<<" | "<<#u<<": "<<u<<" | "<<#v<<": "<<v<<endl

#define repa(i,sta,end,inc) for(int i = sta ; i <= end ; i += inc)
#define repb(i,sta,end,inc) for(int i = sta ; i >= end ; i -= inc)

ll power(ll x , ll y , ll z){ll res = 1;x %= z;while(y){if(y&1){res = res * x % z;}x = x*x % z;y /= 2;}return res%z;}
ll gcd(ll a , ll b){return (b == 0 ? a : gcd(b , a % b));}

const int N = 2 * 100000 + 1;
const int inf = (1<<30);


ll cnt[100005] = {0};

void solve(){
    ll n , k;
    cin >> n >> k;
    ll ans = k;
    cnt[k] = 1;
    repb(i,k-1,1,1){
        cnt[i] = power(k/i,n,mod);
        repa(j,2*i,k,i){
            cnt[i] = (cnt[i] + mod - cnt[j]) % mod;
        }
        ans = (ans + ll(i) * cnt[i] + mod ) % mod;
    }
    cout << (ans + mod ) % mod << endl;
}


int main(){
    FIO;
    int T = 1;
    // cin >> T;
    repa ( i , 1 , T , 1){
        solve();
    }
    return 0;
}


Measured memory_bytes: 4416
N = int(input())
A = input()
listA = list(A)
B = input()
listB = list(B)
C = input()
listC = list(C)
count = 0
for i in range(N):
    if listA[i] != listB[i] and listB[i] != listC[i] and listC[i] != listA[i]:
        count += 2
    elif listA[i] == listB[i] and listB[i] != listC[i]:
        count += 1
    elif listB[i] == listC[i] and listC[i] != listA[i]:
        count += 1
    elif listA[i] == listC[i] and listA[i] != listB[i]:
        count += 1
    elif listA[i] == listB[i] and listB[i] == listC[i] and listC[i] == listA[i]:
        count += 0
print(count)



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
    int k, a, b; cin >> k >> a >> b;
    for(int i = a; i <= b; i++){
        if(i % k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;

    system("pause");
}

Measured memory_bytes: 3700
import sys
import numpy as np

def solve(inp):
    def bit_length(x):
        ret = 0
        while x:
            x >>= 1
            ret += 1
        return ret
    MOD = 998244353
    e = 0
    id_x = -1

    n = inp[0]
    log = bit_length(n)
    size = 1 << log
    d = [e] * (2 * size)
    lz = [id_x] * size

    def op(a, b):
        a1, a2 = a >> 32, a % (1 << 32)
        b1, b2 = b >> 32, b % (1 << 32)
        c1 = (a1 + b1) % MOD
        c2 = (a2 + b2) % MOD
        return (c1 << 32) + c2

    def mapping(x, a):
        if x == -1:
            return a
        a1, a2 = a >> 32, a % (1 << 32)
        c1 = (x * a2) % MOD
        c2 = a2
        return (c1 << 32) + c2

    def composition(x, y):
        if x == -1:
            return y
        return x

    def update(k):
        d[k] = op(d[2 * k], d[2 * k + 1])

    def all_apply(k, f):
        d[k] = mapping(f, d[k])
        if k < size:
            lz[k] = composition(f, lz[k])

    def push(k):
        all_apply(2 * k, lz[k])
        all_apply(2 * k + 1, lz[k])
        lz[k] = id_x

    def build(arr):
        assert len(arr) == n
        for j in range(n):
            d[size + j] = arr[j]
        for j in range(size - 1, 0, -1):
            update(j)

    def all_prod():
        return d[1]

    def range_apply(l, r, f):
        assert 0 <= l <= r <= n
        if l == r:
            return
        l += size
        r += size
        for i in range(log, 0, -1):
            if ((l >> i) << i) != l:
                push(l >> i)
            if ((r >> i) << i) != r:
                push((r - 1) >> i)
        l2 = l
        r2 = r
        while l < r:
            if l & 1:
                all_apply(l, f)
                l += 1
            if r & 1:
                r -= 1
                all_apply(r, f)
            l >>= 1
            r >>= 1
        l = l2
        r = r2
        for i in range(1, log + 1):
            if ((l >> i) << i) != l:
                update(l >> i)
            if ((r >> i) << i) != r:
                update((r - 1) >> i)
	
    q = inp[1]
    X = inp[2::3]
    Y = inp[3::3]
    REP = inp[4::3]
    A = np.zeros(n, dtype=np.int64)
    tmp = 1
    for i in range(n - 1, -1, -1):
        A[i] = (tmp << 32) + tmp
        tmp *= 10
        tmp %= MOD

    build(A)

    ans = np.zeros(q, dtype=np.int64)
    for i in range(q):
        range_apply(X[i] - 1, Y[i], REP[i])
        ans[i] = all_prod() >> 32

    return ans


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
    exit()

from my_module import solve

inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print("\n".join(map(str, ans)))


Measured memory_bytes: 49392
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string>

using namespace std;

int main()
{
    string S, T;    cin >> S;
    int i, l;
    i = 0;
    l = S.size();
    S += "zzzzzzzzzz";
    while(i < l-1){
        if(S.substr(i,6) == "eraser"){
            i += 6;
        }else if(S.substr(i,5) == "erase"){
            i += 5;
        }else if(S.substr(i,8) == "dreamerd" || S.substr(i,8) == "dreamere"){
            i += 7;
        }else if(i == l-7 && S.substr(i,7) == "dreamer"){
            i += 7;
        }else if(S.substr(i,5) == "dream"){
            i += 5;
        }else{
            cout << "NO";
            return 0;
        }
        if(i > l-5 && i < l-1){
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
#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 all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   priority_queue<pair<int, int>> q;
   int n, m;
   cin >> n >> m;
   rep(i, 0, n) {
      int a;
      cin >> a;
      q.push(make_pair(a, 1));
   }
   rep(i, 0, m) {
      int b, c;
      cin >> b >> c;
      q.push(make_pair(c, b));
   }
   ll ans = 0;
   rep(i, 0, n) {
      P p = q.top();
      q.pop();
      ans += p.first;
      p.second--;
      if (p.second > 0) q.push(p);
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 5300