akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long A = sc.nextLong();
        long B = sc.nextLong();
        sc.close();
        long games = getMatchGames(N, A, B);
        System.out.println(games);
    }
    private static long getMatchGames(long N, long A, long B) {
        long small = Math.min(A,B);
        long large = Math.max(A,B);

        long games = 0;
        if ((large - small) % 2 == 0) {
            games = (large - small) / 2;
        } else {
            long win = N - large;
            long lose = small - 1;
            if (win < lose) {
                games += (win + 1);
                small += (win + 1);
                large += win;
            } else {
                games += (lose + 1);
                small -= lose;
                large -= (lose + 1);
            }
            games += getMatchGames(N, small, large);
        }
        return games;
    }
}


Measured memory_bytes: 22736
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	int n; int a; P p[100000]; cin >> n;
	rep(i, n) {
		cin >> a;
		p[i] = { a,i };
	}
	sort(p, p + n);
	int csum = 0;
	rep(i, n) {
		if ((i % 2) != (p[i].second % 2))csum++;
	}
	cout << csum / 2 << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> a(n+1,0);
  rep(i,n){
    cin >> a[i];
  }
  
  rep(_,min(k,41)){
    vector<int> r(n+1,0);
    rep(i,n){
      r[max(0,i-a[i])]++;
      r[min(n,i+a[i]+1)]--;
    }
    rep(i,n){
      r[i+1] += r[i];
    }
    swap(a,r);
  }
  rep(i,n){
    cout << a[i] << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 5056
import functools

def inter(a,b):
    return list(set(a)&set(b))


def resolve():
    n,m=map(int,input().split())
    a=[list(map(int,input().split())) for i in range(n)]
    a=[i[1:] for i in a]
    print(len(list(functools.reduce(inter,a))))    

resolve()

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <utility>
typedef long long lint;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
#define INF 1e18

signed main()
{
	int N, M;
	cin >> N >> M;
	vector<int> X(M);
	rep(i, M) cin >> X[i];

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

	vector<int> diff(N+M-1, 0);
	diff[0] = 0;
	for (int i = 0; i < M-1; i++)
	{
		diff[i] = X[i+1] - X[i];
	}
	sort(diff.begin(), diff.end());
	reverse(diff.begin(), diff.end());
	int ans = X.back() - X.front();
	//cout << ans << endl;
	for (int i = 0; i < N - 1; i++)
	{
		ans -= diff[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <map>
#include <bitset>
#include <algorithm>
#include <string>
#include <queue>

#define ll long long
#define ull unsigned long long
using namespace std;

const ll mod = 1000000007;

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    if (s.find("7") != string::npos) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 3656
from collections import deque
import math
import sys

h,w = map(int,input().split())
s = [0] * h
for i in range(h):
     s[i] = [i for i in str(input())]
memo = [[300] * w for _ in range(h)]
memo[0][0] = 0
box=[deque([]) for _ in range(w+h-1)]
box[0].append([0,0])
ans = 0
for i in range(w+h-1):
     while box[i]:

          y,x = box[i].popleft()
          if y == h-1 and x == w-1:
               if s[y][x] == '.' and s[0][0] == '.':
                    print(ans//2)
               elif s[y][x] == '.' and s[0][0] == '#' :
                    print((ans+1)//2)
               elif s[y][x] == '#' and s[0][0] == '.':
                    print((ans + 1) // 2)
               else:
                    print(ans//2 + 1)
               sys.exit()
          for k, j in [(1, 0), (0, 1)]:
               nexty, nextx = y + k, x + j
               if nexty < h and nextx < w:
                    if memo[nexty][nextx] > 250:
                         memo[nexty][nextx] = ans
                         if s[nexty][nextx] == s[y][x]:
                              box[i].append([nexty, nextx])

                         elif s[nexty][nextx] != s[y][x]:
                              box[i + 1].append([nexty, nextx])


     ans += 1







Measured memory_bytes: 3692
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define int ll
ll po(ll a, ll x, ll m) { if (x == 0) {return 1;} ll ans = 1; ll k = 1;  while (k <= x) {if (x & k) {ans = ((ans * a) % m);} k <<= 1; a *= a; a %= m; } return ans; }
// Udhar kya dekh rha h idhar dekh le
int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n;
	cin >> n;
	int a[n];
	forr(i, n) {
		cin >> a[i];
	}
	int mx = a[0];
	int ans = 0 ;
	for (int i = 1; i < n; i++) {
		if (a[i] < mx) {
			ans += (mx - a[i]);
		}
		mx = max(mx, a[i]);
	}
	cout << ans << "\n";
	return 0;
}

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

int main() {
  string s;
  cin>>s;
  if(s[0]==s[1]&&s[1]==s[2]||s[1]==s[2]&&s[2]==s[3]){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

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

int main(){
  int N, D;
  int count=0;
  cin >> N >> D;
  vector<vector<int>> position(N, vector<int>(2));
  
  for (int i=0;i<N;i++){
    cin >> position.at(i).at(0) >> position.at(i).at(1);
    
    if ( sqrt(pow(position.at(i).at(0),2)+pow(position.at(i).at(1),2)) <= D )
      count++;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 14340
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
string s;
ll n,i,j,ans,tot=1,t;
ll b[20],a[2000010];
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(i=1;i<=n;++i)
	{
		cin>>s;
		t=s.size();
		for(j=0;j<t;++j) b[j]=s[j]-'a'+1;
		sort(b,b+t);
		for(j=0;j<t;++j)
		{
			a[i]=a[i]*29+b[j];
		}
	}
	sort(a+1,a+n+1);
	for(i=1;i<=n+1;++i)
	{
		if(a[i]==a[i-1])
		{
			++tot;
		} 
		else 
		{
			ans+=(tot-1)*(tot)/2;
			tot=1;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
n, k = [int(i) for i in raw_input().split()]
inputs = [int(i) for i in raw_input().split()]
# n, k = 5,3
# inputs = [10,30,40,50,20]

f = [float("inf")] * n

f[0] = 0
f[1] = abs(inputs[1] - inputs[0])

for i in range(2, n):
	for x in range(1, min(i+1,k+1)):
		f[i] = min(f[i], f[i-x] + abs(inputs[i-x]-inputs[i]))

# print f
print f[-1]

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

string s;
stack<char> a;
stack<char> b;

int main () {
    cin >> s;
    for (int i = 0; i < s.length(); i++){
        if (s[i] == '1' || s[i] == '0'){
            a.push(s[i]);
        } else {
            if (!a.empty()){
                a.pop();
            }
        }
    }


    while (!a.empty()){
            b.push(a.top());
            a.pop();   
        }

    while (!b.empty()){
        cout << b.top();
        b.pop();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
set<string> s;
int main(){
    string str;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>str;
        s.insert(str);
    }
    cout<<s.size();
    return 0;
}

Measured memory_bytes: 19120
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;
int N,W;
vector<int> dp,v,w,m;
int solve(){//O(NWlogm) O(NW)は蟻本P302
    for(int i=0;i<N;i++){
	int num = m[i];
	for(int j=1;num > 0; j<<=1 ){
	    int mul = min(j,num);//最後を上手くやる
	    for(int j=W; j>=w[i]*mul;j--){
		dp[j] = max(dp[j],dp[j-w[i]*mul] + v[i]*mul);
	    }
	    num-=mul;
	}
    }
    return dp[W];
}

int main(){
    cin>>N>>W;
    dp = vector<int>(W+1,0);
    v = vector<int>(N);
    w = vector<int>(N);
    m = vector<int>(N);
    for(int i=0;i<N;i++)cin>>v[i]>>w[i]>>m[i];
    cout<<solve()<<endl;
    return 0;
}



Measured memory_bytes: 3244
/*
Sharif Hasan - CSE, PUST
Apr 24, 2020 02: 14 PM
*/
#include<bits/stdc++.h>
#include "string.h"
#define br cout<<"\n"
#define what(x) cout<<"in here var= "<<x<<"\n";

/*STL definations*/
#define pb push_back

#define FOR(i,n) for(int i=0;i<n;i++)
#define FROM(a,i,n) for(int i=a;i<n;i++)
using namespace std;
int main(){
    long long n;
    cin>>n;
    string ans;
    while(n>0){
        int r=n%26;
        if(r==0){
            ans+='z';
            n/=26;
            --n;
        }else{
            ans+=(r-1)+'a';
            n/=26;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3624
#[allow(unused_imports)]
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

const INF: u64 = 1 << 60;

fn warshall_floyd(n: usize, mut edges: Vec<Vec<u64>>) -> Vec<Vec<u64>> {
    for k in 0..n {
        for i in 0..n {
            for j in 0..n {
                edges[i][j] = min(edges[i][j], edges[i][k] + edges[k][j]);
            }
        }
    }
    edges
}

struct Permutation {
    n: usize,
    idx: usize,
}
impl Permutation {
    fn new(n: usize) -> Permutation {
        Permutation { n: n, idx: 0 }
    }
}
impl Iterator for Permutation {
    type Item = Vec<usize>;
    fn next(&mut self) -> Option<Vec<usize>> {
        let mut r = vec![0; self.n];
        let mut idx = self.idx;
        for k in 1..self.n {
            r[k] = idx % (k + 1);
            idx /= k + 1;
        }
        if idx > 0 {
            return None;
        }
        r.reverse();
        let mut b = vec![true; self.n];
        b[r[0]] = false;
        for k in 1..self.n {
            let mut count = 0;
            for j in 0..self.n {
                if b[j] {
                    if count == r[k] {
                        r[k] = j;
                        b[j] = false;
                        break;
                    }
                    count += 1;
                }
            }
        }
        self.idx += 1;
        return Some(r);
    }
}

fn calc_cost(edges: &Vec<Vec<u64>>, r: &Vec<usize>, ord: &Vec<usize>) -> u64 {
    let mut cost = 0;
    for i in 0..r.len() - 1 {
        cost += edges[r[ord[i]]][r[ord[i + 1]]];
    }
    cost
}

fn main() {
    let v: Vec<usize> = read_vec();
    let (N, M, R) = (v[0], v[1], v[2]);
    let r: Vec<usize> = read_vec();
    let mut r = r.iter().map(|&r| r - 1).collect::<Vec<_>>();

    let mut edges = vec![vec![INF; N]; N];
    for i in 0..M {
        let mut v: Vec<usize> = read_vec();
        let (a, b, c) = (v[0] - 1, v[1] - 1, v[2]);
        edges[a][b] = c as u64;
        edges[b][a] = c as u64;
    }
    let edges = warshall_floyd(N, edges);
    let mut ans = std::u64::MAX;
    for ord in Permutation::new(R) {
        ans = min(ans, calc_cost(&edges, &r, &ord));
    }
    println!("{}", ans)
}


Measured memory_bytes: 4352
n = int(input())
pi = list(map(int, input().split()))
count =0
for i in range(len(pi)-2):
    if((pi[i+1]>pi[i] and pi[i+1]<pi[i+2]) or(pi[i+1]<pi[i] and pi[i+1]>pi[i+2])):
        count +=1
print(count)


Measured memory_bytes: 3060
n = int(input())

if n == 0:
    print(0)
    
else:
    digits = []
    i = 0
    base = 1
    while n != 0:
        if n % (base*2) == 0:
            digits.append('0')
        else:
            digits.append('1')
            n -= base

        i += 1
        base *= -2##

    print(''.join(digits[::-1]))

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
    long long n,m;
    while(scanf("%lld%lld",&n,&m)!=EOF)
    {
        long long sum=0;
        if(n<=m/2)
        {
            sum=n;
            m-=2*n;
            sum+=m/4;
        }
        else
            sum=m/2;
        printf("%lld\n",sum);
    }
        return 0;
}


Measured memory_bytes: 128
// A.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
	int n, m;
	cin >> n >> m;
	int ans = (n * (n - 1) + m * (m - 1)) / 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
/**
*    created: 24.06.2020 12:41:32
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcount(bit)
#define mod 1000000007
#define pi acos(-1.0)
using namespace std;

signed main() {

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

    int n;
    cin >> n;
    if (n % 2 == 0) cout << n * n / 4 << endl;
    else cout << (n + 1) / 2 * ((n + 1) / 2 - 1) << endl;
    return 0;
}

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

int fun(int n){
    int s=0;
    while(n!=0){
        s += n%10;
        n=n/10;
    }
    return s;
}

int main() {
    int n,a,b;
    cin >> n >> a >> b;
    int count=0;
    for(int i=1;i<=n;i++){
        if(fun(i)>=a&&fun(i)<=b){
            count +=i;
        }
    }
    cout << count << endl;
}

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

/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

using namespace std;

typedef long long ll;

const int N_MAX = 5002;

int n, k;

int p[N_MAX];
ll c[N_MAX];

int m;

vector <int> cycle[N_MAX];

bool visited[N_MAX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> p[i];
    for(int i = 1; i <= n; i++)
        cin >> c[i];
    for(int i = 1; i <= n; i++)
        if(visited[i] == false)
        {
            int pos = i;
            m++;
            do
            {
                cycle[m].push_back(pos);
                visited[pos] = true;
                pos = p[pos];
            }while(pos != i);
        }
    ll mxc = LLONG_MIN;
    for(int i = 1; i <= n; i++)
        mxc = max(mxc, c[i]);
    ll ans = mxc;
    for(int i = 1; i <= m; i++)
    {
        ll sum = 0;
        for(int j : cycle[i])
            sum += c[j];
        ll mx = LLONG_MIN;
        for(int a = 0; a < (int)cycle[i].size(); a++)
        {
            ll s = 0;
            int b = a;
            for(int cnt = 1; cnt <= min((int)cycle[i].size(), k); cnt++)
            {
                s += c[cycle[i][b]];
                mx = max(mx, max(0LL, sum) * ((k - cnt) / (int)cycle[i].size()) + s);
                b++;
                if(b == (int)cycle[i].size())
                    b = 0;
            }
        }
        ans = max(ans, mx);
    }
    cout << ans << "\n";
    return 0;
}



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

int main() {
    int H, W;

    while (cin >> H >> W, H) {
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cout << ((i+j)&1 ? ".": "#");
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
#include<iostream>
using namespace std;
int main()
{
    int n,k,x,y,p,sum;
    cin>>n>>k>>x>>y;
    if(n<k){
        cout<<(n*x)<<endl;
    }
    else{
        sum=k*x;
        p=(n-k)*y;
        cout<<sum+p<<endl;
    }
}


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

using namespace std;

const int maxn = 1e5 + 10, maxl = 20;
int sp[maxn][maxl], h[maxn], ans, s, e, n;
int tin[maxn], tout[maxn], timer;
vector<int> adj[maxn];

void dfs(int u, int par, int hei = 0)
{
    h[u] = hei;
    sp[u][0] = par;
    for (int i = 1; i < maxl; i++)
        sp[u][i] = sp[sp[u][i - 1]][i - 1];

    tin[u] = timer++;

    for (int v : adj[u])
        if (v != par)
            dfs(v, u, hei + 1);

    tout[u] = timer++;
}

bool is_anc(int u, int v)
{
    return tin[u] <= tin[v] && tout[u] <= tout[v];
}

int lca(int u, int v)
{
    if (is_anc(u, v))
        return u;
    if (is_anc(v, u))
        return v;

    for (int i = maxl - 1; ~i; i--)
        if (!is_anc(sp[u][i], v))
            u = sp[u][i];

    return sp[u][0];
}

int dis(int u, int v)
{
    return h[u] + h[v] - 2 * h[lca(u, v)];
}

void find_ans(int u, int par)
{
    ans = max(ans, h[u] - 1);

    for (int v : adj[u])
        if (v != par)
            find_ans(v, u);
}

int main()
{
    ios::sync_with_stdio(false);
    cin >> n >> s >> e;

    for (int i = 0, u, v; i < n - 1; i++)
        cin >> u >> v, adj[u].push_back(v), adj[v].push_back(u);
    dfs(e, e);

    int d = dis(s, e), lc = s;
    d /= 2;
    while (d--)
        lc = sp[lc][0];
    find_ans(lc, sp[lc][0]);

    cout << ans;

    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i,k,n) for(int i=k;i<n;i++)
#define sum(start, end) accumulate(start, end, 0)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define pb push_back
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef string str;

using namespace std;
template <class T = ll> T in() { T _in; cin >> _in; return (_in); }


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

    str S;
    S = in<str>();

    // abcで重複があったらアウト
    if(S[0] == S[1] || S[0] == S[2] || S[1] == S[2])
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
        
    return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>
#include <iostream>

using namespace std;
int main() {
	int n, r;
	int ans;
	cin >>n >> r;

	if (n <= 10) {
		cout << r + 100 * (10 - n);
	}
	else {
		cout << r;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			String S = sc.next();
			String T = sc.next();
			StringBuilder ans = new StringBuilder();

			int startFlg = -1;
			int flgTmp = -1;
			for (int i = 0; i <= S.length() - T.length(); i++) {
				flgTmp = -1;
				for (int j = 0; j < T.length(); j++) {
					if (S.charAt(i + j) == '?') {
						flgTmp = i;
					} else if (S.charAt(i + j) == T.charAt(j)) {
						flgTmp = i;
					} else {
						flgTmp = -1;
						break;
					}
				}
				if (flgTmp != -1) {
					startFlg = flgTmp;
				}
//				System.out.println(i);
//				System.out.println(startFlg);
			}
			if (startFlg == -1) {
				System.out.println("UNRESTORABLE");
			} else {
				for (int i = 0; i < startFlg; i++) {
					if (S.charAt(i) == '?') {
						ans.append('a');
					} else {
						ans.append(S.charAt(i));
					}
				}
				ans.append(T);
				if (S.length() > startFlg + T.length()) {
					for (int i = startFlg + T.length(); i < S.length(); i++) {
						if (S.charAt(i) == '?') {
							ans.append('a');
						} else {
							ans.append(S.charAt(i));
						}
					}
				}
				System.out.println(ans);
			}
		}
	}
}


Measured memory_bytes: 23124
import java.util.*;

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

        int a = scan.nextInt();
        int[] b = new int[a];
        int c=0;
        int d=0;
        int ans=10000;
        for(int i=0;i<a;i++){
            b[i]=scan.nextInt();
            d+=b[i];
        }
        c=b[0];
        d-=c;
        int j=1;
        while(true){
            if(Math.abs(c-d)==0){
                ans=0;
                break;
            }
            if(ans>Math.abs(c-d)){
                ans=Math.abs(c-d);
            }
            c+=b[j];
            d-=b[j];
            j++;
            if(j==a)break;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23252
from itertools import accumulate


def solve(string):
    n, *a = map(int, string.split())
    *a, = accumulate(a)
    l, c, r = 0, 1, 2
    sll, slr, srl, srr = a[l], a[c] - a[l], a[r] - a[c], a[-1] - a[r]
    ans = max(sll, slr, srl, srr) - min(sll, slr, srl, srr)
    while c < n - 1:
        while abs(a[c] - 2 * a[l + 1]) < abs(a[c] - 2 * a[l]):
            l += 1
        while abs(a[-1] + a[c] - 2 * a[r + 1]) < abs(a[-1] + a[c] - 2 * a[r]):
            r += 1
        sll, slr, srl, srr = a[l], a[c] - a[l], a[r] - a[c], a[-1] - a[r]
        ans = min(ans, max(sll, slr, srl, srr) - min(sll, slr, srl, srr))
        c+=1
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


Measured memory_bytes: 25984
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define OP ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;

const int inf = int(1e9);
const int mod = inf + 7;
const double PI = acos(-1.0);
using namespace std;
const int N = 1e5 + 155;

void solve(){
    int n, l;
    cin >> n >> l;
    vector<string> v;
    rep(i, n)
    {
        string s;
        cin >> s;
        v.pb(s);
    }
    sort(all(v));
    string ans = "";
    rep(i, n) ans += v[i];
    cout << ans;
}

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


Measured memory_bytes: 256
#include <stdio.h>


long memo[128][32];
int a[200];
int N;

/**********************
pos: ??????????????§?????£??????
S:   ?????¬?????§???????¨?
**********************/

long sum(int pos, int S)
{
	if (memo[pos][S] != -1)return (memo[pos][S]);
	
	if (S < 0 || 20 < S){
		return 0;
	}
	
	if (pos == N - 1) {
		if (S == a[N - 1]) {
			return 1;
		}
		else {
			return 0;
		}
	}
	//count[pos][S]++;
	
	
	memo[pos][S] = sum(pos + 1, S + a[pos]) + sum(pos + 1, S - a[pos]);
	return memo[pos][S];
};

int main(void)
{
	int i, j;
	
	scanf("%d", &N);
	
	for (i = 0; i < N; i++){
		for (j = 0; j <= 20; j++)memo[i][j] = -1;
	}
	
	
	for (i = 0; i < N; i++)scanf("%d", &a[i]);
	
	printf("%ld\n", sum(1, a[0]));
	
	/*for (i = 0; i < N; i++){
		for (j = 0; j <= 20; j++){
			printf("i = %d, j = %d, count = %d\n", i, j, count[i][j]);
		}
	}*/
	
	return (0);
}

Measured memory_bytes: 628
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,m;
    cin >> n >> m;
    vvi G(n);
    vi in(n,0);
    rep(i,m) {
        int x,y;
        cin >> x >> y;
        x--; y--;
        G[x].pb(y);
        in[y]++;
    }
    queue<int> q;
    rep(i,n) if(in[i] == 0) q.push(i);
    vi dp(n,0);
    while(!q.empty()) {
        int now = q.front();
        q.pop();
        for(int v : G[now]) {
            chmax(dp[v],dp[now]+1);
            if(--in[v] == 0) q.push(v);
        }
    }
    int ans = 0;
    rep(i,n) chmax(ans,dp[i]);
    cout << ans << endl;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#include<vector>
#include<string>
using namespace std;
 
int main() {
    char a;cin >> a;
    if(a == 'A'){
        cout << 'T' << endl;
    }else if(a == 'C'){
        cout << 'G' << endl;
    }else if(a == 'G'){
        cout << 'C' << endl;
    }else{
        cout << 'A' << endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iostream>
#include<cmath>
#include<map>
#include<set>
#include<climits>
using namespace std;
typedef vector<string>vs;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<double>vd;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll>pll;
typedef vector<ll>vl;
#define rrep(i,x,n) for(int i=(x);i<(n);++i)
#define rep(i,x) rrep(i,0,(x))
#define fi first
#define se second
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define maxs(a,b) (a)=max(a,b)
#define mins(a,b) (a)=min(a,b)

struct UF{
    int N;
    vi par,sz;
    void init(int _N){
        N=_N;
        par=vi(N);
        sz=vi(N,1);
        rep(i,N)par[i]=i;
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y)return;
        if(sz[x]<sz[y])swap(x,y);
        par[y]=x;
        sz[x]+=sz[y];
    }
    bool same(int x,int y){
        return find(x)==find(y);
    }
};

typedef pair<int,pii>piii;
int main(){
    int N,M;
    scanf("%d%d",&N,&M);
    UF uf;
    uf.init(N);
    vector<piii>V;
    rep(i,M){
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        V.pb(piii(c,pii(a,b)));
    }
    sort(all(V));
    int cost=0;
    rep(i,M){
        piii p=V[i];
        if(uf.same(p.se.fi,p.se.se))continue;
        uf.unite(p.se.fi,p.se.se);
        cost+=p.fi;
    }

    printf("%d\n",cost);

    return 0;
}

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

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

    int a, b;
    cin >> a >> b;

    if(a >= 13)
        cout << b << endl;
    else if (a >= 6 and a <= 12)
        cout << b/2 << endl;
    else
        cout << 0 << endl;
    
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;
int MOD = 1000000007;
int used[100001] = {0};
signed main(){
    int n;cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<pair<int,int>> c(n);
    
    rep(i,n){
        int x,y;
        cin >> x >> y;
        a[i] = x;
        b[i] = y;
        c[i] = MP(-x-y,i);
    }
    // SORT(a);
    // SORT(b);
    //cerr << 1 << endl;
    SORT(c);
    int st = 0;
    int sa = 0;
    //cerr << 2 << endl;

    rep(i,n){
        //cerr << "i " << i << endl;
        if(i%2 == 0){
            //t
            int j = c[i].se;
            st += a[j];
        }else{
            int j = c[i].se;
            sa += b[j];
        }
    }
    cout << st - sa << endl;
    
    return 0;   
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://ddcc2019-final.contest.atcoder.jp/tasks/ddcc2019_final_a
// rm -r -f test;oj dl http://arc060.contest.atcoder.jp/tasks/arc060_a

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
 int main(){
 int N,K,sum;
 cin>>N>>K;
 sum=0;
 for(int i=0;i<N;i++){
 int x;
 cin>>x;
 if(x<=K-x){
 sum+=2*x;
 }
 else{
 sum+=2*(K-x);
 }
 }
 cout<<sum<<endl;
 }

Measured memory_bytes: 256
def solve(string):
    n, *uvw = map(int, string.split())
    p = [[] for _ in range(n + 1)]
    for u, v, w in zip(uvw[::3], uvw[1::3], uvw[2::3]):
        p[u].append((v, w))
        p[v].append((u, w))
    s = [(1, 0)]
    l = [-1] * (n + 1)
    while s:
        _s, w = s.pop()
        l[_s] = w % 2
        for _t, _w in p[_s]:
            if l[_t] == -1:
                s.append((_t, w + _w))
    return "\n".join(str(_w) for _w in l[1:])


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n - 1)])))


Measured memory_bytes: 51064
#define ll long long
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define mp make_pair
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int isprime(int n){
    int count =0;
    for(int i=2;i<=sqrt(n);i++)
    if(n%i==0)count++;
    if(count)return 0;
    return 1;
}
int gcd(int a, int b) 
{ 
    if (a == 0) 
       return b; 
    if (b == 0) 
       return a; 
    if (a == b) 
        return a; 
    if (a > b) 
        return gcd(a-b, b); 
    return gcd(a, b-a); 
} 
int main(){
    int n;
    cin>>n;
    int a[n];
    
    for(int i=0;i<n;i++)
    cin>>a[i];
    sort(a,a+n);
    int ans =0;
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            for(int k = j+1;k<n;k++){
                int f =1;
                if(a[i]+a[j]<=a[k])f=0;
                if(a[j]+a[k]<=a[i])f=0;
                if(a[i]+a[k]<=a[j])f=0;
                if(abs(a[i]-a[j])>=a[k])f=0;
                if(abs(a[i]-a[k])>=a[j])f=0;
                if(abs(a[k]-a[j])>=a[i])f=0;
                set<int>s;
                s.insert(a[i]);
                s.insert(a[j]);
                s.insert(a[k]);
                if(f&&s.size()==3)ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}






Measured memory_bytes: 3720
#include <iostream>

 

using namespace std;

 

 int main()
{
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    
    if(x-r >= 0 && y-r >= 0 && x+r <=w && y+r <=h)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 3116
object Main extends App {
  val n = readLine.toInt
  val (a, b) = readLine.split(" ").map(_.toInt) match {
    case Array(a, b) => (a, b)
  }
  val ps: Seq[Int] = readLine.split(" ").map(_.toInt).toSeq

  val firstCounts = ps.count(_ <= a)
  val secondCounts = ps.count(p => p > a && p <= b)
  val thirdCounts = ps.count(_ > b)

  println(Seq(firstCounts, secondCounts, thirdCounts).min)
}


Measured memory_bytes: 25536
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
const int N=100010;
int a[N];
struct A{int v,f;};
vector<A> p[N];
int main(){
    int n,m,i,j;
    ll tmp=0,sum=0,ans=0,ss=0;
    scanf("%d %d",&n,&m);
    for(i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(i>1){
            if(a[i]>a[i-1]){
                ans+=a[i]-a[i-1];
                p[a[i-1]+1].push_back((A){0,1});
                p[a[i]+1].push_back((A){-a[i]+a[i-1],-1});
            }
            else{
                ans+=a[i]+m-a[i-1];
                p[1].push_back((A){m-a[i-1],1});
                p[a[i]+1].push_back((A){-(a[i]+m-a[i-1]),-1});
                p[a[i-1]+1].push_back((A){0,1});
            }
        }
    }
    ss=ans;
    for(i=1;i<=m;i++){
        tmp+=sum;
        for(j=0;j<p[i].size();j++){
            sum+=p[i][j].f;
            tmp+=p[i][j].v;
        }
        ss=min(ss,ans-tmp);
        //printf("%d %lld %lld\n",i,tmp,sum);
    }
    printf("%lld\n",ss);
    return 0;
}


Measured memory_bytes: 6516
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
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;
}


int main() {
  long long mod=1000000007;
  long long a,b;
  cin>>a>>b;
  long long dp[a+3];
  rep(i,a+3){
    dp[i]=0;
  }
  dp[0]=1;
  vector<long long> vec(a+1,true);
  rep(i,b){
    int c;cin>>c;
    vec.at(c)=false;
  }
  rep(i,a){
    if(!vec.at(i)){
      dp[i]=0;
    }
    else{
      (dp[i+1]+=dp[i])%=mod;
      (dp[i+2]+=dp[i])%=mod;
    }
  }
  cout<<dp[a]<<endl;
}


Measured memory_bytes: 1792
read N
ans=0
for ((i=0; i<N; i++)); do
    read x y
    if [[ $y == 'JPY' ]]; then
        ans=$(echo $ans $x | awk '$0+=$2')
    else
        ans=$(echo $ans $x | awk '$0+=$2*38e4')
    fi
done

echo $ans

Measured memory_bytes: 792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string S;
  cin>>N>>S;
  vector<char>list;
  list.push_back(S.at(0));
  if(N==1){
    cout<<1<<endl;
  }
  else{
    for(int i=1;i<S.size();i++){
      if(list.at(list.size()-1)==S.at(i)){
      }
      else{
        list.push_back(S.at(i));
      }
    }
    cout<<list.size()<<endl;
  }
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

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

ll N,ans;
ll A[101010],B[101010];
vector<pll> vv;
ll i, j;
int main(){
    scanf("%lld", &N);
    fornum(i, 0,N){
        scanf("%lld%lld", &A[i], &B[i]);
        vv.push_back(mp(A[i] + B[i],i));
    }
    sort(vv.begin(), vv.end());
    fornum(i,0,N){
        auto va = vv[N-1-i];
        if(i%2){
            ans -= B[va.second];
        }else{
            ans += A[va.second];
        }
    }

    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 3444
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in a:
  b.append(abs(i))
m=[]
for i in a:
  if i>=0:
    m.append(0)
  else:
    m.append(1)
if sum(m)%2==0:
  ans=sum(b)
else:
  k=1000000000
  t=0
  for i in range(n):
    if b[i]<k:
      k=b[i]
      t=i
  ans=sum(b)-2*b[t]
print(ans)

  

Measured memory_bytes: 14412
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
const int ININF = 1000000;
const int MOD = 1000000007;
int main() {
    string S;
    cin >> S;
    int N = S.size();
    int P = 2019;
    vector<long long> val(P, 0);
    long long tenfactor = 1;
    long long cur = 0;
    val[cur]++;
    for(int i = 0; i < N; ++i) {
        cur = (cur + (S[N - i - 1] - '0') * tenfactor) % P;
        tenfactor = (tenfactor * 10) % P;
        val[cur]++;
    }
    long long res = 0;
    for(int p = 0; p < P; ++p)
        res += val[p] * (val[p] - 1) / 2;
    cout << res << endl;
    
}


Measured memory_bytes: 3720
def main():
    x,k,d = map(int,input().split())
    if x>0:
        mv = x//d
        if mv<k:
            x = x - mv*d
            k = k - mv
        else:
            print(x - k*d)
            return
        if k%2==0:
            print(abs(x))
        else:
            print(abs(x-d))
    else:
        mv = -1*x // d
        if mv < k:
            x = x + mv * d
            k = k-mv
        else:
            print(abs(x + k*d))
            return
        if k % 2 == 0:
            print(abs(x))
        else:
            print(abs(x+d))

if __name__ == "__main__":
    main()


Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long m;
	cin>>m;
	int c= pow(m, 0.2);
	//for(int i=(-1*c); i<=c; i++){
	//	for(int j=(-1*c); j<=c; j++){
	for(int i=-200; i<=200; i++){
		for(int j=-200; j<=200; j++){
	
			if(pow(i, 5)-pow(j, 5)==m){
				cout<<i<<" "<<j<<endl;
				return 0;
			}
		}
	}}

Measured memory_bytes: 4108
#include <cstdio>
#include <iostream>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
const int mod=1e9+7;
int n,m;
struct rect{
	int a[3][3];
	void set(int x,int o,int p,int q){
		a[x][0]=o;a[x][1]=p;a[x][2]=q;
	}
	void set0(){
		set(0,1,0,0);
		set(1,0,1,0);
		set(2,0,0,1);
	}
}t,r,R;
rect operator *(rect a,rect b){
	rect s;
	ref(i,0,2)ref(j,0,2){
		s.a[i][j]=0;
		ref(k,0,2)s.a[i][j]=(1LL*a.a[i][k]*b.a[k][j]+s.a[i][j])%mod;
	}
	return s;
}
rect mi(rect a,int b){
	rect s;
	s.set0();
	for(;b;b>>=1,a=a*a)
		if(b&1)s=s*a;
	return s;
}
int main(){
	cin>>n>>m;
	int cnt=1;
	t.set(0,1,2,4);
	r.set(0,1,1,1);
	r.set(1,0,1,2);
	r.set(2,1,1,2);
	R.set(0,1,0,0);
	R.set(1,0,1,2);
	R.set(2,1,0,1);
	ref(i,1,m){
		int x;cin>>x;
		if(x==1)t.set(0,1,1,3);
		else t=t*mi(r,x-cnt-1)*R;
		cnt=x;
	}
	t=t*mi(r,n-cnt);
	printf("%d\n",t.a[0][0]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define forn(i,a,b) for(int i=a; i<=b; i++)
#define ford(i,a,b) for(int i=a; i>=b; i--)
#define MOD 1000000007
using namespace std;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n,h[200000],cost[200000]={0};
	cin>>n;
	forn(i,1,n) cin>>h[i];
	cost[2]=abs(h[2]-h[1]);
	forn(i,3,n) cost[i]=min(cost[i-1]+abs(h[i]-h[i-1]),cost[i-2]+abs(h[i]-h[i-2]));
	cout<<cost[n]<<"\n";
}

Measured memory_bytes: 1408
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

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

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
	int N; cin >> N;
	map<int, LLONG> div2NumMap;
	for (int n = 2; n <= N; ++n)
	{
		int rem = n;
		int d = 2;
		while (rem > 1)
		{
			if (rem % d == 0)
			{
				++div2NumMap[d];
				rem /= d;
			}
			else
			{
				++d;
			}
		}
	}
	LLONG ans = 1;
	for (const auto &kvp : div2NumMap)
	{
		if (kvp.first != 1)
		{
			ans = ans * (kvp.second + 1);
			ans %= MOD;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <string.h>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
	int N;
	cin >> N;
	int a[N] = {};
	rep(i, N) {
		cin >> a[i];
	}
	int count = 0;
	bool exitFlag = false;
	while (1) {
		rep(i, N) {
			if (a[i] % 2 != 0) {
				exitFlag = true;
			}
			else {
				a[i] /= 2;
			}
			if (exitFlag) break;
		}
		if (exitFlag) break;
		count++;
	}

OUT:
	cout << count << endl;
}


Measured memory_bytes: 3588
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv) {
    int size;
    int degree;
    scanf("%d", &size);
    int matrix[size][size];
    
    for(int i=0;i<size;i++)
    {
        for(int j=0;j<size;j++)
        {
            matrix[i][j]=0;
        }
    }
    
    int temp, a;
    for(int i=0;i<size;i++)
    {
        scanf("%d %d",&temp, &degree);
        for(int j=0;j<degree;j++)
        {
            scanf("%d", &a);
            matrix[i][a-1]=1;
        }
    }
    
    for(int i=0;i<size;i++)
    {
        for(int j=0;j<size;j++)
        {
            if(j!=size-1)
                printf("%d ", matrix[i][j]);
            else
                printf("%d", matrix[i][j]);
        }
        printf("\n");
    }
    return (EXIT_SUCCESS);
}




Measured memory_bytes: 2112
n = input()

if n[-1] == "2" or n[-1] == "4" or n[-1] == "5" or n[-1] == "7" or n[-1] == "9":
  print("hon")
elif n[-1] == "0" or n[-1] == "1" or n[-1] == "6" or n[-1] == "8":
  print("pon")
else:
  print("bon")

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

signed main(){

  int n;
  cin>>n;

  constexpr int max_v = 1010;
  vector<vector<int>> imos(max_v,vector<int>(max_v));

  for(int i=0;i<n;++i){
    int x1,x2,y1,y2;
    cin>>x1>>y1>>x2>>y2;
    imos[y1][x1]++;
    imos[y1][x2]--;
    imos[y2][x1]--;
    imos[y2][x2]++;
  }

  for(int i=0;i<max_v;++i)for(int j=1;j<max_v;++j){
    imos[i][j] += imos[i][j-1];
  }
  for(int i=1;i<max_v;++i)for(int j=0;j<max_v;++j){
    imos[i][j] += imos[i-1][j];
  }

  int ans = 0;
  for(auto v:imos)for(auto x:v)ans = max(ans,x);

  cout<< ans <<endl;

}


Measured memory_bytes: 6824
#include<bits/stdc++.h>
using namespace std;
long long mod=1000000000+7,n,m,h,w,jie[200003],ans;
long long mi(long long x,long long t)
{
	if(t==1)
		return x;
	long long sum=mi(x,t/2);
	sum=(sum*sum)%mod;
	if(t%2==1)
		sum=(sum*x)%mod;
	return sum;
}
long long c(long long n,long long m)
{
	return (mi((jie[n-m]*jie[m])%mod,mod-2)*jie[n])%mod;
}
int main()
{
	cin>>n>>m>>h>>w;
	jie[0]=1,jie[1]=1;
	for(long long i=2; i<=200000; i++)
		jie[i]=(jie[i-1]*i)%mod;
	for(long long i=1; h+i<=n&&w+i<=m; i++)
		ans=(ans+(c(n+w-h-1,w+i-1)*c(h+m-w-1,m-w-i)%mod))%mod;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
string S[12];
string T;
int v[26];
bool used[10];
bool zero_NG[26];
int N;
int calc(int idx) {
	if (idx == T.size()) {
		int sum = 0;
		for (int i = 0; i + 1 < N; i++) {
			int t = 0;
			for (int j = 0; j < S[i].size(); j++) {
				t *= 10;
				t += v[S[i][j] - 'A'];
			}
			sum += t;
		}
		int t = 0;
		for (int i = 0; i < S[N - 1].size(); i++) {
			t *= 10;
			t += v[S[N - 1][i] - 'A'];
		}
		return t == sum;
	}
	int sum = 0;
	for (int i = 0; i < 10; i++) {
		if (i == 0 && zero_NG[T[idx] - 'A']) continue;
		if (used[i]) continue;
		used[i] = 1;
		v[T[idx] - 'A'] = i;
		sum += calc(idx + 1);
		used[i] = 0;
	}
	return sum;
}
int main() {
	while (cin >> N, N) {
		T = "";
		memset(zero_NG, 0, sizeof(zero_NG));
		for (int i = 0; i < N; i++) {
			cin >> S[i];
			T += S[i];
			if (S[i].size() > 1) {
				zero_NG[S[i][0] - 'A'] = 1;
			}
		}
		sort(T.begin(), T.end());
		T.erase(unique(T.begin(), T.end()), T.end());
		cout << calc(0) << endl;
	}
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <stack>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
 
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)
 
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;
 #define mod 998244353
int modval[25];
int arr[10];
signed main() {
 
	
	fastio();
//	#define LOCAL_DEFINE
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif	
	//https://www.coursera.org/learn/algorithms-on-strings/home/welcome
	//https://www.coursera.org/lecture/algorithms-on-strings/suffix-array-and-suffix-tree-TV4I6
	
	int n;
	cin>>n;
	int arr[n],arr1[n],arr2[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
		arr1[i]=arr[i];
		arr2[i]=arr[i];
	}
	for(int i=1;i<n;i++)
	{
		arr1[i]=max(arr1[i-1],arr1[i]);
	}
	for(int i=n-2;i>=0;i--)
	{
		arr2[i]=max(arr2[i+1],arr2[i]);
	}
	for(int i=0;i<n;i++)
	{
		if(i==0)
		{
			cout<<arr2[i+1]<<endl;
		}else if(i==(n-1))
		{
			cout<<arr1[n-2]<<endl;
		}else{
			cout<<max(arr1[i-1],arr2[i+1])<<endl;
		}
	}
	return 0;
}

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

int main() {
  int X, Y;
  cin >> X >> Y;

  int a = Y % 2;
  if (a) {
    cout << "No" << endl;
    return 0;
  }

  int minVal = X * 2;
  int maxVal = X * 4;

  if (Y < minVal || maxVal < Y) {
    cout << "No" << endl;
    return 0;
  } 

  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
	int a,b;
	cin >> a >> b;
	int ans = max(a+b, a-b);
	ans = max(ans, a*b);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(1)
	x, k, d = map(int, sys.stdin.readline().split())
	x = abs(x)
	if x == 0:
		if k % 2 == 0:
			print(0)
		else:
			print(d)
		exit()

	if x % d == 0:
		if x // d >= k:
			print(abs(x - d * k))
		else:
			if (k - x // d) % 2 == 0:
				print(0)
			else:
				print(d)
	else:
		if x // d >= k:
			print(abs(x - d * k))
		else:
			if x >= d:
				if x % d < abs(x % d - d):
					if (k - (x // d)) % 2 == 0:
						print(x % d)
					else:
						print(abs(x % d - d))
				else:
					if (k - (x // d + 1)) % 2 == 0:
						print(abs(x % d - d))
					else:
						print(x % d)
			else:
				if k % 2 == 0:
					print(x)
				else:
					if abs(x - d) < x + d:
						print(abs(x - d))
					else:
						print(x + d)




main()

Measured memory_bytes: 71756
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define REP(i,n) for (int i=0;i<(n);++i)
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n), ans(n);
    REP(i, n) cin >> a[i];
    REP(i, n) ans[i] = a[i];
    int m = *std::max_element(a.begin(), a.end());
    sort(ans.rbegin(), ans.rend());

    for(int i = 0; i < n; ++i){
        if(a[i] >= m) cout << ans[1] << endl;
        else cout << m << endl;
    }
    return 0;
}


Measured memory_bytes: 3200