akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn main(){
let a: u32 = read();
let b: u32 = read();
let ans = if (a * b) % 2 == 0 { "Even" } else { "Odd" };
println!("{}", ans);
    
}

Measured memory_bytes: 4352
k, s = gets.chomp.split(' ').map(&:to_i)
cnt = 0
0.upto(k) do |a|
    0.upto(s-a) do |b|
        next if b > k
        c = s - a - b
        
        if c >= 0 && c <= k
            cnt += 1
        end
    end
end

puts cnt

Measured memory_bytes: 1788
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <cstdio>
#define vi vector<int>
#define si set<int>
#define ll unsigned long long 
//#define int long long
#define int unsigned long long
#define double long double

const int maxn = 1e5*2+20;

using namespace std;

int cnt(int x){
  if(x < 10) return 0;
  if(x == 10) return 1;
  return 10*cnt(x/10) + 1;
}

signed main(){
	ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n;
    cin >> n;
   	if(n <= 2){
   		cout << 0;
   		return 0;
   	}

   	int ans = 0;
   	if(n % 2 == 1){
   		cout << 0;
   		return 0;
   	}
    int i = 10;
    while(i <= n){
      ans += n/i;
      i*=5;
    }
    cout << ans;


	return 0;
}

Measured memory_bytes: 764
import java.io.*;

public class Main{
	public static final int YEAR = 2019;
	
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] line = br.readLine().split(" ");
		int L = Integer.parseInt(line[0]);
		int R = Integer.parseInt(line[1]);
		
		if( R - L != R%YEAR - L%YEAR ){
			System.out.println(0);
		}else{
			L %= YEAR; R %= YEAR;
			int min = L*(L+1)%YEAR;
			for(int i=L; i<R; i++) for(int j=i+1; j<=R; j++)
				if( i*j%YEAR < min )
					min = i*j%YEAR;
			System.out.println(min);
		}
	}
}


Measured memory_bytes: 22868
def count_set_bits(n):
    count = 0
    while n:
        count += n & 1
        n >>= 1
    return count


N = int(input())
F = [int("".join(input().split()), 2) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = -float("inf")
for i in range(1, 1 << 10):
    tmp = 0
    for j in range(N):
        tmp += P[j][count_set_bits(i & F[j])]
    ans = max(ans, tmp)
print(ans)


Measured memory_bytes: 9212
#include <stdio.h>
int main()
{
    int n,i,j;
    int Time[500][4]={0};
    scanf("%d",&n);
    for(i=0;i<n-1;i++)
    {
        for (j=0;j<3;j++)
        {
            scanf("%d",&Time[i][j]);
        }
    }
    for (i=0;i<n;i++)
    {
        for (j=i;j<n-1;j++)
        {
            if (j==i) Time[i][3]+=Time[j][1];
            if (Time[i][3]>=Time[j][1])
            {
                if (Time[i][3]%Time[j][2]==0)
                {
                    goto a;
                }
                else Time[i][3]+=Time[j][2]-Time[i][3]%Time[j][2];
            }
            else Time[i][3]=Time[j][1];
            a:
            Time[i][3]+=Time[j][0];
        }
        printf("%d\n",Time[i][3]);
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
    int N,a;
    cin >> N;
    a = N;
    for(int i=1;i<=N;i++){
        if(a==floor(i*1.08)){
            cout << i << endl;
            return 0;
        }
    }

    cout << ":(" << endl;
}

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

typedef long long ll;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int a,b,q;
    cin >> a >> b >> q;
    vector<ll> s(a+2),t(b+2);
    for (int i = 1;i <= a;++i) cin >> s[i];
    for (int i = 1;i <= b;++i) cin >> t[i];
    s[0] = t[0] = -INT64_MAX>>2;
    s[a+1] = t[b+1] = INT64_MAX>>2;
    for (int i = 0;i < q;++i) {
        ll x,n = INT64_MAX;
        cin >> x;
        auto c = lower_bound(s.begin(),s.end(),x),d = lower_bound(t.begin(),t.end(),x);
        n = min(n,abs(x-*c)+abs(*c-*d));
        d--;
        n = min(n,abs(x-*c)+abs(*c-*d));
        c--;
        n = min(n,abs(x-*c)+abs(*c-*d));
        d++;
        n = min(n,abs(x-*c)+abs(*c-*d));
        n = min(n,abs(x-*d)+abs(*d-*c));
        d--;
        n = min(n,abs(x-*d)+abs(*d-*c));
        c++;
        n = min(n,abs(x-*d)+abs(*d-*c));
        d++;
        n = min(n,abs(x-*d)+abs(*d-*c));
        cout << n << endl;
    }
    return 0;
}


Measured memory_bytes: 2944
#include <stdio.h>

int main()
{
    int N;
    int ans;
    // 整数の入力
    scanf("%d", &N);

    // index
    int ind = N / 100;

    // judge
    int p = ind * 111;
    ans = N <= p ? p : p+111;

    // 出力
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int a,b,c;

int main(){
	cin >> a >> b >> c;
	if(min(a,min(b,c)) != max(a,max(b,c)) && (a==b||b==c||c==a)){
		puts("Yes");
	}
	else{
		puts("No");
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define re(i,n) for(i=0;i<n;i++)
#define bre(i,n) for(i=n;i>0;i--)
#define rep(i,l,r) for(i=l;i<r;i++)
#define brep(i,l,r) for(i=r;i>l;i--)
const int inf=1145141919810893;
const int mod=1000000007;
using namespace std;
template<class T>bool chmin(T &a,const T &b){
	if(a>b){
		a=b;
		return true;
	}
	return false;
}
template<class T>bool chmax(T &a,const T &b){
	if(a<b){
		a=b;
		return true;
	}
	return false;
}
template<class T>void debug(T *a,int l,int r,const char *name){
	for(int i=l;i<r;i++)
		cout<<name<<"["<<i<<"]="<<a[i]<<endl;
}
template<int H,int W>int wa(int x1,int y1,int x2,int y2,int(&p)[H][W]){
	return p[y2][x2]-p[y2][x1]-p[y1][x2]+p[y1][x1];
}
struct Unif{
	vector<int> e;
	vector<int> rank;
	Unif(int n):e(n,-1),rank(n,1){}
	void uni(int a,int b){
		if(e[a]!=-1)
			uni(e[a],b);
		else if(e[b]!=-1)
			uni(a,e[b]);
		else{
			if(a==b)
				return;
			int ra=rank[a],rb=rank[b];
			if(ra>=rb){
				e[b]=a;
				if(ra==rb)
					rank[a]++;
			}
			else
				e[a]=b;
		}
	}
	bool find(int a,int b){
		if(e[a]!=-1)
			return find(e[a],b);
		else if(e[b]!=-1)
			return find(a,e[b]);
		else
			return a==b;
	}
	int num(int a){
		if(e[a]!=-1)
			return num(e[a]);
		else
			return a;
	}
};
int A,B,C,D,N,M,K,S,T,H,W;
int p[114514],q[114514],r[114514];
signed main(){
	int i,j,k;
	cin>>N>>M;
	Unif unif(N);
	re(i,N)
		cin>>p[i];
	re(i,M){
		int u,v;
		cin>>u>>v;
		unif.uni(u,v);
	}
	fill(q,q+N,-1);
	int u=0;
	re(i,N){
		int v=unif.num(i);
		if(q[v]==-1){
			q[v]=u;
			u++;
		}
	}
	if(u==1){
		cout<<0<<endl;
		return 0;
	}
	vector<vector<int>> ve(u);
	re(i,N)
		ve[q[unif.num(i)]].push_back(p[i]);
	re(i,u)
		sort(begin(ve[i]),end(ve[i]));
	int sum=0;
	re(i,u)
		sum+=ve[i].size();
	if(sum<(u-1)*2){
		cout<<"Impossible"<<endl;
		return 0;
	}
	int ans=0;
	re(i,u)
		ans+=ve[i][0];
	vector<int> vee;
	re(i,u)
		for(j=1;j<ve[i].size();j++)
			vee.push_back(ve[i][j]);
	sort(begin(vee),end(vee));
	re(i,u-2)
		ans+=vee[i];
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int ans = 0;
    ans += min(x, y)*min(a+b, 2*c);
    ans += fdim(x, y)*min(a, 2*c) + fdim(y, x)*min(b, 2*c);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3692
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;

int main()
{
    int n;
    cin >> n;
    map<long long, int> mp;
    rep(i, n){
        long long a;
        cin >> a;
        mp[a]++; 
    }
    for(const auto& p : mp){
        if(p.second >= 2){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

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

    const int MOD = 1000000007;
    const double PI = acos(-1); 

    //long long
    using ll = long long;

    //出力系
    #define print(x) cout << x << endl
    #define yes cout << "Yes" << endl
    #define YES cout << "YES" << endl
    #define no cout << "No" << endl
    #define NO cout << "NO" << endl
    
    // begin() end()
    #define all(x) (x).begin(),(x).end()

    //for
    #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

    //最大公約数（ll）
    ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

    //素因数分解
    vector<pair<ll, int>>factorize(ll n){
      vector<pair<ll, int>> res;
      for(ll i = 2; i * i <= n; ++i){
        if(n % i) continue;
        res.emplace_back(i, 0);
        while(n % i == 0){
          n /= i;
          res.back().second++;
        }
      }
    if(n != 1) res.emplace_back(n, 1);
    return res;
    }



  // // 二分探索(最小値を出す問題は疑う)
  // bool C(ll x){
  //     ll res = 0;
  //     for(int i = 0; i < N; ++i){
  // 		res += max(0ll, A[i]-x/F[i]);
  //     }
  //     return res <= K;
  // }

  //   ll binary_search(ll ok, ll ng){
  //     while(abs(ok - ng) > 1){
  //       ll mid = (ok + ng) / 2;
  //       if(C(mid)) ok = mid;
  //       else ng = mid;
  //     }
  //     return ok;
  //   }


int main(){
int N;
cin >> N;
vector<ll>a(N);
REP(i, N) cin >> a.at(i);
 
ll four = 0, odd = 0, two = 0;
 
REP(i, N){
	if(a.at(i) % 4 == 0 ) four++;
	else if(a.at(i) % 4 != 0 && a.at(i) % 2 == 0) two = 1;
	else if(a.at(i) % 2 == 1) odd++;
}
// print(odd);
// print(four);
 
if(odd == 0) yes;
else if(four >= odd + two - 1) yes;
else no;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<typename T>
void print(T &arr){
    ll sz = sizeof(arr)/sizeof(arr[0]);
    for(int i = 0;i < sz-1;i++){cout << arr[i] << ' ';}
    cout << arr[sz-1] << endl;
}


int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,-1,1};
const int h_max = 510, w_max = 510;
int h,w;
int is_moved[h_max][w_max] = {};
template<typename T, typename U>
void solve(vector<vector<T>> &mp,vector<vector<U>> &ans, int x, int y){
    is_moved[x][y] = 1;
    // if(px != -1 && mp[x][y]){
    //     if(mp[px][py]%2){
    //         mp[px][py]++;mp[x][y]--;
    //         vector<int> temp = {x+1, y+1, px+1, py+1};
    //         ans.push_back(temp);
    //     }
    // }
    rep(i,4){
        int nx = x + dx[i], ny = y + dy[i];
        if(is_moved[nx][ny] || nx < 0 || ny < 0 || h <= nx || w <= ny)continue;
        if(mp[x][y]%2){
            mp[x][y]--;mp[nx][ny]++;
            vector<int> temp = {x+1,y+1,nx+1,ny+1};
            ans.push_back(temp);
        }
        solve(mp,ans,nx,ny);
        // solve(mp,ans,nx,ny,x,y);
    }
}


int main(){
    cin >> h >> w;
    vector<vector<int>> a(h,vector<int>(w));
    rep(i,h)rep(j,w)cin >> a[i][j];

    vector<vector<int>> ans;
    solve(a,ans,0,0);
    // print(a);
    // print();
    cout << ans.size() << endl;
    print(ans);
    return 0;
}

Measured memory_bytes: 50864
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int n,k,t,i,sum[200001],tot,counter,s;
    while(cin>>n>>k)
    {
        memset(sum,0,sizeof(sum));
        tot=0;
        counter=0;
        s=0;
        for(i=0;i<n;i++)
        {
            cin>>t;
            if(sum[t]==0)
            {
                tot++;
            }
            sum[t]++;
        }
        if(tot>k)
        {sort(sum,sum+200001);
        for(i=0;i<200001;i++)
        {
            if(sum[i]!=0){counter++;
            s+=sum[i];}
            if(counter==tot-k){cout<<s<<endl;break;}
        }}
        if(tot<=k)cout<<'0'<<endl;
    }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,w,h,cnt=0;
    cin>>n>>w>>h;
    for(int i=0;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        if((x>=w)&&(y>=h))
        {
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/python
# -*- coding: utf-8 -*-
N = int(input())
txy = []
for _ in range(N):
    t, x, y = map(int, input().strip().split())
    txy.append((t, x, y))
can_travel = False
prev_t, prev_x, prev_y = 0,0,0
for t, x, y in txy:
    if abs(x-prev_x) + (y-prev_y) > t - prev_t:
        can_travel = False
        break
    elif (abs(x-prev_x) + abs(y-prev_y)) % 2 != (t-prev_t) % 2:
        can_travel = False
        break
    else:
        prev_t, prev_x, prev_y = t, x, y
        can_travel = True
        continue
if can_travel:
    print("Yes")
else:
    print("No")

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll n; cin >> n;
    vector<ll> a(3 * n);
    for (ll i = 0; i < 3 * n; ++i) {
        cin >> a[i];
    }

    sort(a.rbegin(), a.rend());

    ll ans = 0;
    for (ll i = 0; i < 2 * n; i += 2) {
        ans += min(a[i], a[i + 1]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 5596
def main():
    N = int(input())
    *h, = map(int, input().split())

    ans = f(N, h)
    print(ans)


def f(N, h):
    """
    1 <= N <= 100
    0 <= hi <= 100
    整数 l,r を指定する。
    l ≦ x ≦ r を満たすすべての xに対して、花 xの高さを 1高くする。
    条件を満たすための最小の「水やり」操作の回数を求めてください。

    広い範囲の花を高くしたいが、hk を超えてはいけない
    愚直にやる
        各kについてh回水をやる: sum(h)

    広範囲にやりすぎて回数が増えることはあるのか？
    間が多い
        0: 1 1 2 2 1
        1: 0 0 1 1 0
        2: 0 0 0 0 0
    端が多い
        0: 2 2 1 1 2
        1: 1 1 1 1 2, 1 1 0 0 1
        2: 0 0 0 0 1, 0 0 0 0 1
        3: 0 0 0 0 0
    跨ぐ
        0: 1 2 2 1 2
        1: 0 1 1 1 2, 0 1 1 0 1
        2: 0 0 0 0 1, 0 0 0 0 1
        3: 0 0 0 0 0

    愚直にやるでいいのでは
    """
    h = h[:]
    ans = 0
    while True:
        water = False
        for k in range(N):
            if h[k] == 0:
                if water:
                    break
            else:
                h[k] -= 1
                water = True

        if not water:
            break
        ans += 1

    return ans


if __name__ == '__main__':
    main()


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

using namespace std;

using int64 = long long;
const int INF = 1 << 30;

int main() {
  int N, V[100000];
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> V[i];
  }
  vector< pair< int, int > > change[2];
  for(int i = 0; i < 2; i++) {
    map< int, int > add;
    add[-1] = 0;
    add[-2] = 0;
    for(int j = i; j < N; j += 2) {
      add[V[j]]++;
    }
    for(auto &p : add) {
      change[i].emplace_back(N / 2 - p.second, p.first);
    }
    sort(begin(change[i]), end(change[i]));
  }
  int ret = INF;
  for(int i = 0; i < 2; i++) {
    for(int j = 0; j < 2; j++) {
      if(change[0][i].second != change[1][j].second) {
        ret = min(ret, change[0][i].first + change[1][j].first);
      }
    }
  }
  cout << ret << endl;
}


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

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> cnt(n+1,0);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        cnt[a]++;
        cnt[b]++;
    }

    for(int i=1;i<=n;i++) cout<<cnt[i]<<"\n";
    return 0;
}

Measured memory_bytes: 3612
x1,y1,x2,y2 = map(int, input().split())

a = x2 - x1
b = y2 - y1


x3 = x2 - b
y3 = y2 + a

x4 = x1 - b
y4 = y1 + a

print(str(x3) + " " + str(y3) + " " + str(x4) + " " + str(y4))

Measured memory_bytes: 3060
n = gets.chomp.split
a = gets.chomp.split.map(&:to_i)

ans = 0

a.size.times do |p|
  #puts "p:#{p} a[p]:#{a[p]} a[a[p]-1]:#{a[a[p]-1]}"
  if a[a[p]-1] == p+1
    ans += 1
  end
end

puts ans/2

Measured memory_bytes: 8708
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int MAX_N=1000000;

char S[MAX_N];

int main(){
	scanf("%s",S);
	int cnt_j=0,cnt_o=0,cnt_i=0;	//Jの個数
	int ma=0;
	int i=0;
	int n=strlen(S);
	while(i<n){
		while (i<n && S[i]!='J') i++;
		cnt_j=0;
		while (i<n && S[i]=='J'){
			i++;
			cnt_j++;
		}
		if (cnt_j<=ma){
			//新記録を更新できる見込みなし
			continue;
		}
		cnt_o=0;
		while (i<n && S[i]=='O'){
			cnt_o++;
			i++;
		}
		if (cnt_j<cnt_o){
			continue;
		}
		cnt_i=0;
		while (i<n && S[i]=='I'){
			cnt_i++;
			i++;
		}
		if (cnt_i>=cnt_o){
			ma=max(ma,cnt_o);
		}
	}
	printf("%d\n",ma);
	return 0;
}

Measured memory_bytes: 1944
//#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#include<vector>
#include<iostream>
#include <iomanip>
 
using namespace std;
 
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PLDLD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VB;
 
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()
 
const LD eps=1e-10;
const long long INFLL=(LL)(1e9)*(LL)(1e9);
const int INF=1e9;
 
template<class T>
void chmin(T& a, const T b)
{
	if(a>b)
		a=b;
}
template<class T>
void chmax(T& a, const T b)
{
	if(a<b)
		a=b;
}
 
const LL pow(const LL p, const LL q)
{
	LL t=1;
	for(int i=0;i<q;i++)
		t*=p;
	return t;
}

template <typename T>
struct has_iter
{
	private:
		template <typename U>
		static constexpr true_type check(typename U::iterator*);
		template <typename U>
		static constexpr false_type check(...);

	public:
		static constexpr bool value = decltype(check<T>(nullptr))::value;
};


template<typename T, typename U = typename T::iterator>
void print(const T& container)
{
		auto&& first=begin(container), last=end(container);
		auto&& back=prev(last);
		for(auto e=first; e!=last; e=next(e))
			cout<<*e<<" \n"[e==back];
}


extern void* enabler;
template<typename Head, typename enable_if<!has_iter<Head>::value>::type*& = enabler>
void print(const Head& head)
{
	cout<<head<<endl;
}

template<> void print<string>(const string& container)
{
	cout<<container<<endl;
}

template<typename Head, typename... Tail>
void print(const Head& head, const Tail&... tail)
{
	cout<<head<<" ";
	print(tail...);
}

void io_speedup()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec)
{
	for(T& x: vec) is >> x;
	return is;
}


template<typename T, typename U>
ostream& operator << (ostream& os, const pair<T, U>& p)
{
	os<<'('<<p.first<<", "<<p.second<<')';
	return os;
}

template<typename T>
vector<T> read(int n)
{
	vector<T> t(n);
	cin>>t;
	return t;
}

template<typename T>
T read()
{
	T t;
	cin>>t;
	return t;
}


template<unsigned int N> struct IsPrime {
	static const int size=(N>>5) + 1;
	unsigned int is_prime[size];
	constexpr IsPrime() : is_prime() {
		is_prime[0]=0x3;
		for(unsigned int i=2;i<N;i++)
		{
			if((is_prime[i>>5] & (1u<<(i&0x1f))) > 0)  continue;
			for(int j=i+i;j<N;j+=i)
				is_prime[j>>5]|=(1u<<(j&0x1f));
		}
	}
	constexpr bool operator[] (const int p) const
	{
		return (is_prime[p>>5] & (1u<<(p&0x1f))) == 0;
	}
};

template<int N> struct LikelyPrime {
	unsigned short sum[N+1];
	constexpr LikelyPrime(const IsPrime<N> pr) : sum() {
		for(int i=3;i<N;i++)
			sum[i+1]=sum[i]+(unsigned short)((pr[i] && pr[(i+1)/2])?1:0 );
	}
};

int q;
int l,r;
int main()
{
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	constexpr IsPrime<100001> pr;
	constexpr LikelyPrime<100001> s(pr);
	cin>>q;
	while(q--)
	{
		cin>>l>>r;
		cout<<s.sum[r+1]-s.sum[l]<<"\n";
	}
}


Measured memory_bytes: 896
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder s = new StringBuilder(sc.next());
		int prei = -1;
		long cnt = 0;
		long sum = 0;
		for (int bit = 0; bit < (1 << (s.length() - 1)); bit++) {
			for (int i = 0; i < s.length() - 1; i++) {
				if ((bit & (1 << i)) != 0) {
					cnt += Long.parseLong(s.substring(s.length() - 1 - i, s.length() - 1 - prei));
					prei = i;
				}
			}
			cnt += Long.parseLong(s.substring(0, s.length() - 1 - prei));
			prei = -1;
			sum += cnt;
			cnt = 0;
		}
		System.out.println(sum);
	}

}


Measured memory_bytes: 23764
#include "bits/stdc++.h"

using namespace std;

#define rep(loop, N) for (int loop = 0; loop < N; loop++)

struct Node {
	Node* parent = NULL;
	vector<Node*> child;
	long long value = 0;
};
struct Edge {
	int parent = 0;
	int child = 0;
	bool operator <(const Edge& right) const { return parent < right.parent; }
};
struct Tree {
	vector<Node> node;
	Tree(int, vector<Edge>);
};
Tree::Tree(int nodeNum, vector<Edge> edge) {
	node.resize(nodeNum);
	for (Edge& it : edge) {
		node[it.child].parent = &node[it.parent];
		node[it.parent].child.push_back(&node[it.child]);
	}
}

map<long long, int> factorization(long long N) {
	map<long long, int> re;
	while (true) {
		if (N % 2 == 0) {
			N /= 2;
			re[2]++;
			if (N == 1) break;
		}
		else {
			break;
		}
	}
	for (int loop = 3; (long long)loop * (long long)loop <= N; loop += 2) {
		if (N % loop == 0) {
			N /= loop;
			re[loop]++;
			loop -= 2;
			if (N == 1) break;
		}
	}
	if (N > 1) re[N]++;
	return re;
}

struct Memo {
	long long fact = 0;
	long long fact_inv = 0;
	long long inv = 0;
};
class Combination1 {
private:
	long long m_module = 1000000007;
	vector<struct Memo> memo;
public:
	long long calculate(int, int);
	Combination1(int, long long);
};
long long Combination1::calculate(int n, int k) {
	return ((memo[n].fact * memo[k].fact_inv) % m_module * memo[n - k].fact_inv) % m_module;
}
Combination1::Combination1(int memo_max, long long module = 1000000007) {
	m_module = module;
	memo.push_back({ 1,1,0 });
	memo.push_back({ 1,1,1 });
	for (int loop = 2; loop <= memo_max; loop++) {
		struct Memo temp;
		temp.fact = (memo[loop - 1].fact * loop) % m_module;
		temp.inv = m_module - (memo[m_module % loop].inv * int(m_module / loop)) % m_module;
		temp.fact_inv = (memo[loop - 1].fact_inv * temp.inv) % m_module;
		memo.push_back(temp);
	}
}

class Combination2 {
private:
	int size = 0;
	bool add(int);
public:
	vector<int> sequence;
	bool next_combination(void);
	Combination2(int, int);
};
bool Combination2::add(int index) {
	if (index == (int)sequence.size() - 1 && sequence[index] == size - 1
		|| index < (int)sequence.size() - 1 && sequence[index] == sequence[index + 1] - 1) {
		if (index == 0) {
			return false;
		}
		else {
			bool re = add(index - 1);
			sequence[index] = sequence[index - 1] + 1;
			return re;
		}
	}
	else {
		sequence[index]++;
		return true;
	}
}
bool Combination2::next_combination(void) {
	return (sequence.size() == 0) ? false : add(sequence.size() - 1);
}
Combination2::Combination2(int n, int r) {
	size = n;
	for (int loop = 0; loop < r; loop++) sequence.push_back(loop);
	return;
}

void A_Circle_Pond(void) {

	double R; cin >> R;

	cout << R * 2.0 * 3.141592 << endl;
	return;
}

void B_Homework(void) {

	int N, M; cin >> N >> M;
	int counter = 0;
	rep(i, M) {
		int A; cin >> A;
		counter += A;
	}

	if (counter <= N)	cout << N - counter << endl;
	else				cout << -1 << endl;
	return;
}

int main(void) {

	//A_Circle_Pond();
	B_Homework();
	return 0;
}


Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    ans = 1
    
    for i in range(N,0,-1):
        tmp = math.sqrt(i)
        if tmp.is_integer():
            print(i)
            sys.exit()
            	
if __name__ == "__main__":
	main()


Measured memory_bytes: 38640
#!/usr/bin/env python3

# dp[i + 1][w] := i番目までの品物の中から重さがwを超えないように選んだときの、価値の総和の最大値
# 品物を選ぶとき: dp[i + 1][w] = dp[i][w - weigth[i]] + value[i]
# 品物を選ばないとき: dp[i + 1][w] = dp[i][w]

N, W = map(int, input().split())

goods = []
for _ in range(N):
    v, w = map(int, input().split())
    goods.append([v, w])
# print(goods)

inf = float("inf")
dp = [[-inf for _ in range(W + 1)] for j in range(N + 1)]
# print(dp)

for w in range(W):
    dp[0][w] = 0

for i in range(N):
    for w in range(W + 1):
        if w >= goods[i][1]:
            dp[i + 1][w] = max(dp[i][w - goods[i][1]] + goods[i][0], dp[i][w])
        else:
            dp[i + 1][w] = dp[i][w]

print(dp[N][W])


Measured memory_bytes: 42484
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define LINF 1000000000LL * 1000000
#define MAXN 45002
using namespace std;

int n;
int a[100000];
int b[100000];
int main()
{
	ios_base::sync_with_stdio(0);
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b , b + n);
	int x = b[n - 1] / 2 + b[n - 1] % 2;
	int pos = lower_bound(b , b + n , x) - b;
	if(pos == 0)
	{
		cout << b[n - 1] << " " << b[pos];
		return 0;
	}
	if(pos == n - 1)
	{
		cout << b[n - 1] << " " << b[n - 2];
		return 0;
	}
	if(b[pos] - x < x - b[pos - 1])
		cout << b[n - 1] << " " << b[pos];
	else
		cout << b[n - 1] << " " << b[pos - 1];
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int N=300010,M=1000010,P=1e9+7;
const int inf=0x3f3f3f3f;
const int INF=0xcfcfcfcf;
const db eps=1e-9,pi=asin(1)*2;
inline ll read();
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
inline int ADD(int a,int b) { return a+b>=P?a+b-P:a+b; }
inline int MINUS(int a,int b) { return a-b<0?a-b+P:a-b; }
#define plus(a,b) a=ADD(a,b)
#define minus(a,b) a=MINUS(a,b)
#define mul(a,b) a=(1ll*a*(b))%P
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define mp(x,y) make_pair(x,y)

int n;
char s[N];
int dp[N][11];

inline void update(int i,int p1,int p2) { plus(dp[i][p2],dp[i-1][p1]); }

#ifdef FILE
const int RS=1<<20;
char buf[RS],*p1=buf,*p2=buf;
#define getchar() p1==p2&&(p2=(p1=buf)+fread(buf,1,RS,stdin),p1==p2)?EOF:*p1++
#endif
inline ll read()
{
	ll s=0;
	bool flag=false;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') flag=true;
	for(;'0'<=ch&&ch<='9';ch=getchar()) s=(s<<3)+(s<<1)+(ch^'0');
	if(flag) return -s;
	return s;
}

int main()
{
#ifdef FILE
	freopen(FILE ".in","r",stdin);
	freopen(FILE ".out","w",stdout);
#endif
	scanf("%s",s+1);
	n=strlen(s+1);
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		if(s[i]!='1')
		{
			update(i,0,1);
			update(i,1,2);
			update(i,2,1);
			update(i,3,4);
			update(i,4,5);
			update(i,5,4);
			update(i,6,6);
		}
		if(s[i]!='0')
		{
			update(i,0,3);
			update(i,1,0);
			update(i,2,1);
			update(i,3,6);
			update(i,4,3);
			update(i,5,4);
			update(i,6,6);
		}
	}
	printf("%d\n",ADD(dp[n][3],dp[n][6]));
	return 0;
}

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

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int k = sc.nextInt();
    long sum = 0;
    for (int i = 1; i <= k; i++) {
      for (int j = 1; j <= k; j++) {
        for (int l = 1; l <= k; l++) {
          sum += gcd(i, j, l);
        }
      }
    }
    System.out.println(sum);
  }

  private static int gcd(int a, int b, int c) {
    List<Integer> args = new ArrayList<>();
    args.add(a);
    args.add(b);
    args.add(c);
    int ans = 0;
    for (Integer arg : args) {
      ans = gcd(ans, arg);
    }
    return ans;
  }

  private static int gcd (int a, int b) {
    int temp;
    while((temp = a % b) != 0) {
      a = b;
      b = temp;
    }
    return b;
  }
}


Measured memory_bytes: 55304
#include <bits/stdc++.h>
#define pr(s) std::cout << s << std::endl
#define prb(s) std::cout << s
using namespace std;


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


  string s;
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    if (!((i % 2 == 0 && s[i] != 'L') || (i % 2 != 0 && s[i] != 'R'))) {
      pr("No");
      return 0;
    }
  }

  pr("Yes");

  return 0;
}


Measured memory_bytes: 256
using System;

namespace ABC153
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] strs = Console.ReadLine().Split(' ');
			int h = int.Parse(strs[0]);
			int a = int.Parse(strs[1]);

			Console.WriteLine(Math.Ceiling((decimal)h / a));
		}
	}
}

Measured memory_bytes: 13268
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] c = sc.next().toCharArray();
        int count = 0;
        for (int i = 0 ; i < c.length ; i++) {
            if (c[i] == 'x') count++;
        }

        System.out.println(count < 8 ? "YES" : "NO");
    }

}

Measured memory_bytes: 21844
#include <stdio.h>

int main(void){
  int a,b,n,x,i;

  for(;;){
    i=0;
    scanf("%d%d",&n,&x);
    if(n+x == 0) break;

    for(a=1;a<=n;a++)
      for(b=a+1;b<=n;b++)
        if(b < x-a-b && x-a-b <= n)
          i++;

    printf("%d\n", i);
  }

  return 0;
}


Measured memory_bytes: 2596
#include<bits/stdc++.h>
using namespace std;
#define int long long
//4 5
//1 2
//2 5
//#.###
//.###.
//#..##
//#..##

int x[4] = {0, 1, 0, -1};
int y[4] = {1, 0, -1, 0};

const int N = 1100;
int h, w, c1, c2, d1, d2;
char s[N][N];
int a[N][N];
int num;
set<int> adj[N*N];
int d[N*N];

void dfs(int i, int j){
    for (int k=0; k<4; k++){
        int xx = i+x[k];
        int yy = j+y[k];
        if (xx>=0 && yy>=0 && xx<h && yy<w && a[xx][yy]==0 && (s[xx][yy]=='.')){
            a[xx][yy] = num;
            dfs(xx, yy);
        }
    }
    return;
}

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    cin>>h>>w;
    cin>>c1>>c2>>d1>>d2;
    for (int i=0; i<h; i++){
        for (int j=0; j<w; j++){
            cin>>s[i][j];
        }
    }

    for (int i=0; i<h; i++){
        for (int j=0; j<w; j++){
            if (a[i][j]!=0 or s[i][j]=='#') continue;

            num++;
            a[i][j] = num;
            dfs(i, j);
        }
    }
//    for (int i=0; i<h; i++){
//        for (int j=0; j<w; j++){
//            cout<<a[i][j]<<" ";
//        }
//        cout<<endl;
//    }
//
//    cout<<num<<endl;

    set<pair<int, int>> all;

    for (int i=0; i<h; i++){
        for (int j=0; j<w; j++){
            if (a[i][j]==0) continue;
            set<int> u;
            for (int k=i-2; k<=i+2; k++){
                for (int l=j-2; l<=j+2; l++){
                    if(k>=0 && l>=0 && k<h && l<w){
                        if (a[k][l]==0) continue;
                        u.insert(a[k][l]);
                    }
                }
            }
//            cout<<"here ";
//            for (auto e:u){
//                cout<<e<<" ";
//            }
//            cout<<endl;
            for (auto e:u){
                if (e==a[i][j]) continue;
                all.insert({a[i][j], e});
            }
        }
    }

//    for (auto p:all){
//        cout<<p.first<<" "<<p.second<<endl;
//    }


    for (auto p:all){
        adj[p.first].insert(p.second);
        adj[p.second].insert(p.first);
    }
//
    int start = a[c1-1][c2-1];
    int last = a[d1-1][d2-1];
//
    if (start==last) {
        cout<<0<<endl;
        return 0;
    }
//    cout<<start<<" "<<last<<endl;
    memset(d, -1, sizeof(d));
    queue<int> q;
    q.push(start);
    int curr = 1;
    d[start] = 1;
    while(!q.empty()){
        int sz = q.size();
//        cout<<"here "<<curr<<" ";
        while(sz--){
            int u = q.front(); q.pop();
//            cout<<u<<" ";
            for (auto v:adj[u]){
                if (d[v]==-1){
                    d[v] = curr;
                    q.push(v);
                }
            }
        }
//        cout<<endl;
        curr++;
    }


//    for (int i=0; i<=num; i++){
//        cout<<d[i]<<" ";
//    }
//    cout<<endl;


    cout<<d[last]<<endl;


    return 0;
}


Measured memory_bytes: 122688
import bisect
n = int(input())
vs = list(map(int, input().split()))

vs.sort()

while len(vs) > 1:
	a = vs.pop(0)
	b = vs.pop(0)
	c = (a + b) / 2
	vs.insert(bisect.bisect_left(vs, c), c)

print(vs[0])

Measured memory_bytes: 3060
# coding: utf-8
import sys
import itertools

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# Nは最大8まで、Aに使う竹はどれ？
N, A, B, C = lr()
bamboo = [ir() for _ in range(N)]
answer = 10 ** 5
for pattern in itertools.product(range(4), repeat=N):
    use = [0] * 3
    mp = 0
    for p, bam in zip(pattern, bamboo):
        if p == 3:
            continue
        if use[p] != 0:
            mp += 10
        use[p] += bam
    if use.count(0) != 0:
        continue
    mp += abs(A-use[0]) + abs(B-use[1]) + abs(C-use[2])
    if mp < answer:
        answer = mp

print(answer)
# 23

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define DEBUG(x)           cout << '>' << #x << ':' << x << endl;
#define forn(i,n)          for(int i=0;i<(int)n;++i)
#define for1(i,n)          for(int i=1;i<=(int)n;++i)
#define forr(i,n)          for(int i=(int)n-1;i>=0;--i)
#define forre(i,a,b)       for(int i=(int)b;i>=(int)a;--i)
#define fore(i,a,b)        for(int i=(int)a;i<=(int)b;++i)
#define input(arr,n)       for(int i=0;i<n;i++)cin>>arr[i]
#define output(arr,n)      for(int i=0;i<n;i++)cout<<arr[i]<<" "
#define for_each(arr)      for(auto& it:arr)cout<<it<<" "
#define ff                 first
#define ss                 second
#define PI                 acos(-1.0)
#define all(a)             a.begin(),a.end()
#define rall(a)            a.rbegin(),a.rend()
#define Unique(a)          sort(all(a)),a.erase(unique(all(a)),a.end())
#define pb(x)              push_back(x)
#define eb(x)              emplace_back(x) 
#define ppb(x)             pop_back(x)
#define pf(x)              push_front(x)
#define ppf(x)             pop_front(x)
#define in(x,y)            insert({x,y})
#define Sort(a)            sort(a.begin(),a.end())
#define mem(arr,a)         memset(arr,a,sizeof arr)
#define ins(a)             insert(a)
#define max2(a,b)          max(a,b)
#define max3(a,b,c)        max(a,max(b,c))
#define max4(a,b,c,d)      max(a,max3(b,c,d))
#define min2(a,b)          min(a,b)
#define min3(a,b,c)        min(a,min(b,c))
#define min4(a,b,c,d)      min(a,min3(b,c,d))
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<char> vc;
typedef vector<double> vd;
/*inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void Set(int & n, int b) { n |= two(b); }
inline void Reset(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }*/
/*int fx1[]={+1,-1,+0,+0};
int fy1[]={+0,+0,+1,-1};
int fx2={+0,+0,+1,-1,-1,+1,-1,+1};
int fy2={-1,+1,+0,+0,+1,+1,-1,-1};
*/

ll a,b,c,n,ans,cn1,cn2,cn3,t;
string s,s1,s2;

int main()
{
    FIO;
   // #ifndef ONLINE_JUDGE
   // freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
   // #endif
    cin>>s;
    for(int i=0;i<s.size();i++){
    	if(i&1){
    		if(s[i]=='R')
            {
                cout<<"No"<<endl;
                return 0;
            }
    	}else{
            if(s[i]=='L'){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;


    
   	
    #ifdef ONLINE_JUDGE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    #endif
   return 0;
}
 


Measured memory_bytes: 256
n=int(input())
m=list(map(int,input().split()))
l=filter(lambda x:x%4==0,m)
o=filter(lambda x:x%2==0 and x%4!=0,m)
if n//2<=len(list(l))+len(list(o))//2:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 14228
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;
using P = pair<int,int>;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll N,D,A;
    cin >> N >> D >> A;
    vector<pair<int,int>> M(N);
    rep(i,N){
        cin >> M[i].first >> M[i].second;
    }
    sort(ALL(M));
    D *= 2;
    queue<pair<ll,ll>> q; // first := 座標 second := 爆弾の使用回数
    ll tot = 0;
    ll ans = 0;
    rep(i,N){
        ll x = M[i].first;
        ll h = M[i].second;
        while(!q.empty() && q.front().first < x){
            tot -= q.front().second;
            q.pop();
        }
        h -= tot;
        if(h>0){
            ll num = (h+A-1)/A;
            ans += num;
            ll damage = num*A;
            tot += damage;
            q.push({x+D,damage});
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3456
def solve():
    N = int(input())
    plan = [
        [int(x) for x in input().split()] for _ in range(N)
    ]
    plan = [[0, 0, 0]] + plan

    for i in range(1, N+1):
        t0, x0, y0 = plan[i-1]
        t, x, y = plan[i]
        dx = x - x0
        dy = y - y0
        d = abs(dx) + abs(dy)

        if t - t0 < d:
            return False

        if (t-t0-d)%2 != 0:
            return False

    return True


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

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


const int mod = 1e9+7;

long long int dp[2][100005];

string s;


int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>s;
	dp[0][0]=1;
	for(int i=1;i<=s.size();i++){
		if(s[i-1]=='1'){
			dp[0][i]=(dp[0][i]+2*dp[0][i-1])%mod;
			dp[1][i]=(dp[1][i]+dp[0][i-1])%mod;
		}
		else{
			dp[0][i]=(dp[0][i]+dp[0][i-1])%mod;
		}
		dp[1][i]=(dp[1][i]+dp[1][i-1]*3)%mod;
	}
	cout<<(dp[0][s.size()]+dp[1][s.size()])%mod<<endl;
}


Measured memory_bytes: 2000
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

typedef  long long ll;

#define rep(i,a,n) for(ll (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(ll (i)=(a);(i)>=(n);(i)--)

#define INF ll 1 << 60
#define MOD 1000000007


using namespace std;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return a;
}


void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}

int dig(int d){
    int ans = 1;
    if(d == 0) return ans;
    while(d != 0){
        d--;
        ans*=100;
    }
    return ans;
}

ll divisors(ll n) {
    vector<ll> res;

    for(ll i = 1; i*i <= n; ++i) {
        if(n % i != 0) continue;
        res.push_back(i-1);
        if(n/i == i) continue;
        res.push_back((n/i)-1);
    }

    ll ans = 0;

    rep(i,0,res.size()){
        if(res[i] != 0)
        if(n/res[i] == n%res[i]) ans += res[i];
    } 
    return ans;
}

void solve(void){
   int n,i;
   cin >> n >> i;
   cout << n*i - n - i + 1<<endl;
}

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

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

int x[3010],y[3010],d[3010];
int init[4][3010];
int mov[4][3010];


int main(void){
	int n;
	cin >> n;

	{
		map<char,int> dir={{'>',0},{'v',1},{'<',2},{'^',3}};
		rep(i,n){
			char tmp;
			cin >> x[i] >> y[i] >> tmp;
			d[i] = dir[tmp];
		}
	}
	

	rep(i,n){
		int u = -1, l = -1, r = -1 ,b = -1; 

		rep(j,n){
			if(j==i) continue;

			if(x[i] == x[j] and y[j] < y[i]){
				if(u == -1 or y[u] < y[j]) {
					u = j;
				}
			}

			if(x[i] == x[j] and y[i] < y[j]){
				if(b == -1 or y[j] < y[b]) {
					b = j;
				}
			}

			if(y[i] == y[j] and x[j] < x[i]){
				if(l == -1 or x[l] < x[j]) {
					l = j;
				}
			}

			if(y[i] == y[j] and x[i] < x[j]){
				if(r == -1 or x[j] < x[r]) {
					r = j;
				}
			}
		}

		init[0][i] = r;
		init[1][i] = b;
		init[2][i] = l;
		init[3][i] = u;

	}

	/*
	rep(i,n){
		cerr << i << " ";
		rep(j,4) cerr << init[j][i] << " ";
		cerr << endl;
	}
	*/

	int ans = 0;
	
	rep(s,n){
		rep(i,4)rep(j,n) mov[i][j] = init[i][j];

		int cur = s,num = 0;

		while(1){
			//cerr << cur << endl;
			if(cur == -1) break;
			num++;
			rep(i,4){
				if(mov[(i+2)%4][cur]!=-1){
					//cerr << i << " " << mov[(i+2)%4][cur] << " " << mov[i][cur] << endl;
					mov[i][mov[(i+2)%4][cur]] = mov[i][cur];
				}
			}

			int nxt = mov[d[cur]][cur];
			rep(i,4) mov[i][cur] = -1;
			cur = nxt;
		}

		ans = max(ans,num);
	}

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

Measured memory_bytes: 3232
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

int main (){
    int x=0;
    string s;
    cin >> s;
    for(int i = 0; i < s.length(); i++){
        if(s[i]=='+'){
            x+=1;
        }else if(s[i]=='-'){
            x-=1;
        }
    }
    cout << x;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define M 1000000007
//#define M 998244353
using namespace std;
const int inf=4e18;
const double pi=3.14159265358979;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int n;cin>>n;
	int dp[n+1][3],i;dp[0][0]=0;dp[0][1]=0;dp[0][2]=0;
	for(i=1;i<=n;i++)
	{
		int a,b,c;cin>>a>>b>>c;
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a;
		dp[i][1]=max(dp[i-1][2],dp[i-1][0])+b;
		dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c;
	}
	cout<<max({dp[n][0],dp[n][1],dp[n][2]})<<endl;
}

Measured memory_bytes: 2560
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>


using namespace std;

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


    if(C-D<0){
        cout<<"0"<<endl;

    }
    else{
        cout<<C-D<<endl;
    }

}





Measured memory_bytes: 256
/**
 *    author:  Daredevil666
 *    institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define REP(i,a,n) for(i=a;i<=n;i++)
#define F(i,a,b) for(i=a;i<b;i++)
#define RF(i,b,a) for(i=b;i>=a;i--)
#define IOS  ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const ll mod=1e9+7;
const ll MAXN=300200;
ll i,j;
int main()
{
IOS
/*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
#endif // ONLINE_JUDGE*/
ll x,k,d;
cin>>x>>k>>d;
x=abs(x);
if(x/d>=k)
{
   cout<<x-(d*k);
   return 0;
}
k-=x/d;
x=x%d;

if(k%2==0)
{
    cout<<x;
}
else
{
    cout<<abs(x-d);
}
return 0;
}


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

int main() {
    int a;
    cin >> a;
    if((a-9)%10==0){
        cout << "Yes" << endl;
    }
    else if(a-90>=0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


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

const bool DEBUG = 1;

using ll = long long;

int n;
string s;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	if (DEBUG) freopen("input.txt", "r", stdin);
	if (DEBUG) freopen("output.txt", "w", stdout);
	clock_t start = clock();
#endif

	cin>>s;	
	n=s.length();

	ll ans = 0;

	int cnt = 0;
	for (int i = n-1; i >= 0; i--) {
		if (i && s[i] == 'C' && s[i-1] == 'B')
			cnt++, i--;
		else if (s[i] == 'A')
			ans += cnt;
		else cnt = 0;
	}

	cout << ans << endl;


#ifdef LOCAL
	cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}


Measured memory_bytes: 720
#include<iostream>
#include <cstring>
using namespace std;
int dp[100000];
int n,a[100000],k;

int ans(int i)
{
	if(i==n-1)
		return 0;

	if(dp[i]!=-1)
		return dp[i];
  
	int best=1e9;
	for(int j=1;j<=k;j++)
	{
		if(i+j<n)
			best=min(best,abs(a[i]-a[i+j]) + ans(i+j));
	}
	return dp[i]=best;
}

int main()
{
	memset(dp,-1,sizeof(dp));
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>a[i];

	cout<<ans(0)<<endl;

	return 0;
}

Measured memory_bytes: 12116
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	int LEN = 0;

	void doIt() {
		int n = sc.nextInt();
		LEN = (1 << n + 1);
		boolean notTrue[] = new boolean[n];
		Arrays.fill(notTrue, false);
		int says[][] = new int[n][n];
		for(int i = 0; i < n; i++)Arrays.fill(says[i], -1);
		for(int i = 0; i < n; i++) {
			int a = sc.nextInt();
			for(int j = 0; j < a; j++) {
				int x = sc.nextInt() - 1;
				int y = sc.nextInt();
				says[i][x] = y;
			}
		}
		int ans = 0;
		for(int i = 0; i < (1 << n); i++) {
			int num = Integer.bitCount(i);
			out:for(int j = 0; j < n; j++) {
				if((i >> j & 1) == 1) {
					for(int k = 0; k < n; k++) {
						if(says[j][k] != (i >> k & 1) && says[j][k] != -1) {
							num = 0;
							break out;
						}
						
					}
				}
			}
			ans = Math.max(ans, num);
		}
		System.out.println(ans);
	}

	public static void main(String[] args) {
		new Main().doIt();
	}
}


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

int main(){
	int n; cin>>n;
	ll ans=0;
	for(int i=1; i<n; i++){
		ans+=i;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3636