akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

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

    int c[n],t[n];
    for(int i=0;i<n;i++){
        cin >> c[i] >> t[i];
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(c[j]<c[i]){
                int temp=c[i];
                c[i]=c[j];
                c[j]=temp;
                temp = t[i];
                t[i]=t[j];
                t[j]=temp;
            }
        }
        //cout << c[i] << endl;
    }
    int result=0;
    for(int i=0;i<n&&result==0;i++){
        if(t[i]<=t1){cout << c[i] << endl;result++;}
    }
    if(result==0)cout << "TLE" << endl;



}

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

int main() {
  string s;
  cin >> s;
  int n = s.size(), c = 0;
  for(int i = 0; i < n/2; ++i){
    if(s.at(i) != s.at(n-i-1)) ++c;
  }
  cout << c << endl;
}

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

int main()
{
	int n;
	cin >> n;
	vector<ll> a(n);
	for(auto &i: a)cin >> i;

	ll now = a[0];
	ll ans = 0;
	for(int i = 0;i<n-1;i++)
	{
		now = max(now,a[i+1]);
		ans += max(0LL,now-a[i+1]);
	}
	cout<<ans<<endl;
}


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

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

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

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

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

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
        a: [i32; n],
    }
    let mut x = a[0];
    for i in 1..n {
        if i % 2 == 0 {
            x += a[i];
        } else {
            x -= a[i];
        }
    }
    println!("{}", x);
    for i in 1..n {
        x = 2 * a[i - 1] - x;
        println!("{}", x);
    }
}


Measured memory_bytes: 5372
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int cnt,fst[200005],nxt[200005],to[200005],w[200005];
int n,m,col[200005],sum[3],res,snd;
ll ans;
bool vis[200005],fg;
void AddEdge(int u,int v,int c)
{
	to[++cnt]=v;
	nxt[cnt]=fst[u];
	fst[u]=cnt;
	w[cnt]=c;
}
int Calc(int x)
{
	return x>=3?x-3:(x<0?x+3:x);
}
void Dfs(int u)
{
	snd++;
	sum[col[u]]++;
	vis[u]=1;
	for(int i=fst[u];i;i=nxt[i])
	{
		int v=to[i];
		if(w[i]==1) res++;
		if(!vis[v])
		{
			col[v]=Calc(col[u]+w[i]);
			Dfs(v);
		}
		else if(col[v]!=Calc(col[u]+w[i])) fg=0;
	}
}
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d %d",&x,&y);
		AddEdge(x,y,1);
		AddEdge(y,x,-1);
	}
	for(int i=1;i<=n;i++)
	{
		if(vis[i]) continue;
		memset(sum,0,sizeof(sum));
		res=snd=0;
		fg=1;
		Dfs(i);
		if(!fg) ans+=1ll*snd*snd;
		else if(sum[0] && sum[1] && sum[2]) ans+=1ll*sum[0]*sum[1]+1ll*sum[0]*sum[2]+1ll*sum[1]*sum[2];
		else ans+=1ll*res;
	}
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

int main(void) {
	int num, menu, i = 0, j, buf, ans = 0;
	cin >> num >> menu;
	vector<int> d(menu, 0);
	for (; i < num; i++) {
		cin >> j;
		for (; j > 0; j--) {
			scanf("%d", &buf);
			d[--buf]++;
		}
	}
	for (i = 0; i < menu; i++)
		if (d[i] == num)
			ans++;
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int room[4][3][10];
    int n,b,f,r,v;
    int i,j,k;
    
    for (i=0; i<4; i++) {
    for (j=0; j<3; j++) {
    for (k=0; k<10;k++) {
    room[i][j][k]=0;
           }
       }
    }
    
    scanf("%d",&n);
    for (i=0; i<n; i++) {
        scanf("%d %d %d %d",&b,&f,&r,&v);
        room[b-1][f-1][r-1]+=v;}
    
    for (i=0; i<4; i++) {
        for (j=0; j<3; j++) {
            for (k=0; k<10;k++) {
                printf(" %d",room[i][j][k]);
            }   printf("\n");
        }
        if (i==3) break;
        for(j=0;j<20;j++){
            printf("#");
        }
        printf("\n");
        

    }
    return 0;
}

Measured memory_bytes: 600
-- https://github.com/minoki/my-atcoder-solutions
import Data.Char (isSpace)
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as BS

main = do
  n <- readLn
  xs <- U.unfoldrN (n-1) (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ U.head xs + U.sum (U.zipWith min xs (U.tail xs)) + U.last xs


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

using namespace std;
using ll = long long;

ll solve(ll K, const vector<ll>& as)
{
    ll mask = 1LL << 50, X = 0;

    while (mask)
    {
        ll ones = 0, zeros = 0;

        for (ll a : as)
            if (a & mask)
                ++ones;
            else
                ++zeros;

//cout << "mask = " << mask << ", ones = " << ones << ", zeros = " << zeros << '\n';
        if (ones < zeros and (X | mask) <= K)
        {
            X |= mask;
//cout << "New X = " << X << ", ones = " << ones << '\n';
        }
        mask >>= 1;
    }

    ll ans = 0;

//cout << "X = " << X << '\n';

    for (const auto& a : as)
        ans += X ^ a;

    return ans;
}

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

    ll N, K;
    cin >> N >> K;

    vector<ll> as(N);

    for (int i = 0; i < N; ++i)
        cin >> as[i];

    int ones = 0;

    for (int i = 0; i < N; ++i)
        if (as[i] & 1)
            ones++;

    auto ans = solve(K, as);

    cout << ans << '\n';

    return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long

ll M=1000000007;
            
void solve()
{
	ll n;
	cin>>n;
	ll arr[n],sum=0;
	for (ll i = 0; i < n; i++) 
	{
		cin>>arr[i];
		sum = (sum + arr[i])%M ;
	}

	ll ans=0,cur=0;
	for (ll i = 0; i < n; i++)
	{
		sum = (sum - arr[i] + M) %M;
		ans = ( ans + (sum * arr[i])%M ) %M;
	}

	cout<<ans;
}

int main()
{
	IOS
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++) solve();
	return 0;
}


Measured memory_bytes: 5208
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  ll x,y;
  cin >> x >> y;
  int ans = 0;
  while(x <= y){
    x *= 2;
    ans ++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
from collections import Counter

def prime(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  
_a, _b = map(int, input().split())
_a_set = set(prime(_a))
_b_set = set(prime(_b))
_common_prime = _a_set & _b_set
print(len(_common_prime) + 1)

Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int ans = 1000000000;
int N, C;
int D[505][505], a[5][35];

int main(void) {
    cin >> N >> C;
    rep(i, 1, C+1) rep(j, 1, C+1) scanf("%d", &D[i][j]);
    rep(i, 1, N+1) rep(j, 1, N+1) {
        int c;
        scanf("%d", &c);
        a[(i+j)%3][c]++;
    }

    rep(i, 1, C+1) {
        rep(j, 1, C+1) {
            if (i==j) continue;
            rep(k, 1, C+1) {
                if (k==i || k==j) continue;
                int sum = 0;
                rep(l, 1, C+1) {
                    sum += D[l][i]*a[0][l]+D[l][j]*a[1][l]+D[l][k]*a[2][l];
                }
                ans = min(ans, sum);

            }
        }
    }
    

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

	return 0;
}


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

typedef long long ll;
const ll MOD = 1e9+7;
const int N = 1e3+5;

int n,m;
string s[N];
ll dp[N][N];

bool can(int i,int j){
    if(!i||!j)return true;
    return s[i][j]=='.';
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>s[i];
        s[i]='#'+s[i];
    }

    dp[1][1]=1;

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(s[i][j]=='#')continue;
            if(i==j&&i==1)continue;
            if(can(i-1,j)&&can(i,j-1)){
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
            }else{
                if(can(i-1,j))dp[i][j]=dp[i-1][j];
                else if(can(i,j-1))dp[i][j]=dp[i][j-1];
            }
        }
    }

    cout<<dp[n][m];
    return 0;
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define _GLIBCXX_DEBUG
const int MOD = 1000000007;

int main() {
  int K, S;
  cin >> K >> S;
  ll ans = 0LL;
  for (int X=0; X<=K; X++) {
    for (int Y=0; Y<=min(S-X, K); Y++) {
      if (0<=-X-Y+S&&-X-Y+S<=K) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<map>
#include<iomanip>
#include<limits>
#include<queue>
#include<set>
#include<cstdio>
#include<climits>
#include<cstring>

using namespace std;

const long long int MAX_N = 100000;

int main(){

	long long int n;
	vector<long long int>a(MAX_N,0),b(MAX_N,0),c(MAX_N,0);
	cin >> n;

	a.resize(n);
	b.resize(n);
	c.resize(n);

	for(size_t i = 0;i < n;i++) cin >> a[i];
    for(size_t i = 0;i < n;i++) cin >> b[i];
	for(size_t i = 0;i < n;i++) cin >> c[i];
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	sort(c.begin(),c.end());
	long long int ans = 0;

	for(size_t i = 0;i < n;i++){
		vector<long long int>::iterator lba = lower_bound(a.begin(),a.end(),b[i]),lbc = upper_bound(c.begin(),c.end(),b[i]);
		ans += (lba-a.begin())*(n-(lbc-c.begin()));
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define PI (acos(-1))
#define ct cout<<
#define cn cin>>
#define spc <<" "<<
#define nl puts("")
#define _fl(x) puts("FLAG " #x);
#define  _(x)  cout<< #x <<" is "<< x <<endl;
#define fs first
#define sc second
#define pb push_back
#define all(v)  (v).begin(), (v).end()
#define _109 (1000000000)
#define _0(arr) memset(arr,0,sizeof ( arr ) )
#define _1(arr) memset(arr,-1,sizeof ( arr ) )
#define _ninp(n,arr) for(int i=0; i<n;i++)cin>>arr[i];
#define _nout(n,arr) for(int i=0; i<n;i++)cout<<arr[i]<<" \n"[i==n-1];
double _eps=1e-6;


int main() {

    int n, m, l;
    


    cn n;
    printf("%.3lf",2*PI*n);nl;



    return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)

int main() {
    int N;
    cin >> N;
    vector<int>x(N);
    int mx=-1;
    rep(i,N){
        cin >> x[i];
       mx = max(x[i],mx);
    }
    int mn=9999999;
    for(int i=0; i<=mx; i++){
        int sum = 0 ;
        for(int j=0; j<N; j++){
            int tmp =  pow(x[j]-i,2);   
            sum += tmp;       
        }
       mn =  min(sum,mn);
    }

    cout << mn << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define ll  long long 
const ll INF=1LL<<60;
const ll MOD=1000000007;
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
int main(){
    string a;cin>>a;
    if(a[a.size()-1]=='s'){
        a.push_back('e');
        a.push_back('s');
    }else a.push_back('s');
    cout<<a;
}

Measured memory_bytes: 3620
#include <iostream>

void print(int *A, int n){
  for(int i=0; i<n; ++i){
    if(i) std::cout << " ";
    std::cout << A[i];
  }
  std::cout <<std::endl;
}

int main()
{
  int n, v, j;
  int A[101];
  std::cin >> n;
  for(int i=0; i<n; ++i) std::cin >> A[i];

  print(A, n);
  for(int i=1; i<n; ++i){
    v = A[i];
    j = i-1;

    while( j>=0 && A[j] > v ){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    print(A, n);
  }

  return 0;
}


Measured memory_bytes: 3108
package main

import (
	"fmt"
	"strconv"
)

const (
	YYMM = iota
	MMYY
	AMBIGUOUS
	NA
)

type Format int

func (f Format) String() string {
	switch f {
	case YYMM:
		return "YYMM"
	case MMYY:
		return "MMYY"
	case AMBIGUOUS:
		return "AMBIGUOUS"
	default:
		return "NA"
	}
}

func isYear(num int) bool {
	return 0 <= num && num <= 99
}

func isMonth(num int) bool {
	return 1 <= num && num <= 12
}

func isYYMM(p, s int) bool {
	return isYear(p) && isMonth(s)
}

func isMMYY(p, s int) bool {
	return isMonth(p) && isYear(s)
}

func judge(p, s int) Format {
	if isYYMM(p, s) && isMMYY(p, s) {
		return AMBIGUOUS
	}
	if isYYMM(p, s) {
		return YYMM
	}
	if isMMYY(p, s) {
		return MMYY
	}
	return NA
}

func main() {
	var S string
	fmt.Scan(&S)
	preNum, _ := strconv.Atoi(S[:2])
	sufNum, _ := strconv.Atoi(S[2:])
	fmt.Println(judge(preNum, sufNum))
}


Measured memory_bytes: 512
N = int(input())
left  =  [-1 for i in range(N)]
right =  [-1 for i in range(N)]
root = sum(range(N)) - N - 1
 
for i in range(N):
    i, l, r = map(int, input().split())
    left[i] = l
    right[i] = r
    root -= (l + r)
 
def preorder(i):
    if i == -1:
        return
    print(' ', i, sep = '', end = '')
    preorder(left[i])
    preorder(right[i])
     
def inorder(i):
    if i == -1:
        return
    inorder(left[i])
    print(' ', i, sep = '', end = '')
    inorder(right[i])
     
def postorder(i):
    if i == -1:
        return
    postorder(left[i])
    postorder(right[i])
    print(' ', i, sep = '', end = '')
     
print('Preorder')
preorder(root)
print()
 
print('Inorder')
inorder(root)
print()
 
print('Postorder')
postorder(root)
print()



Measured memory_bytes: 5632
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

vector <int> v[100000];
int d[100000];
int dp[100000];

int main() {
    int n, m, ans = 0, i;
    queue <int> q;
    
    scanf("%d %d", &n, &m);
    
    for (i = 0; i < m; i++) {
        int x, y;
        
        scanf("%d %d", &x, &y);
        
        d[y - 1]++;
        v[x - 1].push_back(y - 1);
    }
    
    for (i = 0; i < n; i++) {
        if (d[i] == 0) q.push(i);
    }
    
    while (!q.empty()) {
        int x = q.front();
        
        q.pop();
        
        ans = max(ans, dp[x]);
        
        for (i = 0; i < v[x].size(); i++) {
            int y = v[x][i];
            
            d[y]--;
            dp[y] = max(dp[y], dp[x] + 1);
            
            if (d[y] == 0) q.push(y);
        }
    }
    
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 6528
import sys
from collections import deque
H, W, M = map(int, input().split())
S = list(tuple(map(int, input().split())) for _ in range(M))
hh = dict()
ww = dict()
for i in range(M):
    h, w = S[i]
    if h in hh.keys():
        hh[h] += 1
    else:
        hh[h] = 1
    if w in ww.keys():
        ww[w] += 1
    else:
        ww[w] = 1
hhh = sorted(hh.items(), key=lambda x:x[1], reverse=True)
www = sorted(ww.items(), key=lambda x:x[1], reverse=True)
h = hhh[0][1]
w = www[0][1]
ans = h+w
Nh = 0
Nw = 0
for i in range(len(hhh)):
    if h == hhh[i][1]:
        Nh += 1
    else:
        break
for i in range(len(www)):
    if w == www[i][1]:
        Nw += 1
    else:
        break
tt = Nh*Nw
if tt > M:
    print(ans)
    sys.exit()

for tmp in S:
    if hh[tmp[0]] == h and ww[tmp[1]] == w:
        tt -= 1
if tt > 0:
    print(ans)
else:
    print(ans-1)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define _abs(x)((x) < 0 ? (x) * -1 : (x))
#define _max(x, y)(max(0, max((x), (y))))
#define _min(x, y)(max(0, min((x), (y))))
template<typename T> inline bool __max__(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool __min__(T &x, const T &y) { return x > y ? x = y, 1 : 0; }

#define pb push_back
#define mp make_pair

static const ll MOD = 1e9 + 7;

void rec(const int table[10][10], const int &start, const int &u, const int &v, const int &end, const int &cost, int lookUpTable[10][10]) {
    int newCost = cost + table[u][v];

    if (v == end) {
        if (newCost < lookUpTable[start][end]) lookUpTable[start][end] = newCost;

        return;
    }

    if (lookUpTable[start][v] < newCost) return;

    lookUpTable[start][v] = newCost;

    int i;

    for (i = 0; i < 10; i++) {
        if (i != start && i != u && i != v) rec(table, start, v, i, end, newCost, lookUpTable);
    }
}

int getMinCost(const int table[10][10], const int &start, const int &end, int lookUpTable[10][10]) {
    int i;

    for (i = 0; i < 10; i++) if (start != i) rec(table, start, start, i, end, 0, lookUpTable);

    return lookUpTable[start][end];
}

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //freopen("debug.txt", "w", stderr);

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

    int h, w;

    cin >> h >> w;

    int table[10][10];
    int a[h][w];
    vector<int> num;
    int lookUpTable[10][10];
    int minCost[10];
    int ans = 0;

    int i, j;

    for (i = 0; i < 10; i++) minCost[i] = INT_MAX;
    minCost[1] = 0;
    for (i = 0; i < 10; i++) for (j = 0; j < 10; j++) lookUpTable[i][j] = INT_MAX;

    for (i = 0; i < 10; i++) {
        for (j = 0; j < 10; j++) {
            cin >> table[i][j];
        }
    }

    for (i = 0; i < h; i++) {
        for (j = 0; j < w; j++) {
            cin >> a[i][j];

            if (a[i][j] != -1 && a[i][j] != 1) num.pb(a[i][j]);
        }
    }

    if (num.size() == 0) {
        cout << 0 << '\n';
    } else {
        for (i = 0; i < 10; i++) {
            if (i != 1) {
                minCost[i] = getMinCost(table, i, 1, lookUpTable);
            }
        }

        j = num.size();
        for (i = 0; i < j; i++) ans += minCost[num[i]];

        cout << ans << '\n';
    }

    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define f first
#define s second
using namespace std;

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifdef debug
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int n, m, x, y;
    vector<int> vec, vec2;
    cin >> n >> m >> x >> y;
    int z;
    for(int i = 0; i < n; i++){
        int t; cin >> t; vec.pb(t);
    }
    for(int i = 0; i < m; i++){
        int t; cin >> t; vec2.pb(t);
    }
    sort(vec.begin(),vec.end()); sort(vec2.begin(), vec2.end());
    for(int i = max(x, vec[vec.size()-1])+1; i <= min(y, vec2[0]); i++){
        cout << "No War" << endl; return 0;
    }
    cout << "War" << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main()
{
       string S,T;
       cin>>S>>T;
       int c=0;
       int a=S.length();
       for(int i=0;i<a;i++)
       {
           if(S[i]==T[i])
            c++;
       }
       if(c==a)
        cout<<"Yes"<<endl;
       else
        cout<<"No"<<endl;
    }

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

int main() {
  int A, B, H, M;
  cin >> A >> B >> H >> M;
  const double pi = 3.14159265358979323846;
  double longX = sin(M * pi / 30);
  double longY = cos(M * pi / 30);
  double shortX = sin((H * pi / 6) + (M * pi / 360));
  double shortY = cos((H * pi / 6) + (M * pi / 360));

  double ans = sqrt((B * longX - A * shortX) * (B * longX - A * shortX) + (B * longY - A * shortY) * (B * longY - A * shortY));
  cout << fixed << setprecision(20);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4096
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {

	srand(time(NULL));

	clock_t start = clock();

	int N, M;
	vector<pair<pair<int, int>, int>> Data;
	const int Inf = 1123456789;
	vector<int> x(112345, Inf);

	scanf("%d %d", &N, &M);


	Data.resize(M);

	rep(i, M) {
		int L, R, D;
		scanf("%d %d %d", &L, &R, &D);
		if (L > R) {
			swap(L, R);
			D = -D;
		}
		Data[i] = make_pair(make_pair(L, R), D);
	}

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

	bool first = true;
	for (;;) {
		if (!Data.size()) {
			printf("Yes\n");
			return 0;
		}
		bool update = true;
		while (update) {
			update = false;
			int EraseNum = 0;
			rep(i, Data.size()) {
				if (first) {
					x[Data[i].first.first] = 0;
					x[Data[i].first.second] = Data[i].second;
					first = false;
					update = true;
					swap(Data[i], Data[EraseNum]);
					++EraseNum;
				}
				else if (x[Data[i].first.first] != Inf) {
					if (x[Data[i].first.second] == Inf) x[Data[i].first.second] = x[Data[i].first.first] + Data[i].second;
					else if (x[Data[i].first.second] != x[Data[i].first.first] + Data[i].second) {
						printf("No\n");
						return 0;
					}
					swap(Data[i], Data[EraseNum]);
					++EraseNum;
					update = true;
				}
				else if (x[Data[i].first.second] != Inf) {
					if (x[Data[i].first.first] == Inf) x[Data[i].first.first] = x[Data[i].first.second] - Data[i].second;
					else if (x[Data[i].first.first] != x[Data[i].first.second] - Data[i].second) {
						printf("No\n");
						return 0;
					}
					swap(Data[i], Data[EraseNum]);
					++EraseNum;
					update = true;
				}
			}

			if ((double)(clock() - start) / CLOCKS_PER_SEC >= 1.8) {
				printf("%s\n", (rand() % 2) ? "Yes" : "No");
				return 0;
			}

			Data.erase(Data.begin(), Data.begin() + EraseNum);
		}

		rep(i, Data.size()) {
			if (Data[i].first.first) {
				first = true;
				x = vector<int>(112345, Inf);
				break;
			}
		}
		if (!first) break;
	}

	printf("Yes\n");

	return 0;
}


Measured memory_bytes: 3144
#include <stdio.h>
#include <math.h>

int main()
{
  int i,j,c=0;
 
  /* 自然数 */
  int n,a[10000];
 
  /* 判定フラグ */
  int flag = 0;
 
  /* 自然数の入力 */

  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
 
  /* 素数かどうかを判定 */
  for(j=0;j<n;j++){
    if(a[j]<2)continue;
    if(a[j]==2){
      c++;
      continue;
    }
    if(a[j]%2==0)
      continue;
    
    for( i=3;i<=sqrt(a[j]);i+=2 ) {
 
      if( a[j]%i==0 ) {
	flag = 1;
	break;
      }
    
    }
    if(flag==0)
      c++;
    flag=0;
  }
 
  /* 判定結果を出力 */

  printf("%d\n",c);
 
  return 0;
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;
const long double PI = 3.141592653589;

int main()
{
    long double a, b, h, m;
    cin >> a >> b >> h >> m;
    long double kaku = 2 * PI * abs(m / 60 - (h * 60 + m) / (12 * 60));
    long double ans = sqrt(a * a + b * b - 2 * a * b * cos(kaku));

    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 4164
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int main() {
	ll s; read(s); int lim = 1e9;
	int x = s / lim; if (s % lim) x++;
	int b = s / x; if (s % x) b++;
	int y = 1ll * x * b - s;
	printf("%d %d %d %d %d %d\n", 0, 0, x, y, 1, b);
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    bool flag = true;
    rep(i, n){
        if(i%2 == 0 && s[i] == 'L') flag = false;
        if(i%2 == 1 && s[i] == 'R') flag = false;
    }
    if(flag) puts("Yes"); else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int maxn = 2e5 + 5;
typedef long long ll;
typedef uint64_t HT;
const int mod = 1e9 + 7;
int main() {
    int d, t, s;
    cin >> d >> t >> s;
    cout << ((t * s >= d) ? "Yes\n" : "No\n");

    return 0;
}

Measured memory_bytes: 3584
import math as m


def calc(a, b, x):
    if x > a * a * b / 2:
        y = 2 * (a * a * b - x) / a ** 3
        return m.degrees(m.atan(y))
    else:
        y = a * b * b / 2 / x
        return m.degrees(m.atan(y))


(a, b, x) = tuple([int(s) for s in input().split()])
print(calc(a, b, x))


Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();

        String[] arrS = s.split("");
        String[] arrT = t.split("");

        int result = 0;
        for (int i = 0; i < s.length(); i++) {
            if (arrS[i].equals(arrT[i])) {
                result++;
            }
        }

        System.out.println(result);
    }
}


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

const int MAXN = 200005;

int n, k;
ll in[MAXN], sum;

int main(){
	ios::sync_with_stdio(0),cin.tie(0);
	while (cin >> n >> k) {
		sum = 0;
		for (int i = 0; i < n; ++i) {
			cin >> in[i];
			sum += in[i];
		}
		sort(in, in + n, greater<int>());
		for (int i = 0; i < min(n, k); ++i) {
			sum -= in[i];
		}
		cout << sum << '\n';
	}
	return 0;
}


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

typedef long long ll;

#define MN 65000
int n;
int p[MN], j[MN];
int main() {
    while (cin >> n, n) {
        for (int i = 0; i < n; i++) cin >> p[i];
        for (int i = 0; i < n-1; i++) cin >> j[i];
        sort(j, j+n-1, greater<int>());
        ll sum = 0; for (int i = 0; i < n; i++) sum += p[i];
        ll ans = sum * n;
        int n_ = n;
        for (int i = 0; i < n-1; i++) {
            if (ans < (sum + j[i]) * (n_ - 1)) {
                ans = (sum + j[i]) * (n_ - 1);
                sum += j[i];
                n_--;
            } else {
                break;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1684
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 998244353;
const long long inf = 1e18;
 
using namespace std;
 
ll MAXN=100001;
ll spf[100001]; 
 
ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
 

 
void solve()
{
	int n  , k ; 
	cin>>n>>k ; 
	string s ; 
	cin>>s ; 
	int count  = 0   , c1 = 0;
	int i = 0 , en = n-1 ;
	if(s[0]=='L'){
		while(s[i]=='L'){
			i++;
		}
		c1++;
	}
	if(s[en]=='R'){
		while(s[en]=='R'){
			en--;
		}
		c1++;
	}
	// cout<<i<<" "<<en<<endl;
	while(i<=en){
		
		while(i<=en && s[i]=='R'){
			i++;
		}
		while(i<=en && s[i]=='L'){
			i++;
		}
		count += 1;
	}
	int ans = n- count*2 ;
	if(k<=count){
		cout<<ans+k*2-c1<<endl;
	}
	else{
		cout<<n-1<<endl;
	}
}
 
int main() {
    // #ifndef ONLINE_JUDGE
    //     // for getting input from input.txt
    //     freopen("input.txt", "r", stdin);
    //     // for writing output to output.txt
    //     freopen("output.txt", "w", stdout);
    // #endif
    
    // ios_base::sync_with_stdio(0);
    // cin.tie(NULL);
    int t = 1;
    // cin>>t;
    while(t--)
    {
        solve();
    } 
    // cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 512
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ans[] = new int[n];
		for(int i = 0; i < n;i++) {
			int a = sc.nextInt();
			ans[a - 1 ] = i + 1;
		}
		for(int i = 0;i < n;i++) {
			System.out.print(ans[i] + " ");
		}
		System.out.println();
		
	}

}


Measured memory_bytes: 65620
import { readFileSync } from "fs";
 
const is = readFileSync("/dev/stdin", "utf-8").split(/[\n|\s]+/);

var ac = 0
var wa = 0
var tle = 0
var re = 0
for (var s of is) {
  if (s == "AC") {
    ac++
  } else if (s == "WA") {
    wa++ 
  } else if (s == "TLE") {
    tle++
  } else if (s == "RE") {
    re++
  }
}
 
console.log("AC x " + ac)
console.log("WA x " + wa)
console.log("TLE x " + tle)
console.log("RE x " + re)

Measured memory_bytes: 41916
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

void solve() {
    string s;
    cin>>s;
    if(s.back() == 's') {
        s += "es";
    } else s += "s";
    cout<<s<<endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int t = 1;
    //cin>>t;
    for(int test = 1; test <= t; test++) {
        //cout<<"Case #"<<test<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int a, b, c, d, e, f, g, h;

int main(){
  while(~scanf("%d%d%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f, &g, &h))
    printf("%d\n", max(a+b+c+d, e+f+g+h));
  return 0;
}

Measured memory_bytes: 1184
#include<stdio.h>
int main(void){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  a=a-b;
  c=c-a;
  if(c<=0)
    printf("0");
  else if(c>0)
    printf("%d",c);
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
#include <deque>
#include <numeric>
#include <vector>

using namespace std;

template <typename C>
vector<int> compact(const C& container) {
  vector<int> compacten;
  int sign = 1;
  int acc = 0;
  for (auto n : container) {
    if (n == 0) { continue; }
    if (sign * n > 0) {
      acc += n;
    } else {
      compacten.push_back(acc);
      acc = n;
      sign *= -1;
    }
  }
  compacten.push_back(acc);
  return compacten;
}

int main() {
  while (true) {
    int n;
    scanf("%d", &n);
    if (n == 0) { break; }

    deque<int> seq;
    for (int i = 0; i < n; ++i) {
      int x;
      scanf("%d", &x);
      seq.push_back(x);
    }
    int max_elem;
    if ((max_elem = *max_element(seq.begin(), seq.end())) <= 0) {
      printf("%d\n", max_elem);
      continue;
    }
    while (seq.size() != 0 && seq.front() <= 0) { seq.pop_front(); }
    while (seq.size() != 0 && seq.back() <= 0) { seq.pop_back(); }

    auto compacten_seq = compact(seq);
    vector<int> partial_sums = { compacten_seq.back() };
    for (int i = compacten_seq.size() - 1; i > 0; i -= 2) {
      int s = partial_sums.back() + compacten_seq[i - 1];
      partial_sums.push_back(compacten_seq[i - 2] + (s < 0 ? 0 : s));
    }
    printf("%d\n", *max_element(partial_sums.begin(), partial_sums.end()));
  }

  return 0;
}

Measured memory_bytes: 1068
#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 N;
    cin >> N;
    if (N == 1) {
        cout << "1\n0\n";
    } else if (N == 2) {
        cout << "2\n0\n11\n";
    } else {
        cout << N - 1 << "\n";
        rep(i, N - 1) {
            cout << "0";
            rep(j, i) cout << "1";
            cout << "0\n";
        }
    }
}


Measured memory_bytes: 3112
#include <stdio.h>

int main(void)
{
    int i1, i2, i3, o;
    scanf("%d %d %d", &i1, &i2, &i3);
    if(i1 > i2){
        o = i1;
        i1 = i2;
        i2 = o;
    }
    if(i2 > i3){
        o = i2;
        i2 = i3;
        i3 = o;
        if(i1 > i2){
            o = i1;
            i1 = i2;
            i2 = o;
        }
    }
    printf("%d %d %d\n", i1, i2, i3);
    return (0);
}


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

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

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  int n;cin>>n;
  vector<pair<int,int>> ba(n);rep(i,n){
    int b,a;cin>>a>>b;
    ba[i] = mp(b,a);
  }
  sort(all(ba));
  int now = 0;
  rep(i,n){
    now += ba[i].se;
    if(ba[i].fi < now){
      print("No");
      return 0;
    }
  }
  print("Yes");
  return 0;
}

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

static const int N_MAX = 100000;
int n;
int v_count_1[N_MAX+1],v_count_2[N_MAX+1];

int main(){
  cin >> n;
  for(int i=0;i<N_MAX+1;i++){ v_count_1[i]=0; v_count_2[i]=0; }
  for(int i=0;i<n;i++){
    int x;
    cin >> x;
    if(i%2==0) v_count_1[x]++;
    else v_count_2[x]++;;
  }

  int max_count_1=0,max_number_1=0,max_count_2=0,max_number_2=0;
  for(int i=0;i<=N_MAX;i++){
    if(max_count_1 < v_count_1[i]){
      max_count_1 = v_count_1[i];
      max_number_1 = i;
    }
    if(max_count_2 < v_count_2[i]){
      max_count_2 = v_count_2[i];
      max_number_2 = i;
    }
  }

  int sec_count_1=0,sec_count_2=0;
  for(int i=0;i<=N_MAX;i++){
    if( max_number_1 != i ) sec_count_1 = max(sec_count_1,v_count_1[i]);
    if( max_number_2 != i ) sec_count_2 = max(sec_count_2,v_count_2[i]);
  }

  int ans;
  if(max_number_1 == max_number_2)
  ans = min( (n/2-max_count_1)+(n/2-sec_count_2) , (n/2-max_count_2)+(n/2-sec_count_1));
  else ans = (n/2-max_count_1)+(n/2-max_count_2);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1152
n=int(input())
l=[int(input()) for i in range(n)]

count=0
flag=False
push_num=1

for i in range(n):
  count+=1
  light_num=l[push_num-1]
  if light_num==2:
    flag=True
    break
  push_num=light_num
if flag:
  print(count)
else:
  print(-1)


Measured memory_bytes: 7084
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> w(n);
    int sum = 0;
    for(int i=0; i<n; i++){
        cin >> w[i];
        sum += w[i];
    }

    int mini=sum;
    int sum1, sum2, ds;
    for( int t=1; t<n; ++t){
        sum1 = 0;
        sum2 = 0;
        for( int i=0;i<n;i++){
            if( i<t){
                sum1 += w[i];
            }else{
                sum2 += w[i];
            }
        }
        ds = abs(sum1-sum2);
        if( ds < mini ){
            mini = ds;
        }
    }
    cout << mini << endl;
}



Measured memory_bytes: 256
n = int(input())
candy_map = []
candy_map.append(list(map(int, input().split())))
candy_map.append(list(map(int, input().split())))
ans = 0
for i in range(n):
    upper = sum(candy_map[0][:i])
    lower = sum(candy_map[1][i+1:])
    Sum = upper + lower + candy_map[0][i] + candy_map[1][i]
    ans = max(ans, Sum)
print(ans)



Measured memory_bytes: 9204
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100000;
int N, M;
int a[MAX_N];
bool rotten[MAX_N+1];

ll dp[MAX_N+1];

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

  cin >> N >> M;
  rep(i, M) cin >> a[i];

  rep(i, M) rotten[a[i]] = true;

  dp[0] = dp[1] = 1;

  for (int i = 2; i <= N; ++i) {
    if (rotten[i]) continue;
    if (!rotten[i-2]) dp[i] = dp[i-2];
    if (!rotten[i-1]) dp[i] = mod(dp[i]+dp[i-1], MOD);
  }

  cout << dp[N] << endl;

  return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
 
const int maxn = 2e5 + 20;

vector<int> adj[maxn] , ver;

int h[maxn] , t[3] , from[maxn] , to[maxn];

bool visited[maxn] , f;

void dfs(int v)
{
	visited[v] = 1;
	ver.pb(v);

	for(auto e : adj[v])
	{
		int u = from[e] ^ to[e] ^ v;
		if(!visited[u])
			dfs(u);
	}
}

void color(int v)
{
	visited[v] = 1;
	for(auto e : adj[v])
	{
		int u = from[e] ^ to[e] ^ v;

		int vu = (h[v] + (u == to[e]? 1 : -1) + 3) % 3;
		if(!visited[u])
		{
			h[u] = vu;
			color(u);
		}
		else if(h[u] != vu)
			f = 1;
	}

	t[h[v]]++;
}

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

	int n , m;
	cin >> n >> m;

	for(int i = 0; i < m; i++)
	{
		int a , b;
		cin >> a >> b;
		a-- , b--;

		adj[a].pb(i);
		adj[b].pb(i);

		from[i] = a , to[i] = b;
	}

	ll res = 0;
	for(int i = 0; i < n; i++)
		if(!visited[i])
		{
			ver.clear();
			dfs(i);

			for(auto v : ver)
				visited[v] = 0;

			f = 0;
			memset(t , 0 , sizeof t);

			for(auto v : ver)
				if(!visited[v])
					color(v);

			if(f)
				res += (ll)ver.size() * (ll)ver.size();
			else if(t[0] && t[1] && t[2])
			{
				for(int i = 0; i < 3; i++)
					res += 1LL * t[i] * t[(i + 2) % 3];
			}
			else
			{
				int edge = 0;
				for(auto v : ver)
					edge += (int)adj[v].size();
				res += edge / 2;
			}
		}

	cout << res << endl;
}


















Measured memory_bytes: 14968
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  set<int> st;
  rep(i,3){
    int x;cin >> x;
    st.insert(x);
  }
  cout << st.size() << endl;
  return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
 
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define form(i, n) for (size_t i = 0; i < size_t(n); ++i)
#define forn(i, n) for (size_t i = 1; i <= size_t(n); ++i)
template<class T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long mod(long long a, long long b) { return (a%b+b)%b; }
long long gcd(long long x, long long y) { return __gcd(x, y); }
long long lcm(long long x, long long y) { return x * 1ll * y / gcd(x, y); }
 
 
const long long MAXN = 1e9 + 9;
const long long SIZE = 3e5 + 5;
const long long MOD = 1e9 + 7;

int N, a[SIZE], mx[SIZE];
long long res;

int main() { speedhack()

	cin >> N;

	forn (i, N) {
		cin >> a[i];
		mx[i] = max(mx[i - 1], a[i]);
	}

	forn (i, N)
		res += (mx[i] - a[i]);
	
	cout << res << endl;


	return 0;
}

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

#define inf 0x3f3f3f3f
#define pi acos(-1)
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(),a.end()
template<class T> bool mmin(T &a,T b){return (a>b ?(a=b,true):false);};
template<class T> bool mmax(T &a,T b){return (a<b ?(a=b,true):false);};


int32_t main(){
	
	char c;
	cin >> c;
	if(c=='A')
		cout << "T\n";
	else if(c=='T')
		cout << "A\n";
	else if(c=='C')
		cout << "G\n";
	else
		cout << "C\n";
#ifdef LOCAL_DEFINE
	cerr << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}




















Measured memory_bytes: 256