akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map>
#include <map>
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
#include <complex>
#include<fstream>
using namespace std;
typedef long long LL;

int main(void)
{
	LL n;
	cin >>n;
	vector<LL> a(n);
	vector<LL> b(n);
	for (LL i = 0; i < n; i++) {
		cin >>a[i];
		b[i]=a[i];
	}

	sort(b.begin(),b.end(),greater<LL>());
	

	for (LL i = 0; i < n; i++) {
		if (a[i] == b[0]) {
			cout <<b[1]<<endl;
		}
		else {
			cout <<b[0]<<endl;
		}
	}


	return 0;
}

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

int main() {
	int N;
  	long long p;
  	int a[100010]{0};
  	long long s;
  	int Q;
  	int b;
  	int c;

  	cin >> N;
  	s=0;
	for (int i=0;i<N;i++){
		cin >> p;
      	s=s+p;
      	a[p]++;
    }
  	cin >> Q;  
	for (int i=0;i<Q;i++){
		cin >> b >> c;
      	p=(c-b)*a[b];
      	a[c]+=a[b];
      	a[b]=0;
      	s+=p;
 		cout << s << endl;     	
    }
  	return 0;
}

Measured memory_bytes: 3984
//C - Poll

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

using namespace std;

int main()
{
    int n;

    cin >> n;

    vector<int> a(n);

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

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

    bool flag = true;
    for(int i=1; i<n; i++){
        if (a[i-1] == a[i]) {
            flag = false;
            break;
        }
    }

    if (flag){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back

using namespace std;

typedef pair< int, int > P;
typedef pair< int, P > iP;
typedef long long LL;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const int MOD = (10^9 + 7);

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

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

    int a, b, n;
    cin >> n >> a >> b;
    int v;
    if(a + b > n) v = a + b - n;
    else v = 0;
    cout << min(a, b) << " " << v << endl;
    return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
X = LI2()
X.reverse()

if N == 0:
    print(1)
    exit()

A = [0]*(2*10**5+1)
for i in range(1,2*10**5+1):
    k = 0
    for j in range(18):
        if (i >> j) & 1:
            k += 1
    A[i] = A[i % k] + 1


r = sum(X)

if r >= 2:
    B = [0]*N
    C = [0]*N
    b,c = 0,0
    for i in range(N):
        if i == 0:
            B[i] = 1
            C[i] = 1
            if X[i] == 1:
                b = 1
                c = 1
        else:
            B[i] = (B[i-1]*2) % (r-1)
            C[i] = (C[i-1]*2) % (r+1)
            if X[i] == 1:
                b += B[i]
                b %= r-1
                c += C[i]
                c %= r+1

    for i in range(N-1,-1,-1):
        if X[i] == 1:
            print(1+A[(b-B[i]) % (r-1)])
        else:
            print(1+A[(c+C[i]) % (r+1)])

else:
    C = [0] * N
    c = 0
    for i in range(N):
        if i == 0:
            C[i] = 1
            if X[i] == 1:
                c = 1
        else:
            C[i] = (C[i - 1] * 2) % (r + 1)
            if X[i] == 1:
                c += C[i]
                c %= r + 1

    for i in range(N - 1, -1, -1):
        if X[i] == 0:
            print(1 + A[(c + C[i]) % (r + 1)])
        else:
            print(0)


Measured memory_bytes: 86312
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ff(i,n) for(i=0;i<n;i++)
int main()
{
   ll t;
   t = 1;
   while(t--)
   {
   		string a;
   		cin>>a;
   		if(a=="RRR")
		  	cout<<3<<endl;
		else if(a =="SRS"||a=="RSS"||a=="SSR"||a=="RSR")
		    cout<<1<<endl;
		else if(a=="SSS")
			cout<<0<<endl;
		else
			cout<<2<<endl;			  	
   }
   return 0 ;
} 

Measured memory_bytes: 3616
from itertools import permutations
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
per = list(permutations(range(1,N+1)))
for i in range(len(per)):
    if list(per[i]) == P:
        a = i
    if list(per[i]) == Q:
        b = i
print(abs(a-b))


Measured memory_bytes: 8052
a,b=map(int,input().split()) 
 

def factorization(n):
	lista=[]
	temp=n
	
	i=2
	while i<=int(n**0.5//1):
		if temp%i==0:
			lista.append(i)
			temp=temp//i
		else:
			i=i+1
	if temp!=1:
		lista.append(temp)
	if lista==[]:
		lista.append(n)
	
	lista.append(1)
	return lista
	
#print(factorization(a))
#print(factorization(b))

c=set(factorization(a))&set(factorization(b))
ans=len(c)
print(ans)

Measured memory_bytes: 38768
#include<cstdio>
#include<map>
using namespace std;
typedef pair<int, int> P;

const int MAX_N = 1e5;
int h, w, n;
map<P, int> m;
long ans[10];

int main() {
    scanf("%d %d %d", &h, &w, &n);
    for (int i = 0; i < n; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (a - j + 2 > h || b - k + 2 > w 
                         || a - j < 1 || b - k < 1) continue;
                m[P(a - j, b - k)]++;
            }
        }
    }

    for (auto &i : m) ans[i.second]++;
    ans[0] = static_cast<long>(h - 2) * (w - 2) - m.size();

    for (int i = 0; i < 10; i++) printf("%ld\n", ans[i]);
    return 0;
}


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

int main() {
  int A,B;
  cin >> A >>B;
  int count = 0;
  int N = B-A+1;
  int M = A;
  
  for (int i = 0; i < N;i++){
    int a,b,c,d,e;
    a = M%10;
    M /=10;
    b = M%10;
    M /=10;
    c = M%10;
    M /=10;
    d = M%10;
    M /=10;
    e = M;
    if (a == e && b == d){
      count++;
    }
    A++;
    M = A;
  }
  
  cout << count << endl;
}



Measured memory_bytes: 3552
#include <iostream>
#include <cmath>
#include <cstdio>
#include <string>
#define rep(i,n) for(int (i) = 0; (i) < (n); (i)++)
using namespace std;

int match(string S, char c, int from, int to) {
    for (int i = from; i < to; i++) {
        if (S[i] == c) {
            return i;
        }
    }
    return -1;
}
int ok(string S, int N, int n) {
    char my[10];
    //sprintf_s(my, "%03d", n);
    sprintf(my, "%03d", n);
    int index = match(S, my[0], 0, N - 2);
    if (index == -1) return 0;
    index = match(S, my[1], index + 1, N - 1);
    if (index == -1) return 0;
    index = match(S, my[2], index + 1, N);
    if (index == -1) return 0;
    return 1;
}

int main() {
    int N;
    string S;
    int count = 0;
    cin >> N >> S;
    rep(i, 1000) {
        if (ok(S, N, i)) {
            count += 1;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	int a = 0, b = 0;
	rep(i,s.size() - 2){
		if(s.at(i) == s.at(i + 1) && s.at(i) != s.at(i + 2)){
			a = i;
			b = i + 2;
			break;
		}
		else if(s.at(i) == s.at(i + 2) && s.at(i) != s.at(i + 1)){
			a = i;
			b = i + 2;
			break;
		}
		else if(s.at(i) != s.at(i + 1) && s.at(i + 1) == s.at(i + 2)){
			a = i;
			b = i + 2;
			break;
		}
	}
	rep(i,s.size() - 1){
		if(s.at(i) == s.at(i + 1)){
			a = i;
			b = i + 1;
			break;
		}
	}
	if(b == 0) cout << "-1 -1" << endl;
	else cout << a + 1 << " " << b + 1 << endl;
}


Measured memory_bytes: 512
<?php
while (1) {
    list($h, $w) = explode(" ", trim(fgets(STDIN)));
    if ($h == 0 && $w == 0) exit;

    $str = str_repeat('.#', ($w/2)+1);
    for ($i = 0; $i < $h; $i++) {
        echo substr($str, ($i % 2) ? 0 : 1, $w) . PHP_EOL;
    }
    echo PHP_EOL;
}

Measured memory_bytes: 15564
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e15;
const long double EPS = 1e-10;

int main() {
  int a, b, q;
  cin >> a >> b >> q;
  vector<ll> s(a + 2), t(b + 2);
  rep(i, a) cin >> s[i];
  rep(i, b) cin >> t[i];

  s[a] = -INF, s[a + 1] = INF;
  t[b] = -INF, t[b + 1] = INF;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());

  rep(k ,q) {
    ll x;
    cin >> x;

    vector<ll> ress(2), rest(2);
    auto itrs = lower_bound(s.begin(), s.end(), x);
    ress[0] = *(itrs - 1), ress[1] = *itrs;
    auto itrt = lower_bound(t.begin(), t.end(), x);
    rest[0] = *(itrt - 1), rest[1] = *itrt;

    ll ans = INF;
    rep(i, 2) {
      rep(j, 2) {
        ll ans1 = fabs(x - ress[i]) + fabs(ress[i] - rest[j]);
        ll ans2 = fabs(x - rest[j]) + fabs(rest[j] - ress[i]);
        ans = min({ans, ans1, ans2});
      }
    }

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

Measured memory_bytes: 2944
package main

import "fmt"

func main() {
	var N, i int64
	fmt.Scan(&N)
	L := make([]int64, 2)
	L[0] = 2
	L[1] = 1
	for i = 2; i <= N; i++ {
		t := L[i-1] + L[i-2]
		L = append(L, t)
	}
	fmt.Println(L[N])
}


Measured memory_bytes: 512
import sys
import numpy as np
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(): return list(imap())
def farr(): return list(fmap())
def sarr(): return sinput().split()

n, a = imap()
x = np.array(iarr()) - a
MAX = 50*50+1

dp = np.zeros((n+1, 2*MAX+1)).astype(int)
dp[0][MAX] = 1
for i in range(n):
    for j in range(2*MAX):
        if j-x[i] < 0 or j-x[i] > 2*MAX:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = dp[i][j] + dp[i][j-x[i]]
print(dp[n][MAX]-1)


Measured memory_bytes: 20900
S = input()

if S == "SSS":
    print(0)
if S == "RSS":
    print(1)
if S == "RRS":
    print(2)
if S == "RRR":
    print(3)
if S == "SRS":
    print(1)
if S == "SSR":
    print(1)
if S == "SRR":
    print(2)
if S == "RSR":
    print(1)

Measured memory_bytes: 9120
'use strict'
const main = input => {
  const n = parseInt(input[0], 10), a = input[1].split(' ').map(val => parseInt(val, 10)), b = input[2].split(' ').map(val => parseInt(val));
  // console.log(n, a, b);
  let ans = 0;
  for(let i=0; i<n; i++) {
    if (b[i] >= a[i]) {
      ans += a[i];
      b[i] -= a[i];
      a[i] = 0;
      if (b[i] >= a[i+1]) {
        ans += a[i+1];
        b[i] -= a[i+1];
        a[i+1] = 0;
      } else {
        ans += b[i];
        a[i+1] -= b[i];
        b[i] = 0;
      }
    } else {
      ans += b[i]
      a[i] -= b[i];
      b[i] = 0;
    }
    // console.log(n, a, b, ans);
    
  }
  console.log(ans);
  
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

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

const int N=200008;

int main()
{
	cin.sync_with_stdio(0);
	int n,a,b;
	cin>>n>>a>>b;
	if (n==1 && a==b) cout<<1<<endl; else
	if (n==1 || a>b) cout<<0<<endl; else
	if (a==b)
	{
		cout<<1<<endl;
	}
	else
	{
		cout<<1ll*(b-a)*(n-2)+1<<endl;
	}
}




Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int N,H[200],i=0,max=0,count=1;
    scanf("%d",&N);
    for(i=0;i<N;i++)
    {
        scanf("%d",&H[i]);
    }
    max=H[0];
    for(i=1;i<N;i++)
    {
      if(H[i]>=max)
      {
         count++;
         max=H[i];
      }
    }
    printf("%d\n",count);

return 0;
}


Measured memory_bytes: 128
#![allow(unused_imports)]
#![allow(dead_code)]
#![macro_use]
use std::io::prelude::*;
use std::cmp::{max, min};
use std::collections::BinaryHeap;

const MOD: i64 = 1e9 as i64 + 7;

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 main() {
    input! {
        n: usize,
        s: chars,
        t: chars,
    }
    let mut ans = 2 * n;
    for i in 0..n{
        for j in 0..n - i{
            if s[i + j] != t[j] {
                break;
            }
            if i + j == n - 1 {
                ans = 2 * n - j - 1;
                break;
            }
        }
        if ans < 2 * n{
            break;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
class UnionFind:
    def __init__(self, num):
        self.rank = [0] * num
        self.par = [i for i in range(num)]
        self.n = num

    def find_root(self, node):
        if self.par[node] == node:
            return node
        else:
            self.par[node] = self.find_root(self.par[node])
            return self.par[node]

    def same_root(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def union(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        if self.rank[x] > self.rank[y]:
            self.par[y] = x
        else:
            self.par[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1


def main():
    N, M = map(int, input().split())
    L = [list(map(int,input().split())) for i in range(M)]
    for i in range(M) :
        L[i][0] -= 1
        L[i][1] -= 1
    
    ans = 0
    
    for i in range(M) :
        UF = UnionFind(N)
        for j in range(M) :
            if j == i :
                continue
            UF.union(L[j][0], L[j][1])
        
        ans += (UF.same_root(L[i][0], L[i][1]) == False)
    
    print(ans)

import sys
input = sys.stdin.readline

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<cstdio>

using namespace std;
int abs(int a,int b){
    if(a>b) return a-b;
    return b-a;
}
int main()
{
	int n,a,b,sum;
	while(~scanf("%d",&n)){
        sum=0;
        while(n--){
            scanf("%d%d",&a,&b);
            sum+=(abs(a,b)+1);
        }
        printf("%d\n",sum);
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;



int main(void) {

    int h,w,k;
    cin>>h>>w>>k;
    set<int> s;
    for(int i=0;i<=h;i++){
        s.insert(i*w);
    }
    for(int i=0;i<=w;i++){
        s.insert(i*h);
    }
    for(int i=0;i<=h;i++){
        for(int j=0;j<=w;j++){
            int c=i*w+j*h-2*i*j;
            s.insert(c);
        }
    }
    if(s.find(k)!=s.end()){
        fin("Yes");
    } else {
        fin("No");
    }
    // for(auto it=s.begin();it!=s.end();it++){
    //     cout<<*it<<" ";
    // }
    // cout<<endl;
}



Measured memory_bytes: 13056
#include <valarray>
#include <cstdio>
using namespace std;
typedef valarray<int>V;
int n,m;
V M2(const V &x,const V &y){
	V z(n*n);
	int i=0,j;
	for(;i<n;i++)for(j=0;j<n;j++)z[i*n+j]=(x[slice(i*n,n,1)]*y[slice(j,n,n)]).sum()%m;
	return z;
}
V M1(const V &x){
	V z(n*n);
	int i=0,j;
	for(;i<n;i++)for(j=0;j<n;j++)z[i*n+j]=(x[slice(i*n,n,1)]*x[slice(j,n,n)]).sum()%m;
	return z;
}
V E(const V &x,const int n){
	if(n==1)return x;
	if(n&1)return M2(E(x,n-1),x);
	return M1(E(x,n>>1));
}
void O(const V &r,const V &s){
	int i=0;
    for(;i<n-1;i++)printf("%d ",(r[slice(i*n,n,1)]*s).sum()%m);
    printf("%d\n",(r[slice(i*n,n,1)]*s).sum()%m);
}
main(){
	int i,a,b,c,t;
	for(;scanf("%d%d%d%d%d%d",&n,&m,&a,&b,&c,&t),n;){
		V s(n);
		for(i=0;i<n;i++)scanf("%d",&s[i]);
		V x(n*n);
		if(t){
			x[0]=b;
			x[1]=c;
			for(i=1;i<n-1;i++){
				x[i*n+i-1]=a;
				x[i*n+i]=b;
				x[i*n+i+1]=c;
			}
			x[i*n+i-1]=a;
			x[i*n+i]=b;
			O(E(x,t),s);
		}else{
			for(i=0;i<n;i++)x[i*n+i]=1;
			O(x,s);
		}
	}
}

Measured memory_bytes: 1080
#include <iostream>
#include <queue>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <iomanip>

using namespace std;
typedef long long LL;

int main() {
    int A, B, H, M;
    cin >> A >> B >> H >> M;
    int radisH = H * 360 / 12 == 0 ? 0 : H * 360 / 12;
    int radisM = M * 360 / 60 == 0 ? 0 : M * 360 / 60;
    double minus = 0;
    if (H * 1.0 >= 1.0 * M / 5) {
        minus = abs(radisH - radisM) + 1.0 * M * 30 / 60;
    } else {
        minus = abs(radisH - radisM) - 1.0 * M * 30 / 60;
    }
    if (minus == 90) {
        cout << fixed << setprecision(10) << sqrt(A * A * 1.0 + B * B * 1.0) << endl;
        return 0;
    }
    cout << fixed << setprecision(10) << sqrt(A * A + B * B - 2 * A * B * cos(minus * 1.0 / 180 * acos(-1.0))) << endl;
    return 0;
}

Measured memory_bytes: 4168
function Main(input) {
	lines = input.split("\n");
	N = parseInt(lines[0].split(' ')[0], 10);
	A = parseInt(lines[0].split(' ')[1], 10);
	B = parseInt(lines[0].split(' ')[2], 10);
	C = parseInt(lines[0].split(' ')[3], 10);
	D = parseInt(lines[0].split(' ')[4], 10);
	S = lines[1];
	S = '#' + S + '#';
	can_reach = (start, end) => {
	  for(var i=start; i+1<= end; i++) {
	    if(S[i] == '#' && S[i+1] == '#') return false;
	  }
	  return true;
	};
	if(!can_reach(A, C) || !can_reach(B, D)) {
	  console.log('No');
	  return;
	}
	
	if(C > D){
	  snuke_can_over = false;
	  for(var i=B; i <= D; i++) {
	    if(S[i-1]=='.' && S[i]=='.' && S[i+1]=='.'){
	      snuke_can_over = true;
	    }
	  }
	  if(!snuke_can_over) {
	    console.log('No');
	    return;
	  }
	}
	console.log('Yes');
	return
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
use proconio::input;

fn main() {
    input!(x: i64, k: i64, d: i64);
    let x = x.abs();
    let t = x / d;
    let ans = if k <= t || (k - t) % 2 == 0 {
        x - d * k.min(t)
    } else {
        -(x - d * (t + 1))
    };
    println!("{}", ans)
}


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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    int a,b; cin >> a >> b;
    if(a <= 8 && b <=8)
    {
        cout << "Yay!" << endl;
    }else
    {
        cout << ":(" << endl;
    }
    
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define Mod 1000000007
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
#define INF (ll)(1e17+5)
#define NN (ll)(1e6+5)
int mod(string s,int a) 
{ 
    int ans=0; 
    for (int i=0;i<s.length();i++) 
         ans=(ans*10+(int)s[i]-'0')%a; 
    return ans; 
}
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y) 
{ 
    if (y==0) 
        return 1; 
    else if (y%2==0) 
        return power(x,y/2)*power(x,y/2); 
    else
        return x*power(x,y/2)*power(x,y/2); 
}
ll hcf(ll a,ll b) 
{ 
    if(b==0) 
        return a; 
    return hcf(b,a%b);  
}
int main()
{
   fio;
   /*#ifndef ONLINE_JUDGE 
    	freopen("input.txt", "r", stdin); 
    	freopen("output.txt", "w", stdout); 
    	freopen("error.txt", "w", stderr); 
   #endif*/
   ll TT=1;
   //cin>>TT;
   while(TT--)
   {    
       ll i,a,b,ans=-1;
       cin>>a>>b;
       for(i=1;i<=1000005;i++)
       {
           if((i*8)/100==a&&(i*10)/100==b)
            {
                ans=i;
                break;
            }
       }   
       cout<<ans<<"\n";
   }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 500000
#define S 1000000001
 
void merge(int *, int, int ,int);
void mergeSort(int *, int, int);
int cnt;

int main(){
  int n,s[N];
  cin>>n;
  for(int i=0;i<n;i++) cin>>s[i];
  mergeSort(s,0,n);
   
  for(int i=0;i<n-1;i++)cout<<s[i]<<' ';
  cout<<s[n-1]<<endl<<cnt<<endl;
  return 0;
}
 
void merge(int *a,int left,int mid,int right){
  int n1 = mid - left;
  int n2 = right - mid;
  int l[n1+1], r[n2+1];
   
  for(int i=0;i<n1;i++) l[i]=a[left + i];  
  for(int i=0;i<n2;i++) r[i]=a[mid + i];
  l[n1]=S;
  r[n2]=S;
  int x=0,y=0;

  for(int k=left;k<right;k++){
    if(l[x]<=r[y]){
      a[k]=l[x];
      x++;
    }
    else{
      a[k]=r[y];
      y++;
    }
    cnt++;
  }
}
 
void mergeSort(int *a, int left, int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(a,left,mid);
    mergeSort(a,mid,right);
    merge(a,left,mid,right);
  }
}



Measured memory_bytes: 6940
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={0,31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
inline int read(){
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x;
}
const ll INF=2e5+10;
const ll mod=1e9+7;
ll sum[INF];
ll a[INF];
int n;
ll ans;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=n;i>-1;i--)sum[i]=a[i+1]+sum[i+1],sum[i]%=mod;
	for(int i=0;i<n;i++)ans+=a[i]*sum[i],ans%=mod;
	cout<<ans;
	return 0;
}



Measured memory_bytes: 6792
using System;

class Program
{
    static void Main(string[] args) {
        string s = Console.ReadLine();
        string t = Console.ReadLine();
        Console.WriteLine(solve(s,t) ? "Yes": "No");
    }
    static bool solve(string s, string t) {
        int l = s.Length;
        for(int i = 0; i < l; i ++) {
            if(s == t) return true;
            s = s[l-1].ToString() + s.Substring(0, l-1);
        }
        return false;
    }
}

Measured memory_bytes: 11092
S = input()

ans = []
S = S + 'R'
lenS = len(S)

i = 1 # R start
last = 'R'
cntR = 1
cntL = 0

while i < lenS:
    chara = S[i]
    if last=='R' and chara=='R':
        cntR += 1
    elif last=='R' and chara=='L':
        cntL = 1
        last = 'L'
    elif last=='L' and chara=='L':
        cntL += 1
    elif last=='L' and chara=='R':
        nAll = cntR + cntL
        newl = [0]*(nAll)

        if (cntR+cntL)%2 == 0:
            newl[cntR-1] = nAll//2
            newl[cntR] = nAll//2
        elif cntR < cntL:
            if cntR%2==0:
                newl[cntR-1] = nAll//2
                newl[cntR] = nAll//2 + 1
            elif cntR%2==1:
                newl[cntR-1] = nAll//2 + 1
                newl[cntR] = nAll//2

        elif cntR > cntL:
            if cntR%2==0:
                newl[cntR-1] = nAll//2
                newl[cntR] = nAll//2 + 1
            elif cntR%2==1:
                newl[cntR-1] = nAll//2 + 1
                newl[cntR] = nAll//2
                
        ans.extend(newl)
        last = 'R'        
        cntR = 1
        cntL = 0
    i += 1

print(*ans)

Measured memory_bytes: 7280
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=1<<18;

int main(){
    string s;
    cin>>s;
    ll n=0;
    for(ll i=0;i<s.length();i++){
        n+=s[i]-'0';
        n=n%9;
    }
    if(n%9==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

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

int main() {
  int H,W,A,B;
  cin >> H >> W >> A >> B;
  REP(y,H) {
    REP(x,W) {
      string c = ( ((x >= A) && (y < B)) || ((x < A) && (y >= B)) ) ? "1" : "0";
      cout << c;
    }
    cout << endl;
  }
}



Measured memory_bytes: 1280
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#include <bits/stdc++.h>
using namespace std;
int main() {
  double w,h,x,y;
  cin>>w>>h>>x>>y;
  double ans1;
  int ans2=0;
  
  ans1=w*h/2;
  
  if(w==2*x&&h==2*y)ans2=1;
  cout << fixed << setprecision(9);
  cout<<ans1<<" "<<ans2<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
using namespace std;
int n;
int a[200005];
int main(void){
	cin>>n;
	REP(i,n)cin>>a[i];
	sort(a,a+n);
	REP(i,n-1)if(a[i]==a[i+1]){
		cout<<"NO";
		return 0;
	}
	cout<<"YES";
	return 0;
}

Measured memory_bytes: 1024
def resolve():
    n, m = map(int, input().split())
    for i in range(m):
        l, r = map(int, input().split())
        if i == 0:
            start = l
            end = r
        else:
            if start <= l:
                start = l
            if r <= end:
                end = r
    if start > end:
        print(0)
    else:
        print(end-start+1)
resolve()

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>

int main(void){
    int n;
    char str[20];
    n=0;
    scanf("%d", &n);
    scanf("%s", str);
    for (int i=1; i<=strlen(str); i++){
        if(str[i-1]=='x') n++;
    }
    if(n<=7) printf("YES");
    else printf("NO");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T> using Graph = vector<vector<T>>;

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (__typeof(a.begin()) x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define endl '\n'
#define to first
#define cost second

int n;
bool used[100005];
vector<pair<int, int>> tr[100005];

pair<int, int> dfs1(int s, int d) {
  used[s] = true;
  pair<int, int> res = {s, d};
  for (auto p: tr[s]) {
    if (used[p.to]) continue;
    auto tp = dfs1(p.to, d + p.cost);
    if (tp.cost > res.cost) res = tp;
  }
  return res;
}

int dfs2(int s) {
  used[s] = true;
  int res = 0;
  for (auto p: tr[s]) {
    if (used[p.to]) continue;
    res = max(res, dfs2(p.to) + p.cost);
  }
  return res;
}

int diameter() {
  auto p = dfs1(0, 0);
  rep(i, n) used[i] = false;
  return dfs2(p.to);
}

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

  cin >> n;
  rep(i, n - 1) {
    int s, t, w;
    cin >> s >> t >> w;
    tr[s].push_back({t, w});
    tr[t].push_back({s, w});
  }

  cout << diameter() << endl;

  return 0;
}

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

using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) { return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M; }
inline ll sum_1(const ll i, const ll j) { return (sum_1(j) - sum_1(i - 1) + M) % M; }
inline ll sum_2(const ll i, const ll j) { return (sum_2(j) - sum_2(i - 1) + M) % M; }
inline ll sum_3(const ll i, const ll j) { return (sum_3(j) - sum_3(i - 1) + M) % M; }

ll pow_f(ll b, ll e) {
    ll ans = 1;
    b = b % M;
    while (e) {
        if (e&1) {
            ans = (ans * b) % M;
        }
        b = (b * b) % M;
        e >>= 1;
    }
    return ans;
}

ll nCr(ll n, ll r) {
    if (r > n || n < 0 || r < 0) { return 0; }
    if (n == r || r == 0) { return 1; }
    r = min(r, n-r);
    ll ans = 1;
    for (ll i = 1; i <= r; ++i) {
        ans = (ans * (n-i+1))/(i); 
    }
    return ans;
}

ll nCr(tuple<ll,ll> t) {
    auto n = get<0>(t);
    auto k = get<1>(t);
    return nCr(n+k-1, k);
}

template<typename T>
void print(T v) {
    cout << v << " ";
}

template<typename T>
void print(vector<T> v) {
    for (auto &i : v) {
        print(i);
    }
    cout << endl;
}

void solve() {
    /**
     * 
     * 2*M + 1 <= N
     */ 

    ll n, m;
    cin >> n >> m;
    ll l = 0;
    ll r = m;
    ll diff = m;
    ll cnt = 0;
    for (ll i = 0; i < ceil(m/2.); ++i) {
        ++cnt;
        cout << i+1 << " " << m-i+1 << endl;
    }
    for (ll i = 0; i < m-ceil(m/2.); ++i) {
        ++cnt;
        cout << i+m+2 << " " << 2*m+1-i << endl;
    }
    assert(cnt==m);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifdef D_LOCAL
        freopen("in.in", "r", stdin);
        freopen("out.out", "w", stdout);
    #endif

    solve();

    return 0;
}

Measured memory_bytes: 3672
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll=long long;
ll N,K;
vector<ll> v,a;
int main(){
    cin.tie(0);ios_base::sync_with_stdio(0);
    cin>>N>>K;
    v.push_back(K),a.push_back(0);
    for(int i{1};i<31;++i){
        if(K>>i&1){
            ll L{K^(1<<i)};
            for(int j{};j<i;++j)
                L|=1<<j;
            v.push_back(L),a.push_back(0);
        }
    }
    for(int i{};i<N;++i){
        ll A,B;cin>>A>>B;
        for(int j{};j<(int)v.size();++j)
            if((A&v[j])==A)a[j]+=B;
    }
    cout<<*max_element(a.begin(),a.end())<<endl;
}


Measured memory_bytes: 256
def prime_decomposition(n): #素因数分解でリストを返す
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

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

C=prime_decomposition(A)
D=prime_decomposition(B)
E=list(set(C)&set(D))
print(len(E)+1)

Measured memory_bytes: 38512
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){

  llong k,a,b;
  cin>>k>>a>>b;
  if(b-a<=2){
    cout<<k+1<<endl;
    return 0;
  }
  if(k-a<=0){
    cout<<k+1<<endl;
    return 0;
  }

  llong nokori = k-a+1;
  llong ans = a + (nokori/2) * (b-a) + nokori%2;
  cout<<ans<<endl;


  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
//#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<auto>& a,int n);
double PI = 3.14159265358979;
int n;




signed main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    list<int> lst;
    cin >> n;
    REP(i,n){
        string s;
        cin >> s;
        if(s[0] == 'i'){
            int tmp;
            cin >> tmp;
            lst.push_front(tmp);
        }else if(s.size()==6){
            int x;
            std::cin>>x;
            for(auto itr=lst.begin();itr!=lst.end();itr++){
                if(*itr==x){
                    lst.erase(itr);
                    break;
                }
            }
        }else{
            if(s[6]=='F'){
                lst.pop_front();
            }else{
                lst.pop_back();
            }
        }
    }
    for(auto itr = lst.begin(); itr != lst.end();){
        cout << *itr;
        ++itr;
        if(itr != lst.end()){
            cout << " ";
        }
    }
    std::cout<<"\n";
    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}

//key以上の初めてのitr
int nibul(auto a,auto b){return lower_bound(All(a),b) - a.begin();}
//key以下の最後のitr
int nibuu(auto a,auto b){return upper_bound(All(a),b) - a.begin()-1;}

void input(vector<auto>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 34448
#include <stdio.h>

int main()
{
  int n, a, b;

  char last_word;
  bool judge1 = true;
  
  scanf("%d", &n);

  if(n==1) { printf("Hello World\n"); }
  else {
    scanf("%d", &a);
    scanf("%d", &b);
    printf("%d\n", a+b); 
  }
  
}

Measured memory_bytes: 128
def main():

    n = int(input())
    activities = [[int(x) for x in input().split()] for _ in range(n)]
    dp = [0] * 3
    # dp[i] - the total happiness such that we did activity i on the last considered day
    for day in range(n):
        new_dp = [0] * 3
        for i in range(3):
            for j in range(3):
                if i != j:
                    new_dp[j] = max(new_dp[j], dp[i] + activities[day][j])
        dp = new_dp
    print(max(dp))


main()


Measured memory_bytes: 24308
n = int(input())
words = []
flag = True

for i in range(n):
    word = input()
    if word in words:
        flag = False
        break
    else:
        words.append(word)
if not flag:
    print("No")
    quit()

for i in range(1, n):
    if words[i-1][-1:] != words[i][0:1]:
        flag = False

if flag:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define N 130
#define C 16
using namespace std;
typedef pair<int,int> P;

int r, c, dp[2][C][(1<<C)];
P memo[C][(1<<C)];
string s[N];

void init(){
  
  for(int i=0;i<c;i++)
    
    for(int j=0;j<(1<<c);j++){

      int cnt=0;
      for(int k=0;k<i;k++)
	if(j&(1<<k)) cnt++;
      memo[i][j].first=cnt;
      
      cnt=0;
      for(int k=i;k<c;k++)
	if(j&(1<<k)) cnt++;
      memo[i][j].second=cnt;
      
    }

}

int main(){
  
  cin>>r>>c;
  
  for(int i=0;i<r;i++) cin>>s[i];

  init();
  
  memset(dp,-1,sizeof(dp));
  
  dp[0][0][0]=0;
  
  for(int i=0;i<r;i++){

    for(int j=0;j<c;j++)
      for(int k=0;k<(1<<c);k++) dp[(i+1)%2][j][k]=-1;
    
    for(int j=0;j<c;j++){
      
      for(int k=0;k<(1<<c);k++){
	
	if(dp[i%2][j][k]==-1) continue;
	
	if(memo[j][k].first<s[i].size()){
	  
	  int cost=dp[i%2][j][k], nk=k|(1<<j);
	  
	  if(i&&(k&(1<<j))&&s[i][memo[j][k].first]==s[i-1][s[i-1].size()-memo[j][k].second]) cost+=2;
	  
	  if(j&&(k&(1<<(j-1)))&&s[i][memo[j][k].first]==s[i][memo[j][k].first-1]) cost+=2;
	  
	  if(j==c-1&&memo[j][k].first+1==s[i].size()) dp[(i+1)%2][0][nk]=max(dp[(i+1)%2][0][nk],cost);
	  if(j!=c-1) dp[i%2][j+1][nk]=max(dp[i%2][j+1][nk],cost);
	  
	}

	int nk=k&~(1<<j);
	
	if(j==c-1&&memo[0][nk].second==s[i].size()) dp[(i+1)%2][0][nk]=max(dp[(i+1)%2][0][nk],dp[i%2][j][k]);
	if(j!=c-1) dp[i%2][j+1][nk]=max(dp[i%2][j+1][nk],dp[i%2][j][k]);
	
      }
      
    }
    
  }
  
  int ans=0;
  
  for(int i=0;i<(1<<c);i++) ans=max(ans,dp[r%2][0][i]);

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

Measured memory_bytes: 19612
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <deque>
using namespace std;
 
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
 
const int inf = 2e9;
const int N = 55;
ll n, a[N], ans;

int main() {
	cin >> n;
	for(int i = 1; i <= n; ++i)
		cin >> a[i];
	while(1) {
		int ind = 1;
		for(int i = 1; i <= n; ++i)
			if(a[ind] < a[i])
				ind = i;
		if(a[ind] < n)
			break;
		ll val = a[ind] / n;
		ans += a[ind] / n;
		a[ind] -= (a[ind] / n) * n;
		for(int i = 1; i <= n; ++i)
			if(i != ind)
				a[i] += val;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
/**
 * File              : F-review2.cpp
 * Author            : JCHRYS <jchrys@me.com>
 * Date              : 09.02.2020
 * Last Modified Date: 09.02.2020
 * Last Modified By  : JCHRYS <jchrys@me.com>
 */

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int const MAXN = 51;
int constexpr log(int x) {
    return sizeof(int) * 8 - __builtin_clz(x);
}
int const LOG = log(MAXN);
vector<vector<int>> adj(MAXN);
vector<int> depth(MAXN, 0);
vector<vector<int>> par(MAXN, vector<int>(LOG, 0));

void build(int u = 1, int p = 0) {
    if (p)
        depth[u] = depth[p] + 1;
    else {
        depth[u] = 1;
    }
    par[u][0] = p; 
    for (int i = 0; i < LOG - 1; i++)
        if (par[u][i]) {
            par[u][i + 1] = par[par[u][i]][i];
        }
    for (auto v: adj[u]) {
        if (v == p) continue;
        build(v, u);
    }
}

int lca(int u, int v) {
    if (depth[u] < depth[v]) {
        swap(u, v);
    }
    // depth[u] >= depth[v];
    for (int i = LOG - 1; i >= 0; --i)
        if (depth[par[u][i]] >= depth[v]) {
            u = par[u][i];
        }
    if (u == v) {
        return u;
    }

    for (int i = LOG - 1; i >= 0; --i)
        if (par[u][i] != par[v][i])
            u = par[u][i], v = par[v][i];
    return par[u][0];
}

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

    build();

    int m;
    cin >> m;
    vector<ll> limits(m);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        ll bit = 0;
        int _lca = lca(u, v);
        for (;u != _lca; u = par[u][0]) bit |= 1LL<<(u-1);
        for (;v != _lca; v = par[v][0]) bit |= 1LL<<(v-1);
        limits[i] = bit;
    }

    ll res = 0;
    for (int mask = 0; mask < (1 << m); mask++) {
        ll bit = 0;
        for (int i = 0; i < m; i++) {
            if ((mask >> i) & 1) {
                bit |= limits[i];
            }
        }
        ll val = 1LL << (n - 1 - __builtin_popcountll(bit));
        if (__builtin_popcount(mask)&1) {
            res -= val;
        } else {
            res += val;
        }
    }
    cout << res;
    

    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort()

def main(a):
  if 0 in a:
    ans = 0
  else:
    ans = 1
    for item in a:
      ans *= item
      if ans > 1000000000000000000:
        ans = -1
        break
  return ans

ans = main(a)
print(ans)


Measured memory_bytes: 21580
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

priority_queue<int, vector<int>, greater<int>> l;
priority_queue<int> r;

int main() {
	int N, A[300010]; cin >> N;
	long L=0, R=0;
	for(int i=0; i<3*N; ++i){
	    cin >> A[i];
	    if(i<N){
	        L += A[i];
	        l.push(A[i]);
	    }
	    if(i>=N*2){
	        R += A[i];
	        r.push(A[i]);
	    }
	}
	long P[100010], Q[100010];
	P[0]=L, Q[N]=R;
	for(int i=0; i<N; ++i){
	    if(l.top()<A[N+i]){
	        P[i+1]=P[i]-l.top()+A[N+i];
	        l.pop();
	        l.push(A[N+i]);
	    }
	    else P[i+1]=P[i];
	    if(r.top()>A[N*2-i-1]){
	        Q[N-i-1]=Q[N-i]-r.top()+A[N*2-i-1];
	        r.pop();
	        r.push(A[N*2-i-1]);
	    }
	    else Q[N-i-1]=Q[N-i];
	}
	long ans=P[0]-Q[0];
	for(int i=1; i<=N; ++i) ans=max(ans, P[i]-Q[i]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3832
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num1 = sc.nextInt();
        int num2 = sc.nextInt();
        int num3 = sc.nextInt();
        
        if (num1 < num2 && num2 < num3) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 26160
#include<iostream>
using namespace std;
#define ll long long 
#include<bits/stdc++.h>
#define mod 1000000007
void grid(ll int n,ll int m,string s[])
{
  ll int dp[n+1][m+1];
  memset(dp, 0, sizeof(dp)); 
  int f=0;
  
  for(int i=0;i<m;i++)
  {
     if(s[0][i]=='#')
     f=1;
     if(f==0)
      dp[0][i]=1;
  }
  
  f=0;
  for(int i=0;i<n;i++)
  {
     if(s[i][0]=='#')
     f=1;
    if(f==0)
      dp[i][0]=1;
   }
  
  for(ll int i=1;i<n;i++)
  {
    for(ll int j=1;j<m;j++)
    {
      if(s[i][j]=='#')
        dp[i][j] = 0;
      else
        dp[i][j] = (dp[i-1][j]%mod + dp[i][j-1]%mod)%mod;
    }
  }
  cout<<dp[n-1][m-1]%mod<<endl;

}
int main()
{
 	ll int n,m;
  cin>>n>>m;
  string s[n];
  for(ll int i=0;i<n;i++)
    cin>>s[i];
  grid(n,m,s);
}


Measured memory_bytes: 13324
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {

			int n = sc.nextInt();
			Integer[] a = new Integer[n + 1];
			Integer[] b = new Integer[n];
			for(int i = 0 ; i < n + 1 ; i++) {
				a[i] = sc.nextInt();
			}
			for(int i = 0 ; i < n ; i++) {
				b[i] = sc.nextInt();
			}
			long ans = 0;
			int zan = a[0];
			for(int i = 0 ; i < n ; i++) {
				if(zan < b[i]) {
					b[i] -= zan;
					ans += zan;
					if(a[i + 1] < b[i]) {
						ans += a[i + 1];
						zan = 0;
					} else {
						ans += b[i];
						zan = a[i + 1] - b[i];
					}
				} else {
					ans += b[i];
					zan = a[i + 1];
				}
			}
			System.out.println(ans);

		}
	}

}


Measured memory_bytes: 92792
fun main(args: Array<String>) {
    abc107b()
}

fun abc107b() {
    val (h, w) = readLine()!!.split(" ").map { it.toInt() }
    val aList = (1..h).map { readLine()!!.toCharArray() }

    val horizontalOutIndex = aList
        .mapIndexed { index, chars -> Pair(index, chars.any { it == '#' }) }
        .filter { it.second }.map { it.first }

    val verticalOutIndex = (0 until w).mapNotNull { i ->
        if (aList.map { it[i] }.any { it == '#' }) i else null
    }

    val answer = aList.mapIndexed { indexChars, chars ->
        if (horizontalOutIndex.contains(indexChars)) {
            chars.mapIndexed { indexChar, c ->
                if (verticalOutIndex.contains(indexChar)) c else null
            }.filterNotNull().joinToString(separator = "")
        } else null
    }.filterNotNull()

    println(answer.joinToString(separator = System.lineSeparator()))
}


Measured memory_bytes: 38660
#include <bits/stdc++.h>
using namespace std;
#define ALL(a)  (a).begin(),(a).end()
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  if(N % 2 == 1) cout << "No" << endl;
  else if(S.substr(0, N/2) == S.substr(N/2, N/2)){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N, M; cin >> N >> M;
    vector<pair<int, int>> P(M), Y(M);
    REP(i, 0, M) {
        cin >> P[i].first >> Y[i].first;
        Y[i].second = i;
    }
    sort(ALL(Y));

    int count[N + 1] = {};
    for (auto y : Y) {
        P[y.second].second = ++count[P[y.second].first];
    }

    for (auto p : P) {
        stringstream ss;
        ss << setw(6) << setfill('0') << p.first;
        ss << setw(6) << setfill('0') << p.second;
        cout << ss.str() << endl;
    }
    return 0;
}

Measured memory_bytes: 3456