akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


def f(x): # x以下のペアがk個以上あるかどうかを返す関数
    cnt = 0
    if x < 0: # xが負の場合(plusとminusで尺取り法)
        j = p-1
        for i in range(m)[::-1]:
            while j >= 0:
                if minus[i]*plus[j] <= x:
                    j -= 1
                else:
                    break
            cnt += p - j - 1
    else: # xが正の場合(x>=0)
        #正の数同士で尺取り法
        j = p-1
        for i in range(p):
            while j >= 0:
                if plus[i]*plus[j] > x:
                    j -= 1
                else:
                    break
            cnt += max(0,j - i)
        #負の数同士で尺取り法
        j = 0
        for i in range(m)[::-1]:
            while j < m:
                if minus[i]*minus[j] > x:
                    j += 1
                else:
                    break
            cnt += max(0,i - j)
        # 0x何かの場合 + 0x0の場合 + 負の数x正の数の場合
        cnt += (m+p)*zero + zero*(zero-1)//2 + m*p
    #k個以上あるならtrue
    return cnt >= k
        
n,k = LI()
a = LI()
a.sort()
minus = [x for x in a if x < 0]
plus = [x for x in a if x > 0]
m = len(minus)
p = len(plus)
zero = bl(a,1) - br(a,-1)
ok = 10**18
ng = -10**18-1
while ok-ng > 1:
    mid = (ok+ng)//2
    if f(mid):
        ok = mid
    else:
        ng = mid
print(ok)


    


Measured memory_bytes: 87636
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_B&lang=jp

#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <utility>
#include <climits>
 
using namespace std;
 
#define REP(var, count) for(int var=0; var<count; var++)

int main(void) {
	int N, W;
	cin >> N >> W;
	
	int itemV[110];
	int itemW[110];
	
	REP(i, N) { cin >> itemV[i] >> itemW[i]; }
	
	int dp[110][10010] = {{0}};
	
	for(int i=1; i<=N; i++) {
		for(int c=1; c<=W; c++) {
			int use = INT_MIN;
			if ( (c - itemW[i-1]) >= 0 ) {
				use = dp[i-1][c-itemW[i-1]] + itemV[i-1];
			}
			
			dp[i][c] = max(use, dp[i-1][c]);
		}
	}
	
	int ret = 0;
	for(int c=1; c<=W; c++) {
		ret = max(ret, dp[N][c]);
	}
	
	cout << ret << endl;

}

Measured memory_bytes: 7404
//b
#include <iostream>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <functional>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>

#define REP(i,b,n) for(int i=b;i<n;i++)
#define REPR(i,b,n) for(int i=n-1;i>=b;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define EACH(i, c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n, b) ((n>>b) & 1)
#define PB push_back
#define MP make_pair

using namespace std;

static const double PI = acos(-1.0);
static const double EPS = 1e-9;
typedef long long ll;
typedef pair<int, int> pii;	

int m, n;
int book[10000];

bool chk(int width){
	
	int sum = 0, height = 0;
	
	for(int i=0; i<n; ++i){
		
		if(book[i] > width){
			return false;	//明らかに入らない本が出てきたら広げなくてはいけない
		}
		
		sum += book[i];		//本を詰める
		
		if(sum > width){
			sum = book[i];	//入らなくなったら下の段に移動
			height++;		//段の数を増やす
		}
	}
	
	return height < m;
}	

int main(){
	
	while(cin>>m>>n, (m||n)){
		
		for(int i=0; i<n; ++i){
			cin>>book[i];
		}
		
		int upper = INT_MAX/2, lower = 0, middle;
		
		while(upper - lower > 1){
			
			middle = (upper+lower)/2;
			
			if( chk(middle) ){ 
				upper = middle;
			}
			else{
				lower = middle;
			}
		}
		
		cout << upper << endl;
	}
	
	return 0;	
}

Measured memory_bytes: 1168
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#define FAST ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = (int)1e6 + 5;
const int mod = (int)1e9 + 9;
using namespace std;
 
ll x[maxn];
int v[maxn];
ll c[maxn],cc[maxn];
ll cmx[maxn],ccmx[maxn];
 
int main()
{
	int n; ll C; scanf("%d %lld", &n, &C);
	for(int i = 1; i <= n; i++) scanf("%lld %d", &x[i], &v[i]);
	for(int i = 1; i <= n; i++){
		c[i] = c[i-1] + v[i] - x[i] + x[i-1];
		cmx[i] = max(cmx[i-1], c[i]);
	}
	x[n+1] = C;
	for(int i = n; i >= 1; i--){
		cc[n+1-i] = cc[n-i] + v[i] - x[i+1] + x[i];
		ccmx[n+1-i] = max(ccmx[n-i], cc[n+1-i]); 
	}
	ll ans = 0;
	for(int i = 0; i <= n; i++){
		ans = max(ans, c[i] - x[i] + ccmx[n-i]);
		ans = max(ans, cc[i] - C + x[n+1-i] + cmx[n-i]);
	}
	printf("%lld\n", ans);
	return 0;
}

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

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

void solve(std::string S){
    for (int i = 0; i < (int)S.size(); i++) {
        char c = S[i];
        if ( i % 2 == 0) {
            if (!(c == 'R' || c == 'U' || c == 'D')) {
                cout << NO << endl;
                return;
            }
        } else {
            if (!(c == 'L' || c == 'U' || c == 'D')) {
                cout << NO << endl;
                return;
            }
        }
    }
    cout << YES << endl;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

typedef long long int ll;
ll N;
ll ans = 0;
ll memo;

bool check(ll x){
   string S = to_string(x);
   if(count(S.begin(),S.end(),'3') == 0 || count(S.begin(),S.end(),'5') == 0 || count(S.begin(),S.end(),'7') == 0){
      return 0;
   }else{
      return 1;
   }
}

void dfs(ll x){
   if(x > N){
      return;
   }
   if(check(x)){
      ans++;
   }
   if(x * 10 < 1000000000){
      dfs(x * 10 + 3);
      dfs(x * 10 + 5);
      dfs(x * 10 + 7);
   }
   return;
}

int main(){
 cin >> N;
 ans = 0;
 dfs(0);
 cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

#ifndef DEBUG
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
#else
template <class T, class... Args>
void debug(const T &x, const Args &... args) {}
template <class T> void debugVector(const vector<T> &v) {}
#endif

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K, C;
    cin >> N >> K >> C;
    string s;
    cin >> s;
    vector<int> L, R;
    int lastd = -INF;
    for(int i = 0; i < N; i++) {
        if(s[i] == 'o' && lastd + C < i) {
            lastd = i;
            L.emplace_back(i);
        }
        if(L.size() == K) {
            break;
        }
    }
    lastd = INF;
    for(int i = N - 1; i >= 0; i--) {
        if(s[i] == 'o' && i + C < lastd) {
            lastd = i;
            R.emplace_back(i);
        }
        if(R.size() == K) {
            break;
        }
    }
    reverse(ALL(R));
    for(int i = 0; i < K; i++) {
        if(L[i] == R[i]) {
            cout << L[i] + 1 << "\n";
        }
    }
}

Measured memory_bytes: 5708
N, M = map(int, input().split())

def solve(N,M):
    dp = [[float('inf')]*(N+1) for _ in range(M+1)]
    C = list(map(int, input().split()))
    dp[0][0] = 0
    for i in range(1,M+1):
        dp[i][0] = 0
        for j in range(1,N+1):
            dp[i][j] = dp[i-1][j]
            if j>=C[i-1]:
                dp[i][j] = min(dp[i][j],dp[i][j-C[i-1]]+1)
    ans = dp[M][N]
    return ans
print(solve(N,M))


Measured memory_bytes: 43732
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin>>N;
  vector<ll> B(N-1);
  REP(i,N-1) cin >> B[i];
  vector<ll> A(N);
  REP(i,N-1) A[i] = B[i];
  A[N-1] = B[N-2];
  REP(i,N-1){
    if(B[i] < max(A[i],A[i+1])){
      A[i+1] = B[i];
    }
  }
  A[N-1] = B[N-2];
  ll ans = 0;
  REP(i,N) ans += A[i];
  cout << ans << endl;
  return 0;
}

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

int main(){
  int a,b;
  cin >> a>> b;
  cout << ((a-b<0)?0:a-b) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
#ifdef DEBUG
template<typename T>
class Vec : public vector<T>{
public:
    Vec(){}
    Vec(int n):vector<T>(n){}
    Vec(int n, T a):vector<T>(n,a){}
    T& operator[](long long n){
        if(n < 0 or n >= this->size())throw out_of_range("Vec");
        return this->at(n);
    }
    const T& operator[](long long n)const{
        if(n < 0 or n >= this->size())throw out_of_range("Vec");
        return this->at(n);
    }
};
#define vector Vec
template<typename T>
ostream &operator<<(ostream &os, set<T> st) {
    for(auto x : st) cerr << x << ' ';
    return os;
}
template<typename T, typename S>
ostream &operator<<(ostream &os, map<T, S> mp) {
    for(auto x : mp) cerr << x << ' ';
    return os;
}
#endif
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    ll k;
    cin >> n >> k;
    vector<ll>a(n), f(n);
    rep(i,n)cin >> a[i];
    rep(i,n)cin >> f[i];
    if(accumulate(a.begin(), a.end(), 0LL) <= k){
        cout << 0 << endl;
        return 0;
    }
    sort(a.begin(), a.end());
    sort(f.begin(), f.end());
    ll ng = 0;
    ll ok = 1LL<<60;
    while(ok - ng > 1){
        ll mid = (ok + ng) / 2;
        vector<ll> b;
        rep(i,n){
            ll t = mid / f[i];
            b.push_back(t);
        }
        reverse(b.begin(), b.end());
        ll cost = 0;
        rep(i,n){
            cost += max(0LL, a[i] - b[i]);
        }
        show(mid);
        show(b);
        show(cost);
        if(cost <= k){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    cout << ok << endl;
}


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

//const double PI = acos(-1);
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second

int n,k;
vector<int> a;

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

  cin >> n >> k;
  REP(i,n) {
    int tmp;
    cin >> tmp;
    a.pb(tmp);
  }

  sort(a.begin(),a.end());

  //put the id of left side into 'mi'
  int mi = n;
  for (int i = n-1; i >= 0; i--) {
    //if a[i] is greater than k -> see next number
    if (a[i] >= k) {
      mi = min(mi,i);
      continue;
    }

    //if a[i] is not greater than k -> get next number until the sum is greater than k
    int sum = a[i];
    int tmp_id = i;
    while (tmp_id - 1 >= 0 && sum + a[tmp_id - 1] < k) {
      sum += a[--tmp_id];
    }

    //if the pointer is at the end and sum is still less than k -> end the program
    if (tmp_id == 0 && sum < k) break;

    // -> else find the left minimal
    //the minimal number to be added
    int diff = k - sum;
    while (tmp_id - 1 >= 0 && a[tmp_id - 1] >= diff) {
      tmp_id--;
    }

    mi = min(mi,tmp_id);
  }

  cout << mi << endl;
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF=1e9+7;
int main()
{
    string s; cin>>s;
	s='0'+s;
	vector<int> v;
	for(int i=(int)s.size()-1; i>=0; i--){
		int d=s[i]-'0';
		v.push_back(d);
	}
	reverse(v.begin(), v.end());
	int n=v.size();
	int dp[2][1000010];
	dp[0][0]=0;
	dp[1][0]=INF;
	for(int i=1; i<n; i++){
		dp[0][i]=min(dp[1][i-1]+1, dp[0][i-1])+v[i];
		dp[1][i]=min(dp[1][i-1], dp[0][i-1]+1)+10-1-v[i];
	}
	cout<<min(dp[0][n-1], dp[1][n-1]+1)<<endl;
	return 0;
}


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

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

	string s;
	cin >> s;

	int x = 0, m = 0;
	for( int i = 0; i < n; i++ ) {
		if( s[ i ] == 'I' ) {
			x += 1;
		}
		else {
			x -= 1;
		}
		m = max( m, x );
	}

	cout << m << endl;
	return 0;
}

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

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

    set<string> ss;
    string s;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        ss.insert(s);
    }
    cout<<ss.size()<<"\n";



    return 0;
}


Measured memory_bytes: 19272
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
	Scanner scan = new Scanner(System.in);
	String S = scan.next();
	
	if(S.charAt(2)==S.charAt(3) && S.charAt(4)==S.charAt(5)){
		System.out.println("Yes");
	}else{
		System.out.println("No");
	}
}
}

Measured memory_bytes: 23764
#include <stdio.h>

typedef struct
{
    char name[16];
    int time;
} proc;

#define QUEUE_SIZE (200000)
proc queue[QUEUE_SIZE];

int main(void)
{
    int n, q;
    proc tmp;
    int front, rear;
    int current;
    int i;

    scanf("%d %d", &n, &q);
    for (i = 0; i < n; i++){
        scanf("%s %d", tmp.name, &tmp.time);
        queue[i] = tmp;
    }

    front = 0;
    rear = n;
    current = 0;
    while (front != rear){
        tmp = queue[front];
        front = (front + 1) % QUEUE_SIZE;

        if (tmp.time <= q){
            current += tmp.time;
            printf("%s %d\n", tmp.name, current);
        }
        else {
            current += q;
            tmp.time -= q;
            queue[rear] = tmp;
            rear = (rear + 1) % QUEUE_SIZE;
        }
    }

    return 0;
}

Measured memory_bytes: 4296
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e9
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<int>> matrix;

int n, m, s, t;
matrix w;
vector<ll> cost;
vector<bool> dicision;

void input() {
    cin >> n >> m;
    w = matrix(3*n);
    rep(i, m) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        w[u].push_back(v+n);
        w[u+n].push_back(v+2*n);
        w[u+2*n].push_back(v);
    }
    cin >> s >> t;
    s--;
    t--;
}

int main() {
    input();
    cost = vector<ll>(3*n, INF);
    dicision = vector<bool>(3*n, false);
    cost[s] = 0;
    dicision[s] = true;
    unordered_set<int> nowNode, nextNode;
    nowNode.insert(s);
    int deep = 0;
    while (nowNode.size()) {
        deep++;
        nextNode.clear();
        for (int i : nowNode) {
            for (int j : w[i]) {
                if (dicision[j]) continue;
                dicision[j] = true;
                nextNode.insert(j);
                cost[j] = deep;
            }
        }
        nowNode = nextNode;
    }
    if (cost[t] == INF) {
        cout << -1 << endl;
        return 0;
    }
    cout << cost[t] / 3 << endl;
}


Measured memory_bytes: 19072
N,K=map(int,input().split())

zero=0
half=0
#余り0の数と余りK/2の数の個数を数える

for i in range(1,N+1):
  if i%K==0:
    zero+=1
  elif i%K==(K/2):
    half+=1
print((zero**3)+(half**3))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    // ios::sync_with_stdio(false);
    // cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int d;
    cin >> d;
    vi  c(26);
    REP(i, 26) cin >> c[i];
    vvl s(d, vl(26));
    REP(i, d) REP(j, 26) cin >> s[i][j];

    vi last(26);
    ll ans = 0;
    vi a(d);
    REP(i, d) {
        ll ans2 = -LINF;
        ll ans_i = -1;
        REP(x, 26) {
            ll tmp = s[i][x];
            REP(j, 26) {
                if (x != j) tmp -= c[j] * ((i + 1) - last[j]);
            }
            if (chmax(ans2, tmp)) ans_i = x;
        }
        last[ans_i] = i + 1;
        ans += ans2;
        // cout << ans_i + 1 << endl;
        a[i] = ans_i + 1;
    }
    mt19937 mt{ random_device{}() };
    uniform_int_distribution<int> dist_d(1, d);
    uniform_int_distribution<int> dist_c(1, 26);
    REP(_, 100000) {
        vi lst(26);
        ll ans_n = 0;
        int x = dist_d(mt);
        int y = dist_c(mt);
        REP(i, d) {
            int t = a[i];
            if (x - 1 == i) t = y;
            ans_n += s[i][t - 1];
            lst[t - 1] = i + 1;
            REP(j, 26) if (t - 1 != j) ans_n -= c[j] * ((i + 1) - lst[j]);
        }

        if (ans_n > ans) a[x - 1] = y;
    }
    printlnv(a);
}


Measured memory_bytes: 3696
#include <cstdio>
#include <bitset>

using namespace std;

const int maxn=1005, mod=1e9+7;

bitset < maxn > l[maxn];
int dp[maxn][maxn];

inline int sum(int a, int b){
	if(a+b>=mod){
		return a+b-mod;
	}
	if(a+b<0){
		return a+b+mod;
	}
	return a+b;
}


int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	char s[maxn];
	for(int i=0; i<n; i++){
		scanf("%1005s", &s);
		for(int j=0; j<m; j++){
			if(s[j]=='.'){
				l[i+1][j+1]=1;
			}
		}
	}
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			if(i==1 && j==1){
				dp[i][j]=1;
			}
			else if(l[i][j]){
				dp[i][j]=sum(dp[i-1][j], dp[i][j-1]);
			}
		}
	}
	printf("%d", dp[n][m]);
	return 0;
}

Measured memory_bytes: 4224
n=int(input())
lists=[]
for i in range(n):
    tup=tuple(map(int,input().split()))
    lists.append(tup)

use=()
for some in lists:
    if some[2]==0:
        continue
    else:
        use=some
        break

for i in range(0,101):
    for j in range(0,101):
        height=use[2]+abs(i-use[0])+abs(j-use[1])   
        ok=True
        for inn in lists:
            if inn[2]==0:
                if height>abs(i-inn[0])+abs(j-inn[1]):
                    ok=False
            if inn[2]>0:
                if inn[2]+abs(i-inn[0])+abs(j-inn[1])!=height:
                    ok=False
        if ok:
            ans=[i,j,height]
            print(*ans)
            break
        else:
            continue


Measured memory_bytes: 3064
#pragma region

#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define IFOR(i, begin, end) for (int i = (end)-1; i >= (begin); i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define MOD 1000000007
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;
typedef long long ll;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "vec[ ";
  REP(i, vec.size())
  i == 0
      ? os << vec[i]
      : os << ", " << vec[i];
  os << " ]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const deque<T> &deq) {
  os << "deq[ ";
  REP(i, deq.size())
  i == 0
      ? os << deq[i]
      : os << ", " << deq[i];
  os << " ]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &m) {
  os << "{ ";
  for (auto &&k : m) &k == &(*m.begin()) ? os << k.first << " => " << k.second : os << ", " << k.first << " => " << k.second;
  os << " }";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &m) {
  os << "{ ";
  for (auto &&k : m) &k == &(*m.begin()) ? os << k.first << " => " << k.second : os << ", " << k.first << " => " << k.second;
  os << " }";
  return os;
}

#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);

  string S;
  cin >> S;
  int N = S.length(), C = 0;
  REP(i, N / 2) {
    if (S[i] != S[N - i - 1]) C++;
  }
  cout << C << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  long long int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define S set<int>
#define pb(v) push_back(v)
int main(){
    CIN(N);CIN(K);
    int ans = 1;
    REP(a,N){
        if(a==0){
            ans*=K;
        }else{
            ans*=(K-1);
        }
    }
    COUT(ans);
    return 0;
}


Measured memory_bytes: 764
class Problem
  attr_accessor :a, :b, :n, :m, :h, :w

  def initialize
    @n = gets.to_s.to_i
    @a = gets.to_s.split.map{ |v| v.to_i }
  end

  def solve
    maxi = a[0]
    ans = 1
    1.upto(n-1) do |i|
      if maxi <= a[i]
        ans += 1
        maxi = a[i]
      end
    end
    ans
  end

  def show(ans)
    puts ans
  end
end

Problem.new.instance_eval do
  show(solve)
end


Measured memory_bytes: 14364
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,k = readInts()
A = sorted(readInts())
print(sum(A[:k]))


Measured memory_bytes: 10472
#!/usr/bin/env python3
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

(n, m), a, *q = [[*map(int,o.split())] for o in open(0)]
UF = UnionFind(n)
k = (n - m - 1) * 2
if k > n:
    exit(print("Impossible"))
if not k:
    exit(print(0))

for c, f in q:
    UF.union(c, f)

from collections import*
d = defaultdict(list)
for e, i in enumerate(a):
    d[UF.find(e)] += i,

ans, b = 0, []
for r, p in d.items():
    p.sort()
    ans += p.pop(0)
    b += p
    k -= 1
b.sort()
print(ans + sum(b[:k]))

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

int main() {
    int N; cin >> N;
    int ans = 0;
    for (int c = 1; c <= N; c+= 2) {
        int n_divisors = 0;
        for (int x = 1; x <= c; x++) {
            if (c%x == 0) {
                n_divisors++;
            }
        }
        if (n_divisors == 8) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define REP(i, a, n) for(int i = (a); i <= (n); i++)
#define M 1000001
using namespace std;
typedef pair<int, int> pii;

bool p[M];
int m, n, table[1000][1000], nx[M], ny[M], dp1[M], dp2[M];

int isin(int y, int x) {
  return 0 <= x && x < 1000 && 0 <= y && y < 1000;
}

pii dfs(int m, int n) {
  if(dp1[n] >= 0) return pii(dp1[n], dp2[n]);

  pii ret = pii(0, p[n] ? n : 0);
  REP(i, -1, 1) {
    int qy = ny[n] + 1, qx = nx[n] + i;
    if(!isin(qy, qx)) continue;
    int q = table[qy][qx];
    if(q <= m) {
      pii t = dfs(m, q);
      ret = max(ret, t);
    }
  }

  dp1[n] = ret.first + p[n];
  dp2[n] = ret.second;
  return pii(dp1[n], dp2[n]);
}

int main(void) {
  REP(i, 1, 1000000) p[i] = true;
  p[1] = p[2] = false;
  REP(i, 2, 1000000) if(p[i]) for(int j = i * 2; j <= 1000000; j += i) p[j] = false;

  int x = 0, y = 0, cnt = 1000 - 2, r = 1000000;
  REP(i, 0, 999) REP(j, 0, 999) table[i][j] = 0;
  while(cnt >= 0) {
    REP(j, 0, cnt) { table[y][x] = r; ny[r] = y; nx[r] = x; x++; r--; }
    REP(j, 0, cnt) { table[y][x] = r; ny[r] = y; nx[r] = x; y++; r--; }
    REP(j, 0, cnt) { table[y][x] = r; ny[r] = y; nx[r] = x; x--; r--; }
    REP(j, 0, cnt) { table[y][x] = r; ny[r] = y; nx[r] = x; y--; r--; }
    if(r < 0) cout << y << " " << x << endl;
    x++;
    y++;
    cnt -= 2;
  }

  while(cin >> m >> n, m != 0 && n != 0) {
    REP(i, 1, m) dp1[i] = dp2[i] = -1;
    pii ans = dfs(m, n);
    cout << ans.first << " " << ans.second << endl;
  }

  return 0;
}

Measured memory_bytes: 23712
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1e9+7
#define hell2 1e9+9
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll long long
#define ld long double 
#define no_of_digits(n) floor(log10(n)) + 1
#define see(x) cout << (#x) << " is " << (x) << endl
#define INF 1e9

using namespace std;

ll mult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll multbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=multbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;
}
ll add(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll sub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
int isPowerof2(ll x) { return (x && !(x & x-1)); } 
ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; } 

// max({a, b, c, d})

vector<ll>adj[200005];
ll update[200005];
ll ans[200005];

int binaryToDecimal(string n) 
{ 
    string num = n; 
    int dec_value = 0; 
  
    // Initializing base value to 1, i.e 2^0 
    int base = 1; 
  
    int len = num.length(); 
    for (int i = len - 1; i >= 0; i--) { 
        if (num[i] == '1') 
            dec_value += base; 
        base = base * 2; 
    } 
  
    return dec_value; 
} 

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

    int a[n+1];
    for(int i=1;i<=n;i++)
        cin >> a[i];

    int cnt=0;

    for(int i=1;i<=n;i++)
    {
        if(i == a[i]) continue;
        else if(i != a[a[i]]) cnt = -INF;
        else 
        {
            if(i == a[a[i]]) cnt++;
        }
    }

    cnt /= 2;
    if(cnt < 0) cout << "NO\n";
    else if(cnt <= 1) cout << "YES\n";
    else cout << "NO\n";
}




Measured memory_bytes: 6016
import java.lang.*;
import java.io.*;
import java.util.*;


public class Main {
	
	public static void main(String[] args) throws java.lang.Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(in, out);
		out.close();
	}
}

class TaskA {
	
	public void solve(InputReader in, PrintWriter out) {
		String s = in.next();
		int n = s.length();
		int ans = 0;
		
		for (int i=n-1; i>=0; --i) {
			if (judge(s, i)) {
				ans = i;
				break;
			}
		}
		
		out.println(ans);
	}
	
	boolean judge(String s, int n) {
		if (n%2 == 1) return false;
		
		for (int i=0,j=n/2; j<n; i++,j++) {
			if (s.charAt(i) != s.charAt(j)) {
				return false;
			}
		}
		return true;
	}
}

class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;
	
	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
	}
	
	public String next() {
		while (tokenizer==null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	
	public int nextInt() {
		return Integer.parseInt(next());
	}
	
	public double nextDouble() {
		return Double.parseDouble(next());
	}
	
	public long nextLong() {
		return Long.parseLong(next());
	}
}
 

Measured memory_bytes: 21460
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>

using namespace std;
#define ff(i,n,m) for(int i=n;i<m;i++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
	int n;
	cin >> n;
	i64 p = 1;
	ff(i, 0, n) {
		p *= (i + 1);
		p %= 1000000007;
	}
	cout << p << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>


using namespace std;

int main() {
    int n;
    cin >> n;
    vector<string> blue(n);
    for (int i = 0; i < n; i++) {
        cin >> blue[i];
    }
    int m;
    cin >> m;
    vector<string> red(m);
    for (int i = 0; i < m; i++) {
        cin >> red[i];
    }

    int ans = 0;
    auto calc = [&](string s) {
        int buf = 0;
        for (string t : blue) {
            if (t == s) buf++;
        }
        for (string t : red) {
            if (t == s) buf--;
        }
        return buf;
    };

    for (string t : blue) {
        ans = max(ans, calc(t));
    }

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

Measured memory_bytes: 384
#include<string>
#include<iostream>
#include<deque>
#include<cstdlib>
#include<algorithm>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
#define rep(i, x, n) for(i=x;(i)<(n);(i)++)

const int MOD = 1000000007;
const int infty = 1000000000;

typedef struct item {
	ulli v;
	ulli w;
};

int main() {
	int n;
	cin >> n;
	int pw;
	cin >> pw;
	deque<item> nodes;
	deque<deque<ulli>> dp;
	int i;
	rep(i, 0, n) {
		ulli w, v;
		cin >> w >> v;
		nodes.push_back({ v, w });
	}
	rep(i, 0, n) {
		deque<ulli> temp(pw + 1, 0);
		if (i == 0) {
			int j;
			rep(j, nodes[i].w, pw + 1) {
				temp[j] = nodes[i].v;
			}
			dp.push_back(temp);
			continue;
		}
		int j;
		temp = dp[i - 1];
		rep(j, 0, pw + 1 - nodes[i].w) {
			temp[j + nodes[i].w] = max(temp[j + nodes[i].w], dp[i - 1][j] + nodes[i].v);
		}
		dp.push_back(temp);
	}
	cout << dp[n - 1][pw] << endl;
	return 0;
}

Measured memory_bytes: 85908
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)

int main(){
    set<int> s;
    int a,b,k;
    cin >> a >> b >> k;
    for(int i=0;i<k;i++){
        if(a+i>b)break;
        s.insert(a+i);
    }
    for(int i=0;i<k;i++){
        if(b-i<a)break;
        s.insert(b-i);
    }
    for(auto &&x:s){
        cout << x <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
const ll INF = 1061109567;
const double EPS = 1e-10;
int main(){
    int n;
    int count=0;
    cin>>n;
    for(int i=0;i<n;i++){
        ll buf;
        cin>>buf;
        while(buf%2==0){
            count++;
            buf/=2;
        }
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String R = sc.next();
		int mae = Integer.parseInt(R.substring(0,3));
		int ato = Integer.parseInt(R.substring(1,4));
		if(mae%111==0 || ato%111==0){
			out.print("Yes");
		}else{
			out.print("No");
		}

		
	}
}

Measured memory_bytes: 21844
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstdlib>
#include <memory.h>
#include <ctime>
#include <bitset>

using namespace std;

#define ABS(a) ((a>0)?a:-(a))
#define MIN(a,b) ((a<b)?(a):(b))
#define MAX(a,b) ((a<b)?(b):(a))
#define FOR(i,a,n) for (int i=(a);i<(n);++i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define pnt pair <int, int>
#define mp make_pair
#define PI 3.1415926535897
#define MEMS(a,b) memset(a,b,sizeof(a))
#define LL long long
#define U unsigned

int c[100100];

int main()
{
#ifdef Fcdkbear
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	double beg = clock();
#endif

	int n, q;
	scanf("%d%d", &n, &q);
	FOR(i, 0, q) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		b--;
		if (a) {
			c[a] ^= 1;
		}
		if (b) {
			c[b] ^= 1;
		}
	}
	FOR(i, 1, n) {
		if (c[i] & 1) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;

#ifdef Fcdkbear
	double end = clock();
	fprintf(stderr, "*** Total time = %.3lf ***\n", (end - beg) / CLOCKS_PER_SEC);
#endif
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define ll long long

int mod = 998244353;

signed main() {
  int N, M; cin >> N >> M;
  scc_graph g(N);
  rep(i, M) {
    int a, b; cin >> a >> b;
    g.add_edge(a-1, b-1);
    g.add_edge(b-1, a-1);
  }
  
  vector<vector<int>> gg = g.scc();
  
  cout << gg.size()-1 << endl;
  

}


Measured memory_bytes: 11200
#include <stdio.h>
int main()
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(x+r>W||x-r<0||y+r>H||y-r<0)
		printf("No\n");
	else
		printf("Yes\n");
	return 0;
}

Measured memory_bytes: 1012
#include<stdio.h>
#include<iostream>
#include<list>
#include<map>
#include<vector>
#include<algorithm>
#include<string.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << x << endl;
using namespace std;

int main(){
    double xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2;
    while(cin >> xa1 >> ya1 >> xa2 >> ya2 >> xb1 >> yb1 >> xb2 >> yb2){
        if((xa1 > xb2) || (ya1 > yb2) || (xb1 > xa2) || (yb1 > ya2)){
            cout << "NO" << endl;
        }else{
            cout << "YES" << endl;
        }
    }
}

Measured memory_bytes: 1220
def answer(in0, in1):

    N = int(in0)
    A = [int(a) for a in in1.split()]

    cnt = 0

    while (True):
        for i in range(N):
            a = A[i]
            if a % 2 != 0:
                print(cnt)
                return
            A[i] = int(a / 2)
        cnt += 1


answer(input(), input())


Measured memory_bytes: 2940
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
int vis[1000000];
int n;int sum;
void pre()
{
    memset(vis, 0, sizeof(vis));
for(int i = 2; i <= 999999; i++)
	for(int j = i*2; j <= 999999; j += i)
		vis[j] = 1;
}
int main()
{
    pre();
    while(scanf("%d",&n)!=EOF)
    {
        sum=0;
        for(int i=2;i<=n;i++)
        {
            if(!vis[i])
                sum++;
        }
        printf("%d\n",sum);
    }
    return 0;
}

Measured memory_bytes: 4936
#include <iostream>
#include <vector>

int main()
{
  constexpr int N = 5;
  std::vector<int> times(N);
  int to_be_last = -1;
  int rest = 10;
  for(int i=0; i<N; i++) {
    int t;
    std::cin >> t;
    if(t%10 != 0 && t%10 < rest) {
      to_be_last = i;
      rest = t % 10;
    }
    times[i] = t;
  }

  int m = 0;
  for(int i=0; i<N; i++) {
    if(i == to_be_last) {
      m += times[i];
    } else {
      m += ((times[i] + 9) / 10) * 10;
    }
  }

  std::cout << m << std::endl;
  return 0;
}


Measured memory_bytes: 3584
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// END NO SAD

typedef long long ll;
typedef pair<int, int> pii;

void solve() {
  int n;
  cin >> n;
  int ret = 0;
  for(int a = 1; a <= n; a++) {
    if(a < n-a) ret++;
  }
  cout << ret << "\n";
}

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#include<functional>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.20f\n",(x))
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define cotu cout
#define Endl endl
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
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;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll H,W; cin >> H >> W;
    ll a[10010];
    ll N; cin >> N;
    rep(i,0,N) cin >> a[i];
    ll grid[105][105];
    ll i = 0;
    ll j = 0;
    ll color = 1;
    while(true){
        grid[i][j] = color;
        a[color-1]--;
        if(a[color-1] == 0) color++;

        if(i % 2 == 0){
            if(j == W-1){
                i++;
            }else{
                j++;
            }
        }else{
            if(j == 0){
                i++;
            }else{
                j--;
            }
        }

        if(a[N-1] == 0) break;
    }

    rep(i,0,H){
        rep(j,0,W){
            if(j != 0) cout << " ";
            cout << grid[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3704
def slove():
    import sys
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    t = 1
    for i in range(2, n + 1):
        t = (t * i) % (10 ** 9 + 7)
    for i in range(2, m + 1):
        t = (t * i) % (10 ** 9 + 7)
    if abs(n - m) == 1:
        print(t)
    elif abs(n - m) == 0:
        t = (t * 2) % (10 ** 9 + 7)
        print(t)
    else:
        print(0)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38512
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    string t;
    cin >> s >> t;
    int n=s.size();
    rep(i,n){
        string m= s.substr(i,n-i) + s.substr(0,i);
        // cout << m << endl;

        if(m==t){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
ll inf = 1LL << 60;
ll dp[102][100005];
int main() {
	int n, W;
	cin >> n >> W;
	ll w[102], v[102];
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> w[i] >> v[i];
		sum += v[i];
	}
	for (int i = 0; i <n; i++) {
		for (int j = 0; j <= sum; j++) {
			dp[i][j] = inf;
		}
	}
	dp[0][0]=0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= sum; j++) {
			if (j >= v[i]) {
				dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
			}
			else {
				dp[i + 1][j] = dp[i][j];
			}
		}
	}
	long long ans = 0;
	for (int j = 0; j <= sum; j++) {
		if (dp[n][j] <= W) {
			ans = j;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 79232
#include <stdio.h>
#include <stdlib.h>

static void swap (int *a, int *b) {
    int tmp;

    tmp = *a;
    *a = *b;
    *b = tmp;
}

static int gcd (int a, int b) {
    int r;

    if ( a < b )
        swap(&a, &b);

    r = a % b;
    while ( r != 0 ) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

static int gcd3 (int a, int b, int c) {
    return gcd(gcd(a, b), c);
}

int main (void) {
    int         K;
    int         i, j, k;
    long long   ans = 0;

    scanf("%d", &K);

    for ( i=1; i<=K; i++ ) {
        for ( j=1; j<=K; j++ ) {
            for ( k=1; k<=K; k++ ) {
                ans += gcd3(i, j, k);
            }
        }
    }

    printf("%lld\n", ans);
    return EXIT_SUCCESS;
}



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

struct UnionFind {
  vector<int> par, siz;
  UnionFind (int n) {
    par.resize(n), siz.resize(n);
    for (int i = 0; i < n; i++) {
      par.at(i) = i, siz.at(i) = 1;
    }
  }
  int root(int x) {
    if (par.at(x) == x) return x;
    return par.at(x) = root(par.at(x));
  }
  int size(int x) {
    return siz.at(root(x));
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  bool unit(int x, int y) {
    x = root(x), y = root(y);
    if (x == y) return false;
    if (siz.at(x) > siz.at(y)) {
      par.at(y) = x, siz.at(x) += siz.at(y);
    } else {
      par.at(x) = y, siz.at(y) += siz.at(x);
    }
    return true;
  }
};

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  UnionFind UF(N);
  vector<vector<int>> F(N);
  for (int i = 0, a, b; i < M && cin >> a >> b; i++) {
    F.at(--a).push_back(--b);
    F.at(b).push_back(a);
    UF.unit(a, b);
  }
  vector<vector<int>> B(N);
  for (int i = 0, c, d; cin >> c >> d; i++) {
    B.at(--c).push_back(--d);
    B.at(d).push_back(c);
  }
  for (int i = 0; i < N; i++) {
    int tmp = UF.size(i);
    tmp--;
    for (auto b : B.at(i)) if (UF.same(i, b)) tmp--;
    tmp -= F.at(i).size();
    cout << tmp << "\n"; 
  }
}

Measured memory_bytes: 12536