akhauriyash/Code-Regression huggingface dataset:
#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 rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl;
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ');
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
//cout << fixed << setprecision(10);

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

  int ans = 0;
  rep(i,s.size()-3+1) {
    if (s.substr(i,3) == "ABC") ans++;
  }

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

Measured memory_bytes: 256
# 入力
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

def bf(graph: list):
    neg = -10**16
    n = len(graph)
    dist = [neg]*n
    dist[0] = 0
    ansn_1 = neg
    ans_n = neg
    
    for i in range(n+1):
        for frm, node in enumerate(graph):
            for cost, to in node:
                dist[to] = max(dist[to], dist[frm] + cost)
        
        if i == n-1:
            ansn_1 = dist[-1]
        elif i == n:
            ans_n = dist[-1]
            
    if ansn_1 != ans_n:
        return "inf"
    else:
        return ans_n
        

n,m = li()

graph = [[] for _ in range(n)]
for i in range(m):
    a,b,c = li()
    a -= 1
    b -= 1
    graph[a].append((c,b))
    
ans = bf(graph)
print(ans)

Measured memory_bytes: 3316
#include<iostream>
#include<stdio.h>

using namespace std;

int gcd(int x,int y){
	if(x<y) swap(x,y);
	int r=0;
	while(y>0){
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

int main(){
	int x,y,a;
	scanf("%d %d\n",&x,&y);
	a = gcd(x,y);
	printf("%d\n",a);
	return 0;
}


Measured memory_bytes: 3220
N = int(input())
s = []
for _ in range(N):
    s.append(input())
M = int(input())
t = []
for _ in range(M):
    t.append(input())
set_s = list(set(s))
max_yen = -9999
for x in range(len(set_s)):
    yen = s.count(set_s[x]) - t.count(set_s[x])
    if yen > max_yen:
        max_yen = yen
if max_yen < 0:
    print("0")
else:
    print(max_yen)

Measured memory_bytes: 3064
// #pragma GCC optimize ("Ofast")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define all(_obj) _obj.begin(),_obj.end()
#define F first
#define S second
#define INF 1e18
#define pll pair<ll, ll> 
#define vll vector<ll>
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=1e5+11,mod=1e9+7;
inline ll max(ll a,ll b) {return ((a>b)?a:b);}
inline ll min(ll a,ll b) {return ((a>b)?b:a);}
inline vll read(int n) {vll v(n);for (int i = 0; i < v.size(); i++)cin>>v[i];return v;}
ll psum[200000];
void sol(void)
{
cin>>n;
ll sum=0;
ll cnt=0;
map<ll,ll> vis;
cin>>x>>m;
vis[x]=1;
sum+=x;
if(n<=MAXN)
{
    n--;
    while(n--)
    {
    x=(x*x)%m;
    sum+=x;
    }
    cout<<sum;
    return ;
}
psum[1]=x;
for(int i=2;i<=MAXN;i++)
{
  x=(x*x)%m;
  if(vis[x])
  {
    cnt=i-vis[x];
    ll calc=psum[i-1]-psum[vis[x]-1];
    n-=(i-1);
    int rem=n%cnt;
    sum+=(calc*(n/cnt))-psum[vis[x]-1]+psum[vis[x]-1+rem];
    break;
  }
  else
  {
      sum+=x;
      psum[i]+=psum[i-1]+x;
      vis[x]=i;
  }
}
cout<<sum;
return ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    //cin>>test;
    for(int i=1;i<=test;i++)
    sol();
}


Measured memory_bytes: 7108
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>

using namespace std;
using ll = long long;

int main() {
	ll N;
	cin >> N;
	ll bt, bx, by;
	bt = 0;
	by = 0;
	bx = 0;
	for (ll i = 0; i < N; i++)
	{
		ll nt, nx, ny;
		cin >> nt >> nx >> ny;
		ll distance = abs(nx - bx) + abs(ny - by);
		ll time = abs(nt - bt);
		if (distance > time) {
			cout << "No" << endl;
			return 0;
		}
		else if (distance == time) {}
		else if ((distance - time) % 2) {
			cout << "No" << endl;
			return 0;
		}
		bt = nt;
		by = ny;
		bx = nx;
	}
	cout << "Yes" << endl;
	return 0;
}

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

using namespace std;

#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define vvii vector<vector<pair<int, int>>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'

constexpr int INF = 2e18;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 3;

// Asymptotic complexity: O(n log n).
struct pto {
  double x, y;
  bool operator<(const pto &p) const {
    return x < p.x || (x == p.x && y < p.y);
    /* a impressao será em prioridade por mais a esquerda, mais
       abaixo, e antihorário pelo cross abaixo */
  }
};

double cross(const pto &O, const pto &A, const pto &B) {
  return (A.x - O.x) * (B.y - O.y) - (A.y - O.y) * (B.x - O.x);
}

vector<pto> convex_hull(vector<pto> P) {
  int n = P.size(), k = 0;
  vector<pto> H(2 * n);
  // Sort points lexicographically
  sort(P.begin(), P.end());
  // Build lower hull
  for (int i = 0; i < n; ++i) {
    // esse <= 0 representa sentido anti-horario, caso deseje mudar
    // trocar por >= 0
    while (k >= 2 && cross(H[k - 2], H[k - 1], P[i]) <= 0)
      k--;
    H[k++] = P[i];
  }
  // Build upper hull
  for (int i = n - 2, t = k + 1; i >= 0; i--) {
    // esse <= 0 representa sentido anti-horario, caso deseje mudar
    // trocar por >= 0
    while (k >= t && cross(H[k - 2], H[k - 1], P[i]) <= 0)
      k--;
    H[k++] = P[i];
  }
  H.resize(k);
  /* o último ponto do vetor é igual ao primeiro, atente para isso
  as vezes é necessário mudar */
  return H;
}

int mh(pto a, pto b) { return abs(a.x - b.x) + abs(a.y - b.y); }

// #define MULTIPLE_TEST_CASES
void solve() {
  int n;
  cin >> n;

  vector<pto> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i].x >> v[i].y;
  }

  v = convex_hull(v);

  int ans = 0;
  for (int i = 0; i < v.size(); ++i) {
    for (int j = 0; j < v.size(); ++j) {
      ans = max(ans, mh(v[i], v[j]));
    }
  }
  cout << ans << endl;
}

signed main() {
  // freopen(".in", "r", stdin);
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);

  int t = 1;
#ifdef MULTIPLE_TEST_CASES
  cin >> t;
#endif
  while (t--)
    solve();
}

Measured memory_bytes: 15936
use proconio::input;

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

    let mut count = 0;
    for five_handred in 0..(a + 1) {
        for one_handred in 0..(b + 1) {
            for fifty in 0..(c + 1) {
                let sum = 500 * five_handred + 100 * one_handred + 50 * fifty;
                if x == sum {
                    count += 1;
                }
            }
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 2116
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <ctime>
#include <deque>
#include <ctime>
#include <string>
#include <algorithm>
#include <vector>
#include <bitset>
#include <cassert>
#include <cstring>

#define fi first
#define se second

using namespace std;
const int MAXN = 201;

int n;
pair<int, int> mas1[MAXN];
pair<int, int> mas2[MAXN];

int p[MAXN];
bool used[MAXN];
vector<int> g[MAXN];

bool kun(int v){
    if (used[v]){
        return false;
    }

    used[v] = true;

    for (auto to : g[v]){
        if ((p[to] == -1) || (kun(p[to]))){
            p[to] = v;
            return true;
        }
    }

    return false;
}

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

    cin >> n;
    for (int i = 0; i < n; ++i){
        cin >> mas1[i].fi >> mas1[i].se;
    }

    for (int i = 0; i < n; ++i){
        cin >> mas2[i].fi >> mas2[i].se;
    }

    for (int i = 0; i < n; ++i){
        for (int j = 0; j < n; ++j){
            if ((mas1[i].fi < mas2[j].fi) && (mas1[i].se < mas2[j].se)){
                g[i].push_back(j);
            }
        }
    }

    int ans = 0;
    fill(p, p + n, -1);
    for (int i = 0; i < n; ++i){
        fill(used, used + n, false);
        if (kun(i)){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int n, m;
    string s, t;
    cin >> n >> m >> s >> t;
    vector<vector<int>> dpi(n+1, vector<int>(m+1, 0));
    auto dpo = dpi;
    int ans = 0;
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= m; ++j) {
            if((i && s[i-1] == 'I') ) dpi[i][j] = 1;
            if((j && t[j-1] == 'I')) dpi[i][j] = 1;
            if(i && dpi[i-1][j] > 0 && s[i-1] == 'O') chmax(dpo[i][j], dpi[i-1][j]+1);
            if(i && dpo[i-1][j] > 0 && s[i-1] == 'I') chmax(dpi[i][j], dpo[i-1][j]+1);
            if(j && dpi[i][j-1] > 0 && t[j-1] == 'O') chmax(dpo[i][j], dpi[i][j-1]+1);
            if(j && dpo[i][j-1] > 0 && t[j-1] == 'I') chmax(dpi[i][j], dpo[i][j-1]+1);
            ans = max(ans, dpi[i][j]);
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 34332
a = []
b = []
c = []
d = []
n,m = list(map(int,input().split()))
for i in range(n):
    e,f = list(map(int,input().split()))
    a.append(e)
    b.append(f)
for i in range(m):
    e,f = list(map(int,input().split()))
    c.append(e)
    d.append(f)

ans = 50
distance = 'a'

for i in range(n):
    for j in range(m):
        e = abs(a[i]-c[j])+abs(b[i]-d[j])
        if distance == 'a':
            distance = e
            ans = j
        elif distance > e:
            distance = e
            ans = j
    print(ans+1)
    ans = 50
    distance = 'a'

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <numeric>
#include <cstring>
using namespace std;
using ll = long long;

int main(){
    ll L,R;
    cin >> L >> R;
    ll min=2018;
    if (R-L < 2019){ 
        for (ll i=L;i<R;i++){
            for (ll j=i+1;j<=R;j++){
                int a = i % 2019;
                int b = j % 2019;
                int c = (a * b) % 2019;
                if (min > c){
                    min = c;
                }
                if (min == 0){
                    break;
                } 
            }
        }
    }
    else {
        for (int i=1;i<=2019;i++){
            int a = L % 2019;
            int b = i % 2019;
            int c = (a * b) % 2019;
            if (min > c){
                    min = c;
                }
                if (min == 0){
                    break;
                } 
        }
    }

    
    cout << min;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




int main() {
  ll n,c,k;
  cin>>n>>c>>k;
  
  ll ans=0;

  vector<ll> p(n);

  rep(i,n){
    cin>>p[i];
  }

  sort(all(p));

  ll bus=0;
  bool oko=false;
  rep(i,n){
    if(oko) {
      if(p[i]<=bus) continue;
      else oko=false;
    }
    if(i+c-1<n && p[i]+k>=p[i+c-1]){
      ans++;
      i+=c-1;
    }

    else if(i+c-1>=n && p[i]+k>=p[n-1]){
      ans++;
      break;
    }
    else{
      ans++;
      bus=p[i]+k;
      oko=true;
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    for(auto& x : b)
        cin >> x;
    int ans = 0;
    for(int i = 0; i < n; ++i) {
        int sum = c;
        for(int j = 0, x; j < m; ++j) {
            cin >> x;
            sum += x * b[j];
        }
        ans += (sum > 0);
    } 
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define loop(i,a,b) for(int i = a; i < b; i++)
#define rep(i,a) loop(i,0,a)


int main()
{	
	int out = 3;
	int A[3];
	rep(i,3)
		cin>>A[i];
	if(A[0]==A[1]){
		out--;
		if(A[1]==A[2])
			out--;
	}
	else if(A[0]==A[2])
		out--;
	else if(A[1] == A[2])
		out--;	
	cout<<out<<endl;
	
		
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef unsigned long long ll;
 
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define fi first
#define se second
#define II pair <int,int>
 
const int N=2e5+10;
 
ll cal(ll a, ll p, ll n){
   long long tich=a,du=1,p1=p;
  while (p>0)
  {
    if (p%2==1) du=du*tich%n;
    tich=tich*tich%n;
    p/=2;
  }
  return du;
}
 
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    string s;
    cin >> s;
    reverse(s.begin(),s.end());
    ll f[N]; int len=s.length();
    FOR(i,1,len) {
        ll so=cal(10,i,2019);
        f[i]=f[i-1]+(s[i-1]-'0')*so;
    }
    map <ll,ll> dd; int ans=0;
    FOR(i,0,len) {
        ans+=dd[f[i]%2019];
        dd[f[i]%2019]++;
    }
    cout << ans;
}

Measured memory_bytes: 5336
#!/usr/bin/ruby
#encoding: utf-8

$n = gets.to_i
$ans = 0

# mが七五三数になっていて、n以下かどうか
def check(m)
  flg3 = false
  flg5 = false
  flg7 = false

  mstr = m.to_s
  (0..mstr.size-1).each do |i|
    if mstr[i] == '3'
      flg3 = true
    elsif mstr[i] == '5'
      flg5 = true
    elsif mstr[i] == '7'
      flg7 = true 
    end
  end

  if (flg3 && flg5 && flg7 && (m <= $n)) 
    return true
  else
    return false
  end
end

def dfs(m)
  $ans += 1 if check(m) == true 
  if m <= 1000000000
    dfs(10*m + 3) 
    dfs(10*m + 5) 
    dfs(10*m + 7) 
  end
end

dfs(0)
puts $ans



Measured memory_bytes: 1788
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
using namespace std;
int main() {
	string S;
	cin >> S;
	int ans = 0;
	if (S == "SSS") { cout << 0; }
	if (S == "SSR") { cout << 1; }
	if (S == "SRS") { cout << 1; }
	if (S == "SRR") { cout << 2; }
	if (S == "RSS") { cout << 1; }
	if (S == "RSR") { cout << 1; }
	if (S == "RRS") { cout << 2; }
	if (S == "RRR") { cout << 3; }
}



Measured memory_bytes: 3620
/// awoooooo
 
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
 
const int N = (int)2e6 + 5;
const int inf = (int)1e9 + 7;
 
int n;
int a[N], b[N];
 
int main(){
  scanf("%d", &n);
  for(int i = 1; i < n; ++i){
    scanf("%d", b + i);
  }
  b[n] = b[n - 1];
  ll ans = 0;
  for(int i = 1; i <= n; ++i){
    int t = b[i];
    if(i > 1) t = min(t, b[i - 1]);
    ans += t;
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <utility>
using namespace std;
typedef pair<int,int> ii;

int n,q;
long long m;

int p[100005];
long long components;

int parent(int i){return (p[i]==i)?i:p[i]=parent(p[i]);}

vector<ii> diff;

int main(){
	for (int x=0;x<100005;x++) p[x]=x;
	
	scanf("%d%lld%d",&n,&m,&q);
	components=n;
	
	int a,b,c;
	while (q--){
		scanf("%d%d%d",&a,&b,&c);
		if (c==0){
			a=parent(a),b=parent(b);
			if (a!=b){
				components--;
				p[a]=b;
			}
		}
		else{
			diff.push_back(ii(a,b));
		}
	}
	
	if (!diff.empty() && components<=2){
		printf("No");
		return 0;
	}
	
	for (auto &it:diff){
		if (parent(it.first)==parent(it.second)){
			printf("No");
			return 0;
		}
	}
	
	long long lo=n-(diff.empty()),hi=(components*(components-1))/2+n-components;
	
	//printf("%d %d %d\n",lo,hi,components);
	
	printf((lo<=m && m<=hi)?"Yes":"No");
}

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


template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int ab, bc, ca;
    cin >> ab >> bc >> ca;
    cout << (ab*bc)/2 << endl;
}


Measured memory_bytes: 256
from collections import defaultdict
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
xs = list(map(int, input().split()))
dd = defaultdict(set)
for i, x in enumerate(xs):
    dd[x].add(i+1)

G = [set() for _ in range(N+1)]
G2 = [set() for _ in range(N+1)]
es = []
for i in range(M):
    u, v = map(int, input().split())
    if xs[u-1] == xs[v-1]:
        G2[v].add(u)
        G2[u].add(v)
    elif xs[u-1] > xs[v-1]:
        G[u].add(v)
    else:
        G[v].add(u)
    e = (min(u,v), max(u,v))
    es.append(e)

xs = list(set(xs))
xs.sort()

d = dict()
cc = dict()
for i in range(N):
    if not (G[i+1] or G2[i+1]):
        print(-1)
        sys.exit()
for x in xs:
    for u in dd[x]:
        if u in cc or not G2[u]:
            continue
        cc[u] = 1
        stack = [u]
        while stack:
            q = stack.pop()
            for c in G2[q]:
                e = (min(q,c), max(q,c))
                d[e] = x
                if c in cc:
                    continue
                stack.append(c)
                cc[c] = 1 - cc[q]
for x in xs:
    for i in dd[x]:
        for c in G[i]:
            e = (min(i,c), max(i,c))
            d[e] = x
            if i not in cc:
                cc[i] = 1 - cc[c]
print("".join("BW"[cc[i]] for i in range(1,N+1)))
for i in range(M):
    print(d[es[i]])



Measured memory_bytes: 143608
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    priority_queue<ll, vl, greater<ll>> l, r;
    vector<ll> a(3 * n);
    ll lsum = 0, rsum = 0;
    for (int i = 0; i < 3 * n; ++i) {
        cin >> a[i];
    }
    vector<ll> ls(n + 1), rs(n + 1);
    for (int i = 0; i < n; ++i) {
        l.push(a[i]);
        lsum += a[i];
    }
    ls[0] = lsum;
    for (int i = n; i < 2 * n; ++i) {
        lsum += a[i];
        l.push(a[i]);
        lsum -= l.top();
        l.pop();
        ls[i - n + 1] = lsum;
    }
    for (int i = 2 * n; i < 3 * n; ++i) {
        r.push(-a[i]);
        rsum -= a[i];
    }
    rs[n] = rsum;
    for (int i = 2 * n - 1; i >= n; --i) {
        rsum -= a[i];
        r.push(-a[i]);
        rsum -= r.top();
        r.pop();
        rs[i - n] = rsum;
    }
    ll ret = -INF;
    for (int i = 0; i <= n; ++i) {
        chmax(ret, ls[i] + rs[i]);
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 6516
#include<stdio.h>
int main(void){
	int N,A[200],i,j;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	for(i=0;i<1000;i++){
		for(j=0;j<N;j++){
			if(A[j]%2){
				printf("%d\n",i);
				return 0;
			}
			else{
				A[j]/=2;
			}
		}
	}
	return 0;		
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define test ll tx; tx=1; while(tx--)
typedef long long int ll;
int main() {
    FIO;
    test{
        string s,t;
        cin>>s>>t;
        ll m,n,i,j;
        n=s.length();
        m=t.length();
        ll dp[n+1][m+1];
        ll par[n+1][m+1];
        // We will need a 2d array par to backtack.
        for(i=0;i<=n;i++){
            dp[i][0]=0;
        }
        for(i=0;i<=m;i++){
            dp[0][i]=0;
        }
        for(i=1;i<=n;i++){
            for(j=1;j<=m;j++){
                if(s[i-1]==t[j-1]){
                    dp[i][j]=1+dp[i-1][j-1];
                    par[i][j]=1;
                }
                else{
                   if(dp[i][j-1]>dp[i-1][j]){
                        dp[i][j]=dp[i][j-1];
                        par[i][j]=-1;
                    }
                    else{
                        dp[i][j]=dp[i-1][j];
                        par[i][j]=-2;
                    }
                }
            }
        }
        //Backtracking the solution
        string ans;
        i=n; j=m;
        while(i>0 && j>0){
            if(par[i][j]==1){
                ans+=s[i-1];
                i--;
                j--;
            }
            else{
                if(par[i][j]==-1){
                    j--;
                }
                else{
                    i--;
                }
            }
        }
        reverse(ans.begin(),ans.end());
        cout<<ans<<endl;
    }
	return 0;
}


Measured memory_bytes: 140928
#include<bits/stdc++.h>
using namespace std;
int main()
{
    double n,d;
    cin>>n>>d;
    double x,y;
int cnt=0;
    for(int i=0;i<n;i++)
    {
        cin>>x>>y;
        double p=sqrt(x*x+y*y);
        if(p<=d)
        {
           cnt++;
        }
    }
    cout<<cnt;
}


Measured memory_bytes: 3844
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int m = Integer.parseInt(br.readLine());
		int[] p = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			p[i] = i;
		}
		while (m-- > 0) {
			String s = br.readLine();
			int a = Integer.parseInt(s.split(",")[0]);
			int b = Integer.parseInt(s.split(",")[1]);
			int t = p[a];
			p[a] = p[b];
			p[b] = t;
		}
		for (int i = 1; i <= n; i++) {
			System.out.println(p[i]);
		}
	}
}

Measured memory_bytes: 9364
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
using vi = vector<int>;
using vl = vector<i64>;
using vd = vector<double>;
using pi = pair<int, int>;
using pl = pair<i64, i64>;
using pd = pair<double, double>;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(vector<T> &v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

int main() {
  int n;
  cin >> n;
  vector<pair<pair<string, int>, int>> v(n);
  REP(i, n) {
    string s;
    int p;
    cin >> s >> p;
    v[i].first.first = s;
    v[i].first.second = -p;
    v[i].second = i + 1;
  }
  sort(ALL(v));
  for (auto &&i : v) {
    cout << i.second << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;

int main() {
	int a;
	while (cin >> a) {
	    if (a == 0) break;
	    double b = 0, c = 0, x[a];
    	for (int i = 0; i < a; i++) {
	        cin >> x[i];
	        b += x[i];
	    }
	    b = b / a;
	    for (int i = 0; i < a; i++) {
	        c += pow((x[i] - b), 2);
	    }
	    c = sqrt(c / a);
	    printf("%.6f", c);
	    cout << endl;
	}
}



Measured memory_bytes: 3188
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string[] str;
            for (int i = 1; true; i++)
            {
                str = Console.ReadLine ().Split (' ');
                if (str[0] == "0") break;
                Console.WriteLine ("Case " + i + ": " + str[0]);
            }
        }
    }

    class MyLibrary
    {

        // 自作の関数
        public static int MyFunction (int n)
        {
            return 0;
        }
    }
}


Measured memory_bytes: 17764
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
 
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 200005;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));

void solve()
{
     ll n,m;
     cin >> n >> m;
     ll a[n+1];
     for(ll i=1;i<=n;i++)   cin >> a[i];
     vector<ll> v[n+1];
     for(ll i=0,x,y;i<m;i++)
     {
          cin >> x >> y;
          v[x].pb(y);
          v[y].pb(x);
     }
     ll ans = 0;
     for(ll i=1;i<=n;i++)
     {
          ll val = a[i];
          ll chk = 1;
          for(auto X:v[i])
          {
               if(a[X]>=val)     chk = 0;
          }
          ans += chk;
     }
     cout<<ans;
}

int main()
{
     FAST;
     ll t = 1;
  //   cin >> t;
     while(t--)
     {    
          solve();
     }
}

Measured memory_bytes: 10276
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, tri[1000005][29], e = 1, l, ids[200005], id, lc[200005], cs;
long long ans;
char s[1000005];
int main(){
	scanf("%d", &n);
	rep(i,n){
		scanf("\n%s", s);
		l = strlen(s); id = 0;
		for(int j=l-1; j>0; j--){
			if(tri[id][s[j]-'a'] == 0){
				tri[id][s[j]-'a'] = e++;
				tri[e-1][26] = id;
				tri[e-1][28] = 1 << (s[j]-'a');
			}
			id = tri[id][s[j]-'a'];
		}
		tri[ids[i] = id][27] |= 1 << (s[0]-'a');
		lc[i] = 1 << (s[0]-'a');
	}
	rep(i,n){
		for(id = ids[i], cs = lc[i]; true; id = tri[id][26]){
			ans += __builtin_popcount(cs & tri[id][27]);
			cs |= tri[id][28];
			if(id == 0) break;
		}
	}
	printf("%lld\n", ans-n);
}

Measured memory_bytes: 116740
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>

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

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;

vector<int> dijkstra(int i,int n, vector<vector<pair<int, int>>> graph) {
  vector<int> d(n, INF);
  d[i] = 0;
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
  q.push(make_pair(0, i));
  while (!q.empty()) {
    pair<int, int> p = q.top();
    q.pop();
    int v = p.second;
    if (d[v] < p.first) {
      continue;
    }
    for (auto x : graph[v]) {
      if (d[x.first] > d[v] + x.second) {
        d[x.first] = d[v] + x.second;
        q.push(pair<int, int>(d[x.first], x.first));
      }
    }
  }
  return d;
}

signed main() {
  int N;
  cin >> N;
  
  vector<vector<pair<int, int>>> vec(N);
  int a, b;
  REP(i, N-1){
    cin >> a >> b;
    a--; b--;
    vec[a].push_back(make_pair(b, 1));
    vec[b].push_back(make_pair(a, 1));
  }

  vector<int> dist1 = dijkstra(0, N, vec);
  vector<int> dist2 = dijkstra(N-1, N, vec);

  int ans = 0;
  REP(i, N){
    if(dist1[i] <= dist2[i]) ans++;
    else ans--;
  }

  if(ans > 0) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;

  return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if (A + B > C + D){
    cout << "Left" << endl;
  }
  else if (A + B < C + D){
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

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

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

for (int i=0;i<h+2;i++) {
  if (i==0) {
    for (int j=0;j<w+2;j++)
      cout << "#";
    cout << endl;
  }
  else if (i!=h+1) {
    string s;
    cin >> s;
    cout << "#" << s << "#" << endl;
  }  
  else {
    for (int j=0;j<w+2;j++)
      cout << "#";
    cout << endl;
  }
}
}

Measured memory_bytes: 256
N, x = [int(i) for i in input().split()]

a = [int(i) for i in input().split()]
ans = 0 

if a[0] > x:
    ans+=a[0]-x
    a[0] = x

for i in range(1, N):
    if (a[i-1]+a[i] > x):       
        ans+= (a[i]-(x-a[i-1]))
        a[i] = x-a[i-1]
        
print(int(ans))

Measured memory_bytes: 14052
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n,m;
    cin >> n >> m;
    vector<int> s(m);
    vector<int> c(m);
    rep(i,m){
        cin >> s[i];
        cin >> c[i];
        s[i]--;
    }
    rep(i,1000){
        bool hantei= true;
        
        string kazu = to_string(i);
        if(kazu.size() != n) hantei=false;
        
        rep(j,m){
            
            if(kazu[s[j]] - '0' != c[j]){
                hantei = false;
            }
           
        }
        if(hantei){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 <<endl;
}

Measured memory_bytes: 256
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.conv, std.stdio, std.typecons;

void main()
{
  auto ai = readln.split.map!(to!int).array;
  ai.sort();
  writeln(ai.map!(to!string).join(' '));
}

Measured memory_bytes: 2500
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	Anm := make([][]int, n)
	for i := range Anm {
		Anm[i] = make([]int, m)
	}
	Bn := make([]int, m)
	for i := range Anm {
		for j := range Anm[i] {
			fmt.Scan(&Anm[i][j])
		}
	}
	for i := range Bn {
		fmt.Scan(&Bn[i])
	}
	for i := 0; i < n; i++ {
		var prod int
		for j := 0; j < m; j++ {
			prod += Anm[i][j] * Bn[j]
		}
		fmt.Println(prod)
	}
}



Measured memory_bytes: 1756
#include "bits/stdc++.h"
using namespace std;
#define MODULO 1000000007
#define PI 3.14159265359
typedef long long int ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
     int a;
     cin>>a;
     int x=a+(a*a)+(a*a*a);
     cout<<x<<endl;
    return 0;
}


Measured memory_bytes: 3656
// ITP1_8_D Ring
import java.io.*;

class Main {

   public static void main(String[] args) {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

      try {
         String s = br.readLine();
         String p = br.readLine();
         s = s + s;
         if (s.indexOf(p) != -1)
            System.out.println("Yes");
         else
            System.out.println("No");
      }

      catch (Exception e) {
         System.err.println(e);
      }
   }
}

Measured memory_bytes: 17052
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <numeric>
#include <math.h>

#define user spaesk
#define lli long long int
#define ld long double
#define ff first
#define ss second
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

typedef vector<vector<lli> > matrix ;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;
const int NN = 5e3 + 6;

lli n, w;
lli W[102], V[102];
lli cache[102][N];

lli dp(lli idx, lli weight) {

    if(idx > n + 1) {
        return 0;
    }

    lli &ans = cache[idx][weight];

    if(ans != -1) {
        return ans ;
    }

    if(weight >= W[idx])
        ans = max(V[idx] + dp(idx + 1, weight - W[idx]), dp(idx + 1, weight));
    else
        ans = dp(idx + 1, weight);

    return ans ;

}

void solve()
{

    cin>>n>>w;

    memset(cache, -1, sizeof cache);

    for(int i = 1; i <= n; i ++) {
        cin>>W[i]>>V[i];
    }

    lli ans = dp(1, w);

    cout<<ans;

    cout<<"\n";
    return ;
}

/*
*/

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

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


Measured memory_bytes: 239744
def main(n,a):
    lst = sorted(a, reverse = True)
    first, second = lst[0:2]
    res = []
    for i in range(len(a)):
        if a[i] == first:
            res.append(str(second))
        else:
            res.append(str(first))
    return res

n = int(input())
a = [int(input()) for _ in range(n)]
print("\n".join(main(n,a)))

Measured memory_bytes: 26400
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
#include<deque>
#include<chrono>
using namespace std;
#define pi 3.141592653589793238


#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f0 get<0>
#define f1 get<1>
#define f2 get<2>
typedef vector<ll> vi;
typedef vector<vi> vvi;


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    
    //cin >> T;
    while (T--) {
        ll n, m;
        cin >> n >> m;
        vector<ll> v(n + 2);
        for(i = 0; i < m; i++){
            ll l, r;
            cin >> l >> r; 
            v[l]++;
            v[r + 1]--;
        }
        for(i = 1; i<= n; i++){
            v[i] += v[i - 1];
        }
        ll ans = 0;
        for(i = 1;i <= n; i++){
            if(v[i] == m){
                ans++;
            }
        }
        cout << ans;
    }

    return 0;
}


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

#define MOD (1000000000+7)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) x.begin(), x.end()
#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i > (b); i--)
#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];

// template starts
typedef long long int ll;
ll fact(ll n, ll p){
	ll ans = 1;
	for(ll i = 1; i <= n; i++){
		ans *= i;
		ans %= p;
	}
	return ans;
}
ll power(ll x, ll n, ll p){
	ll res = 1;
	if(n == 1) return x%p;
	if(n%2 == 1) res = x%p;

	ll temp = power(x,n/2,p);
	return res*((temp*temp)%p)%p;
}
ll inv(ll a, ll p){
	return power(a,p-2,p);
}
ll nCr(ll n, ll r, ll p){
	if(r > n) return 0;
	ll t1 = fact(n,p);
	ll t2 = inv(fact(r,p),p);
	ll t3 = inv(fact(n-r,p),p);

	return (((t1*t2)%p)*t3)%p;
}
vector<vector<ll> > multiply(vector<vector<ll> > &a, vector<vector<ll> > &b, ll p){
	int r1,c1,r2,c2;
	r1 = a.size(); c1 = a[0].size();
	r2 = b.size(); c2 = b[0].size();

	vector<vector<ll> > result(r1,vector<ll>(c2,0));

	if(c1 != r2) return result;

	for(int i = 0; i < r1; i++){
		for(int j = 0; j < c2; j++){
			for(int k = 0; k < c1; k++){
				result[i][j] += a[i][k]*b[k][j];
				result[i][j] %= p;
			}
		}
	}
	return result;
}
vector<vector<ll> > power(vector<vector<ll> >&a,ll n, ll p){
	int r = a.size();
	vector<vector<ll> > result(r,vector<ll>(r,0));
	for(int i = 0; i < r; i++) result[i][i] = 1;

	while(n > 0){
		if(n%2 == 1){
			result = multiply(result,a,p);
		}
		n /= 2;
		a = multiply(a,a,p);
	}
	return result;
}
// template ends here

void solve(){
	// code starts from here
	ll h1,p1,h2,p2;
	cin >> h1 >> p1 >> h2 >> p2;
	ll t1 = h2/p1 + !(h2%p1 == 0);
	ll t2 = h1/p2 + !(h1%p2 == 0);
	
	if(t1 <= t2) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

	int T;
	T = 1;
	while(T--){
		solve();
	}

	return 0;
}


Measured memory_bytes: 3652
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
 
    val a = sc.nextInt()!!
    val b = sc.nextInt()!!
 
    (1..1000).forEach { i ->
        if (a.toDouble().equals(Math.floor(i * 0.08)) && b.toDouble().equals(Math.floor(i * 0.1))) {
            println(i)
            return
        }
    }
 
    println(-1)
}

Measured memory_bytes: 31392
/* 
	Author: ankrypt
*/

#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;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 15
#define PI 3.141592653589793
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fi(a, b, c, d) for(int a = b; a < c; a += d)
#define fl(a, b, c, d) for(ll a = b; a < c; a += d)
#define fei(a, b, c, d) for(int a = b; a <= c; a += d)
#define fel(a, b, c, d) for(ll a = b; a <= c; a += d)
#define quit exit(0)
#define mem(x, a) memset(x, a, sizeof x)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pcl pair<char, ll>
#define psl pair<string, ll>


ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
vector<ll> V;
unordered_map<ll, ll> mp;
set<ll> s;
string S = "";
ll cases;

int main() {
	go;
    cin >> arr[0] >> arr[1] >> arr[2] >> arr[3] >> arr[4];
    fi(i, 0, 5, 1) {
    	if(!arr[i]) {
    		cout << i + 1 << "\n";
    		break;
    	}
    }
    
	return 0;
}
/*
	Powered by Buggy Plugin
*/




Measured memory_bytes: 3584
import java.util.Scanner;

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

    int Area = x * y;
    int Length = x + x + y + y;

    System.out.print(Area);
    System.out.print(" ");
    System.out.println(Length);
  }
}


Measured memory_bytes: 26292
#include<stdio.h>
int main(void){
	int m,f,r;
	while(1){
		scanf("%d %d %d",&m,&f,&r);
		if(m == -1 && f == -1 && r == -1){
			break;
		}
		if(m == -1 || f == -1){
			printf("F\n");
		}
		else if(m+f >= 80){
			printf("A\n");
		}
		else if(m+f >= 65 && m+f < 80){
			printf("B\n");
		}
		else if(m+f >= 50 && m+f < 65){
			printf("C\n");
		}
		else if(m+f >= 30 && m+f < 50){
			if(r >= 50){
				printf("C\n");
			}
			else{
				printf("D\n");
			}
		}
		else{
			printf("F\n");
		}
	}
	return 0;
}

Measured memory_bytes: 584
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    HashMap<String, Integer> map1 = new HashMap<String, Integer>();
    HashMap<String, Integer> map2 = new HashMap<String, Integer>();
    int n = sc.nextInt();
    String[] str1 = new String[n];
    for(int i = 0; i < n; i++) {
      str1[i] = sc.next();
      if(map1.containsKey(str1[i])) {
        map1.put(str1[i], map1.get(str1[i]) + 1);
      } else {
        map1.put(str1[i], 1);
      }
    }
    int m = sc.nextInt();
    String[] str2 = new String[m];
    for(int i = 0; i < m; i++) {
      str2[i] = sc.next();
      if(map2.containsKey(str2[i])) {
        map2.put(str2[i], map2.get(str2[i]) + 1);
      } else {
        map2.put(str2[i], 1);
      }
    }
    int ans = 0;
    for(String s : map1.keySet()) {
      if(map2.containsKey(s)) {
        ans = Math.max(ans, map1.get(s) - map2.get(s));
      } else {
        ans = Math.max(ans, map1.get(s));
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 20820
#include <stdio.h>
int main()
{
    int number[10];
    int i, j, temp;
    for (i = 0; i < 10; i++)
    scanf("%d", &number[i]);
    for (i = 0; i < 10; i++)
    {
        for (j = 0; j < 10-i; j++)
        {
            if (number[j] < number[j+1])
            {
                temp = number[j+1];
                number[j+1] = number[j];
                number[j] = temp;
            }
        }
    }
    for (i = 0; i < 3; i++)
    {
        printf("%d\n", number[i]);
    }
    return 0;
}

Measured memory_bytes: 600
#!/usr/bin/env python3
#EDPC C

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
dp = [[0]*3 for _ in range(n+1)]
for i in range(n):
    a,b,c = LI()
    dp[i+1][0] = max(dp[i][1] + a,dp[i][2] + a)
    dp[i+1][1] = max(dp[i][0] + b,dp[i][2] + b)
    dp[i+1][2] = max(dp[i][0] + c,dp[i][1] + c)
print(max(dp[-1]))

Measured memory_bytes: 55148
#include <cstdio>
#include <algorithm>
using namespace std;
int W[10],K[10];
int main() {
	for(int i=0;i<10;i++)
		scanf("%d",&W[i]);
	for(int i=0;i<10;i++)
		scanf("%d",&K[i]);
	sort(W,W+10);
	sort(K,K+10);
	int w=0,k=0;
	for(int i=7;i<=9;i++) w+=W[i],k+=K[i];
	printf("%d %d\n",w,k);
}

Measured memory_bytes: 1040
#include <stdio.h>

int main(void){

	long long int a, b;
	
	scanf("%lld", &a);
	scanf("%lld", &b);

	if(a <= 0 && b >= 0){
	
		printf("Zero\n");
		return 0;

	}else if(a < 0 && b <0){

		if((b - a)%2 == 0){
			printf("Negative\n");
			return 0;
		}else{
			printf("Positive\n");
			return 0;
		}
	}else if(a > 0 && b > 0){
	
		printf("Positive\n");
		return 0;

	}	

}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>

using namespace std;

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

int main() {
    int r, g, b;
    cin >> r >> g >> b;

    if ((r * 100 + g * 10 + b) % 4 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
long solve(int,int,int*);

int main(){
  int N,K;
  long ans;
  int *h;
  scanf("%d %d",&N,&K);
  h=malloc(sizeof(int)*N);
  for(int i=0;i<N;i++) scanf("%d",&h[i]);
  ans=solve(N,K,h);
  printf("%ld\n",ans);
  free(h);
  return 0;
}
long solve(int N,int K,int* h){
  long dp[N];
  long inf=1000000001;
  for(int i=1;i<N;i++) dp[i]=inf;
  dp[0]=0;
  for(int i=1;i<N;i++){
    for(int j=1;j<K+1 && j<i+1;j++){
      int h1=abs(h[i]-h[i-j]);
      if(dp[i]>dp[i-j]+h1) dp[i]=dp[i-j]+h1;
    }
  }
  return dp[N-1];
}

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

A = format(max(0,a-1), 'b')
B = format(b, 'b')


AA = []
BB = []

if(len(A) >= 2):
    for i in range(len(A)):
        if(i == len(A)-1):
            if(((a-1)%4 == 1) or ((a-1)%4 == 2)):
                AA.append("1")
            else:
                AA.append("0")
        else:
            if((A[i] == "1") and (A[-1] == "0")):
                AA.append("1")
            else:
                AA.append("0")
else:
    AA.append(A[0])

if(len(B) >= 2):
    for i in range(len(B)):
        if(i == len(B)-1):
            if((b%4 == 1) or (b%4 == 2)):
                BB.append("1")
            else:
                BB.append("0")
        else:
            if((B[i] == "1") and (B[-1] == "0")):
                BB.append("1")
            else:
                BB.append("0")
else:
    BB.append(B[0])


AA = "".join(AA)
BB = "".join(BB)

AA = int('0b'+AA,0)
BB = int('0b'+BB,0)

ans = AA^BB

print(ans)

Measured memory_bytes: 3064
import sys
args = sys.stdin.readlines()
n, m = map(int, args[0].split(' '))
l_1 = 1
r_1 = n

for gate in args[1:]:
  l, r = map(int, gate.split(' '))  
  if l > l_1:
    l_1 = l
  if r < r_1:
    r_1 = r

ids = r_1 - l_1 + 1
if ids < 0:
  print(0)
else:
  print(ids)

Measured memory_bytes: 11028
#include <stdio.h>
int main(void)
{
	int X,Y,W,H,N;
	int n,i,j,x,y;
	int count;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		count=0;
		scanf("%d%d%d%d",&X,&Y,&W,&H);
		scanf("%d",&N);
		for(j=0;j<N;j++){
		scanf("%d%d",&x,&y);
		if((x>=X)&&(x<=(X+W))&&(y>=Y)&&(y<=Y+H))
		count++;
		}
		printf("%d\n",count);
	}
	return 0 ;
}

Measured memory_bytes: 600