akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

bool is_ok(string &s, string &t, int pos)
{
    rep(i, t.size())
    {
        if (s[pos + i] != '?' && s[pos + i] != t[i])
        {
            return false;
        }
    }
    return true;
}

void change(string &s, string &t, int pos)
{
    rep(i, t.size())
    {
        s[i + pos] = t[i];
    }
    rep(i, s.size())
    {
        if (s[i] == '?')
            s[i] = 'a';
    }
}
int main(int argc, char const *argv[])
{
    string s, t;
    cin >> s >> t;
    for (int i = s.size() - t.size(); i >= 0; i--)
    {
        if (is_ok(s, t, i))
        {
            change(s, t, i);
            cout << s << endl;
            return 0;
        }
    }
    cout << "UNRESTORABLE" << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque
h,w = list(map(int, input().split()))
maze = [ input() for _ in range(h)]

def bfs(que):
  d = 0
  while que:
    y,x = que.popleft()
    d = dist[y][x]
    for dy, dx in ((0,1),(1,0),(0,-1),(-1, 0)):
      next_y = y + dy
      next_x = x + dx
      if(0 <= next_y and next_y < h and 0 <= next_x and next_x < w and maze[next_y][next_x] != "#" and dist[next_y][next_x] == -1):
        que.append((next_y,next_x))
        dist[next_y][next_x] = d + 1
  return d

ans = -1
for i in range(h):
  for j in range(w):
    que = deque()
    dist = [ [-1]*w for _ in range(h) ]
    if(maze[i][j] != "#"):
      dist[i][j] = 0
      que.append((i, j))
      ans = max([ans, bfs(que)])
print(ans)



Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#define int long long
using namespace std;
char aa[123456];
signed main() {
	int n, ans = 0; cin >> n;
	if (n % 2 == 1 || n < 2) {
		cout << 0 << endl;
	}
	else {
		ans += n / 244140625 / 2; ans += n / 5 / 2;
		ans += n / 1220703125 / 2; ans += n / 25 / 2;
		ans += n / 6103515625 / 2; ans += n / 125 / 2;
		ans += n / 30517578125 / 2; ans += n / 625 / 2;
		ans += n / 152587890625 / 2; ans += n / 3125 / 2;
		ans += n / 762939453125 / 2; ans += n / 15625 / 2;
		ans += n / 3814697265625 / 2; ans += n / 78125 / 2;
		ans += n / 48828125 / 2; ans += n / 390625 / 2;
		ans += n / 9765625 / 2; ans += n / 19073486328125 / 2;
		ans += n / 1953125 / 2; ans += n / 95367431640625 / 2;
		ans += n / 476837158203125 / 2; ans += n / 2384185791015625 / 2;
		ans += n / 11920928955078125 / 2; ans += n / 59604644775390625 / 2;
		ans += n / 298023223876953125 / 2;
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#define rep(S, L) for (int i = S; i < L; ++i)
using namespace std;

int main() {
  string ss;
  cin >> ss;
  int s[10];
  for (int i = 0; i < ss.size(); ++i) {
    s[i] = ss[i] - (char)'0';
  }

  int diff = 1000;
  for (int i = 0; i < ss.size() - 2; ++i) {
    int n = s[i] * 100 + s[i + 1] * 10 + s[i + 2];
    diff = min(diff, abs(753 - n));
  }
  cout << diff << endl;

  return 0;
}


Measured memory_bytes: 3172
N, K = map(int, (input().split()))
h = list(map(int, input().split()))
# print(N, h)

# dpの最小値を変更する関数
def chmin(a, b):
    if a > b:
        return b
    else:
        return a

# 無限大の値
f_inf = float('inf')

# DP テーブルを初期化　(最小化問題なので INF に初期化)
dp = [f_inf] * (10 ** 5 + 10)

# 初期条件
dp[0] = 0

# 足場 i-1 から足場 i へ移動する。コストは|h[i]−h[i-1]|
# 足場 i-2 から足場 i へと移動する コストは |h[i]−h[i-2]|
for i in range(1, N):
    for j in range(1, K + 1):
        if i - j >= 0:
            dp[i] = chmin(dp[i], dp[i-j] + abs(h[i] - h[i - j]))

print(dp[N - 1])

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

vector<int> v;

int n,k;
int main () {
    cin >> n >> k;
    for(int i=0; i<n; i++) {
        int h;
        cin >> h;
        v.push_back(h);
    }
    sort(v.begin(), v.end());
    int ans = 1000000009;
    k--;
    for(int i=k; i<n; i++) {
        int d = v[i] - v[i-k];
        ans = min(ans, d);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 892
#include<stdio.h>
int main()
{
   
    int a,b,c;
  int d;
    scanf("%d %d",&a,&b);
      scanf("%d %d",&c,&d);

   
    // 出力
	if(a == c){
	    printf("0");//printf("%c",s[0])//文字一つ分のみを出力
    }else{
		printf("1");
    }
  

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define FOR0(i,n) for(int i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll, ll>
#define pb push_back
#define ll long long
#define ld long double	
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e18
// double power(double num, double g) {
// 	if (g == 0)return 1;
// 	if (g % 2 == 1)return (num * power((num * num), g / 2));
// 	return power( (num * num) , g / 2);
// }

int main(){
	string s;
	cin >> s;
	if (s == "ABC") cout << "ARC";
	else cout << "ABC";
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

using namespace std;
using ll = long long;

ll sqrt_lli(ll n) {
	int i;
	for (i = 1; n > 0; i++) {
		n -= i * 2 + 1;
	}
	return i - 1;
}


int main()
{
    
    int N;
    ll D;
    int cnt = 0;
    cin >> N >> D;

    ll D_2 = D*D;
    rep(i,N){
        ll x,y;
        cin >> x >> y;
        ll dist_2 = x*x + y*y;
        ll diff = D_2 - dist_2;
        if(diff >= 0){
            cnt++;
        }
    }
    cout << cnt<< endl;
    return 0;
}


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

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

int main() {
  ll N, M; cin >> N >> M;
  ll a[N];
  ll p[N];
  for (ll i = 0; i < N; i++) {
    p[i] = 0;
    cin >> a[i];
    while (a[i]%2 == 0) {
      a[i]/=2; p[i]++;
    }
  }
  bool ok = true;
  for (ll i = 0; i < N-1; i++) {
    if (p[i]!=p[i+1]) {ok = false;}
  }
  if (!ok) {cout << 0 << endl; return 0;}
  ll lcm = a[0];
  for (ll i = 1; i < N; i++) {
    if ((1LL << (p[0]-1)) * lcm * a[i] / gcd(lcm, a[i]) > M) {cout << 0 << endl; return 0;}
    else {lcm = lcm * a[i] / gcd(lcm, a[i]);}
  }
  ll x = M / (lcm * (1LL << (p[0]-1)));
  cout << (x+1)/2 << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N,K;
    cin >> N >> K;
    vector<ll> H(N);
    rep(i,N) cin >> H[i];
    
    sort(ALL(H));
    ll ans = 0;
    rep(i,N-K)ans += H[i];
    cout << ans << endl;
}

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


int main() {
  int n;
  cin >> n;
  int count=0;
  int q[n];
  int a[n],b[n];
  int an=0,bn=0;
  rep(i,n){q[i]=i+1;}
  rep(i,n){cin >> a[i];}
  rep(i,n){cin >> b[i];}
  do{
    bool as=0,bs=0;
    rep(i,n){
        if(q[i]!=a[i]){
            as=1;
        }
        if(q[i]!=b[i]){
            bs=1;
        }
      }
    if(as==0){an=count;}
    if(bs==0){bn=count;}
    count++;
  }while(next_permutation(q,q+n));
  cout << abs(an-bn) << endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<long long> a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }
    
    sort(a.begin(), a.end());
    long long ans = 0; 
    for(int i = 0; i < n; i += 2)
    {
        if (n % 2 == 1) {
            if (i + 1 == n) {
                ans += a.at(i);
                break;
            }
        }
        if (a.at(i) < 0 && a.at(i + 1) < 0) ans += -1 * a.at(i) + -1 * a.at(i + 1);
        else if (a.at(i) < 0) ans += max((a.at(i) + a.at(i + 1)), (-1 * a.at(i) + -1 * a.at(i + 1)));
        else ans += max(a.at(i) + a.at(i + 1), -1 * a.at(i) + -1 * a.at(i + 1));
    }
    cout << ans << endl;
}

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

using namespace std;

int main(){
  int n,res = (1 << 29);
  cin >> n;
  vector<int> s(n+1);s[0] = 0;
  for(int i = 0;i < n;i++){
    int x;cin >> x;
    s[i+1] = s[i] + x;
  }
  for(int i = 1;i <= n;i++){
    res = min(res,abs(s[n]-s[i]-s[i]+s[0]));
  }
  cout << res;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

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

func same(s, t []byte) bool {
	if len(s) != len(t) {
		return false
	}
	for i := range s {
		if s[i] != t[i] {
			return false
		}
	}
	return true
}

func main() {
	defer stdout.Flush()
	S := readBytes()
	K := []byte("keyence")

	if len(S) < len(K) {
		println("NO")
		return
	}
	if len(S) == len(K) {
		if same(S, K) {
			println("YES")
		} else {
			println("NO")
		}
		return
	}

	d := len(S) - len(K)
	for i := 0; i+d < len(S); i++ {
		t := make([]byte, len(K))
		copy(t, S[0:i])
		copy(t[i:], S[i+d:])
		if same(t, K) {
			println("YES")
			return
		}
	}
	println("NO")
}

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


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	long long a,b,c,d,n;cin>>a>>b>>c>>d>>n;
	c=min(c,4*a);
	c=min(c,2*b);
	long long ans=0;
	if(n%2==1)ans+=c;
	ans+=min(c*2,d)*(n/2);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import math
import sys

n=int(input())

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

if d[0]!=0 or 0 in d[1:]:
    print(0)
    sys.exit()

lis=[0 for i in range(n)]

for i in range(n):
    lis[d[i]]+=1

for i in range(1,n-1):
    if lis[i]==0 and lis[i+1]!=0:
        print(0)
        sys.exit()
s=1

i=0
while i+1<=n-1 and lis[i+1]!=0:
    s=(s*pow(lis[i],lis[i+1],998244353))%998244353
    i+=1
print(s)


Measured memory_bytes: 20824
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);
        int n = sc.nextInt();
        Map<String, Integer> map1 = new HashMap<>();
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            Integer count = map1.getOrDefault(s, 0);
            map1.put(s, ++count);
        }

        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            String s = sc.next();
            Integer count = map1.getOrDefault(s, 0);
            map1.put(s, --count);
        }

        int max = 0;
        for (Map.Entry<String, Integer> e : map1.entrySet()) {
            max = Math.max(max, e.getValue());
        }

        System.out.println(max);
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<math.h>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<map>
#define INF 999999999999
#define EPS 1.0e-6

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int n, m;
int c[20];
ll x[21000];
ll d[21000][260];

int main()
{
	while (cin >> n >> m) {
		if (n == 0 && m == 0)return 0;
		for (int i = 0; i < m; i++) {
			cin >> c[i];
		}

		for (int i = 1; i <= n; i++) {
			cin >> x[i];
		}
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= 256; j++) {
				d[i][j] = INF;
			}
		}
		d[0][128] = 0;

		for (int i = 0; i < n ; i++) {
			for (int j = 0; j <= 255; j++) {
				if (d[i][j] != INF) {
					for (int k = 0; k < m; k++) {
						int l = j + c[k];
						//cout << l << endl;
						if (l < 0)d[i + 1][0] = min(d[i + 1][0], d[i][j]+x[i + 1] * x[i + 1]);
						else if (l > 255) {
							d[i + 1][255] = min(d[i + 1][255], d[i][j]+(x[i + 1] - 255)*(x[i + 1] - 255));
							//cout << d[i + 1][256] << endl;
						}
						else{
							d[i+1][l]= min(d[i + 1][l], d[i][j] + (x[i + 1] - l)*(x[i + 1] - l));
							//cout << i + 1 << " " << j << " " << l << " " << d[i + 1][l];
						}
						//cout << i + 1 << " " << j << " " << l << " " << d[i + 1][l]<<endl;
						
					}
				}
			}
		/*
			for (int j = 0; j <= 256; j++) {
				cout << i<< "j:" <<j<<" "<<d[i][j] << endl;

			}
			cout << endl;
			*/
			
		}
		ll ans = INF;
		for (int i = 0; i <= 255; i++) {
			//cout <<"d[n-1][i]:"<< d[n][i] << endl;
			ans = min(ans, d[n][i]);
		}
		cout << ans << endl;
	}

	return 0;
}

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

typedef long long ll;
const ll INF = 1LL<<60, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define all(v) (v).begin(), (v).end()

template<class T> inline void chmax(T &a, T b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, T b) {if(a > b) a = b;}

ll dp[110][100010] = {0};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll N,W;
  cin >> N >> W;
  ll w[110],v[110];
  rep(i,N) cin >> w[i] >> v[i];
  rep(i,N){
    rep(sumw,W+1){
      if(sumw >= w[i]){
        chmax(dp[i+1][sumw], dp[i][sumw-w[i]]+v[i]);
      }
      chmax(dp[i+1][sumw], dp[i][sumw]);
    }
  }
  cout << dp[N][W] << endl;
  return 0;
}

Measured memory_bytes: 79360
#include <stdio.h>

int main(){
	int i,j,time[3][6];
	for(i = 0;i < 3;i++){
		scanf("%d %d %d %d %d %d",&time[i][0],&time[i][1],&time[i][2],&time[i][3],&time[i][4],&time[i][5]);
	}
	for(i = 0;i < 3;i++){
		for(j = 2;j >= 0;j--){
			time[i][j + 3] -= time[i][j];
			if(time[i][j + 3] < 0){
				time[i][j + 2]--;
				time[i][j + 3] += 60;
			}
		}
	}
	for(i = 0;i < 3;i++){
		printf("%d %d %d\n",time[i][3],time[i][4],time[i][5]);
	}
	return 0;
}

Measured memory_bytes: 600
#include<cstdio>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstring>
#include<iostream>
using namespace std;
#define N 10010
#define M 1000010
inline int rd()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c^48);c=getchar();}
	return f*x;
}
char s[N];
int main()
{
    scanf("%s",s+1);
    int len=strlen(s+1);
    for(int i=1;i<=len;i++)
    	printf("x");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
# define M_PI           3.14159265358979323846  /* pi */
using namespace std;

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

	vector<int>a(n);
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
	}
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());

	int A = 0;
	int B = 0;
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) A += a.at(i);
		else B += a.at(i);
	}
	cout << A - B << endl;
}

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

int main()
{
    int n;
    std::string s;
    std::cin >> n >> s;
    s += '#';
    int w = 0;
    for(int i = 0; i <= n; i++){
        if(s[i] == '.')w++;
    }
    
    int rw = w, lb = 0, min = INT_MAX;

    for(int i = 0; i <= n; i++){
        min = std::min(min,rw + lb);
            if(s[i] == '#')lb++;
            else rw--;
    }
    std::cout << min << std::endl;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, M;
    cin >> N >> M;
    vec k(M);
    mat s(M);
    REP(i,0,M) {
        cin >> k[i];
        REP(j,0,k[i]) {
            ll _s;
            cin >> _s;
            s[i].pb(_s);
        }
    }
    vec p(M);
    REP(i,0,M) cin >> p[i];

    ll cnt = 0;
    REP(i,0,1<<N) {
        bool f = true;
        REP(j,0,M) {
            ll c = 0;
            FORR(sw,s[j]) c += (i >> (sw-1) & 1);                
            if(c % 2 != p[j]) f = false;
        }
        if(f) ++cnt;
    }
    PR(cnt);

    return 0;
}

/*



*/

Measured memory_bytes: 3632
#include<bits/stdc++.h> 
using namespace std; 
   
int countFreq(string &pat, string &txt) 
{ 
    int M = pat.length(); 
    int N = txt.length(); 
    int res = 0; 
    for (int i = 0; i <= N - M; i++) 
    {  
        int j; 
        for (j = 0; j < M; j++) 
            if (txt[i+j] != pat[j]) 
                break; 
        if (j == M)   
        { 
           res++; 
           j = 0; 
        } 
    } 
    return res; 
} 
int main() 
{ int n;
cin>>n;
   string txt;
   cin>>txt;
   string pat="ABC";
   cout << countFreq(pat, txt); 
   return 0; 
} 

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

using LL = long long;

int main(){
    LL n;
    cin>>n;
    vector<LL> idou;
    for(LL i=1; i*i<=n; i++){
        if(n%i==0){
            idou.push_back(i+(n/i)-2);
            // cout<<i<<" "<<(n/i)<<" "<<i+(n/i)-2<<endl;
        }
    }
    auto min_itr = min_element(idou.begin(),idou.end());
    cout<<*min_itr<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;


using Edge = pair<int,int>;
int N,M;
vector<vector<Edge>> G;
vector<int> dist;
vector<int> used;
bool ok = true;

void dfs(int i){
   if(used[i] == 1) return;
   
   used[i] = 1;

   for(auto v : G[i]){
      if(used[v.first] == 1){
         if(dist[v.first] != (dist[i] + v.second)) ok = false;
         continue;
      }
      dist[v.first] = v.second + dist[i];
      dfs(v.first);
   }
}

int main(){
   cin >> N >> M;
   G.resize(N);
   dist.resize(N);
   used.resize(N,-1);
   rep(i,M){
      int L,R,D;
      cin >> L >> R >> D;
      L--; R--;
      G[L].push_back(Edge{R,D});
      G[R].push_back(Edge{L,-D});
   }

   rep(i,N){
      if(used[i] == -1){
         dfs(i);     
      }
   }
   if(ok) cout << "Yes" << endl;
   else cout << "No" << endl;
  
}



Measured memory_bytes: 11392
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define int int64_t
#define double long double
#define rep(i, N) for(int i=0; i<N; i++)
#define repr(i, N) for(int i=N-1; i>=0; --i)
#define all(v) v.begin(),v.end() 
using namespace std;
//using pr = pair<int, int>;
using tup  = tuple<int, int, int>;
using vec  = vector<int>;
using vvec = vector<vec>;

//プロトタイプ宣言

//グローバル変数
const int INF = 1000000000;
//const int MAX_N = ;
//const int MAX_M = ;
//vvec dp(MAX_N, vec(MAX_M));

//関数：
/* メイン・プログラム */
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, k, s; cin >> n >> k >> s;
	vec ans(n);
	
	//if(s <= n-k+1) {
	//	rep(i, s+k-1) ans[i] = 1;
	//	for(int i=s+k-1; i<n; i++) ans[i] = 0;
	//} else {
	//	int tp = s/(n-k+1);
	
	//	rep(i, n-k) {
	//		ans[i] = tp;
	//	}
	//	ans[n-k] = s - ((s/(n-k+1)) * (n-k));
	//	for(int i=n-k+1; i<n; i++) {
	//		ans[i] = tp;
	//	}
	//}
	
	rep(i, n) {
		if(s < INF) {
			if(i < k) ans[i] = s;
			else ans[i] = s+1;
		} else {
			if(i < k) ans[i] = s;
			else ans[i] = 1;
		}
	}
	
	rep(i, n) {
		cout << ans[i] << ' ';
	}
	cout << endl;
	return 0;
}

/*	(n * m) % dvs = ((n%dvs) * (m%dvs)) % dvs
*/

//std::string str;
//str = std::to_string(int i);
//bitset<3> s(N);
//int ans = (char)grid - '0';
//int id = lower_bound(all(arr), x) - arr.begin();
//cout << fixed << setprecision(10) << tld << endl;
//vector<int> sub(itr,itr+d); //イテレーターで部分数列(i=0...d)を指定

/*	struct data {
	char *name;
	int age;
	int height;
	double weight;
};*/

/*	string ans(lgd, '0');
	string &refer = ans;
	for(int i=0; i<lgd; i++) refer[i] = (char)vd[i] + '0';*/

/*	map<int,int> mp;
for(auto p : mp) {
	ct += p.second*(p.second-1); }

map<int,int>::iterator itr;
for(itr = mp.begin(); itr != mp.end(); itr++) {
	ans += itr->second * (itr->second-1);
}*/


Measured memory_bytes: 2176
import Control.Applicative ((<$>), (<*>))
import Control.Monad (replicateM, unless)
import Data.List (foldl')
import Data.Vector (Vector, (!), (//))
import qualified Data.Vector as V
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS

main :: IO ()
main = do
  n <- readLn
  m <- readLn
  unless (n == 0 && m == 0) $ do
    solve n <$> replicateM m (map read <$> words <$> getLine) >>= print
    main

solve :: Int -> [[Int]] -> Int
solve n xss = let s1 = al ! 1
              in max 0 . subtract 1 . IS.size $ IS.foldl' (\s i -> IS.union s (al ! i)) s1 s1
  where al = foldl' (\v [a, b] -> let v' = v // [(b, (IS.insert a (v ! b)))]
                                  in v' // [(a, (IS.insert b (v' ! a)))]
                    ) (V.replicate (n+1) IS.empty) xss



Measured memory_bytes: 90032
# 貪欲法 + 山登り法 + スワップ操作 + アニーリング
import time
s__ = time.time()
limit = 1.9
#limit = 10

from numba import njit
import numpy as np

d = int(input())
cs = list(map(int, input().split()))
cs = np.array(cs, dtype=np.int64)
sm = [list(map(int, input().split())) for _ in range(d)]
sm = np.array(sm, dtype=np.int64)

@njit('i8(i8[:], i8)', cache=True)
def total_satisfaction(ts, d):
    ls = np.zeros(26, dtype=np.int64)
    s = 0
    for i in range(d):
        t = ts[i]
        t -= 1
        s += sm[i][t]
        ls[t] = i + 1

        dv = cs * ((i+1) - ls)
        s -= dv.sum()
    return s

@njit('i8(i8, i8[:], i8)', cache=True)
def loop(mxsc, ts, tmpr):
    it = 50
    rds = np.random.randint(0, 4, (it,))
    rdd = np.random.randint(1, d, (it,))
    rdq = np.random.randint(1, 26, (it,))
    rdx = np.random.randint(1, 12, (it,))
    for i in range(it):
        bk1 = 0
        bk2 = 0
        if rds[0] == 0:
            # trailing
            di = rdd[i]
            qi = rdq[i]

            bk1 = ts[di]
            ts[di] = qi
        else:
            # swap
            di = rdd[i]
            xi = rdx[i]
            if di + xi >= d:
                xi = di - xi
            else:
                xi = di + xi
            
            bk1 = ts[di]
            bk2 = ts[xi]
            ts[di] = bk2
            ts[xi] = bk1

        sc = total_satisfaction(ts, d)

        delta = sc - mxsc
        if delta > 0:
            #print('d>0', mxsc, '->', sc)
            mxsc = sc
        else:
            # Random < e^(Δ/T) の場合も更新
            exp = np.exp(delta / tmpr)
            #if i == 0:print('delta=', delta, 'tmpr=', tmpr, exp)
            r = np.random.random()
            if r <= exp:
                #print('d<0', mxsc, '->', sc, delta, tmpr, exp)
                mxsc = sc
            else:
                # 戻す
                if rds[0] == 0:
                    ts[di] = bk1
                else:
                    ts[di] = bk1
                    ts[xi] = bk2

    return mxsc

@njit('i8[:]()', cache=True)
def greedy():
    ts = np.array([0] * d, dtype=np.int64)
    for i in range(d):
        mx = -1e10
        mxt = None
        for t in range(1, 26+1):
            ts[i] = t
            s = total_satisfaction(ts, i + 1)
            if s > mx:
                mx = s
                mxt = t
        ts[i] = mxt
    return ts

ts = greedy()
#ts = np.random.randint(1, 26, (d,)).astype(np.int64)
mxsc = total_satisfaction(ts, d)
mxbk = mxsc

# annealing vars
t0 = 2e3
t1 = 6e2

s_ = time.time()
mxsc = loop(mxsc, ts, t0)
e_ = time.time()

consume = s_ - s__
elapsed = e_ - s_
#print('consume:', consume)
#print('elapsed:', elapsed)

if consume < limit:
    lp = int((limit - consume) / elapsed)
    for i in range(lp):
        t = i / lp
        tmpr = np.power(t0, 1 - t) * np.power(t1, t)
        mxsc = loop(mxsc, ts, tmpr)
        #print(mxsc)

for t in ts:    print(t)
#print(mxbk, mxsc)
#print(time.time() - s__)
#print(mxsc)


Measured memory_bytes: 122544
import java.util.*;
public class Main {
	
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		HashMap<String,HashMap<Integer,Integer>> hm = new HashMap<>();
		List<String> citys = new ArrayList<>();
		for(int i=1;i<=num;i++) {
		    String city = sc.next();
		    
		    
		    if(hm.containsKey(city)){
		        HashMap<Integer,Integer> hmap = hm.get(city);
		        hmap.put(sc.nextInt(), i);
		        hm.remove(city);
		        hm.put(city,hmap);
		    } else {
		        citys.add(city);
		        
		        HashMap<Integer,Integer> hmap = new HashMap<>();
		        hmap.put(sc.nextInt(), i);
		        hm.put(city,hmap);
		    }
		}
		
		Collections.sort(citys);
		int cityNum = citys.size();
		
		for (int i=0;i<cityNum;i++) {
		    String city = citys.get(i);
		    HashMap<Integer,Integer> hmap = hm.get(city);
		    Object[] mapkey = hmap.keySet().toArray();
            Arrays.sort(mapkey);
            int count = mapkey.length;
        
            for (int j=1;j<=count;j++){
                int n = (Integer)mapkey[count-j];
                System.out.println(hmap.get(n));
		    }
		}
		
	}
}

Measured memory_bytes: 36044
import sys, math
from sys import stdin, stdout
rem = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 6+5)
#from resource import *; setrlimit(RLIMIT_STACK, (RLIM_INFINITY, RLIM_INFINITY))
take = lambda: map(int, stdin.readline().strip().split())
from bisect import bisect_left,bisect_right

k=input()
print (k/2*(k-k/2))


Measured memory_bytes: 2568
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <cstring>
#include <unordered_map>
#include <functional>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef long double ld;
#define fastio 	ios::sync_with_stdio(false);cin.tie(NULL)
#define printvector(vec) for(auto &v: vec){cout<<v<<" | ";}cout<<"\n";
template<typename T> ostream& operator<<(ostream &s,vector<T> vec){for(auto &v: vec){s<<v<<" ";}s<<"\n";return s;}
template<typename T> void print(T v){cout<<v<<" ";}
template<typename T, typename... Args> void print(T first, Args... args){cout<<first<<" ";print(args...);}

/*int main(){
	int x,a,b;
	cin>>x>>a>>b;
	x-=a;
	x=x%b;
	cout<<x;
}*/

/*map<tuple<ll,int,int,int,int>, ll> memo;
ll ways(ll x, vector<int> &val, vector<int> &coins, int pos){
	//cout<<x<<"\n";
	if(x < 0) return 0;
	if(x == 0) return 1;
	auto tp = make_tuple(x, coins[0], coins[1], coins[2], pos);
	if(memo.count(tp)){
		//cout<<"\nmemo "<<memo[tp]<<"\n";
		return memo[tp];
	}
	ll ans = 0;
	for(int i=pos; i<val.size(); ++i){
		if(coins[i] > 0){
			coins[i]--;
			ans += ways(x - val[i], val, coins, i);
			coins[i]++;
		}
	}
	//auto tp = make_tuple(x, coins[0], coins[1], coins[2]);
	return (memo[tp] = ans);
}

int main(){
	int a,b,c,x;
	cin>>a>>b>>c>>x;
	vector<int> coins {a,b,c};
	vector<int> val {500,100,50};
	//memset(memo, -1, sizeof memo);
	//cout<<val<<coins;
	cout<<ways(x, val, coins,0);
}
*/

int main(){
	int n;
	cin>>n;
	int mat[3][105], ans[3][105];
	memset(mat, 0, sizeof mat);
	memset(ans, 0, sizeof ans);
	for(int i=1; i<=2; ++i){
		for(int j=1; j<=n; ++j){
			cin>>mat[i][j];
		}
	}
	
	for(int i=1; i<=2; ++i){
		for(int j=1; j<=n; ++j){
			ans[i][j] = mat[i][j] + max(ans[i-1][j], ans[i][j-1]);
		}
	}
	
	cout<<ans[2][n];
	
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
    long long N, K; cin >> N >> K;
    long long p[N];

    for(int i = 0; i < N; i++) {
        cin >> p[i];
    }

    double MAX = 0;
    for(int i = 0; i < K; i++) {
        MAX += 0.5 * p[i] + 0.5;
    }

    double prev = MAX;
    for(int i = K; i < N; i++) {
        double cur = prev + (0.5 * p[i] + 0.5) - (0.5 * p[i - K] + 0.5);
        if(MAX < cur) {
            MAX = cur;
        }
        prev = cur;
    }

    printf("%0.12lf\n", MAX);
}

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

long long x[100001];
long long y[100001];
int mod = 1e9+7;
int main(){
	int n,m;
	
	cin >> n >> m;
	for(int i = 1;i<=n;i++){
		cin >> x[i];
	}
	for(int j = 1;j<=m;j++){
		cin >> y[j];
	}
	long long xt = 0,yt = 0;
	for(int i = 1;i<=n;i++){
		xt+=(x[i]*(i-1));
		xt%=mod;
		xt-=(x[i]*(n-i));
		xt%=mod;
	}
	for(int i = 1;i<=m;i++){
		yt+=(y[i]*(i-1));
		yt%=mod;
		yt-=(y[i]*(m-i));
		yt%=mod;
	}
	cout << (xt*yt)%mod;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef pair<pair<int, int>, int> ppi;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef bitset<60> Bitset;
const ll INFL = 1LL << 60;
const int INF = 1000000005;
const int MAX = 300000;
const int MOD = 1000000007;
struct Graph{int to,coin; ll cost;};
struct Edge{int from,to,coin; ll cost;};
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int dx[4] = {1,0,-1,0};
int dy[4]= {0,1,0,-1};
//------------------------------------------------------------------------------------------------------------------------------

int main(void) {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int h,w;cin>>h>>w;
    string s[55];
    for(int i = 0; i < h; i++) cin>>s[i];
    int black = 0;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(s[i][j]=='#') black++;
        }
    }
    queue<pii> que;
    vvi d(h,vi(w,INF));
    d[0][0] = 1;
    que.push({0,0});
    while(!que.empty()){
        pii p = que.front(); que.pop();
        int x = p.first,y = p.second;
        if(x==h-1 && y==w-1) break;
        for(int i = 0; i < 4; i++) {
            int nx = x + dx[i],ny = y + dy[i];
            if(0<=nx&&nx<h&&0<=ny&&ny<w&&s[nx][ny]=='.'&&d[nx][ny]==INF){
                d[nx][ny] = d[x][y] + 1;
                que.push({nx,ny});
            }
        }
    }
    if(d[h-1][w-1]==INF){
        cout<<-1<<endl;
    }
    else{
        cout<<h*w-d[h-1][w-1]-black<<endl;
    }
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

int cal(int n) {
  int num = 1;
  for (int i = 1; i <= 2; i++) {
    num = num * (n - i + 1) / i;
  }
  return num;
}
int main() {
  int a, b;
  cin >> a >> b;

  int c = 0;
  if (a >= 2 && b >= 2) {
    c = cal(a) + cal(b);
  } else if (a >= 2 && b < 2) {
    c = cal(a);
  } else if (a < 2 && b >= 2) {
    c = cal(b);
  }
  cout << c << endl;

  return 0;
}

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

int parent[(int)1e5+1];
int depth[(int)1e5+1];
int n;

int find(int x) {
  if (parent[x] == x) {
    return x;
  } else {
    return parent[x] = find(parent[x]);
  }
}

void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;

  if (depth[x] < depth[y]) {
    parent[x] = y;
  } else {
    parent[y] = x;
    if (depth[x] == depth[y]) depth[x]++;
  }
}

bool same(int x, int y) {
  return find(x) == find(y);
}
int main() {
  int m;
  cin>>n>>m;
  int p[n+1];
  p[0] = 0;
  for (int i=0; i<n; i++) cin>>p[i+1];

  for (int i=0; i<=n; i++) {
    parent[i] = i;
    depth[i] = 0;
  }

  for (int i=0; i<m; i++) {
    int x, y;
    cin>>x>>y;
    unite(x, y);
  }

  int ans = 0;
  for (int i=1; i<=n; i++) {
    if (p[i] == i) {
      ++ans;
    } else if (same(i, p[i])) {
      ++ans;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1408
import math
def toRad(theta):
    return theta * math.pi / 180
def calc_S(_a, _b, _c):
    return (_a * _b * math.sin(toRad(_c))) / 2
def calc_L(_a, _b, _c):
    return _a + _b + math.sqrt(_a**2 + _b**2 - 2*a*b*math.cos(toRad(_c)))
def calc_H(_a, _b, _c):
    return _b * math.sin(toRad(_c))

a, b, c = map(int, input().split())
print(calc_S(a, b, c))
print(calc_L(a, b, c))
print(calc_H(a, b, c))

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

int li[3][3];
int k[110][2];
int main() {
	int a;
	memset(k,-1,sizeof(k));
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
		{
			cin>>a;
			k[a][0]=i;
			k[a][1]=j;
		}
	int n; cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		if(k[a][0]==-1) continue;
		int x=k[a][0];
		int y=k[a][1];
		li[x][y]=1;
	}
	int f=0;
	for(int i=0;i<3;i++)
		if(li[i][0]+li[i][1]+li[i][2]==3) f=1;
	for(int i=0;i<3;i++)
		if(li[0][i]+li[1][i]+li[2][i]==3) f=1;
	if(li[0][0]+li[1][1]+li[2][2]==3) f=1;
	if(li[0][2]+li[1][1]+li[2][0]==3) f=1;
	
	
	if(f) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
	int n,m,x,a[110]={0};
	scanf("%d%d%d",&n,&m,&x);
	for(int i=0;i<m;i++){
		int t;
		scanf("%d",&t);
		a[t]=1;
	}
	int costa=0,costb=0;
	for(int i=x;i<n;i++){
		costa+=a[i];
	}
	for(int i=x;i>0;i--){
		costb+=a[i];
	}
	printf("%d\n",costa<costb?costa:costb);
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main() {
    int r,g,b,n;
    cin >> r >> g >> b >> n;

    int ans = 0;

    int z;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            z = n - (i*r + j*g);
            if (z >= 0 && z % b == 0) {
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
            using namespace std;
            #define int long long
            #define fi first
            #define se second
            #define pi pair<int,int>  
            #define pb push_back

            // dont forget to initialize global variables inside main() ;
            

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

            int tt=1;       
            
            
            while( tt-- ){
                int n;cin>>n;
                vector<int > v(n);
                for(int i=0;i<n;i++)
                    cin>>v[i];
                sort(v.begin(),v.end());
                int c=0;
                for(int i=0;i<n;i++){
                    for(int j=i+1;j<n;j++){
                        for(int k=j+1;k<n;k++){
                            if( v[i]==v[j] || v[j]==v[k] )
                                continue;
                            if( v[i]+v[j]>v[k] )
                                c++;
                        }
                    }
                }
                cout<<c<<endl;

            }

            return 0;
        }

                    
     

Measured memory_bytes: 3656
package main

import (
	"fmt"
	"sort"
)

// go run ./main.go < in

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	var prices []int
	for i := 0; i < a; i++ {
		var x int
		fmt.Scan(&x)
		prices = append(prices, x)
	}

	sort.Sort(sort.IntSlice(prices))

	sum := 0
	for _, v := range prices[:b] {
		sum += v
	}
	fmt.Println(sum)

}


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

int main(){
  int N,K;
  cin >> N >> K;
  int num=0;
  
  vector<int> h(N);
  for(int i=0; i<N; i++){
    cin >> h.at(i);
  }

  for(int i=0; i<N; i++){
    if(h.at(i) >= K){
      num++;
    }
  }

  cout << num << endl;
}

Measured memory_bytes: 640
def main():
    """
    1 <= N  <= 10^5
    1 <= X  <= 10^9
    1 <= xi <= 10^9
    xi != xj
    xi != X
    """
    N, X = map(int, input().split())
    *xs, = map(int, input().split())

    ans = f(N, X, xs)
    print(ans)


def f(N, X, xs):
    """
    直線上に N 個の都市
    i 番目の都市は座標 xi

    あなたの目的は、これら全ての都市を 1度以上訪れること
    あなたは、はじめに正整数 Dを設定
    その後、あなたは座標 Xから出発し、以下の移動 1、移動 2を好きなだけ行う

        移動 1: 座標 yから座標 y+Dに移動する
        移動 2: 座標 yから座標 y−Dに移動する

    全ての都市を 1 度以上訪れることのできる Dの最大値を求めよ
    ここで、都市を訪れるとは、その都市のある座標に移動すること


    D=1, OK
    """
    ds = [abs(X - x) for x in xs]
    ans = ds[0]
    from fractions import gcd

    for d in ds:
        ans = gcd(d, ans)

    return ans


if __name__ == '__main__':
    main()


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


int FAB(int a,int b){
    int digit1 = 0;
    int digit2 = 0;
    while(a!=0){
    a = a / 10;
    ++digit1;
  }
  while(b!=0){
    b = b / 10;
    ++digit2;
  }

    return max(digit1,digit2);
}

int main(){
    ll n;
    cin>>n;
    int x = 0;
    for(ll i=1; i*i<=n;i++){
        if(n%i == 0){
            if(x==0){
                x = FAB(i,n/i);
            }else{
                x = min(x,FAB(i,n/i));
            }
        }
    }
    cout<<x<<endl;
}

Measured memory_bytes: 3624
import scala.io.StdIn.readInt

object Main extends App {
  val s1 = {for(i<-1 to 4) yield readInt }.sortWith(_>_).take(3).sum
  val h = readInt
  val g = readInt
  val s2 = if(h>g) h else g
  println(s1+s2)
}

Measured memory_bytes: 43924
n = int(input())
a = list(map(int,input().split()))
counter = []
for i in range(n):
    count = 0
    if a[i] % 2 == 0:
        while a[i] % 2 == 0:
            a[i] //= 2
            count += 1
        counter.append(count)
    else:
        print(0)
        quit()

print(min(counter))

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str = br.readLine();
        
    int[] intArray = Arrays.stream(str.split(" ")) //" "で区切ってString配列へ
    .mapToInt(Integer::parseInt) //数値にして
    .toArray(); //配列へ

    int n= intArray[0];
    int powder= intArray[1];

        
    int needPowder=0;
    int min=10000;
    
    for(int i=0;i<n;i++){
        int a = Integer.parseInt(br.readLine());
        needPowder+=a;
        
        if(min>=a){
            min=a;
        }
    }   
        
    
    int lastPowder=powder-needPowder;
    
    int lastD=lastPowder/min;
  
        System.out.println(n+lastD);
    }
}


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

int n,a[110], x, ans, d;

int main ()
{
	cin >> n >> d >> x;
	for (int i=1; i<=n; i++)
	cin >> a[i];
	for (int i=1; i<=n; i++)
	{
		ans++;
		int dem=1;
		while (a[i]*dem<d)
		{
			ans++;
			dem++;
		}
	}
	
	cout << ans + x;
}


Measured memory_bytes: 256
r = 100001
p = [1]*r
p[0] = p[1] = 0
for i in range(int(r**0.5)):
	if p[i]:
		p[2*i::i] = [0 for x in range(2*i,r,i)]
prime = []
for i in range(r):
	if p[i]: prime.append(i)
	
while 1:
	n = int(raw_input())
	if n == 0: break
	ans = 0
	i = 0
	while 1:
		s = 0
		j = i
		while 1:
			s += prime[j]
			if s >= n:
				if s == n:
					ans += 1
				break
			j += 1
		i += 1
		if prime[i] > n: break
	print ans

Measured memory_bytes: 8224
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Diagnostics;
using Enu = System.Linq.Enumerable;

public class Program
{
    public void Solve()
    {
        var S = Reader.String();
        long ans = 0;

        for (int mask = 0; mask < (1 << S.Length - 1); mask++)
        {
            long curr = 0;
            for (int i = 0; i < S.Length; i++)
            {
                curr = curr * 10 + S[i] - '0';
                if (i == S.Length - 1 || (mask >> i & 1) == 1)
                {
                    ans += curr;
                    curr = 0;
                }
            }
        }

        Console.WriteLine(ans);
    }
}

class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    static string[] Split(string s) { return s.Split(separator, op); }
    static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; }
    static string Next() { CheckNext(); return A[i++]; }
    static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}

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

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define PB push_back
#define POB pop_back
#define MP make_pair
#define FI first
#define SE second
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;

const double EPS = 1e-9;
const double PI = acos(-1);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

ll addMod(ll a, ll b){
	return (a+b) % MOD;
}

ll mulMod(ll a, ll b){
	return (a*b) % MOD;
}

/////////////////////////////////////////////////////////

int n, a;
ll dp[55][55][2505];
int x[55];

ll solve(int idx, int use, int tot){
	if(idx == n){
		if(use > 0 && tot % use == 0 && tot / use == a) return 1;
		return 0;
	}
	ll& ret = dp[idx][use][tot];
	if(ret != -1) return ret;
	ret = 0;
	ret += solve(idx+1,use+1,tot+x[idx]);
	ret += solve(idx+1,use,tot);
	return ret;
}

int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> a;
	FOR(i,n) cin >> x[i];
	sort(x,x+n);
	memset(dp,-1,sizeof dp);
	cout << solve(0,0,0) << endl;
	return 0;
}

Measured memory_bytes: 59520
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    unsigned long long n,a,b,sum,blue,sp,sub;
    cin >> n >> a >> b;

    sp = n;

    sum = a + b;
    n = n / sum;
    blue = n * a;

    sp = sp - n * sum;
    
    if(sp >= a){
        blue = blue + a;
    }

    else if(sp < a){
        blue = blue + sp;
    }

    cout << blue <<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

ll min(ll a, ll b) {return a < b ? a : b;}
ll min(int a, ll b) {return a < b ? a : b;}
ll min(ll a, int b) {return a < b ? a : b;}
ll min(int a, int b) {return a < b ? a : b;}

ll max(ll a, ll b) {return a > b ? a : b;}
ll max(int a, ll b) {return a > b ? a : b;}
ll max(ll a, int b) {return a > b ? a : b;}
ll max(int a, int b) {return a > b ? a : b;}

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
#define int long long

int n;
string s;
int dp[2][1500000];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> s;
    dp[0][0] = s[0] - '0';
    dp[1][0] = 11 - (s[0] - '0');
    for (int i = 1; i < s.size(); i++)
    {
        dp[0][i] = min(dp[0][i - 1], dp[1][i - 1]) + s[i] - '0';
        dp[1][i] = min(dp[0][i - 1] + 11 - (s[i] - '0'), dp[1][i - 1] + 9 - (s[i] - '0'));
    }
    cout << min(dp[0][s.size() - 1], dp[1][s.size() - 1]);
}


Measured memory_bytes: 19740
import java.util.Scanner;

public class Main{
    public static int n,s,count=0;
    public static void main(String[] args){
        Scanner sc =new Scanner(System.in);
        while(true){
            n=sc.nextInt();
            s=sc.nextInt();
            if(n==0 && s==0)break;
            count=0;
            dfs(0,0,0);
            System.out.println(count);
        }
    }
    //x:足す数の種類(0~9)　y:合計値  z:足す数の個数
    public static void dfs(int x,int y,int z){
        //条件の達成
        if(y==s && z==n){
            count++;
            return;
        }
        //0~9の探索終了、あるいは足す個数が一定数
        if(x==10 || z==n)return;
        //再帰
        dfs(x+1,y+x,z+1);
        dfs(x+1,y,z);
    }
}


Measured memory_bytes: 26368