akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n, m;
    std::cin >> n >> m;
    std::vector<std::deque<int>> g(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        std::cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    std::vector<i64> cnt(n + 10);
    for (int i = 0; i < n; i++) {
        int deg = g[i].size();
        if (deg % 2) {
            std::cout << "No" << std::endl;
            return 0;
        }
        cnt[deg]++;
    }

    for (int i = n; i >= 0; i--) {
        cnt[i] += cnt[i + 1];
    }

    if (cnt[6] >= 1 || cnt[4] >= 3) {
        std::cout << "Yes" << std::endl;
        return 0;
    } else if (cnt[4] <= 1) {
        std::cout << "No" << std::endl;
        return 0;
    }

    int s = 0;
    while (g[s].size() < 4) s++;
    std::deque<int> q { s };
    std::vector<int> done(n);
    done[s] = 1;
    int p = 0;
    while (!q.empty()) {
        int v = q.front();
        q.pop_front();
        for (int to : g[v]) {
            if (to != s && g[to].size() == 4) { p++; continue; }
            if (done[to]) continue;
            done[to] = 1;
            q.push_back(to);
        }
    }
    std::cout << (p == 4 ? "No" : "Yes") << std::endl;

    return 0;
}


Measured memory_bytes: 68608
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char ch[1111];
int i,j,k,n,m,t1,t2,t4,a[31],w;
bool check(){
	int i,j,k;
	for (i=1;i<=w;i++)
	 if (a[i]&1) a[i]--,t1--;
	if (t1) return 0;
	for (i=1;i<=w;i++)
	 if (a[i]%4) a[i]-=2,t2--;
	if (t2<0||(t2&1)) return 0;
	return 1;
}
int main(){
	scanf("%d%d",&n,&m);memset(a,0,sizeof(a));w=26;
	for (i=1;i<=n;i++){
		scanf("%s",ch);
		for (j=0;j<m;j++) a[ch[j]-'a'+1]++;
	}
	t1=t2=t4=0;
	for (i=1;i<=n;i++)
	 for (j=1;j<=m;j++){
	 	k=((n-i+1==i)?1:0)+((m-j+1==j)?1:0);
	 	if (!k) t4++;
	 	if (k==1) t2++;
	 	if (k==2) t1++;
	 }
	t2/=2;t4/=4;
	puts(check()?"Yes":"No");
	return 0;
}

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

#define N 444

int n, a[N], b[N];
const int mod = 998244353;

int fac[N], ri[N], rfac[N];
int dp[N][N];

inline void sub(int &x, long long y) {
    x = (x - y) % mod;
    if (x < 0) x += mod;
}

int main() {
    fac[0] = rfac[0] = ri[1] = 1;
    for (int i = 1; i < N; i ++) {
        fac[i] = 1ll * i * fac[i-1] % mod;
        if (i > 1) ri[i] = 1ll * (mod - mod / i) * ri[mod%i] % mod;
        rfac[i] = 1ll * ri[i] * rfac[i-1] % mod;
    }
    scanf("%d", &n);
    int S = 0;
    for (int i = 0; i < n; i ++) scanf("%d %d", &a[i], &b[i]), S += a[i];
    dp[0][0] = mod - 1;
    int asum = 0, bsum = 0;
    for (int i = 0; i < n; i ++) {
        for (int as = asum; ~as; as --) {
            for (int bs = 0; bs <= bsum; bs ++) if (dp[as][bs]) {
                int pw = 1;
                for (int j = 0; j < b[i]; j ++) {
                    sub(dp[as+a[i]][bs+j], 1ll * dp[as][bs] * pw % mod * rfac[j]);
                    pw = 1ll * pw * a[i] % mod;
                }

            }
        }
        asum += a[i], bsum += b[i] - 1;
    }
    int ans = 0;
    for (int as = 1; as <= asum; as ++) {
        int pw = ri[as];
        for (int bs = 0; bs <= bsum; bs ++) {
            ans = (ans + 1ll * fac[bs] * pw % mod * dp[as][bs]) % mod;
            pw = 1ll * pw * ri[as] % mod;
        }
    }
    printf("%d\n", 1ll * ans * S % mod);
}


Measured memory_bytes: 896
#include <stdio.h>
#define MAX 987654321
int V, E, A[15][15], MEMO[15][32768], VISIT[15][32768];
void input(void);
void init_A(void);
void init_MEMO(void);
int DP(int origin, int dest, int VIA);
int TSP(void);
int main(void) {
    //freopen("in.txt", "r", stdin);
    input();
    printf("%d\n", TSP());
    return 0;
}
int TSP(void){
    int i, VIA_init, min = MAX;
    for(i = 0; i < V; i++){
        init_MEMO();
        VIA_init = (1 << V) - 1 & ~(1 << i);
        int cnd = DP(i, i, VIA_init);
        if (cnd < min) min = cnd;
    }
    if (min >= MAX)
        return -1;
    else
        return min;
}
int DP(int origin, int dest, int VIA){ // single source memoization
    if(VIA == 0){
        if (A[origin][dest] != -1) return A[origin][dest];
        else return MAX;
    }
    if(VISIT[dest][VIA] == 1) return MEMO[dest][VIA];
    VISIT[dest][VIA] = 1;
    int i, min = MAX;
    for (i = 0; i < V; i++){
        if (A[i][dest] != -1 && (VIA & (1 << i)) != 0){
            int cnd = A[i][dest] + DP(origin, i, VIA & ~(1 << i));
            if (cnd < min) min = cnd;
        }
    }
    MEMO[dest][VIA] = min;
    return min;
}
/*
int DP(int dest, int VIA){ // single source backward tracking
    if(VIA == 0) return A[0][dest];
    int i, min = MAX;
    for (i = 1; i < V; i++){
        if (A[i][dest] != -1 && (VIA & (1 << i)) != 0){
            int cnd = A[i][dest] + DP(i, VIA & ~(1 << i));
            if (cnd < min) min = cnd;
        }
    }
    return min;
}*/
void input(void){
    scanf("%d%d", &V, &E);
    init_A();
    int i, s, t, d;
    for(i = 0; i < E; i++){
        scanf("%d%d%d", &s, &t, &d);
        A[s][t] = d;
    }
}
void init_A(void){
    int i, j;
    for(i = 0; i < V; i++)
        for(j = 0; j < V; j++) A[i][j] = -1;
}
void init_MEMO(void){
    int i, j;
    for(i = 0; i < V; i++){
        for(j = 0; j < (1<<V); j++){
            MEMO[i][j] = 0;
            VISIT[i][j] = 0;
        }
    }
}

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


#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

ll a[N], n, sum;
map < ll, int > u;
vector < int > g[N];
vector < pair < int, int > > edges; 
int cur = 1;
int l[N];
int c[N];
bool cmp (int x,int y) { return a[x] > a[y];}
void dfs (int v, int pr = 0, int dep = 0) {
    //cout << v << '\n';
    sum += dep;
    for (auto to : g[v]) {
        if (to == pr) continue;
        dfs (to, v, dep + 1);
    }
}

int main () { 
    cin >> n;
    For (i, 1, n) {
        cin >> a[i];
        u[a[i]] = i;
        if (a[i] > a[cur]) cur = i;
        l[i] = 1;
        c[i] = i;
    }
    
    sort(c + 1, c + n + 1, &cmp);
    
    For (x, 1, n - 1) {
        int i = c[x];
        //cout << i << ' ' << l[i] << '\n';
        ll dis = a[i] - (n - l[i]) + l[i];
        if (!u.count(dis)) {
            //cout << n << ' ' << l[i] << '\n'; 
            //cout << i << ' ' << dis << '\n';
            puts("-1");
            exit(0);
        }
        if (i == u[dis]) {
            //cout << u[dis] << ' ' << dis << '\n';
            puts("-1");
            exit(0);
        
        }
        int j = u[dis];
		l[j] += l[i];
		edges.pb(mp(i, j));
		g[j].push_back(i);
	}
	cur = c[n];
    dfs(cur);
    if (sum != a[c[n]]) {
        //cout << sum << ' ' << a[c[n]] << '\n';
        puts("-1");
        exit(0);
    }
    
    for (auto it : edges) {
        cout << it.F << ' ' << it.S << '\n';
    }
    return Accepted;
}

// Coded By OB

Measured memory_bytes: 32756
class SegTree:
    """
    内部実装1-indexed．
    set_valやfoldには0-indexedでアクセス．
    2べきに直さなくてよい．
    Range Sum Query．
    X_unit 0 X_f sum
    """
    from operator import add
    X_unit = 0
    X_f = add

    def __init__(self, N):
        self.N = N
        self.X = [self.X_unit] * (N + N)

    def build(self, seq):
        for i, x in enumerate(seq, self.N):
            self.X[i] = x
        for i in range(self.N - 1, 0, -1):
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def set_val(self, i, x):
        i += self.N
        self.X[i] += x
        while i > 1:
            i >>= 1
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def fold(self, L, R):
        L += self.N
        R += self.N
        vL = self.X_unit
        vR = self.X_unit
        while L < R:
            if L & 1:
                vL = self.X_f(vL, self.X[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.X_f(self.X[R], vR)
            L >>= 1
            R >>= 1
        return self.X_f(vL, vR)


def main():
    N, Q = (int(i) for i in input().split())
    seg = SegTree(N)
    for _ in range(Q):
        com, x, y = (int(i) for i in input().split())
        if com == 0:
            seg.set_val(x-1, y)
        else:
            print(seg.fold(x-1, y))


if __name__ == '__main__':
    main()



Measured memory_bytes: 10288
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ans = 0;
		int[] b = new int[n-1];
		for(int i = 0; i < n-1; i++) {
			b[i] = sc.nextInt();
		}
		for(int i = 0; i < n; i++) {
			if(i==0) {
				ans += b[i];
			}
			else if(i==n-1) {
				ans+=b[i-1];
			}
			else {
				ans += Math.min(b[i-1], b[i]);
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main (){
  int N;
   cin >>N;
  vector<int>data(N);
  for (int i=0 ; i<N; i++){
  cin >>data.at(i);
  }
  data.at(0)-=1;
  for (int i=0;i<N-1;i++){
      if (data.at(i+1)-data.at(i)>0){
        data.at(i+1)-=1;
        }
  }
  vector<int>data1(N);
  data1=data;
  sort(data1.begin(),data1.end());
  if (data==data1){
  cout <<"Yes"<<endl;
  }
  else{
   cout <<"No"<<endl;
  }
}
      
  


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int query(int y1, int x1, int y2, int x2)
{
    int ans;
    cout << "? " << y1 << ' ' << x1 << ' ' << y2 << ' ' << x2 << endl;
    cin >> ans;
    return ans;
}

void solve(int y1, int x1, int y2, int x2, int n, vector<vector<bool> >& isBomb)
{
    if(n == 0)
        return;
    if(n == -1)
        n = query(y1, x1, y2, x2);

    int h = y2 - y1 + 1;
    int w = x2 - x1 + 1;
    if(h * w == n){
        for(int y=y1; y<=y2; ++y){
            for(int x=x1; x<=x2; ++x){
                isBomb[y][x] = true;
            }
        }
        return;
    }

    if(h > w){
        int y3 = y1 + h / 2;
        int m = query(y1, x1, y3 - 1, x2);
        solve(y1, x1, y3 - 1, x2, m, isBomb);
        solve(y3, x1, y2, x2, n - m, isBomb);
    }
    else{
        int x3 = x1 + w / 2;
        int m = query(y1, x1, y2, x3 - 1);
        solve(y1, x1, y2, x3 - 1, m, isBomb);
        solve(y1, x3, y2, x2, n - m, isBomb);
    }
}

const int SIZE = 4;

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

    vector<vector<bool> > isBomb(h, vector<bool>(w, false));
    for(int y=0; y<h; y+=SIZE){
        for(int x=0; x<w; x+=SIZE){
            int y2 = min(y + SIZE, h) - 1;
            int x2 = min(x + SIZE, w) - 1;
            solve(y, x, y2, x2, -1, isBomb);
        }
    }

    long long ans = 0;
    long long tmp = 1;
    for(int y=0; y<h; ++y){
        for(int x=0; x<w; ++x){
            if(isBomb[y][x]){
                ans += tmp;
                ans %= k;
            }
            tmp *= 2;
            tmp %= k;
        }
    }
    cout << "! " << ans << endl;

    return 0;
}


Measured memory_bytes: 724
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<string>
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  for (int i=0; i<N; i++) cin >> p[i];
  
  int cnt = 0;
  for (int i=1; i<N-1; i++) {
    if (p[i] < p[i+1] && p[i] > p[i-1] || p[i] < p[i-1] && p[i] > p[i+1]) cnt++;
  }
  cout << cnt << endl;
}
  

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

using namespace std;


#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),v).end()

#define PB(a) push_back(a)
#define MOD 1000000007

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

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

  int n;cin>>n;
  for(int j=0;j<n;j++){
      std::vector<int> v(3);
      for(int i=0;i<3;i++) cin>>v[i];
      sort(v.begin(),v.end());
      if(v[0]*v[0]+v[1]*v[1]==v[2]*v[2]) cout<<"YES"<<endl;
      else cout<<"NO"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3132
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::HashMap;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_variables)]
        #[allow(unused_mut)]
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, string).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, string).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("parse error")
    };
}

fn main() {
    input!{
        n: usize,
        w: i64,
        nap: [(i64, usize); n]
    }
    let mut max_value = 0;
    let mut dp = vec![vec![std::i64::MAX; 1001*100]; n + 1];
    dp[0][0] = 0;
    for i in 1..n+1 {
        let (weight, value) = nap[i-1];
        for j in 0..1001*100 {
            let new_weight = if value > j { dp[i - 1][j] } else { cmp::min(dp[i - 1][j], if dp[i - 1][j - value] == std::i64::MAX {dp[i - 1][j - value]} else {dp[i - 1][j - value] + weight} )};
            if new_weight <= w { max_value = cmp::max(max_value, j) };
            dp[i][j] = new_weight;
        }
    }
    println!("{}", max_value);
}


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

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> cnt(M, 0);
    for (int i = 0; i < N; i++) {
        int K;
        cin >> K;
        for (int j = 0; j < K; ++j) {
            int A;
            cin >> A;
            A--;
            cnt[A]++;
        }
    }
    int ans = 0;
    for (int i = 0; i < M; ++i) {
        if (cnt[i] == N) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

ans = 0

for i in range(1, n-1):
    if p[i-1] < p[i] < p[i+1]:
        ans += 1
    elif p[i+1] < p[i] < p[i-1]:
        ans += 1

print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

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

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

int main() {
	int a,b,c,x,y;cin>>a>>b>>c>>x>>y;
	int ans[3];
	ans[0]=2*max(x,y)*c;
	ans[1]=a*x+b*y;
	ans[2]=2*min(x,y)*c;
	if(x>=y) ans[2]+=a*(x-y);
	else ans[2]+=b*(y-x);
	sort(ans,ans+3);
	cout<<ans[0]<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main(){

string s,t;
int a,b;
string u;
cin>>s>>t>>a>>b>>u;

if(u==s){
    a--;
}
else if(u==t){
    b--;
}
cout<<a<<" "<<b;



return 0;
}

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

int main(){
  vector<vector<int>> c(3,vector<int>(3));
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3;j++){
      cin >> c.at(i).at(j);
    }
  }
  //行ごとの最小値を求める
  int min_c1 = min(c.at(0).at(0),min(c.at(0).at(1),c.at(0).at(2)));
  int min_c2 = min(c.at(1).at(0),min(c.at(1).at(1),c.at(1).at(2)));
  int min_c3 = min(c.at(2).at(0),min(c.at(2).at(1),c.at(2).at(2)));
  bool ans = false;
  for(int i = 0; i <= min_c1;i++){
    for(int j = 0; j <= min_c2;j++){
      for(int k = 0;k <= min_c3;k++){
        int b1 = c.at(0).at(0) - i;
        int b2 = c.at(0).at(1) - i;
        int b3 = c.at(0).at(2) - i;
        if((i + b1) != c.at(0).at(0))continue;
        if((i + b2) != c.at(0).at(1))continue;
        if((i + b3) != c.at(0).at(2))continue;
        if((j + b1) != c.at(1).at(0))continue;
        if((j + b2) != c.at(1).at(1))continue;
        if((j + b3) != c.at(1).at(2))continue;
        if((k + b1) != c.at(2).at(0))continue;
        if((k + b2) != c.at(2).at(1))continue;
        if((k + b3) != c.at(2).at(2))continue;
        ans = true;
      }
    }
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		if(a==5 || a==3 || a==7){
			System.out.println("YES");
			return;
		}
		System.out.println("NO");
	}
}

Measured memory_bytes: 23124
#coding:utf-8
from collections import Counter
N = int(input())
ls = []
for n in range(N):
    ls.append("".join(sorted(input())))
#print (ls)
cnt = Counter(ls)
#print (list(cnt.values()))
ans = [i*(i-1)/2 for i in list(cnt.values())]
print (int(sum(ans)))

Measured memory_bytes: 20520
#include <iostream>

int main(){
   int N, K;
   std::cin >> N >> K;

   int ans = 1;
   for(int i=0; i<N; ++i){
      if(ans<K) ans *= 2;
      else ans += K;
   }
   std::cout << ans << std::endl;
   return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
char s[50 + 5], t[50 + 5];

int main() {
	scanf("%s%s", s, t);
	int L = strlen(s), l = strlen(t);
	int test = 0;
	for (int i = L - 1;i >= l - 1;i--) {
		for (int j = 0;j < l;j++) {
			if (s[i - j] == '?')continue;
			if (s[i - j] != t[l - 1 - j])goto A;
		}
		test = 1;
		for (int j = 0;j < l;j++)s[i - j] = t[l - 1 - j];
		break;
	A:continue;
	}
	if (test) {
		for (int i = 0;i < L;i++)if (s[i] == '?')s[i] = 'a';
		printf("%s", s);
	}
	else printf("UNRESTORABLE");
	return 0;
}

Measured memory_bytes: 128
def solve():
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    diff_0_1 = A[0] - A[1]
    A[1] += diff_0_1
    A[2] += diff_0_1
    cnt = diff_0_1

    diff_0_2 = A[0] - A[2]
    if diff_0_2 % 2 == 0:
        cnt += diff_0_2 // 2
    else:
        cnt += diff_0_2 // 2 + 1 + 1
    
    print(cnt)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3064
// ABC142 C

#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

using namespace std;

int const MAXN = 1e5 + 5;
int a[MAXN], b[MAXN];

int main() {
  
  int n; cin >> n;
  for (RI i = 1; i <= n; ++i)
    cin >> a[i], b[a[i]] = i;
  for (RI i = 1; i <= n; ++i)
    cout << b[i] << " ";

  return 0;
}

// created by Daniel yuan


Measured memory_bytes: 1536
#include <stdio.h>
 
int a[] = {500, 100, 50, 10, 5, 1};
int main() {
    int n, tmp, ans;
    while(scanf("%d", &n) && n != 0) {
        ans = 0;
        tmp = 1000 - n;
        for(int i=0; i<6; i++) {
            ans += tmp / a[i];
            tmp %= a[i];
        }
        printf("%d\n", ans);
    }
}



Measured memory_bytes: 2100
S=input()
T=input()

lt=len(T)
ls=len(S)
S+='%'*lt

if ls<lt:
    flg=0
else:
    for i in range(ls-lt+1,-1,-1):
        # print('***',S[i:i+lt])
        flg=1
        for j in range(i,i+lt):
            s=S[j]
            # print(s,T[j-i])
            if s=='?': continue
            if s=='%' or s!=T[j-i]:
                flg=0
                break
        if flg==1:
            break
if flg:
    print((S[0:i]+T+S[i+lt:ls]).replace('?','a'))
else:
    print('UNRESTORABLE')

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

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var temp = ReadLine();
            var A = temp[0];
            var B = temp[1];

            var C = A - B * 2;

            if (C < 0)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(C);
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 11220
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			String s = sc.next();
			int l = s.length();
			String t = "";
			int k = 0;
			boolean flag = false;
			for(int i = 0; i < l; i++) {
				if(s.charAt(i) == '@') {
					flag = true;
				}else {
					if(flag) {
						if(k == 0) {
							k = s.charAt(i) - '0';
						}else {
							for(int j = 0; j < k; j++) {
								t += s.charAt(i);
							}
							k = 0;
							flag = false;
						}
					}else {
						t += s.charAt(i);
					}
				}
			}
			System.out.println(t);
		}
		sc.close();
	}
}


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


public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] s = br.readLine().split(" ");
        int[] a = new int[n];
        
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(s[i]);
        }
        
        int count = 0;
        for (int i = 0; i < n; i++) {
            while (a[i]%2 == 0) {
                a[i] /= 2;
                count++;
            }
        }
        System.out.println(count);
    }
}





Measured memory_bytes: 26836
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  vector<int> B(N);
  REP(i, N) cin >> B[i];

  vector<int> C(N);
  REP(i, N) cin >> C[i];

  sort(ALL(A));
  sort(ALL(C));

  int ans = 0;
  REP(i, N){
    int left = lower_bound(ALL(A), B[i])-A.begin();
    int right = C.end()-upper_bound(ALL(C), B[i]);
    ans += right*left;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 2560
import sys

def generate_next_hexes(x, y):
    hexes = [(x, y - 1), (x, y + 1), (x - 1, y), (x + 1, y)]
    if y % 2:
        hexes += [(x - 1, y - 1), (x - 1, y + 1)]
    else:
        hexes += [(x + 1, y - 1), (x + 1, y + 1)]
    return hexes

def update_map(hex_map, hexes):
    num_updated_hexes = 0
    distance = 0
    while hexes:
        next_hexes = []
        for pos in hexes:
            if (1 <= pos[0] <= m and 1 <= pos[1] <= n) and (pos not in hex_map or distance < hex_map[pos]):
                hex_map[pos] = distance
                num_updated_hexes += 1
                next_hexes += generate_next_hexes(pos[0], pos[1])
        distance += 1
        hexes = next_hexes
    return num_updated_hexes

while True:
    (m, n) = [int(i) for i in sys.stdin.readline().split()]
    if m == n == 0:
        break

    s = int(sys.stdin.readline())
    stores = []
    for i in range(s):
        pos = [int(j) for j in sys.stdin.readline().split()]
        stores.append(tuple(pos))
    hex_map = {}
    update_map(hex_map, stores)

    t = int(sys.stdin.readline())
    candidates = []
    for i in range(t):
        pos = [int(j) for j in sys.stdin.readline().split()]
        candidates.append(tuple(pos))

    max_num_blocks = 0
    for candidate in candidates:
        new_hex_map = hex_map.copy()
        num_blocks = update_map(new_hex_map, [candidate])
        max_num_blocks = max(max_num_blocks, num_blocks)

    print(max_num_blocks)

Measured memory_bytes: 7036
#!/usr/bin/env python3
import sys


def solve(S: int, W: int):
    print("safe" if S > W else "unsafe")
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    solve(S, W)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9104
# C - When I hit my pocket...

K, A, B = map(int, input().split())

if B - A <= 2:
    print(1 + K)
else:
    n_change = (K-(A-1)) // 2
    if n_change == 0:
        print(1 + K)
    else:
        print(n_change * B - (n_change-1) * A + (K - 2*n_change - (A-1)))

Measured memory_bytes: 2940
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int               long long
#define ff                first
#define ss                second
#define md                1000000007
#define md1               998244353
#define inf               1000000000000000
#define minf              -1000000000000000
#define pb                push_back
#define in                insert
#define mkp               make_pair
#define mpll              map<ll,ll>
#define len(p)            (ll)p.size()
#define pll               pair<ll,ll>
#define all(v)            v.begin(),v.end()
#define mem(a,t)          memset(a,t,sizeof(a))
#define endl              "\n"
#define ar                array
#define vl                vector<ll>
#define vpll              vector<pair<ll,ll>>
#define f(i,yha,wha)      for(ll i=yha;i<wha;i++)
#define rf(i,wha,yha)     for(ll i=wha;i>=yha;i--)
#define f0(n)             for(ll i=0;i<n;i++)
#define f1(n)             for(ll i=1;i<=n;i++)
#define fg(i,yha,wha,gap) for(ll i=yha;i<wha;i+=gap)


void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
ll pw(ll x, ll y)
{
    if (y == 0)
        return 1;
    if (y == 1)
        return x;
    ll ans = pw(x, y / 2);
    ans = ans * ans;
    if (y % 2 == 1)
        ans = ans * x;
    return ans;
}






void solve()
{
    ll x;
    cin >> x;
    ll b = 1;

    while (1)
    {
        ll tp = pw(b, 5);
        ll ta = x + tp;
        ll a = pow(ta, 0.2);
        if (pw(a, 5) == ta)
        {
            cout << a << " " << b << endl;
            return;
        }
        if (tp > x)
        {
            b++;
            continue;
        }
        ta = x - tp;
        a = pow(ta, 0.2);
        if (pw(a, 5) == ta)
        {
            b = -b;
            cout << a << " " << b << endl;
            return;
        }
        b++;
    }


}

int32_t main()
{
    flash();
    int t;
    t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 4080
#include <bits/stdc++.h>
using namespace std;
int main(){
  int sum,A,B,C,D;
  cin >> A >> B >> C >> D;
  if (A>B)
    sum += B;
  else
    sum += A;
  if (C>D)
    sum += D;
  else
    sum += C;
  cout << sum <<"\n";
}

Measured memory_bytes: 256
def main()->None:
    H, W = map(int, input().split())
    range_H = range(H)
    range_W = range(W)
    src = [input() for _ in range_H]
    #print(src)
    ans = [["." for _ in range_W] for _ in range_H]
    # 周囲4マスの探索するときの配列の場所指定の配列
    dxdy = [(-1,0),(0,-1),(0,1),(1,0)]
    # x, yで配列の位置を指定
    for y in range_H:
        for x in range_W:
            c = "."
            if src[y][x] == ".":continue
            for dx, dy in dxdy: # 周囲８マスを探索
                if x+dx < 0 or x+dx > W-1 or y+dy < 0 or y+dy > H-1 :continue
                if src[y+dy][x+dx] == "#": #周囲に黒マスがあれば対象の黒マスは黒くしていい
                    c = "#"
            ans[y][x] = c
    #print(ans)
    flag = True
    counter = 0
    for i in ans:
        res = "".join(i)
        if res == src[counter]:
            counter += 1
        else:
            flag = False
    if flag: print("Yes")
    else: print("No")



if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<stack>
#include<cstdlib>
#include<cstdio>

using namespace std;

stack<int> st;
int solve(string);
int main(){
    string str;
    while(cin >>str){
        if(str == "+" || str == "-" || str == "*" || str == "/")
            st.push(solve(str));
        else st.push(atoi(str.c_str()));
        if(getchar()=='\n'){
            cout << st.top() << endl;
            return 0;
        }
    }
}

int solve(string str){
    int b = st.top(); st.pop();
    int a = st.top(); st.pop();
    if(str=="+")return a + b;
    else if(str=="-")return a - b;
    else if(str=="*")return a * b;
    else if(str=="/")return a / b;
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i< (n);i++)
#define rep1(i,n) for(int i=1;i<= (n);i++)
using namespace std;
typedef long long ll;
const static ll MOD = (1e+9)+7;

int main(){
    int N,K,C;cin>>N>>K>>C;
    string S;cin>>S;
    vector<int> left(N,-1);
    vector<int> right(N,-1);
    int before = -1;
    int cnt = 0;
    for(int i=0;i<N;i++){
        if(S[i] == 'o'){
            if(before == -1 || i > before+C){
                left[i] = ++cnt;
                before = i;
            }
        }
    }
    if(cnt > K)return 0;
    before = N;
    for(int i=N-1;i>=0;i--){
        if(S[i] == 'o'){
            if(before == N || i < before-C){
                right[i] = cnt--;
                before = i;
            }
        }
    }
    rep(i,N){
        if(left[i] == right[i] && left[i]!=-1){
            cout<<(i+1)<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3332
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <set>

using namespace std;

class Event {
  public:
    int t;
    int x;
    bool is_addition;
    Event(int _t, int _x, bool _is_addition) { t = _t; x = _x; is_addition = _is_addition; }
};

bool has_smaller_t(const Event& a, const Event& b)
{
  return a.t < b.t;
}

int main()
{
  int nstop, npeople;
  cin >> nstop >> npeople;
  vector<Event> event;
  for (int i = 0; i < nstop; i++) {
    int begin, end, x;
    cin >> begin >> end >> x;
    event.emplace_back(begin-x, x, true);
    event.emplace_back(end-x, x, false);
  }
  stable_sort(event.begin(), event.end(), has_smaller_t);
  set<int> stop;
  int index = 0;
  for (int i = 0; i < npeople; i++) {
    int person;
    cin >> person;
    while (index < (int)event.size() && event.at(index).t <= person) {
      if (event.at(index).is_addition) {
        stop.insert(event.at(index).x);
      } else {
        stop.erase(event.at(index).x);
      }
      index++;
    }
    if (stop.empty()) {
      cout << "-1\n";
    } else {
      cout << *stop.begin() << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 15388
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n,z;
  cin>>n;
  vector<bool>a(1000000000,false);
  for(int i=0;i<n;i++){
    cin>>z;
    if(a[z-1]){
      cout<<"NO"<<endl;
      return 0;
    }else{
      a[z-1]=true;
    }
  }
  cout<<"YES"<<endl;
}

Measured memory_bytes: 122368
n = int(input())
a, b = map(int, input().split())
c, d = map(int, input().split())


def get_dist(w, a, b):
    return sum(map(lambda x, y: abs(x - y), divmod(a, w), divmod(b, w)))


print(min(get_dist(w, a - 1, b - 1) + get_dist(w, c - 1, d - 1) for w in range(1, n + 1)))

Measured memory_bytes: 7736
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;


// 68 11 55 - rank 3
// 69 12 19 - rank 3
// 70 12 34 - rank 100
// 71 12 58 - rank 4
// 72 13 24 - rank 20
// 73 13 39

ull gcd(ull a, ull b) {
    while (b != 0) {
        auto na = a % b;
        a = b;
        b = na;
    }
    return a;
}


void oneCase() {
    int n, m, r;
    cin >> n >> m >> r;
    vector<int> p(r);
    for (auto& el : p) {
        cin >> el;
        --el;
    }
    sort(p.begin(), p.end());
    vector<vector<ll>> dist(n, vector<ll>(n, 1e18));
    for (int i = 0; i < m; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        --a;
        --b;
        dist[a][b] = c;
        dist[b][a] = c;
    }
    for (int i = 0; i < n; ++i) {
        dist[i][i] = 0;
    }
    for (int k = 0; k < n; ++k) {
        for (int left = 0; left < n; ++left) {
            for (int right = 0; right < n; ++right) {
                dist[left][right] = min(dist[left][right], dist[left][k] + dist[k][right]);
            }
        }
    }

    ll best = 1e18;
    do {
        ll cur = 0;
        for (int i = 1; i < r; ++i) {
            cur += dist[p[i]][p[i - 1]];
        }
        best = min(best, cur);
    } while (std::next_permutation(p.begin(), p.end()));

    cout << best << "\n";
}


int main() {
    int t = 1;
//    cin >> t;
    while (t--) {
       oneCase();
    }

    return 0;
}

ll fact(ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        res = (res * n) % mod;
        --n;
    }
    return res;
}


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

int main(){
    string s; cin >> s;

    int big = 0;
    int ans = 0;
    for(int i=0; i<3; i++){
        if(s[i] == 'R'){
            big++;
        }else{
            ans = max(ans , big);
            big = 0;
        }
    }

    ans = max(ans , big);

    cout << ans << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
//#define P pair<ll, ll>
#define dvec vector<vector<ll>>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;}
template<class T> inline bool chmin(T& a, T b){if (a > b) { a = b; return true; } return false;}
ll INF = 1e+18;
int iINF = 1e9;


ll
calc(dvec arr, int N, int M, bool plus)
{
  ll bet = 0;
  ll del = 0;
  ll pop = 0;
  if(plus){
    rep(i, 0, M){
      bet += arr[i][0];
      del += arr[i][1];
      pop += arr[i][2];
    }

  } else {
    for(ll i = N - 1; i >= N - M; --i){
      bet += arr[i][0];
      del += arr[i][1];
      pop += arr[i][2];
    }
  }

  return abs(bet) + abs(del) + abs(pop);

}

int main()
{
  int N, M; cin >> N >> M;
  vector<vector<ll>> arr(N);
  rep(i, 0, N){
    ll x, y, z; cin >> x >> y >> z;
    arr[i].push_back(x);
    arr[i].push_back(y);
    arr[i].push_back(z);
  }
  

  ll ans = 0;
  for(ll bit = 0; bit < (1 << 3); ++bit){
    vector<ll> comp(N, 0);
    rep(i, 0, N){
      rep(k, 0, 3){
        if(bit & (1 << k)) comp[i] += arr[i][k];
        else comp[i] += -arr[i][k];
      }
    }

    ll sum = 0;
    sort(comp.begin(), comp.end(), greater<ll>());
    rep(i, 0, M){
      sum += comp[i];
    }
    if(ans < sum) ans = sum;
  }

  cout << ans << endl;

}


Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
const ll mod = 1e9+7;
const int N = 3e5;
int cx[N];
int cy[N];
int visx[N],visy[N];
int ccx[N],ccy[N];
int px[N],py[N];
void solve(){
    int h,w,m;
    cin>>h>>w>>m;
    for(int i=1;i<=m;i++){
        cin>>px[i]>>py[i];
        cx[px[i]]++;
        cy[py[i]]++;
    }
    int mx = 0,my = 0;
    int cnt = 0;
    for(int i=1;i<=h;i++)mx = max(mx,cx[i]);
    for(int i=1;i<=w;i++)my = max(my,cy[i]);
    for(int i=1;i<=h;i++){
        if(cx[i]==mx)visx[i]++;
    }
    for(int i=1;i<=w;i++){
        if(cy[i]==my){
            visy[i]++;
            cnt++;
        }
    }
    for(int i=1;i<=m;i++){
        if(visy[py[i]])ccx[px[i]]++;
    }
    int ans = mx+my-1;
    for(int i=1;i<=h;i++){
        if(visx[i] and ccx[i]<cnt)ans = max(ans,mx+my);
    }
    cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 11768
#include <iostream>
#define MOD 1000000007
using namespace std;
using ull = unsigned long long;

ull f(ull n){
    ull ans = 1;
    for(ull i = 1; i <= n; ++i){
        ans = ans * i % MOD;
    }
    return ans;
}


int main(){
    ull N, M;
    cin >> N >> M;
    
    if(N < M){
        ull temp = N;
        N = M;
        M = temp;
    }

    ull ans;
    if(N - M >= 2){
        cout << 0 << endl;
        return 0;
    }else if(N - M == 0){
        ans = 2 * (f(N) * f(N) % MOD) % MOD;
    }else{
        ans = f(N) * f(N-1) % MOD;
    }
    
    cout << ans << endl;

    return 0;
    
}


Measured memory_bytes: 256
local n = io.read("*n")
local a = {}
for i = 1, n do a[i] = io.read("*n") end
local cnt = 0
for i = 1, n - 1 do
  if(i < a[i] and a[a[i]] == i) then
    cnt = cnt + 1
  end
end
print(cnt)


Measured memory_bytes: 2424
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
long double pi=3.14159265358979323846L;
double eps=1e-12;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll popcount(ll n){
    ll ret=0;
    while(n>0){
        ret+=n%2;
        n/=2;
    }
    return ret;
}
ll gya[1000010];
ll kai[1000010];
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll n,T;cin>>n>>T;
    ll t[n];
    cin>>t[0];
    ll now=T;
    ll ans=0;
    ll mae=0;
    rep(i,1,n){
        cin>>t[i];
        if(t[i]<=now)now=t[i]+T;
        else{
            ans+=now-mae;
            mae=t[i];
            now=t[i]+T;
        }
    }
    ans+=now-mae;
    cout<<ans<<endl;
}


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

void solve(long long N, vector<long long> A){
	sort(A.begin(), A.end());
  reverse(A.begin(), A.end());

  long long a = 0, b = 0;
  for ( long long i = 0; i < A.size() - 1; i++ ) {
    if (A[i] == A[i+1]) {
      if (a == 0) {
        a = A[i];
        i += 1;
      } else {
        b = A[i];
        break;
      }
    }
  }
  cout << a * b << endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> A(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A[i]);
	}
	solve(N, A);
	return 0;
}



Measured memory_bytes: 1792
import java.util.*;

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

      int n = Integer.parseInt(sc.next());

      int[][] c = new int[n][2];
      for(int i=0;i<n;i++){
        c[i][0] = i+1;
        c[i][1] = Integer.parseInt(sc.next());
      }

      Arrays.sort(c, (a, b)->a[1]-b[1]);

      for(int i=0;i<n;i++){
        System.out.println(c[i][0]);
      }



    }
}


Measured memory_bytes: 52724
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  string ans = "Yes";
  while(a > 0 && c > 0){
    c = c - b;
    if(c <= 0){
      break;
    }
    a = a - d;
    if(a <= 0){
      ans = "No";
    }
    
  }
  cout << ans;
}

Measured memory_bytes: 3576
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if (i + j) % 2 == 0:
                print("#", end = '')
            else:
                print(".", end = '')
        print()
    print()


Measured memory_bytes: 7000
function Main(input) {
  input = input.split(" ").map(Number);
var A = input[0];
var B = input[1];
if( A > B ){
console.log("a > b")
}else if(A < B){
console.log("a < b")
}else{
console.log("a == b")
}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
  ll n,m=0;cin>>n;
  vector<ll> a(n+1,0);
  vector<ll> ball(n+1,0);//入れる個数
  vector<ll> ans(0);

  rep(i,n)cin>>a[i+1];

  for(int i=n;0<i;i--)
  {
    ll cnt=1,sum=0;
    while(cnt*i<=n){
      sum^=ball[i*cnt];
      cnt++;
    }
    
    if(sum!=a[i]){
      m++;
      ball[i]^=1;
      ans.pb(i);
    }
  }
  cout<<m<<endl;
  rep(i,m)cout<<ans[i]<<" ";
  cout<<endl;
}


Measured memory_bytes: 4980
#include <iostream>
using namespace std;
int main(){
	int a, b, c, x = 0, y = 0;
	char t;
	while(cin >> a >> t >> b >> t >> c){
		if(a*a + b*b == c*c) x++;
		if(a == b) y++;
	}
	cout << x << endl << y << endl;
	return 0;
}

Measured memory_bytes: 1160
import math

n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

sum1 = 0
sum2 = 0
sum3 = 0
inf = 0
for i in range(n):
    tmp = abs(x[i] - y[i])
    sum1 += tmp
    sum2 += tmp ** 2
    sum3 += tmp ** 3
    inf = max(inf, tmp)
print("{:.6f}".format(sum1))
print("{:.6f}".format(sum2 ** (1 / 2)))
print("{:.6f}".format(sum3 ** (1 / 3)))
print("{:.6f}".format(inf))




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

int main() {
  int K, S;
  cin >> K >> S;
  
  int res = 0;
  
  for (int x = 0; x <= K; ++x) {
    for (int y = 0; y <= K; ++y) {
      int z = S - x - y;
        if (0 <= z && z <= K) ++res;
    }
  }
  
  cout << res << endl;
  
  return 0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i > 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  double b = 0;
  REP(i, n) {
    double tmp;
    cin >> tmp;
    b += 1/tmp;
  }

  double anser = 1 / b;

  cout << fixed << setprecision(5) << anser << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<=(b);++i)
#define DEC(i,a,b) for(int i=(a);i>=(b);--i)
#define dbg(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
template<typename T,typename U> inline bool smax(T&x,const U&y){return y>x?(x=y,1):0;}
template<typename T,typename U> inline bool smin(T&x,const U&y){return y<x?(x=y,1):0;}
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define X first
#define Y second
template<typename T>
inline void rd(T&w){
	char c;
	while(!isdigit(c=getchar()));w=c&15;
	while(isdigit(c=getchar()))w=(w<<1)+(w<<3)+(c^48);
}
const int N=1e5+7;
int n,v[N],top;
ll x[N],c,s[N],t[2][N<<1][25];
inline ll ask(int l,int r,int k){
	if(l>r)return 0;
	int s=log2(r-l+1);
	return max(t[k][l][s],t[k][r-(1<<s)+1][s]);
}
int main(){
	rd(n),rd(c);top=log2(n)+1;
	REP(i,1,n)rd(x[i]),rd(v[i]),s[i]=v[i]+s[i-1],t[0][i][0]=s[i]-x[i],t[1][i][0]=s[i]-2ll*x[i];
	REP(j,1,top)REP(i,1,n)
		t[0][i][j]=max(t[0][i][j-1],t[0][i+(1<<j-1)][j-1]),
		t[1][i][j]=max(t[1][i][j-1],t[1][i+(1<<j-1)][j-1]);
	
	ll ans=ask(1,n,0);
	DEC(i,n,1){
		int p=upper_bound(x+1,x+i,c-x[i])-x-1;
		smax(ans,max(s[n]-s[i-1]-c+x[i]+ask(1,p,1),2ll*(x[i]-c)+s[n]-s[i-1]+ask(p+1,i-1,0)));
		smax(ans,x[i]-c+s[n]-s[i-1]);
	}
	cout<<max(ans,0ll);
	return 0;
}


Measured memory_bytes: 43520