akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(unknown_lints)]
#![allow(unused_variables)]
#![allow(unused_must_use)]
#![allow(unused_mut)]
#![allow(dead_code)]
#![allow(unused_assignments)]

use std::collections::HashMap;
use std::io::{stderr, Write};
use std::process::exit;

macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

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()));
        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)*}
    };
}

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)*}
    };
}

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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn csvec_new(src: Vec<char>) -> Vec<i32> {
    let mut cs: Vec<i32> = vec![0];
    cs.push(0);
    debug!(cs);
    let len = src.len();
    let mut new = 0;
    for i in 1..len {
        if src[i-1] == 'A' && src[i] == 'C' {
            new = new + 1;
        }
        cs.push(new);
        debug!(src[i-1]);
        debug!(src[i]);
        debug!(cs);
    }
    cs
}

fn main() {
    input!{
        n: usize,
        q: usize,
        s: String,
        lr: [(usize, usize); q]
    } debug!(n);
    debug!(q);
    debug!(s);
    debug!(lr);
    let s: Vec<char> = s.chars().collect();
    let cs = csvec_new(s);
    debug!(cs);
    let stdout_ = std::io::stdout();
    let mut stdout = std::io::BufWriter::new(stdout_.lock());
    for i in 0..q {
        debug!(i);
        let (l, r) = lr[i];
        debug!(l);
        debug!(r);
        let res = cs[r] - cs[l];
        //println!("{}", res);
        writeln!(stdout, "{}", res).unwrap();
    }
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

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


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
long long a,b,j;
int s;
int main()
{
	 cin>>a>>b;
	 j=a;
	 while(j<=b)
	 {
	 	s++;
	 	j*=2;
	 }
	 cout<<s<<endl;


    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	
	
	public static long gcd(long a, long b){
		if(a<b) return gcd(b,a);
		if(b==0) return a;
		return gcd(b,a%b);
	}
	public static long lcm(long a, long b){
		long g = gcd(a,b);
		return a/g*b;
	}
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] t = new long[N];
        
        for(int i=0;i<N;i++) t[i]=sc.nextLong();
        
        long ans = t[0];
        for(int i=1;i<N;i++) ans = lcm(ans,t[i]);
        
        System.out.println(ans);
    }
}

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

using namespace std;

int main() {
  string S;
  cin >> S;
  int n = S.size();
  vector<vector<int>> dp(n + 1,vector<int>(2));
  dp[1][0] = 1;
  for (int i = 2; i <= n; ++i) {
    if (S[i-1] != S[i-2]) dp[i][0] = dp[i-1][0] + 1;
    if (i < 4 || S[i-1] != S[i-3] || S[i-2] != S[i-4])
      dp[i][1] = dp[i-2][1] + 1;
    if (i > 2) dp[i][0] = max(dp[i][0], dp[i-1][1] + 1);
    if (i > 2) dp[i][1] = max(dp[i][1], dp[i-2][0] + 1);
  }
  cout << max(dp[n][0], dp[n][1]) << endl;
}


Measured memory_bytes: 14412
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include "math.h"
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int N;
vector <int > D;
vector <int > num;




int main()
{

	cin >> N;

	D.resize(N);

	REP(i,N){
		cin >> D[i];
	}

	num.resize(13);
	vector <int> temp;
	REP(i,N){
		num[D[i]]++;
		if(num[D[i]]>2){
			cout << 0;
			return 0;
		}
	}

	vector <int> list;
	REP(i,13){
		if(num[i]==2){
			temp.push_back(i);
			temp.push_back(24-i);
		} else if(num[i] == 1){
			list.push_back(i);
		}
	}

	int M = list.size();
	int ans = 0;
	REP(i,pow(2,M)){
		vector <int> all = temp;
		all.push_back(0);
		REP(j,M){
			if((int)(i/pow(2,j))%2)
				all.push_back(list[j]);
			else
				all.push_back(24-list[j]);
		}

		int mi = 30;
		REP(j,all.size()-1){
			FOR(k,j+1,all.size()){
				mi = min(mi,min(max(all[j],all[k])-min(all[k],all[j]),24-max(all[j],all[k])+min(all[j],all[k])));
			}
		}
		ans = max(ans,mi);
	}
	cout << ans;
}



Measured memory_bytes: 512
X,N = map(int,input().split())

if N == 0:
    P = []
else:
    P = [int(x) for x in input().split()]

for i in range(100):
    q = X - i
    if q not in P:
        print(q)
        break
    q = X + i
    if q not in P:
        print(q)
        break

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

int main(){
  int h,m,s,h1,m1,s1;
  for(int i=0;i<3;i++){
    cin >> h >> m >> s >> h1 >> m1 >> s1;
    int sum,sum1;
    sum = h*3600 + m*60 + s;
    sum1 = h1*3600 + m1*60 + s1;
    sum = sum1 - sum;
    h = sum / 3600;
    sum %= 3600;
    m = sum / 60;
    sum %= 60;
    cout << h << " " << m << " " << sum << endl;
  }
}

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

class Program
{
    static void Main(string[] args)
    {
        List<string> a = new List<string> { "1", "3", "5", "7", "8", "10", "12" };
        List<string> s = new List<string> { "4","6","9","11" };
        string[] x = Read.Strs();
        if (x[0] == "2" || x[1] == "2") { Console.WriteLine("No"); }
        else
        {
            if ((s.IndexOf(x[0]) > -1&&s.IndexOf(x[1])>-1)|| (a.IndexOf(x[0]) > -1 && a.IndexOf(x[1]) > -1)) { Console.WriteLine("Yes"); }
            else { Console.WriteLine("No"); }
        }
    }
    public static Boolean uso() { return false; }
    public static bool IsPrime(long n)
    {
        if (n < 2) return false;
        if (n == 2) return true;

        for (int i = 2; i < n; i++)
        {
            if (n % i == 0) return false;
        }
        return true;
    }

}
public static class Read
{
    public static void outl(string n = "") { Console.WriteLine(n); return; }
    public static int Int()
    {
        return int.Parse(Console.ReadLine());
    }
    public static int[] Ints()
    {
        return Console.ReadLine().Split().Select(int.Parse).ToArray();
    }
    public static string Str() { return Console.ReadLine(); }
    public static string[] Strs() { return Console.ReadLine().Split(); }
}

Measured memory_bytes: 11104
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.nextLine();
		List<Double> list = Arrays.stream(sc.nextLine().split(" ")).map(Double::valueOf).sorted()
				.collect(Collectors.toList());
		int size = list.size();
		double avg = list.get(0);
		for (int i = 1; i < size; i++) {
			avg = (avg + list.get(i)) / 2d;
		}
		System.out.println(avg);
	}
}


Measured memory_bytes: 26964
n = int(input())
a_list = list(map(int, input().split()))
a_set = set(a_list)
m = max(a_list)
a_list.sort()
 
pre_a = 0
for a in a_list:
    if a == pre_a:
        a_set.discard(a)
    if a in a_set:
        j = a * 2
        while j <= m:
            a_set.discard(j)
            j += a
    pre_a = a

print(len(a_set))

Measured memory_bytes: 32236
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	var Input = input.split(" ");
	
	var a = parseInt(Input[0], 10);
	var b = parseInt(Input[1], 10);
  
  	if(a > 9 || b > 9){
      	console.log(-1);
    }else{
      	console.log(a * b);
    }
	

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
std::mt19937 rnd(time(NULL));
#define rand rnd
#define pr std::pair<int,int>
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
#ifdef mod
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;}
template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;}
#endif
int fir[100010],dis[400010],nxt[400010],id,d[100010];
void link(int a,int b){nxt[++id]=fir[a],fir[a]=id,dis[id]=b;}
bool vis[100010];
void DFS(int x){
	vis[x]=1;
	for(int i=fir[x];i;i=nxt[i])if(!vis[dis[i]])DFS(dis[i]);
}
int main(){
#ifdef LOCAL
	freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
#endif
	int n=gi(),m=gi(),u,v;
	for(int _=0;_<m;++_)u=gi(),v=gi(),link(u,v),link(v,u),++d[u],++d[v];
	for(int i=1;i<=n;++i)if(d[i]&1)puts("No"),exit(0);
	if(m<n+2)puts("No"),exit(0);
	if(m>n+2)puts("Yes"),exit(0);
	int a=-1,b=-1;
	for(int i=1;i<=n;++i)
		if(d[i]==4)(~a?b:a)=i;
		else if(d[i]==6)puts("Yes"),exit(0);
	vis[a]=vis[b]=1;
	for(int i=fir[a];i;i=nxt[i])if(!vis[dis[i]])DFS(dis[i]);else puts("Yes"),exit(0);
	puts("No");
	return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
struct City
{
    int y;
    int id;
    bool operator<(const City& o) const 
    {
        return y<o.y;
    }
};
vector<City> g[maxn];
string ans[maxn];
int n,m,p,y;
int main()
{
    cin>>n>>m;
    for(int i=1;i<=m;++i)
    {
        cin>>p>>y;
        g[p].push_back({y,i});
    }
    for(int i=1;i<=n;++i)
    {
        sort(g[i].begin(),g[i].end());
        string fi = to_string(i);
        while(fi.size()<6) fi = "0" + fi;
        for(int j=0;j<g[i].size();j++)
        {
            string sn = to_string(j+1);
            while(sn.size()<6) sn = "0" + sn;
            ans[g[i][j].id] = fi + sn;
        }
    }
    for(int i=1;i<=m;++i)
        cout<<ans[i]<<endl;
}

Measured memory_bytes: 12416
fun main(args: Array<String>) = ABC160B.main()

object ABC160B {
    fun main() {
        val x = readLong()
        val n1 = x / 500
        val r1 = x % 500
        val n2 = r1 / 5

        val ans = n1 * 1000 + n2 * 5
        println(ans)
    }


    /*####################################################################################*/

    fun readLong() = readLine()!!.toLong()
    fun readInts() = readLine()!!.split(" ").map { it.toInt() }
}

Measured memory_bytes: 33652
H,W,A,B = map(int,input().split())

if A * 2 > W or B * 2 > H:
    print ("No")

else:

    ans = ""

    for i in range(W-A):
        ans += "0"

    for i in range(A):
        ans += "1"

    for i in range(H-B):
        print (ans)

    ans = ""

    for i in range(W-A):
        ans += "1"
    for i in range(A):
        ans += "0"

    for i in range(B):
        print (ans)


Measured memory_bytes: 3956
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int N, M;
	cin >> N >> M;

	ll B[100001] = {};
	int mae;
	cin >> mae;
	int a1 = mae;
	int nanshuu = 0;
	ll kihon = 0;
	rep1(i, N - 1) {
		int a;
		cin >> a;
		int sa = a - mae;
		if (sa < 0) {
			sa += M;
			nanshuu++;
			kihon -= M - mae;
		}
		B[a] += sa;
		mae = a;
	}
	int aN = mae;
	kihon += (ll)nanshuu * M + aN - a1;

	ll saishou = kihon;
	rep1(x, M - 1) {
		int tmp = nanshuu;
		if (x > a1) tmp++;
		if (x > aN) tmp--;
		kihon += B[x] - tmp;
		chmin(saishou, kihon);
	}

	co(saishou);

	Would you please return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
static const int INFTY = (1 << 30);
ll N, A, B, C, D, E;
ll func2(ll a, ll b)
{
    return (a % b == 0) ? a / b : a / b + 1;
}
void func()
{
    cin >> N >> A >> B >> C >> D >> E;
    ll ans = 0;
    ll min = A;
    ans = func2(N, A);
    if (B >= min)
        ans += 1;
    if (B < min)
        min = B, ans = func2(N, B) + 1;
    if (C >= min)
        ans += 1;
    if (C < min)
        min = C, ans = func2(N, C) + 2;
    if (D >= min)
        ans += 1;
    if (D < min)
        min = D, ans = func2(N, D) + 3;
    if (E >= min)
        ans += 1;
    if (E < min)
        ans = func2(N, E) + 4;
    cout << ans << endl;
}
int main()
{
    func();
}

Measured memory_bytes: 3616
N=int(input())
S=input()

r1=S.count("#")
r2=N-r1
c1=r1
c2=r2


it1=0
it2=N-1
it1f=False
it2f=False
r3=0
isLeft=None

while it1<it2:
  if S[it1]!=".":
    if it1f==True and it2f==True and c1<=c2:
      r3+=1
      it1+=1
      it1f=False
      c1-=1
    else:
      it1f=True
  else:
    it1+=1
    c2-=1

  if S[it2]!="#":
    if it1f==True and it2f==True and c1>c2:
      r3+=1
      it2-=1
      it2f=False
      c2-=1
    else:
      it2f=True
  else:
    it2-=1
    c1-=1

print(r3)

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

ll inf = 1e18;
int N;
vector<ll> A;
vector<vector<int>> edge;
vector<ll> ans;
vector<stack<pair<ll, int>>> dp;

void dfs(int now, int pre, int premx) {
    int l = 0, r = N+1;
    while (r-l > 1) {
        int c = (l+r)/2;
        if (dp[c].top().first < A[now]) l = c;
        else r = c;
    }
    int mx = max(premx, l+1);
    ans[now] = mx;
    bool stacked = false;
    if (dp[l+1].top().first > A[now]) {
        dp[l+1].push({A[now], now});
        stacked = true;
    }
    
    for (int nxt : edge[now]) {
        if (nxt == pre) continue;
        dfs(nxt, now, mx);
    }
    
    if (stacked) {
        dp[l+1].pop();
    }
    return;
}

int main() {
    cin >> N;
    A.resize(N+1);
    edge.resize(N+1);
    dp.resize(N+1);
    ans.resize(N+1, 0);
    ans[0] = 1;
    for (int i = 0; i < N; i++) cin >> A[i+1];
    for (int i = 0; i < N-1; i++) {
        int u, v;
        cin >> u >> v;
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    dp[0].push({0, -1});
    for (int i = 1; i <= N; i++) {
        dp[i].push({inf, -1});
    }
    dfs(1, -1, 0);
    for (int i = 1; i <= N; i++) {
        cout << ans[i] << "\n";
    }
    return 0;
}


Measured memory_bytes: 172480
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}
ll modcombi[2001][2001]={0}; //[i][j] iCj
void makecombi(){
  modcombi[0][0]=1;
  for(int i=1;i<=2000;i++){
    modcombi[i][0]=1;
    for(int j=1;j<=2000;j++){
      modcombi[i][j]=(modcombi[i-1][j-1]+modcombi[i-1][j])%MOD;
    }
  }
}
int main(){
  makecombi();
  int N,K;
  cin>>N>>K;
  for (int i(1);i<=K;i++){
    cout << (modcombi[N-K+1][i] * modcombi[K-1][i-1])%MOD << endl;
  }
  return 0;
}



Measured memory_bytes: 31488
#include <iostream>

using namespace std;
const long long MAXN = 5e5+5;
long long arr[MAXN];
long long ans;
long long last;
int main(){
    long long n,t;
    cin>>n>>t;
    for(long long i=1;i<=n;i++){
        cin>>arr[i];
        if(arr[i]>=last){
            last = arr[i]+t;
            ans+=t;
        }else if(arr[i]<=last){
            ans+=((arr[i]+t)-last);
            last = arr[i]+t;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
from collections import Counter
n = int(input())
ls = list(map(int,input().split()))
lso = ls[::2]
lse = ls[1::2]
lso.sort()
lse.sort(reverse=True)
co = Counter(lso)
ce = Counter(lse)
co1,co2 = co.most_common()[0][0],co.most_common()[0][1]
ce1,ce2 = ce.most_common()[0][0],ce.most_common()[0][1]
coo1,coo2,cee1,cee2 = 0,0,0,0
if co2 != n//2:
    coo1,coo2 = co.most_common()[1][0],co.most_common()[1][1]
if ce2 != n//2:
    cee1,cee2 = ce.most_common()[1][0],ce.most_common()[1][1]
if co1 == ce1:
    print(n-max(co2+cee2,ce2+coo2))
else:
    print(n-co2-ce2)

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

int main() {
  int n, k, sum;
  cin >> n >> k;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }

  for (int i = 0; i < n; i++) {
    sum += min(vec[i], k - vec[i]) * 2;
  }

  cout << sum << endl;
}

Measured memory_bytes: 3612
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
A, B = map(int, input().split())
Ps = list(map(int, input().split()))

c1 = 0
c2 = 0
c3 = 0
for p in Ps:
    if p <= A: c1 += 1
    elif p <= B: c2 += 1
    else: c3 += 1
print(min(c1, c2, c3))

    


Measured memory_bytes: 7976
def is_contain(circle, target, index):
    for char in target:
        if char == circle[index]:
            index += 1
            if index == len(circle): index = 0
            continue
        else:
            return False
    return True


circle = input()
target = input()

index = 0

while True:
    try:
        index = circle.index(target[0], index)
        if is_contain(circle, target, index):
            print('Yes')
            break
        index += 1
    except ValueError:
        print('No')
        break


Measured memory_bytes: 5564
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
l = list(li())

longest = max(l)
others = sum(l) - longest
print('Yes') if others > longest else print('No')

Measured memory_bytes: 3064
n = int(input())
s = []
while n!=0:
    if n<=26:
        s.append(n)
        n = 0
    else:
        x = n % 26
        if not x:
            x = 26
        s.append(x)
        n = (n - 1) // 26
t = []
for i in range(len(s)-1,-1,-1):
    t.append(chr(s[i]+96))
print(''.join(t))

Measured memory_bytes: 9056
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
typedef pair<int, int> P;

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int R, C, N;
    cin >> R >> C >> N;
    vector<P> S;
    rep(i, N) {
        int x[2], y[2];
        rep(j, 2) cin >> x[j] >> y[j];
        int check = 0;
        rep(j, 2) {
            if ((x[j] == 0 || x[j] == R) || (y[j] == 0 || y[j] == C)) check++;
        }
        //cout << check << endl;
        if (check == 2) {
            rep(j, 2) {
                //cout << x[j] << " " << y[j] << " ";
                int len = 0;
                if (x[j] == 0) len = y[j];
                else if (y[j] == C) len = C + x[j];
                else if (x[j] == R) len = R + C * 2 - y[j];
                else if (y[j] == 0) len = R * 2 + C * 2 - x[j];
                //cout << len << endl;
                S.push_back({len, i + 1});
            }
        }
    }
    sort(S.begin(), S.end());
    stack<int> st;
    rep(j, S.size()) {
        if (st.size() > 0 && st.top() == S[j].second) st.pop();
        else st.push(S[j].second);
        //cout << S[j].first << " " << S[j].second << endl;
    }
    //cout << st.size() << endl;
    if (st.size() > 0) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }


    return 0;
}


Measured memory_bytes: 6512
#!/usr/bin/env python3
import sys
def input():
    return sys.stdin.readline()[:-1]

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

def main():
    N = int(input())

    ans = 1e18
    for i in range(1, N + 1):
        if i * i > N:
            break
        if N % i != 0:
            continue
        j = N // i
        ans = min(ans, i + j - 2)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 63672
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename T>
class SegmentTree
{
    public:
        vector<T> t;
        int n, H;
        void init(int n)
        {
            this->n = n;
            t.resize(2*n);
            this->H = sizeof(int)*8 - __builtin_clz(n);
        }
        void build()
        {   
            for(int i = n-1; i>0;i--)
                t[i] = max(t[i<<1],t[(i<<1)|1]);
        }
        void update(int pos, T val)
        {   pos+=n;
            t[pos] = max(val, t[pos]);
            for( ; pos>1;pos>>=1)
                t[pos>>1] = max(t[pos],t[pos^1]);
        }
        T  query(int l, int r)
        {
            T res = -1e9;
            for(l+=n,r+=n;l<r;l>>=1,r>>=1)
            {
                if(l&1)     res=max(res ,t[l++]);
                if(r&1)     res=max(t[--r], res);
            }
            return res;
        }
};
int main()
{
    int n;
    scanf("%d", &n);
    vector<ll> h(n), a(n);
    for(int i =0; i<n;i++)
        scanf("%d",&h[i]);
    for(int i =0; i<n;i++)
        scanf("%d",&a[i]);
    const int HMAX = 200005;

    SegmentTree<ll> tr; tr.init(HMAX);
    for(int i = 0; i< n; i++)
    {
        //we need max dp[i] for i between [0, h[i]- 1];
        ll ans  = max(tr.t[h[i] + HMAX] , tr.query(0,h[i]) + a[i] );
        tr.update(h[i] , ans);
    }

    cout<<tr.query(0,HMAX)<<"\n";
    
    
}

Measured memory_bytes: 6528
// AtCoder agc002

#include <bits/stdc++.h>
#define ld long double
#define ll long long int
#define mod 1000000007
#define ll_inf 1000000000000000
#define int_inf 1000000000
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define eps 1e-9
#define PI acos(-1.0)
#define ii pair<int,int>
#define iii pair<int,ii>
#define se second
#define fi first
using namespace std;
int cnt[15];
int main(){
    //cout.precision(12);
    //ifstream fin("in");
    int a,b,c;
    cin>>a>>b>>c;
    cnt[a]++; cnt[b]++; cnt[c]++;
    if(cnt[5]==2 && cnt[7]==1)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
n = int(input())
s = str(input())
b = []
nb = 0
w = []
nw = 0
for s_ in s:
  if s_ == "#":
    nb += 1
  if s_ == ".":
    nw += 1
  b.append(nb)
  w.append(nw)
ans = []
#print(b)
#print(w)
for i in range(n):
  if i == n-1 and s[i] == ".":
    ans.append(b[i]+1)
  elif i == 0:
    ans.append(w[n-1])
  else:
    ans.append(b[i-1]+w[n-1]-w[i-1])
ans.append(b[n-1])
#print(ans)
if n == 1:
  print("0")
else:
  print(min(ans))


Measured memory_bytes: 20960
#include <bits/stdc++.h>
#define Rep(i,n) for(int i = 0; i < (n); i++)
#define For(i,start,end) for(i64 i = start; i < end; i++)
inline void nl(){std::cout<<std::endl;}
using namespace std;
typedef long long ll;
typedef unsigned long ul;

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;

//----------------library in this time--------------------------------
template <typename T>
T gcd(const T a,const T b) {
    return (b == 0) ? a : gcd (b, a % b);
}
template <typename T>
T lcm(const T a, const T b) {
    return a * b / gcd(a,b);
}
template <typename T>
inline T ave(const T a, const T b) {
    return (a + b) / 2.0f;
}
//------------------------main function-------------------------------
void Main(){
    u64 n,m,sum = 0;
    cin >> n >> m;
    multiset<u64> a;
    Rep(i, n){
        u64 ff;
        cin >> ff;
        sum += ff;
        a.insert(ff);
    }
    
    for(auto itr = a.rbegin(); m >0 ; m--,itr++){
        if(*itr == 0)break;
        sum -= *itr - (*itr / 2);
        a.insert(*itr / 2);
    }
    cout << sum << endl;
}
//--------------------------------------------------------------------
int main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    
    Main();
    return 0;
}



Measured memory_bytes: 9600
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N,Q;
  cin>>N>>Q;
  vector<int> c[N];
  REP(i,N-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    c[a].push_back(b);
    c[b].push_back(a);
  }
  lint ans[N];
  REP(i,N)ans[i]=0;
  REP(i,Q){
    int p;
    lint x;
    cin>>p>>x;
    p--;
    ans[p]+=x;
  }
  queue<int> q;
  q.push(0);
  int d[N];
  REP(i,N)d[i]=0;
  d[0]=1;
  while(!q.empty()){
    int p=q.front();
    q.pop();
    for(auto e:c[p]){
      if(d[e])continue;
      d[e]=1;
      ans[e]+=ans[p];
      q.push(e);
    }
  }
  REP(i,N){
    cout<<ans[i]<<" ";
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 18228
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;

int main(){
    int N, Y, a, b, c;
    bool find_flag = false;
    cin >> N >> Y;
    Y /= 1000;

    for (a=0; a<=N; a++) {
        for (b=0; b<=N-a; b++) {
            c = N - (a + b);
            if (10 * a + 5 * b + c == Y) {
                find_flag = true;
                break;
            }
        }
        if (find_flag) break;
    }

    if (find_flag) cout << a << " " << b << " " << c << endl;
    else cout << "-1 -1 -1" << endl;

    return 0;
}

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();
        int b = sc.nextInt();
        int area = a*b;
        int length = (a + b)*2;
        System.out.println(area + " " + length);
        sc.close();
    }
}


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

int main() {
    int64_t h, n, damage = 0;
    cin >> h >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        damage += a; 
    }
    if (damage >= h)
        cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#define debug(x) cout << #x << "==" << x << endl;
using namespace std;

const int INF = 1e+8;

//??\???
#define MAX_N 50000
#define MAX_M 20
int N;
int M;
int C[MAX_M];

// dp ????????????
int dp[MAX_N + 1];


void print_dp_array(int n) {
  for(int i = 0; i <= n; i++) {
    if(dp[i] == INF) {
      cout <<  "INF ";
    } else {
      cout << setw(3) << dp[i];
    }
  }
  cout << endl;
}


int main() {
  ios::sync_with_stdio(false);

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

  // ?????????
  fill(dp, dp + MAX_N + 1, INF);
  dp[0] = 0;


  for(int s = 0; s <= N ; s++) {

    if(dp[s] != INF) {
      for(int i = 0; i < M; i++) {
        dp[s + C[i]] = min(dp[s + C[i]], dp[s] + 1);
      }
    }
  }


  cout << dp[N] << endl;


  return 0;
}

Measured memory_bytes: 3344
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

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

    vector<ll> t(n);
    rep(i,n) cin >>t[i];

    vector<ll> d(n-1);
    rep(i,n-1) d[i] = t[i+1]-(t[i]+1);
    sort(all(d), greater<ll>());

    ll ans = t[n-1]+1 - t[0];
    rep(i,k-1) ans -= d[i];
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 4412
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n; cin >> n;
    map<ll,ll> mp;
    rep(i,n) {
        int a; cin >> a;
        mp[a]++;
    }
    ll ans = 0;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        ll n = itr->first;
        ll ct = itr->second;
        if (n <= ct) ans += ct-n;
        else ans += ct;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6272
use proconio::input;

fn main() {
    input! {
        a: i32,
        b: i32,
        c: i32,
        d: i32,
    }

    if (a - c).abs() <= d {
        println!("Yes");
        return;
    }

    if (a - b).abs() <= d && (b - c).abs() <= d {
        println!("Yes");
        return;
    }

    println!("No");
}


Measured memory_bytes: 2076
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
//#include<algorithm>
//#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

char AB[200001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint(), M = getint();
	rep(i, M) {
		int a = getint(), b = getint();
		if (a == 1) AB[b] |= 1;
		if (b == N) AB[a] |= 2;
	}

	bool kotae = 0;
	rep1(i, 200000) if (AB[i] == 3) kotae = 1;

	if (kotae) printf("POSSIBLE");
	else printf("IMPOSSIBLE");

	Would you please return 0;
}

Measured memory_bytes: 512
import numpy as np

def main():
    h, w, k = map(int, input().split())
    s = [input() for i in range(h)]
    s = np.array(s)

    ans = np.array([[0]*w]*h)

    g = 1
    nls = []

    for i in range(h):
        if s[i] != "."*w:
            lsha = 0
            for j in range(w):
                ans[i][j] = g
                if s[i][j] == "#":
                    lsha = j
                    g = g + 1
            if lsha != w-1:
                for k in range(w-lsha-1):
                    ans[i][lsha+1+k] = ans[i][lsha] 
        else:
            nls.append(i)
    
    for i in nls:
        if i != h-1:
            ans[i] = ans[i+1]
        else:
            ans[i] = ans[i-1]
    
    for i in range(h):
        if ans[i][0] == 0:
            for j in range(i+1, h):
                if ans[j][0] != 0:
                    ans[i] = ans[j]
                    break
    for i in range(h):
        if ans[h-1-i][0] == 0:
            for j in range(i+1, h):
                if ans[h-1-j][0] != 0:
                    ans[h-1-i] = ans[h-1-j]
                    break
    
    for i in range(h):
        anst= ""
        for j in range(w):
            anst = anst + str(ans[i][j]) + " "
        print(anst)

if __name__ == "__main__":
    main()

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

int comparator(const void *p, const void *q)
{
    int l = *(const int *)p;
    int r = *(const int *)q;
    return (r-l);
}

int main()
{
    int n, i, sa = 0, sb = 0;
    scanf("%d", &n);
    int *v = calloc(n, sizeof(int));
    for(i = 0; i < n; i ++)
        scanf("%d", v + i);
    qsort(v, n, sizeof(int), comparator);
    for(i = 0; i < n; i += 2)
        sa += v[i];
    for(i = 1; i < n; i += 2)
        sb += v[i];
    printf("%d", sa-sb);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
typedef long long ll;

using namespace std;

int main() {
  while (true) {
    int h, w;
    cin >> h >> w;

    if (h == 0 && w == 0) break;

    REP(i, h) {
      REP(j, w) {
        if (i % 2 == 0 && j % 2 == 0) {
          cout << "#";
        } else if (i % 2 == 0 && j % 2 != 0) {
          cout << ".";
        } else if (i % 2 != 0 && j % 2 == 0) {
          cout << ".";
        } else if (i % 2 != 0 && j % 2 != 0) {
          cout << "#";
        }
      }
      cout << "\n";
    }
    cout << "\n";
  }
}


Measured memory_bytes: 3024
N = gets.to_i
A = gets.split.map(&:to_i)
sum = 0
h={}
N.times do |i|
    j = A[i] - 1
    if i == A[j]-1 && !h.has_key?(i)
        sum += 1
        h[i]=true
        h[j]=true
    end
end
puts sum

Measured memory_bytes: 14596
#include <iostream>
#include <iomanip>
#include <cmath>

typedef long double ld;

ld dissq(double x1, double y1, double x2, double y2)
{
	return (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
}

int main()
{
	ld x1, y1, x2, y2;
	std::cin >> x1 >> y1 >> x2 >> y2;
	int q; std::cin >> q;
	for (int i=0; i<q; i++) {
		ld x0, y0;
		std::cin >> x0 >> y0;
		ld s = (dissq(x0,y0,x1,y1) + dissq(x1,y1,x2,y2) - dissq(x0,y0,x2,y2)) / (2.0 * dissq(x1,y1,x2,y2));
		ld x = (1.0 - s) * x1 + s * x2;
		ld y = (1.0 - s) * y1 + s * y2;
		std::cout << std::setprecision(8) << std::fixed << 2.0 * x - x0 << " " << 2.0 * y - y0 << std::endl;
	}
	return 0;
}



Measured memory_bytes: 3272
//PCK2015予選4
#include<iostream>
using namespace std;

int main(){
    int N; cin>>N;
    for(int i=0;i<N;++i){
        int x,y,b,p;
        cin>>x>>y>>b>>p;
        int A = x*b+y*p;
        int B = (x*(b<5?5:b)+y*(p<2?2:p))*0.8;
        cout<<(A>B?B:A)<<endl;
    }
}



Measured memory_bytes: 3088
parseInt(x) = parse(BigInt, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	p = 10^9+7
	n,m = readline() |> split |> parseMap
	if abs(n-m)>1
		println(0)
	elseif n==m
		x = 2
		for i in 1:n
			x=x*i%p
		end
		for i in 1:m
			x=x*i%p
		end
		println(x)
	else
		x = 1
		for i in 1:n
			x=x*i%p
		end
		for i in 1:m
			x=x*i%p
		end
		println(x)
	end
end

main()

Measured memory_bytes: 173576
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int f = sc.nextInt();
        int b = sc.nextInt();
        if(b > (m + f)){
            System.out.println("NA");
        }else{
            if(b > m){
                System.out.println(b-m);
            }else{
                System.out.println(0);
            }
        }
    }
}


Measured memory_bytes: 26316
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
const int MAXN=21;
int p[MAXN];
int main()
{
	int ans=0;
	int n=read();
	for(int i=1;i<=n;++i)
		p[i]=read();
	for(int i=2;i<n;++i)
		if((p[i]<p[i-1] && p[i]>p[i+1]) || (p[i]>p[i-1] && p[i]<p[i+1]))
			++ans;
	cout<<ans<<endl;
	return 0;
}


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

int main() {
    string x;
    cin >> x;
    if(x[x.size()-1]=='1'||x[0]!='1'||x[x.size()-2]!='1'){
        puts("-1");
        return 0;
    }
    for(int i=0,j=x.size()-2;j>=0&&i<x.size()-1;i++,j--){
        if(x[i]!=x[j]){
            puts("-1");
            return 0;
        }
    }
    vector<int> v;
    for(int i=0;i<x.size();i++){
        if(x[i]=='1'){
            v.push_back(i);
        }
    }
    for(int i=0;i<v.size();i++){
        cout << i+1 << " " << i+2 << endl;
    }
    int cur = v.size()+2;
    for(int i=1;i<v.size();i++){
        for(int j=v[i-1];j<v[i]-1;j++){
            cout << i+1 << " " <<cur++ << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 2040
// Problem : A - Lucky 7
// Contest : AtCoder Beginner Contest 162
// URL : https://atcoder.jp/contests/abc162/tasks/abc162_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define cerr if(1)cerr
#define size(x) (int)x.size()

const int N = 1e6 + 1;

string s;

void solve() {
	cin >> s;
	if (s[0] == '7' || s[1] == '7' || s[2] == '7') cout << "Yes";
	else cout << "No";
}

int main() { cin.tie(0)->sync_with_stdio(0);
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
}


Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<cmath>
using namespace std;
int main(){
	
	int a[5];
	int s[5];
	
	while(cin>>a[0],a[0]!=0){
		bool p[4]={false};
		p[a[0]]=true;
		for(int i=1;i<5;i++){
			cin>>a[i];
			p[a[i]]=true;
		}
		int w,l;
		if(p[1]&&p[2]&&p[3]||!p[2]&&!p[3]||!p[1]&&!p[3]||!p[1]&&!p[2]){
			w=3;
			l=3;
		}
		else if(p[1]&&p[3]){
			w=3;
			l=1;
		}
		else if(p[2]&&p[3]){
			w=2;
			l=3;
		}
		else if(p[1]&&p[2]){
			w=1;
			l=2;
		}	
		for(int i=0;i<5;i++){
			if(w==l)
				s[i]=3;
			else{
				if(a[i]==w)
					s[i]=1;
				else 
					s[i]=2;
			}
		}
		for(int i=0;i<5;i++)
			cout<<s[i]<<endl;
	}
	
}

Measured memory_bytes: 1160
import sys
from itertools import product

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    H, W, K = map(int, readline().split())

    A = product((0, 1), repeat=W - 1)
    B = []
    for bars in A:
        ok = True
        for i in range(W - 2):
            if bars[i] and bars[i + 1]:
                ok = False
                break
        if ok:
            B.append(bars)

    dp = [0] * W
    dp[0] = 1

    for _ in range(H):
        dp, dp_prev = [0] * W, dp
        for bars in B:
            for i in range(W):
                if i > 0 and bars[i - 1]:
                    dp[i - 1] = (dp[i - 1] + dp_prev[i]) % MOD
                elif i < W - 1 and bars[i]:
                    dp[i + 1] = (dp[i + 1] + dp_prev[i]) % MOD
                else:
                    dp[i] = (dp[i] + dp_prev[i]) % MOD

    print(dp[K - 1])

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9164
using System;
using System.Collections.Generic;

class AtCoder {
    public static void Main() {
        var person = int.Parse(Console.ReadLine());
        var input_2 = Console.ReadLine().Split(' ');
        var choco = new List<int>();
        var eat = 0;
        for (int i = 0; i < person; i++) {
            choco.Add(int.Parse(Console.ReadLine()));
        }
        var day = int.Parse(input_2[0]);
        var last = int.Parse(input_2[1]);

        if (day > 0) {
            eat += person;
            for (int i = 0; i < person; i++) {
                int chocoCycle = choco[i];
                int fix = 1;
                while (day >= (chocoCycle * fix) + 1) {
                    eat++;
                    fix++;
                }
            }
        }
        Console.Write(last + eat);
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    ll h, w, n;
    cin >> h >> w >> n;
    map<P, ll> ma;
    rep(i,n){
        ll a, b; 
        cin >> a >> b;
        --a, --b;
        for(int p = 0; p <= 2; p++){
            for(int q = 0; q <= 2; q++){
                int ni = a - p;
                int nj = b - q;
                if(0 <= ni && ni < h - 2 && 0 <= nj && nj < w - 2) ma[P(ni, nj)]++;
            }
        }
    }
    map<int, ll> ans;
    for(auto p : ma) ans[p.second]++;
    ans[0] = (h - 2) * (w - 2);
    for(int i = 1; i <= 9; i++) ans[0] -= ans[i];
    rep(i,10) cout << ans[i] << endl;
}

Measured memory_bytes: 59824
S = [int(s) for s in input()]

res = []
for i in range(2**4):
    s = S[0]
    c = []
    for j in range(3):
        m = i >> j & 1
        if m == 0:
            s = s + S[j+1]* -1
            c.append("-")
        else:
            s = s + S[j+1]
            c.append("+")

    if s == 7:
        print(str(S[0])+""+c[0]+""+str(S[1])+""+c[1]+""+str(S[2])+""+c[2]+str(S[3])+"=7")
        break




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

class UnionFind{
private:
    std::vector<int> parent;
    std::vector<int> size;
    
public:
    UnionFind(int N){
        parent.resize(N);
        size.resize(N);
        for(int i = 0; i < N; i++){
            parent[i] = i;
            size[i] = 1;
        }
    }

    int root(int x){
        if (parent[x] == x) return x;
        int rx = root(parent[x]);
        parent[x] = rx;
        return rx;
    }

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        parent[rx] = ry;
        size[ry] += size[rx];
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    
    int get_size(int x){
        return size[root(x)];
    }
};

int main(){
    int N, M;
    std::cin >> N >> M;
    std::vector< int > P(N);
    for(int i=0; i<N; i++){
        std::cin >> P[i];
    }
    UnionFind tree(N);
    for(int i=0; i<M; i++){
        int tmp1, tmp2;
        std::cin >> tmp1 >> tmp2;
        tree.unite(tmp1-1, tmp2-1);
    }
    
    int ans = 0;
    for(int i=0; i<N; i++){
        if(tree.same(i, P[i]-1)){
            ans++;
        }
    }
    
    
    std::cout << ans << std::endl;
    
    return 0;
    
}


Measured memory_bytes: 4516
#include<cstdio>
using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7, inv2 = 500000004;
const int MAXN = 200010, MAXC = 4100, MAXA = 2010;

struct Pack{
	int a, b;
}p[MAXN];

int fac[MAXC << 1], finv[MAXC << 1];  
int f[MAXC][MAXC];

inline ll fpow(ll a, ll b){
	ll res = 1;
	while (b){
		if (b & 1)
			res = res * a % mod;
		a = a * a % mod, b >>= 1; 
	}
	return res;
}

inline ll C(int n, int m){
	return 1ll * fac[n] % mod * finv[m] % mod * finv[n - m] % mod;
}

int main(){
	int N;
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i){
		scanf("%d %d", &p[i].a, &p[i].b);
		++f[MAXA - p[i].a][MAXA - p[i].b];
	}
	fac[0] = 1;
	for (int i = 1; i <= 8000; ++i)
		fac[i] = 1ll * fac[i - 1] * i % mod;
	finv[8000] = fpow(fac[8000], mod - 2);
	for (int i = 7999; i >= 1; --i)
		finv[i] = 1ll * finv[i + 1] * (i + 1) % mod;
	for (int i = 1; i <= 4010; ++i){
		for (int j = 1; j <= 4010; ++j){
			f[i][j] = (f[i][j] + f[i - 1][j]) % mod;
			f[i][j] = (f[i][j] + f[i][j - 1]) % mod;
		}
	}
	ll ans = 0;
	for (int i = 1; i <= N; ++i){
		ans = (ans + f[MAXA + p[i].a][MAXA + p[i].b]) % mod;
		ans = (ans + mod - C(p[i].a + p[i].b << 1, p[i].a << 1)) % mod;
	}
	printf("%lld", ans * inv2 % mod);
	return 0;
}


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

typedef long long ll;

// height, color
ll dp[111][2] = {};

int main(){
    int l, k;
    cin >> l >> k;

    dp[k][1] = 1;
    dp[1][1] = 1;

    for(int i = 1; i <= l; i++){
        dp[i+1][0] += dp[i][1];
        dp[i+1][1] += dp[i][0];
        dp[i+k][1] += dp[i][0];
    }

    ll ans = 0;
    for(int i = 1; i <= l; i++){
        ans += dp[i][1];
    }

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


Measured memory_bytes: 3116
using System;

namespace Atcoder2
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();

            if (char.IsUpper(input[0]))
            {
                Console.WriteLine("A");
            } else
            {
                Console.WriteLine("a");
            }
        }
    }
}

Measured memory_bytes: 25884
#include<bits/stdc++.h>
#define LL long long
#define MAXN 100005
#define INF (1<<25)
#define P int(998244353)
using namespace std;

int N;
int x, a[MAXN];

int main(){
	
	cin>>N>>x;
	
	LL ans = 0;
	for(int i=1;i<=N;i++){
		cin>>a[i];
		
		if(a[i] > x){
			ans += a[i] - x;
			a[i] = x;
		}
		
		if(i==1) continue;
		
		if(a[i]+a[i-1] > x){
			ans += a[i]+a[i-1] - x;
			a[i] = x - a[i-1];
		}
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 768