akhauriyash/Code-Regression huggingface dataset:
dishes_1 = [int(input()) for i in range(5)]
dishes_2 = [i % 10 for i in dishes_1]
dishes_sort = []

min_time = 0

for i in range (5):
    if dishes_2[i] == 0:
       dishes_sort.append(dishes_1[i])

for i in range (9, 0, -1):
    for j in range (5):
        if dishes_2[j] == i:
            dishes_sort.append(dishes_1[j])

for i in range (4):
    for j in range (9):
        if dishes_sort[i] % 10 == 0:
           break
        else:
            dishes_sort[i] += 1
            
print (sum(dishes_sort))

Measured memory_bytes: 3064
import math
N=int(input())
A=list(map(int,input().split()))
flag=True
if N%2==0:
    if 0 in A or len(set(A))!=N//2:
      flag=False
else:
    if len([0 for a in A if a==0])!=1 or len(set(A))!=N//2+1:
      flag=False
if flag:
  print(2**(N//2)%(10**9+7))
else:print(0)

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

#define pb push_back
#define sz size()
#define clr clear()

vector<bool> pt;

void MakeTable(int n){
  pt.clr;
  pt.pb(false);pt.pb(false);pt.pb(true);
  
  while((int)pt.sz<=n+1){
    pt.pb(true);
    pt.pb(false);
  }
  
  int i = 3;
  while(i*i<=n){
    for(int j=3*i;j<=n;j+=2*i)pt[j]=false;
    do{i+=2;}while(!pt[i]);
  }
}

int main(){
  int i,n;
  MakeTable(10000000);

  for(;;){
    cin >> n;
    if(!n)break;

    for(i=n;i>=0;i--){
      if(pt[i] && pt[i-2] && pt[i-6] && pt[i-8])break;
    }

    cout << i << endl;
  }
}

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

using namespace std;
typedef long long ll;

int main(){
    
    ios_base::sync_with_stdio(0);
    int a,b;
    cin>>a>>b;
    while(1){
        if(a==0 && b==0)    break;
        for(int i=0;i<a;i++){
            for(int j=0;j<b;j++){
                cout<<"#";
            }
            cout<<"\n";
        }
        cout<<"\n";
        cin>>a>>b;
    }
    return 0;
}




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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      k: chars,
      d: usize,
    }
    const MOD: usize = 1e9 as usize + 7;
    let n = k.len();
    let mut dp = vec![vec![vec![0; d]; 2]; n+1];
    dp[0][0][0] = 1;

    for i in 0..n {
        let c = (k[i] as u8 - '0' as u8) as usize;
        for flag in 0..2 {
            for m in 0..d {
                for dig in 0..10 {
                    if dig < c {
                        dp[i+1][1][(dig + m) % d] += dp[i][flag][m];
                        dp[i+1][1][(dig + m) % d] %= MOD;
                    } else if dig == c {
                        dp[i+1][flag][(dig + m) % d] += dp[i][flag][m];
                        dp[i+1][flag][(dig + m) % d] %= MOD;
                    } else {
                        if flag == 1 {
                            dp[i+1][flag][(dig + m) % d] += dp[i][flag][m];
                            dp[i+1][flag][(dig + m) % d] %= MOD;
                        }
                    }
                }
            }
        }
    }
    let ans = MOD + dp[n][1][0] + dp[n][0][0] - 1; // exclude 0
    println!("{}", ans%MOD);
}


Measured memory_bytes: 22780
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<utility>
#define mod 1000000007
#define pb push_back
#define ll long long
using namespace std;
ll dp[214514],col[214514];
int main(){
	ll n;
	vector<ll> a;
	cin>>n;
	a.pb(0);
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		if(x!=a[a.size()-1])a.pb(x);
	}
	ll k=a.size();
	dp[0]=1;
	for(int i=1;i<=k;i++){
		dp[i] = dp[i-1] + col[ a[i] ];
		dp[i]%=mod;
		col[ a[i] ] +=dp[i-1];
		col[a[i] ]%=mod;
	}
	cout<<dp[k]<<endl;
	return 0;
}

Measured memory_bytes: 5488
from bisect import bisect_left
N, M = map(int, input().split())
G = [[] for _ in range(N)]
P = [0]*M
Y = [0]*M
for i in range(M):
    P[i], Y[i] = map(int, input().split())
    G[P[i]-1].append(Y[i])

for i in range(N):
    G[i].sort()

for i in range(M):
    right = bisect_left(G[P[i]-1], Y[i])+1
    print(str(P[i]).rjust(6, '0')+str(right).rjust(6, '0'))


Measured memory_bytes: 64160
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=n;i++)
long h[100007];
int main(){
  long n,k,a,b,ans,sum;
  cin>>n>>k;
  
  rep(i,n){
    cin>>a>>b;
    h[a]=h[a]+b; 
  }
  sum=0;
  rep(i,10000000){
    sum+=h[i];
    if(sum>=k){
      ans=i;break;
    }
  
  }
  cout<<ans;
}

Measured memory_bytes: 1024
import sys

def main():
    inputData = input().strip().split(" ")
    result = 0
    ball = int(inputData[0])
    people = int(inputData[1])

    if people <= 1:
        return 0

    if ball > people:
        result = ball - people
        result += 1

    else:
        return 0

    result -= 1

    return result


if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    ll n, m;
    cin >> n >> m;
    if(n>2 && m>2){
        cout << (n-2)*(m-2) << endl;
    }
    else if(n==1 && m==1){
        cout << 1 << endl;
    }
    else if(n==1 && m>2){
        cout << m-2 << endl;
    }
    else if(m==1 && n>2){
        cout << n-2 << endl;
    }
    else cout << 0 << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
                     
#define int             long long
#define ld              long double
#define mp              make_pair
#define ff              first
#define ss              second
#define pb              push_back
#define fo(i,n)         for(i=0;i<n;i++)
#define fo1(i,n)        for(i=1;i<=n;i++)
#define FO(i,a,b)       for(i=a;i<=b;i++)
#define FOR(i,a,b)      for(i=a;i>=b;i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<int,int>
#define vpii            vector<pii>
#define vvi             vector<vi>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x)           cout<<setprecision(x)<<fixed;
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define in(a,n)         vi a(n);fo(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);fo1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define sz(v)           (int)v.size()
#define gcd             __gcd
#define lcm(x,y)        x*(y/gcd(x,y))
#define endl            '\n'
#define PI              3.14159265358979323846
const int inf =         1e18;
const int mod =         1e9+7;
void __p(int x) {cout<<x;}
void __p(int32_t x){cout<<x;}
void __p(float x){cout<<x;}
void __p(double x){cout<<x;}
void __p(ld x) {cout<<x;}
void __p(char x){cout <<'\''<<x<<'\'';}
void __p(const char *x){cout <<'\"' <<x<<'\"';}
void __p(const string &x) {cout<<'\"'<<x<<'\"';}
void __p(bool x) {cout<<(x?"true":"false");}
void _p() {cout << "]\n";}
template<typename T,typename V>     void __p(const pair<T,V> &x) {cout<<'{';__p(x.first);cout<<',';__p(x.second);cout<<'}';}
template<typename T>                void __p(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __p(i); cout << "}";}
template <typename T,typename... V> void _p(T t, V... v) {__p(t);if(sizeof...(v))cout<<", ";_p(v...);}
int po(int x,int p) {int ans=1;x%=mod;while(p>0){if(p&1)ans=(ans*x)%mod;p=p>>1;x=(x*x)%mod;}return ans;}
int inv(int x){return po(x,mod-2)%mod;}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout<<"["<<#x<<"]=[";_p(x)
#else 
#define dbg(x...)
#endif
//=================================================================================




const int N=1e6+6;
int n,m,k,x,y,z,a,b,c,d,i,j,l,r,f,q;








void sol()
{   
    cin>>n;
    
    
    
    
    cout<< (n>=30?"Yes":"No") <<endl;
}





int32_t main()
{   
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //pre();
    //sp(10);
    // w(t)
    sol();
    return 0;
}

Measured memory_bytes: 3668
import sys
import math
sys.setrecursionlimit(10000000)
input=sys.stdin.readline

a,b,h,m = map(int,input().split())

# if h ==0 :h=12  
# if m ==0 :m=60

md = (m/60) * 360
hd = (h/12) * 360 + (m * (360/12/60))

d = abs(md-hd)
print( (a**2 + b**2 - 2 * a * b * math.cos(math.radians(d))) **0.5)


Measured memory_bytes: 9504
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
using namespace std;

int main(){
  int n; cin >> n;
  map<int, bool> mp;
  int a[n+1];
  for(int i=1; i<=n; i++) {
    cin >> a[i];
    mp[a[i]] = true;
  }

  sort(a+1, a+n+1);
  int c = a[n], d, e;
  d = *(lower_bound(a+1, a+n+1, c/2));
  e = *(lower_bound(a+1, a+n+1, c/2)-1);

  if(c%2 == 1){
    if(abs(c-2*d) < abs(c-2*e)){
      cout << c << " " << d << endl;
    }
    else{
      cout << c << " " << e << endl;
    }
  }
  else{
    if(abs(c/2-d) < abs(c/2-e)){
      cout << c << " " << d << endl;
    }
    else{
      cout << c << " " << e << endl;
    }
  }
  return 0;
}


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

int main(){
	int a, b, c;
	cin >> a >> b >> c;

	int ans = 0;

	for (int i = 0; i < c; i++) {
		if (b - a >= 0) {
			b = b - a;
			ans++;
		}
		else {
			break;
		}
	
	}

	cout << ans << endl;


	

	return 0;
}



Measured memory_bytes: 256
/* Simplicity and Goodness */

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//             tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B)
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 2e3+2;

void solve()
{
    int n;
    scn(n);

    vi a(n), b(n), c(n);

    rep(i, 0, n)
    scn(a[i]);

    rep(i, 0, n)
    scn(b[i]);

    rep(i, 0, n)
    scn(c[i]);

    sort(a.begin(), a.end()); sort(b.begin(), b.end()); sort(c.begin(), c.end());
    
    vl cb(n, 0), ca(n, 0);

    rep(i, 0, n) {
        auto it = upper_bound(c.begin(), c.end(), b[i]);

        if(it == c.end()) {
            break;
        } else {
            cb[i] = c.end() - it;
        }
    }

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

    rep(i, 0, n) {
        auto it = upper_bound(b.begin(), b.end(), a[i]);

        if(it == b.end()) {
            break;
        } else {
            int id = it - b.begin();
            ca[i] = cb[id];
        }
    }

    ll cnt = 0;

    rep(i, 0, n) {
        cnt += ca[i];
    }

    lprin(cnt);
}

int main()
{
    int t = 1;
    // scn(t);
    
    while(t --) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 5900
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;
#define chmax(x, y) do { x = max(x, y); } while(0)
#define chmin(x, y) do { x = min(x, y); } while(0)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;

ll N;
vector<ll> a(3);
vector<pair<ll, ll>> v;

signed main() {
  cin >> N;
  rep(i, 3)
    cin >> a[i];
  rep(i, N) {
    string s;
    cin >> s;
    v.push_back({s[0] - 'A', s[1] - 'A'});
  }


  if (a[0] + a[1] + a[2]  == 0) {
    // そもそもダメ
    cout << "No" << endl;
    return 0;
  } else if (a[0] + a[1] + a[2] <= 2) {
    // 何とかすればYesになるかも => DP
    map<vector<ll>, string> mp; // map[{0,1,1}] = "ABC"
    mp[a] = "";
    vector<char> ans;
    rep(i, N) {
      ll x = v[i].first, y = v[i].second;
      map<vector<ll>, string> mp2;

      for (auto t : mp) {
        auto val = t.first;
        auto str = t.second;
        if (val[x] > 0) {
          vector<ll> val2 = val;
          string str2 = str + (string() + (char)(y + 'A'));
          val2[x]--; val2[y]++;
          mp2[val2] = str2;
        }
        if (val[y] > 0) {
          vector<ll> val2 = val;
          string str2 = str + (string() + (char)(x + 'A'));
          val2[x]++; val2[y]--;
            mp2[val2] = str2;
        }
      }

      if (mp2.size() == 0) {
        cout << "No" << endl;
        return 0;
      }
      swap(mp, mp2);
    }
    cout << "Yes" << endl;
    for (auto c : mp.begin()->second) {
      cout << c << endl;
    }
  } else {
    vector<char> ans;
    rep(i, N) {
      ll x = v[i].first, y = v[i].second;
      // cout << "a, b, c = " << a[0] <<  " " << a[1] << " " << a[2] << endl;
      // cout << "x, y = " << x <<  " " << y << endl;
      if (a[x] == 0 && a[y] == 0) {
        cout << "No" << endl;
        return 0;
      } else if (a[x] > a[y]) {
        a[x]--;
        a[y]++;
        ans.push_back(y + 'A');
      } else {
        a[y]--;
        a[x]++;
        ans.push_back(x + 'A');
      }
    }
    cout << "Yes" << endl;
    for (auto c : ans) {
      cout << c << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 5624
#include <stdio.h>
#include <math.h>
 
int s[1002];
 
#define gc() getchar_unlocked()
int in()
{
    int n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc();
    while (c >= '0');
    return n;
}
 
int main()
{
    int n, i, is;
    double m, fs, a;
     
    while (n = in()) {
        is = 0; for (i = 0; i < n; i++) is += s[i] = in();
        m = (double)is/n;
        fs = 0; for (i = 0; i < n; i++) {
            a = s[i]-m;
            fs += a*a;
        }
        printf("%.8lf\n", sqrt(fs/n));
    }
    return 0;
}


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

int main() {
  int N; std::cin >> N;
  std::vector<int> a(N);
  for (int i = 0; i < N; ++i) std::cin >> a[i];
  
  long long res = 0;
  int right = 0;
  long long sum = 0;
  
  for (int left = 0; left < N; ++left) {
    while (right < N && ((sum ^ a[right]) == sum + a[right])) {
      sum += a[right];
      ++right;
    }
    
    if (left == right) ++right;
    else sum -= a[left];
    
    res += (right - left);
    }
  
  std::cout << res << std::endl;
  
  return 0;
}


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

using namespace std;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    for(int i = 0; i < (int)s.size() - 8; i ++){
        cout << s[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>

#define PI 3.14159265359	

using namespace std;

int main(){
	int n, x, count;
	while (1){
		count = 0;
		cin >> n >> x;
		if (n == 0 && x == 0) break;
		for (int i = 1; i <= n; i++){
			for (int j = i + 1; j <= n; j++){
				for (int k = j + 1; k <= n; k++){
					if (i + j + k == x) count++;
				}
			}
		}
		cout << count << endl;
	}
}

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

using namespace std;

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

int main() {
    int W, H, N;
    cin >> W >> H >> N;

    vector<vector<int>> inputs(N, vector<int>(3));
    rep(i, N){
        rep(j, 3){
            cin >> inputs.at(i).at(j);
        }
    }

    vector<vector<bool>> canvas(H, vector<bool>(W, true));
    for(vector<int> input : inputs){
        if(input.at(2) == 1){
            rep(i, H){
                rep(j, input.at(0)){
                    canvas.at(i).at(j) = false;
                }
            }
        } else if(input.at(2) == 2){
            rep(i, H){
                for(int j=input.at(0); j<W; j++){
                    canvas.at(i).at(j) = false;
                }
            }
        } else if(input.at(2) == 3){
            rep(i, W){
                rep(j, input.at(1)){
                    canvas.at(j).at(i) = false;
                }
            }
        } else if(input.at(2) == 4){
            rep(i, W){
                for(int j=input.at(1); j<H; j++){
                    canvas.at(j).at(i) = false;
                }
            }
        }
    }
    int ans = 0;
    for(vector<bool> row : canvas){
        for(bool c : row){
            if(c) ans++;
            // cout << c;
        }
    }
    cout << ans << endl;
}

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

#define pb push_back
#define PQ priority_queue
#define make_unique(x) sort((x).begin(), (x).end()); (x).erase(unique((x).begin(), (x).end()), (x).end())

typedef long long ll;
typedef long double ld;

//__builtin_popcount(x)

using namespace std;

const int mod = 1e9 + 7;

ll add(ll a, ll b) {
    ll res = a + b;
    if (res >= mod) res -= mod;
    return res;
}

ll sub(ll a, ll b) {
    ll res = a - b + mod;
    if (res >= mod) res -= mod;
    return res;
}

ll mul(ll a, ll b) {
    return (((a % mod) * (b % mod)) % mod);
}

/* Z-FUNCTION
ll l = 0, r = 0, n = (int)s.size();
vector<int> z(n, 0);
for (int i = 1; i < n; i++) {
    if (r >= i) {
        z[i] = min(1ll*z[i-l], r-i+1);
    }
    while (z[i] + i < n && s[z[i]] == s[z[i] + i]) z[i]++;
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
}
*/

/*vector<int> find_dividers(int x) {
    vector<int> dividers;

    for (int i = 1; i <= sqrt(x); i++) {
        if (x % i == 0) {
           dividers.push_back(i);
            if (i * i != x) {
                dividers.push_back(x / i);
            }
        }
    }

    return dividers;
}*/

/*int nok(int a, int b) {
    return a / __gcd(a, b) * b;
}*/

void solve() {
    int x;
    cin >> x;
    cout << (!x) << endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout.setf(ios::fixed);
    //cout.precision(10);

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

    return 0;
}


Measured memory_bytes: 3632
using System;
using System.Linq;
using System.Collections.Generic;
using static program.Input;
using static program.MyMath;

namespace program {
  class Program {
    static void Main()
    {
      var n = ScanLongArray();
      Console.WriteLine(LCM(n[0],n[1]));
    }
    static public void Out(object s) { Console.Write($"{s} "); }
  }
  
  static class Input {
    static public int ScanInt() { return int.Parse(Console.ReadLine()); }
    static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
    static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
    static public long ScanLong() { return long.Parse(Console.ReadLine()); }
    static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
    static public int[] ScanIntArray() { return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); }
    static public uint[] ScanUintArray() { return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); }
    static public double[] ScanDoubleArray() { return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); }
    static public long[] ScanLongArray() { return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); }
    static public ulong[] ScanUlongArray() { return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); }

    static public string ScanStr() { return Console.ReadLine(); }
    static public string[] ScanStrArray() { return ScanStr().Split(); }
  }
  
  static class MyMath {
    public static int GCD(int a, int b) {
        Func<int, int, int> gcd = null;
        gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
        return a > b ? gcd(a, b) : gcd(b, a);
    }
    public static long GCD(long a, long b) {
        Func<long, long, long> gcd = null;
        gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
        return a > b ? gcd(a, b) : gcd(b, a);
    }
    public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) {
      if(b==0) {
        x=1; 
        y=0;
        return a;
      }
      var d = extGCD(b, a%b, ref y, ref x);
      y -= a/b *x;
      return d;
    }
    public static int LCM(int a, int b) { return a * b / GCD(a, b); }
    public static long LCM(long a, long b) { return a * b / GCD(a, b); }
  }
}


Measured memory_bytes: 13396
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 無限 #####
# f_inf = float('inf')

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N = inputInt()
	A = inputList()

	A.sort()

	for i,val in enumerate(A):
		if i == 0:
			continue
		if val == A[i-1]:
			print("NO")
			sys.exit()

	print("YES")

if __name__ == "__main__":
	main()


Measured memory_bytes: 78792
N,M = map(int,input().split())
a = [0]*N
b = [0]*N
for i in range(N):
    a[i],b[i] = map(int,input().split())
c = [0]*M
d = [0]*M
for i in range(M):
    c[i],d[i] = map(int,input().split())

ans = []
for i in range(N):
    for j in range(M):
        tmp = abs(a[i]-c[j])+abs(b[i]-d[j])
        ans.append(tmp)
    print(ans.index(min(ans))+1)
    ans = []


Measured memory_bytes: 3064
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> // include pb_ds

using namespace std;
using namespace __gnu_pbds; // namespace for pb_ds

/* short forms */
#define Accelerate                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define mt make_tuple
#define cld(x, y) (((x) / (y)) + ((x) % (y) != 0)) //integer ceil division
#define tc(tt) \
    int tt;    \
    cin >> tt; \
    for (int _tt = 0; _tt < tt; _tt++) // testcase
#define all(cont) (cont).begin(), (cont).end()
#define sz(cont) (int)(cont).size()
#define endl '\n'
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl //print with precision
#define dbg(x) cerr << #x << "is" << (x) << endl
#define leadzero(a) __builtin_clz(a)      // count leading zeroes
#define trailzero(a) __builtin_ctz(a)     // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)

/* constants */
const double PI = 3.1415926535897932384626433832795;
const double EPS = 1e-9;

/* typedefs */
typedef pair<int,int> pii;
typedef priority_queue<int, vector<int>, greater<int> > min_heap;
typedef priority_queue<int, vector<int> > max_heap;
typedef tree<int,null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> 
    indexed_set; // integer set with indexing / pb_ds

/* main program */


int main() {
    Accelerate;
    int k,x;
    cin >> k >> x;
    int l = -1000000,u=1000000;
    set<int>s;
    for(int i=x;i<=min(u,x+k-1);i++) s.insert(i);
    for(int i=x;i>=max(l,x-k+1);i--) s.insert(i);
    while(!s.empty()) {
        cout << *s.begin() << " ";
        s.erase(*s.begin());
    }
    
    cout << endl;   
    
    return 0;
}

Measured memory_bytes: 256
def main():

    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    mod = pow(10, 9) + 7
    A.sort()

    if K == 1: return 0

    g1 = [1, 1]
    g2 = [1, 1]
    inv = [0, 1]

    for i in range(2, N+1):
        g1.append((g1[-1] * i) % mod)
        inv.append( ( -inv[mod % i] * (mod//i)) % mod )
        g2.append((g2[-1] * inv[-1]) % mod)

    def combi(n, r):
      r = min(r, n-r)
      return g1[n]*g2[r]*g2[n-r]%mod



    maxes = 0
    for j in range(K-1, N):
        maxes += (A[j]*combi(j, K-1)) % mod
    mins = 0
    for i in range(N-K+1):
        mins += (A[i]*combi(N-i-1, K-1)) % mod

    return (maxes - mins) % mod


if __name__ == '__main__':
    print(main())

Measured memory_bytes: 77096
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#ifdef WAAUTOMATON
#define debug(args...)                                                                             \
    {                                                                                              \
        dbg, args;                                                                                 \
        cerr << endl;                                                                              \
    }
#define massert(x) assert(x)
#else
#define debug(args...) // Just strip off all debug tokens
#define massert(x)
#endif
struct debugger
{
    template <typename T>
    debugger &operator,(const T &v)
    {
        cerr << v << " ";
        return *this;
    }
} dbg;
const int MAXN = 100000;
vector<int> g[MAXN + 10];
int in[MAXN + 10];
bool vis[MAXN + 10];
int cnt[MAXN + 10];
int dfs(int now,int fa)
{
	int cnt=0;
	for(auto i:g[now]) {
		if (i!=fa) {
			cnt+=dfs(i,now);
		}
	}
	if (cnt>1)
		throw 1;
	return cnt^1;
}
void solve(long long n, vector<long long> a, vector<long long> b)
{
    int sum = n;
    for (int i = 0; i < n - 1; ++i) {
        g[a[i]].push_back(int(b[i]));
        g[b[i]].push_back(a[i]);
        in[a[i]]++;
        in[b[i]]++;
    }
	bool flag=true;
	try {
		int x= dfs(1,0);
		if (x==1) flag=false;
	} catch(...) {
		flag=false;
	}
	if (flag) {
		puts("Second");
	} else {
		puts("First");
	}
}

int main()
{
#ifdef WAAUTOMATON
    freopen("./in_D_2.txt","r",stdin);
#endif
    long long N;
    scanf("%lld", &N);
    vector<long long> a((N - 1) - 1 + 1);
    vector<long long> b((N - 1) - 1 + 1);
    for (int i = 0; i <= (N - 1) - 1; i++) {
        scanf("%lld", &a[i]);
        scanf("%lld", &b[i]);
    }
    solve(N, a, b);
    return 0;
}


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

int main()
{
   int n,cnt=0;
   cin>>n;
   for(int i=1;i<=9;i++){
    if(n%i==0 && 1<=(n/i)&&(n/i)<=9){
        cout<<"Yes"<<endl;
        return 0;
    }


   }
   cout<<"No"<<endl;
   return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int max = Integer.MIN_VALUE;
		int min = Integer.MAX_VALUE;
		long b = 0;
		for(int i = 1;i<=n;i++){
			int a = sc.nextInt();
			b = b + a;
			if(max<a) {
				max = a;
			}
			if(min>a) {
				min = a;
			}
		}
		System.out.println(min+" "+max+" "+b)	;
	}
}

Measured memory_bytes: 31752
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

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

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

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

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

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

    let tin = vec![a, b, a + b];

    let filt: Vec<_>  = tin.iter().filter(|x| **x != 0 && **x % 3 == 0).collect();

    if filt.len() > 0 {
        println!("Possible");
    } else {
        println!("Impossible");
    }
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long d = sc.nextLong();
        long kijun = d*d;
        int ans = 0;

        for (int i=1;i<=n;i++) {
            long x = sc.nextLong();
            long y = sc.nextLong();
            long nagasa = x*x+y*y;
            if (kijun>=nagasa) {
                ans++;
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 60604
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

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

int a[100010], b[100010];
pair<ll, ll> c[100010];
signed main(void)
{
	int n;
	cin >> n;
	REP(i, n) cin >> a[i];
	REP(i, n) cin >> b[i];

	c[0] = PII{a[0], a[0]};
	FOR(i, 1, n) {
		if(a[i] > a[i-1]) c[i] = {a[i], a[i]};
		else if(a[i] == a[i-1]) c[i] = {1, a[i]};
		//else {cout << 0 << endl; return 0;}
	}
	//REP(i, n) cout << c[i].first << " " << c[i].second << endl;
	//cout << endl;

	if(b[n-1] < c[n-1].first || c[n-1].second < b[n-1]) {
		cout << 0 << endl;
		return 0;
	}
	c[n-1] = {b[n-1], b[n-1]};
	for(int i=n-2; i>=0; --i) {
		if(b[i] > b[i+1]) {
			if(b[i] < c[i].first || c[i].second < b[i]) {cout << 0 << endl; return 0;}
			c[i] = {b[i], b[i]};
		} else if(b[i] == b[i+1]) {
			if(c[i].first > b[i]) {cout << 0 << endl; return 0;}
			c[i].first = max(c[i].first, 1LL);
			c[i].second = min(c[i].second, b[i]);
		} /*else {
			cout << 0 << endl;
			return 0;
		}*/
	}

	ll ans = 1;
	REP(i, n) {
		//cout << c[i].first << " " << c[i].second << endl;
		ans = (ans*(c[i].second-c[i].first+1)) % MOD;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3328
ew,eh,n=[int(x) for x in input().rstrip().split()]
fw=0
fh=0
ansx=0
ansy=0
for i in range(n):
    x,y,a=[int(x) for x in input().rstrip().split()]
    if(a==1):
        fw=max(fw,x)
    elif(a==2):
        ew=min(ew,x)
    elif (a==3):
        fh=max(fh,y)
    elif (a==4):
        eh=min(eh,y)

if(ew-fw<0):
    ansx=0
elif(eh-fh<0):
    ansy=0
else:

    ansx=ew-fw
    ansy=eh-fh

print(ansx*ansy)

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

using namespace std;

int n, m, d;

int main() {
	scanf("%d%d%d", &n, &m, &d);
	if (d % 2)
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++)
				printf((i + j) % 2 ? "R" : "Y");
			printf("\n");
		}
	else {
		d /= 2;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				// printf("%d%d", i + j, i - j + m);
				if ((i + j) / 2 / d % 2 == 0) {
					if ((i - j + m) / 2 / d % 2 == 0)
						printf("R");
					else
						printf("Y");
				} else {
					if ((i - j + m) / 2 / d % 2 == 0)
						printf("G");
					else
						printf("B");
				}
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main()
{
    map<ll, ll>mp;
    ll n, m, tot = 0;
    cin>>n;
    for(int i = 0; i < n - 1; i++)
    {
        ll x;
        cin>>x;
        mp[x]++;
    }
    for(int i = 1; i <= n; i++) cout<<mp[i]<<"\n";
	return 0;
}


Measured memory_bytes: 16132
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N;
    std::cin >> N;

    int64_t ans = 0;
    std::vector<int64_t> A;
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        A.push_back(t);
        ans += t - 1;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val (A, B, C) = readLine()!!.split(" ").map(String::toInt)
    var map = TreeSet<Int>()
    map.add(A)
    map.add(B)
    map.add(C)
    println(
        if(map.size==2){
            "Yes"
        }else{
            "No"
        })
}

Measured memory_bytes: 38000
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

N = int(sys.stdin.readline())
list_b = list(map(int, sys.stdin.readline().split()))
list_a = [0]*N
list_a[N-1] = list_b[N-2]

for i in range(N-1, 0, -1):
    if(list_b[i-2] < list_b[i-1]):
        list_a[i-1] = list_b[i-2]
    else:
        list_a[i-1] = list_b[i-1]

if(list_a[1] > list_b[0]):
    list_a[0] =list_a[1]
else:
    list_a[0] =list_b[0]

sum = 0

for i in range(N):
    sum += list_a[i]

# print(list_a)

print(sum)


Measured memory_bytes: 5584
N = int(input())
X = list(map(int, input().split()))
x = []
for i in range(N):
    x.append([X[i], i])
x.sort()
B = []

for i in range(N):
    if i < N // 2:
        B.append([x[N//2][0], x[i][1]])
    else:
        B.append([x[(N-1)//2][0], x[i][1]])

B.sort(key=lambda x: x[1])

for i in range(N):
    print(B[i][0])

Measured memory_bytes: 64364
while True:
    t,d,l=map(int,input().split())
    if t==0:
        break
    ls=[]
    for i in range(t):
        ls.append(int(input()))
    ans=0
    r=0
        
    for j in range(t):
        if ls[j]>=l:
            ans+=1
            if r<d:
                r=d-1
        else:
            if r>0:
                ans+=1
                r-=1
    if ans>0:
        print(ans-1)
    else:
        print(0)



Measured memory_bytes: 9536
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//たこ焼きの数
		int n = scan.nextInt();
		
		int [] s  = new int[50];
		for(int i  = 0; i < n ; i++) {
			s[i] = scan.nextInt();
		}
		// 体力
		int ans = 0;

		for(int i = 0; i < n; i++) {
			for(int j = i + 1; j < n; j++) {
				//体力の回復量
				ans += s[i] * s[j];
			}
		}

		System.out.println(ans);
	}
}

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

#define MAX_WEIGHT 100000

int **mat;
int *d;
int n;

void MST();
int Search(int*,int*);
int Test_Set(int*);

int main(void){
	int i,j;
	int sum=0;

	scanf("%d",&n);

	d=(int*)malloc(sizeof(int)*n);

	mat=(int**)malloc(sizeof(int*)*n);
	for(i=0;i<n;i++) mat[i]=malloc(sizeof(int)*n);

	for(i=0;i<n;i++){
		for(j=0;j<n;j++) scanf("%d",&mat[i][j]);
	}

	MST(n);

	for(i=0;i<n;i++) sum+=d[i];
	printf("%d\n",sum);

	free(d);
	for(i=0;i<n;i++) free(mat[i]);
	free(mat);

	return 0;
}

void MST(){
	int r,u;
	int i;
	int A[n];

	for(i=0;i<n;i++){
		A[i]=0;
		d[i]=MAX_WEIGHT+1;
	}
	r=0;
	d[r]=0;

	while(Test_Set(A)==0){
		u=Search(d,A);
		A[u]=1;

		for(i=0;i<n;i++){
			if(A[i]==1 || mat[u][i]==-1) continue;
			if(mat[u][i]<d[i]) d[i]=mat[u][i];
		}
	}

}

int Search(int *d,int *A){
	int i;
	int min=MAX_WEIGHT+1;
	int u;

	for(i=0;i<n;i++){
		if(A[i]==1) continue;
		
		if(d[i]<min){
			min=d[i];
			u=i;
		}
	}

	return u;
}

int Test_Set(int *A){
	int i;

	for(i=0;i<n;i++){
		if(A[i]==0) return 0;
	}	
	return 1;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const int maxn = 2010, mod = 924844033 ;
int dp[maxn * 2][maxn][2] ;
int fac[maxn] ;
bool link[2 * maxn] ;
int main() {
    int n, k, cnt = 0 ;
    scanf("%d%d", &n, &k) ;
    fac[0] = 1 ;
    for (int i = 1; i <= n; i ++) fac[i] = 1ll * fac[i - 1] * i % mod ;
    for (int i = 1; i <= k; i ++)
        for (int t = 1; t <= 2; t ++)
            for (int j = i; j <= n; j += k) {
                cnt ++ ;
                if (j != i) link[cnt] = 1 ;
            }
    dp[0][0][0] = 1 ;
    for (int i = 0; i < n * 2; i ++)
        for (int j = 0; j <= n; j ++) {
            dp[i + 1][j][0] = (dp[i][j][0] + dp[i][j][1]) % mod ;
            if (link[i + 1]) dp[i + 1][j + 1][1] = dp[i][j][0] ;
        }
    ll ans = 0 ;
    for (int i = 0; i <= n; i ++) {
        ll tmp = 1ll * (dp[n * 2][i][0] + dp[n * 2][i][1]) % mod * fac[n - i] % mod ;
        if (i & 1) ans = (ans - tmp + mod) % mod ;
        else ans = (ans + tmp) % mod ;
    }
    printf("%lld\n", ans) ;
    return 0 ;
}


Measured memory_bytes: 63104
#include <iostream>
#include <string>
#include <exception>
#include <cctype>

using namespace std;

struct Result {
	int v, p, ex;
};

#define PARSER_DECL(name) \
	Result name (const string &s, int p)

PARSER_DECL(expr);
PARSER_DECL(term);
PARSER_DECL(factor);
PARSER_DECL(expr_in);

void range_check(int x){
	if(x < 0 || x >= 1024){ throw exception(); }
}

PARSER_DECL(expr){
	Result r;
	r = term(s, p);
	while(s[r.p] == '+' || s[r.p] == '-'){
		Result q = term(s, r.p + 1);
		if(s[r.p] == '+'){
			r.v += q.v;
		}else{
			r.v -= q.v;
		}
		range_check(r.v);
		r.p = q.p;
	}
	range_check(r.v);
	return r;
}
PARSER_DECL(term){
	Result r;
	r = factor(s, p);
	r.ex = 0;
	while(s[r.p] == '*'){
		Result q = factor(s, r.p + 1);
		r.ex = 1;
		r.v *= q.v;
		r.p = q.p;
		range_check(r.v);
	}
	range_check(r.v);
	return r;
}
PARSER_DECL(factor){
	Result r;
	if(s[p] == '('){
		r = expr_in(s, p + 1);
		if(s[r.p] != ')'){ throw exception(); }
		range_check(r.v);
		++r.p;
	}else if(isdigit(s[p])){
		r.v = 0;
		while(isdigit(s[p])){
			r.v = (r.v * 2) + (s[p] - '0');
			range_check(r.v);
			++p;
		}
		r.p = p;
	}else{
		throw exception();
	}
	return r;
}

PARSER_DECL(expr_in){
	Result r;
	r = term(s, p);
	while(s[r.p] == '+' || s[r.p] == '-'){
		Result q = term(s, r.p + 1);
		r.ex = 1;
		if(s[r.p] == '+'){
			r.v += q.v;
		}else{
			r.v -= q.v;
		}
		range_check(r.v);
		r.p = q.p;
	}
	if(r.ex == 0){ throw exception(); }
	range_check(r.v);
	return r;
}

const char SYMBOLS[] = "01+-*()";

int recur(string &s, int p){
	int answer = -1;
	bool parse_req = true;
	for(int i = p; i < s.size(); ++i){
		if(s[i] == '.'){
			parse_req = false;
			for(int j = 0; SYMBOLS[j] != '\0'; ++j){
				s[i] = SYMBOLS[j];
				answer = max(answer, recur(s, i + 1));
			}
			s[i] = '.';
			break;
		}
	}
	if(parse_req){
		try {
			Result r = expr(s, 0);
			if(s[r.p] != '\0'){ throw exception(); }
			answer = r.v;
		}catch(exception e){
		}
	}
	return answer;
}

int main(){
	string s;
	cin >> s;
	cout << recur(s, 0) << endl;
	return 0;
}

Measured memory_bytes: 1252
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){
   int w,a,b;
   cin >> w >> a >> b;

   int ans = 0;
   if((a<=b && b<= a+w)||(a<=b+w && b+w <= a+w)) ans = 0;
   else if( b+w < a) ans = a- (b+w);
   else if( a+w < b) ans = b - (a+w);

   cout << ans << endl;



   return 0;
}

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

int main(){
    int num;
    cin >> num;
    const int right = 7;
    int op = -1;
    vector<int> deg(4);
    rep(i,4) {
        deg[3-i] = num %10;
        num = num / 10;
    }
    char ans1,ans2,ans3;
    rep(i,2){
        rep(j,2){
            rep(k,2){
                int ans = deg[1] *pow(-1,i) + deg[2] * pow(-1,j) + deg[3]*pow(-1,k);
                if (ans == right -deg[0]){
                    ans1 = (i == 0)?'+':'-';
                    ans2 = (j == 0)?'+':'-';
                    ans3 = (k == 0)?'+':'-';
                    cout << deg[0] << ans1 << deg[1] << ans2 << deg[2] << ans3 << deg[3] << '=' << 7 << endl;
                    return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl

ll H, W, N, a[10000 + 10], ans[110][110], counter, index;

int main() {
	cin >> H >> W >> N;
	repi(i, 0, N) rd(a[i]);

	repi(i, 0, H) {
		repi(j, 0, W) {
			if (i % 2 == 0) ans[i][j] = index + 1;
			else ans[i][W - 1 - j] = index + 1;
			counter++;
			if (counter == a[index]) {
				index++;
				counter = 0;
			}
		}
	}

	repi(i, 0, H) {
		repi(j, 0, W) {
			wr(ans[i][j]);
			if (j != W - 1) cout << " ";
			else cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 512
# coding: utf-8
A, B, C = [input() for _ in range(3)]

x = A[0]
cnt_a = 0
cnt_b = 0
cnt_c = 0
#for _ in range(len(A)+len(B)+len(C)):
while True:
    if x == "a":
        if cnt_a < len(A):
            x = A[cnt_a]
            cnt_a += 1
        else:
            print("A")
            break
    elif x == "b":
        if cnt_b < len(B):
            x = B[cnt_b]
            cnt_b += 1
        else:
            print("B")
            break
    else:
        if cnt_c < len(C):
            x = C[cnt_c]
            cnt_c += 1
        else:
            print("C")
            break


Measured memory_bytes: 3064
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

signed main() {
	int N; cin >> N;
	set<int> a;
	for (int i = 0; i < N; ++i) {
		int ai; cin >> ai;
		a.insert(ai);
	}
	cout << (a.size() == N ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 9600
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int A[210000], DP[210000][5] = {};

int main(){
    int L;
    cin >> L;
    for(int i = 0; i < L; i++){
        cin >> A[i];
    }
    for(int i = 1; i <= L; i++){
        DP[i][0] = DP[i - 1][0] + A[i - 1];
        DP[i][1] = DP[i - 1][1] + A[i - 1] % 2 + (A[i - 1] == 0) * 2;
        DP[i][1] = min(DP[i][1], DP[i][0]);
        DP[i][2] = DP[i - 1][2] + (A[i - 1] + 1) % 2;
        DP[i][2] = min(DP[i][2], DP[i][1]);
        DP[i][3] = DP[i - 1][3] + A[i - 1] % 2 + (A[i - 1] == 0) * 2;
        DP[i][3] = min(DP[i][3], DP[i][2]);
        DP[i][4] = DP[i - 1][4] + A[i - 1];
        DP[i][4] = min(DP[i][4], DP[i][3]);
    }
    cout << DP[L][4] << endl;
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	for (int i = 0, p, count = 0; i < n; i++) {
		cin >> p;
		if (i + 1 != p) {
			count++;
			if (count > 2) {
				cout << "NO" << endl;
				return 0;
			}
		}
	}
	cout << "YES" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 string a,b,c;
 int x,y;
 cin>>a>>b;
 cin>>x>>y;
 cin>>c;
 if(c==a)
 x--;
 else
 y--;
 cout<<x<<" "<<y<<endl;
 return 0;
}


Measured memory_bytes: 256
import bisect

# d := {"a":[], "b":[], ..., "z":[]}
d = {}
key = list("abcdefghijklmnopqrstuvwxyz")
for i in range(26):
    d[key[i]] = []

# 1文字ずつ分割してリスト化
S = list(input())
N = len(S)

T = list(input())
M = len(T)

for i in range(N):
    d[S[i]].append(i + 1)

# print(d)

S_set = set(S)

ans = 0
now = 0
# Tの1文字目, 2文字目, ...
for i in range(M):
    if T[i] in S_set:
        next = bisect.bisect_right(d[T[i]], now)
        # print("i,next = ", i, next)
        # 右端ではない場合
        if next < len(d[T[i]]):
            now = d[T[i]][next]
        # 右端になる場合
        else:
            now = d[T[i]][0]
            ans += N
    else:
        print(-1)
        exit()

ans += now
print(ans)


Measured memory_bytes: 83736