akhauriyash/Code-Regression huggingface dataset:
// 問題名: Curling 2.0
// URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1144&lang=jp
// 所要時間: 70分
// --感想--
// 障害物がぶつかると壊れるという設定を見落としていて、01BFSで解けると思い、初めての01BFSの実装をうきうきしながらやっていたら
// 全然違う問題でショックだった。普通の全探索だが、DFSで戻ってくる際に壊した障害物を復活させる点は目新しかった。

#include <bits/stdc++.h>
using namespace std;

int ans, c[22][22], gx, gy, h, w;

void dfs(int ny, int nx, int nd, int nt){ // (y座標, x座標, 向き, 操作回数)
    int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
    int py = ny, px = nx;
    int by, bx;
    bool flag = true;
    while (1){
        py += dy[nd];
        px += dx[nd];
        if (py < 0 || h <= py){
            flag = false;
            break;
        }
        if (px < 0 || w <= px){
            flag = false;
            break;
        }
        if(py==gy&&px==gx){
            if(ans == -1 || nt < ans)
                ans = nt;
            flag = false;
            break;
        }
        if(c[py][px] == 1){
            by = py;
            bx = px;
            py -= dy[nd];
            px -= dx[nd];
            if(py == ny && px == nx)
                flag = false;
            break;
        }
    }
    if(flag && nt < 10){
        c[by][bx] = 0; // 障害物を壊す
        for (int i = 0; i < 4;i++)
            dfs(py, px, i, nt + 1);
        c[by][bx] = 1; // 壊した障害物を元に戻す
    }
}

int main(){
    while(1){
        cin >> w >> h;
        if(h==0)
            break;
        for (int i = 0; i < h;i++)
            for (int j = 0; j < w;j++)
                cin >> c[i][j];
        int sx, sy;
        for (int i = 0; i < h;i++){
            for (int j = 0; j < w;j++){
                if(c[i][j] == 2){
                    sy = i;
                    sx = j;
                }
                if (c[i][j] == 3){
                    gy = i;
                    gx = j;
                }
            }
        }
        ans = -1;
        for (int i = 0; i < 4; i++)
            dfs(sy, sx, i, 1);
        cout << ans << endl;
    }
}


Measured memory_bytes: 3016
a=input().split(' ')
b=0
d=0
c=input().split(' ')
a[0]=int(a[0])
a[1]=int(a[1])
while b<a[0]:
    c[b]=int(c[b])
    b=b+1
c.sort()
b=0
while a[1]>b:
    d=d+c[b]
    b=b+1
print(d)



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

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

int n, x, y;
map<int, int> m;
// vector<vector<long long>> a(n, vector<int>(n, -1));

long long calc_cost(int s, int g)
{
    long long cost = 0;
    if (s <= x && y <= g)
    {
        cost = (x - s) + (g - y) + 1;
    }
    else if (s <= x && x < g && g < y)
    {
        cost = max(x - s, 0) + min(g - x, 1 + y - g);
    }
    else if (x < s && g < y)
    {
        cost = min(g - s, s - x + 1 + y - g);
    }
    else if (x < s && s < y && y <= g)
    {
        cost = min(y - s, s - x + 1) + max(g - y, 0);
    }
    else
    {
        cost = g - s;
    }
    return cost;
}
int main()
{

    cin >> n >> x >> y;
    long long cost = 0;
    for (int i = 1; i < n; i++)
    {
        for (int j = i + 1; j <= n; j++)
        {
            // cout << i << " " << j << " " << calc_cost(i, j) << endl;
            m[calc_cost(i, j)]++;
        }
    }

    rep(i, n - 1)
    {
        cout << m[i + 1] << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;

#define N 100000
#define mod_32(n) (n&((1<<5)-1))
int prime[(N>>5)+1];
 
void init(){
	memset(prime,-1,sizeof(prime));
	prime[0] = prime[0] - (1<<0) - (1<<1);
	for(int i=2;i*i <= N;i++){
		if( prime[i>>5] & (1 << mod_32(i)) ){
			for(int j=i*i;j<=N;j+=i){
				prime[j>>5] -= (prime[j>>5] & (1<<mod_32(j)));
			}
		}
	}
}
inline bool isprime(int n){
	return !!(prime[n>>5] & (1<<mod_32(n)));
}


int main(){
	init();
	vector<long long> p;
	for(int i = 2 ; i <= 100000 ; i++){
		if( isprime(i) ){
			p.push_back(i);
		}
	}
	long long m,a,b;
	while(scanf("%lld%lld%lld",&m,&a,&b) && m ){
		long long ans = 0;
		long long A = 0;

		for(int i = 0 ; i < p.size() ; i++){
			for(int j = i ; j < p.size() ; j++){
				if( p[i] * p[j] <= m && a*p[j] <= p[i]*b){
					if( p[i]*p[j] > ans ){
						ans = p[i]*p[j];
						A = p[i];
					}
				}else if( p[i] * p[j] > m ){
					break;
				}
			}
		}
		cout << A << " " << ans / A << endl;
	}
	
}

Measured memory_bytes: 1372
n = int(input())
a = [int(x) for x in input().strip().split()]
b = [int(x) for x in input().strip().split()]

p = 0
for x, y in zip(a, b):
    if x > y:
        p += x - y
    else:
        p -= (y - x) // 2

if p <= 0:
    print('Yes')
else:
    print('No')


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


int main(){
    char x;
    cin>>x;
    int a = 'A'-'a';
    if(x>='a'&&x<='z'){
        
        cout<<'a'<<endl;
        return 0;
    }else{
        cout <<'A'<<endl;
    
    }
    return 0;
}


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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cout << #a << " = " << a << endl

const ll inf = 1e15;
const ll mod = 1e9+7;

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

int N, K;
string S;
int num[100001];
char state[100001];

int main() {
    cin >> N >> K;
    cin >> S;

    int count = 0;
    char pre = S[0];
    int key = 0;
    REP(i,N) {
        if (pre == S[i]) {
            count++;
        } else {
            //num.push_back(count);
            //state.push_back(pre);
            num[key] = count;
            state[key] = pre;
            pre = S[i];
            count = 1;
            key += 1;
        }
    }
    num[key] = count;
    state[key] = pre;
    key += 1;

    int result = 0;
    for (int i = 0; i < key; i+=2) {
        //cout << n << endl;
        //cout << i << endl;
        int total = 0;
        int inc = (state[i] == '1') ? 2*K : 2*K-1;
        for (int j = 0; j <= inc && i+j < key; j++) {
            total += num[i+j];
        }
        //cout << total << endl;
        result = max(result, total);
        if (i == 0 && state[i] == '0') {
            i--;
        }
    }
    cout << result << endl;
}


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

int main() {
  int N;
  string arare;
  cin >> N;
  
  for(int i=0; i<N; i++){
    cin >> arare;
    if(arare == "Y") {
      cout << "Four" << endl;
      return 0;
    }
  }
  
  cout << "Three" << endl;

}


Measured memory_bytes: 256
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from functools import reduce
from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
def lcm(a, b):
  return a*b//gcd(a, b)

class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * n
    
  #要素xが属するグループの根を探して返す
  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]
  
  #xが属するグループとyが属するグループを併合する
  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)
    
    if x == y:
      return
    
    if self.parents[x] > self.parents[y]:
      x, y = y, x
    
    self.parents[x] += self.parents[y]
    self.parents[y] = x
  
  #xが属するグループに含まれる要素数(サイズ)を返す
  def size(self, x):
    return -self.parents[self.find(x)]
  
  #要素x,yが同じグループに属するかどうかを返す
  def same(self, x, y):
    return self.find(x) == self.find(y)
  
  #要素xが属するグループに属する要素をリストで返す
  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]
  
  #すべてのグループの根をリストで返す
  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]
  
  #存在するグループの数を返す
  def group_count(self):
    return len(self.roots)
  
  #根と根の下に属する要素のリスト辞書を返す
  def all_group_members(self):
    return {r: self.members(r) for r in self.roots()}
  
  #print(uf)で根と要素のリストを文字列で返す
  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
  n, m, k = map(int, input().split())
  deg = [0]*n
  ans = [0]*n
  uf = UnionFind(n)
  for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    deg[a] += 1
    deg[b] += 1
    uf.union(a, b)
  
  for _ in range(k):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if uf.same(c,d):
      deg[c] += 1
      deg[d] += 1
  
  for i in range(n):
    ans[i] = uf.size(i) - 1 -deg[i]
  
  print(' '.join(map(str, ans)))
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 30256
import java.util.*;

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

        long X = sc.nextLong();
        long Y = sc.nextLong();

        int result = 0;

        for (;;) {
            X = X * 2;
            result++;
            if (X > Y) {
                break;
            }
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 23764
#include<iostream>
using namespace std;
int main()
{
    char ch[200001];
    int n,ans=1;
    cin>>n;
    cin>>ch;
    for(int i=1;i<n;++i)
    {
        if(ch[i]!=ch[i-1])++ans;
    }
    cout<<ans;
}

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

int main(){
  string s;
  cin >> s;
  
  char* p = "abcdefghijklmnopqrstuvwxyz";
  
  int x;
  
  for(int i=0; i<26; i++){
    if (s.find(p[i]) >= s.size() ){
      cout << p[i] << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const ll MAXN = 1e18;
int main() {
	int n; cin >> n;
	ll a[n] = {};
	for (int i = 0; i < n; i++)
		cin >> a[i];
	if (count(a, a + n, 0)) {
		cout << 0 << "\n";
		return 0;
	}
	ll prod = 1;
	for (int i = 0; i < n; i++) {
		if (a[i] <= MAXN / prod)
			prod *= a[i];
		else {
			cout << -1 << "\n";
			return 0;
		}
	}
	cout << prod << "\n";
}


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

int main()
{
ll n ;
cin >> n ;
if(n/100==7)ans="Yes";
n%=100;
if(n/10==7)ans="Yes";
n%=10;
if(n==7)ans="Yes";

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

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio (false) ;cin.tie(NULL);
#define tc  int t;cin>>t;for(int i=0;i<t;i++)
#define ll long long int
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define um(a,b) unordered_map<a,b>
#define vv(a) vector<a>
#define pp(a,b) pair<a,b>
ll power(ll a,ll b,ll mod){  ll ans=1;  while(b>0){
  if(b&1){ ans=(ans*a)%mod;} a=(a*a)%mod;  b=b/2; } return ans;}
#define imax 1000
ll find(ll sum,ll*brr,ll m){
  ll s=0;
  ll e=m;
  ll ans=0;
  while(s<=e){
    ll mid=(s+e)/2;
    if(brr[mid]<=sum){
        ans=mid;
        s=mid+1;
    }else{
      e=mid-1;
    }
  }
  return ans;

}
int main(){
FIO
ll n,m,k;
cin>>n>>m>>k;
ll arr[n+1],brr[m+1];
for(ll i=1;i<=n;i++){
 cin>>arr[i];
}
for(ll j=1;j<=m;j++){
    cin>>brr[j];
}
arr[0]=0,brr[0]=0;
for(ll i=1;i<=n;i++){
    arr[i]=arr[i]+arr[i-1];
}
for(ll j=1;j<=m;j++){
    brr[j]=brr[j]+brr[j-1];
}
ll ans=0;
for(ll i=0;i<=n;i++){
    //cout<<i<<" "<<arr[i];
    if(k>=arr[i]){
    ll temp=find(k-arr[i],brr,m);
    //cout<<temp<<endl;
    ans=max(ans,temp+i);
    }
}
cout<<ans<<endl;



}


Measured memory_bytes: 6732
#include <iostream>
#include <string>
#include <cstdlib> //func147bでインクルード
#include <vector>  //func146b
using namespace std;
 
 
void func145b()
{
    int n,m;
    string s,tmp;
    cin >> n >> s;
    tmp = "No";
    m = n / 2;
    if (n % 2 == 0) {
        if (s.substr(0, m) == s.substr(m, m)) {
            tmp = "Yes";
        }
    }
    cout << tmp << endl;
 
}
 
int main(){
  func145b();
  return 0;
}

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

int main(void){
    int n;
    cin >> n;
    vector<int> next(n);
    vector<int> footprint(n, 0);
    for (int i = 0; i < n; i++){
        cin >> next[i];
    }
    
    int number = 0;
    int cnt = 0;
    while(true){
        footprint[number] = 1;
        number = next[number] - 1;
        cnt++;
        if(footprint[number] == 1){
            cout << -1 << endl;
            break;
        }
        if(number == 1){
            cout << cnt << endl;
            break;
        }
    }
}


Measured memory_bytes: 1024
N, A, B = map(int, input().split())

def digsum(n):
    total = 0
    while n > 0:
        total += n%10
        n /= 10
        n = int(n)
    return total

ans = 0
for i in range(1, N+1):
    if A <= digsum(i) <= B:
        ans += i

print(ans)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int friendid[100000]={0};


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	vector< vector<int> > v;
	vector<int> u;
	int n,m,r,l,id=0,k;
	cin >> n >> m;
	for(int i=0;i<n;i++){
		u.push_back(i);
		u.push_back(0);
		v.push_back(u);
		u.pop_back();
		u.pop_back();
	}
	for(int i=0;i<m;i++){
		cin >> r >> l;
		++v[r][1];
		++v[l][1];
		v[r].push_back(l);
		v[l].push_back(r);
	}

	queue<int> q;
	for(int i=0;i<n;i++){

		if(friendid[i]==0){


			q.push(i);
			++id;
			friendid[i]=id;
			while(q.size()){
				k = q.front();
				q.pop();
				for(int j=0;j<v[k][1];j++){
					if(friendid[v[k][j+2]]==0){
						friendid[v[k][j+2]]=id;
						q.push(v[k][j+2]);
					}
				} 
			}
		}
	}


	int qn;
	cin >> qn;
	for(int i=0;i<qn;i++){
		cin>>r>>l;
		if(friendid[r]==friendid[l])cout << "yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}

Measured memory_bytes: 9936
#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
map<char,int>::iterator it;
  vector<int>v;
  int arr[200000],arr1[200000];
int main()
{

int n,a,sum=0;
cin>>n;
for(int i=0;i<n-1;i++)
{
    cin>>arr[i];
}
sum=arr[0];
for(int i=0;i<n-1;i++)
{
    if(i==n-2){sum+=arr[i];}
else if(arr[i]<=arr[i+1])
{
    sum+=arr[i];
}
else{sum+=arr[i+1];}
}
cout<<sum<<endl;


}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(deprecated)]

use std::cell::{Cell, Ref, RefCell, RefMut};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
use std::usize;

const MOD_10_9_7: u64 = 1_000_000_007;
const INF: i64 = 1_000_000_000_000;
const MIN_INF: i64 = -1_000_000_000_000;

/// FYI: https://github.com/vain0x/scan-bench
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let s: String = read!(String);

    let c = s.chars().collect::<Vec<char>>();

    // 条件1
    if c[0] != 'A' {
        println!("WA");
        return;
    }

    // 条件2
    let r = c.get(2..(c.len() - 1)).unwrap();
    if r.iter().filter(|&&x| x == 'C').count() != 1 {
        println!("WA");
        return;
    }

    // 条件3
    let mut excluded = c
        .iter()
        .filter(|&&x| x != 'A' && x != 'C')
        .map(|&x| x as u8);
    if excluded.any(|x| x < 97 || 122 < x) {
        println!("WA");
        return;
    }
    println!("AC");
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int N;
  cin >> N;
  vector<vi32> g(N);
  rep(i, N - 1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  vi32 dist(N);
  auto dfs = [&](auto dfs, int u, int p) -> void {
    for (auto v : g[u]) if (v != p) {
      dist[v] = dist[u] + 1;
      dfs(dfs, v, u);
    }
  };
  dfs(dfs, 0, -1);
  vector<vi32> lst(2);
  rep(i, N) {
    if (dist[i] & 1) {
      lst[1].emplace_back(i);
    } else {
      lst[0].emplace_back(i);
    }
  }
  int n = lst[0].size();
  int m = lst[1].size();
  if (n > m) swap(n, m), swap(lst[0], lst[1]);

  vi32 ans(N);
  vi32 used(N + 1);
  int x = 1;
  if (n <= N / 3) x = 3;
  each(l, lst[0]) {
    ans[l] = x;
    used[x] = 1;
    x += 3;
    if (x > N) x = 3;
  }
  int num = 1;
  rep(i, N) {
    if (ans[i] != 0) continue;
    while (used[num]) num++;
    ans[i] = num;
    used[num] = 1;
  }
  cout << ans << endl;
}


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

int main()
{
    int a, b, x;
    cin >> a >> b >> x;
    string ans = "NO";
    if (a + b >= x && a <= x)
        ans = "YES";
    cout << ans << "\n";
    return 0;
}


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

using namespace std;

int main(int argc, char *argv[])
{
    int N;
    cin >> N;
    const int M = 1e9 + 7;
    vector<vector<bool>> A(N, vector<bool>(N));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            int v;
            cin >> v;
            if (v) A[i][j] = true;
        }
    }
    vector<int> dp(1 << N);
    dp[0] = 1;
    for (int i = 1; i < 1 << N; i++) {
        int n = __builtin_popcount(i);
        for (int bit = 0; bit < N; bit++) {
            if ((i & 1 << bit) && A[n - 1][bit]) {
                dp[i] += dp[i & ~(1 << bit)];
                dp[i] %= M;
            }
        }
    }
    cout << dp[(1 << N) - 1] << endl;
    return 0;
}


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

using namespace std;

int main()
{
    int N, T;
    while (cin >> N >> T, N) {
        string s;
        cin >> s;

        vector<vector<double>> dp(T + 1, vector<double>(N));
        for (int i = 0; i < N; i++) {
            dp[0][i] = (s[i] == 'R');
        }        
        for (int i = 0; i < T; i++) {
            for (int j = 0; j < N; j++) {
                if (dp[i][j] == 0) continue;
                for (int k = 1; k <= 6; k++) {
                    int nj = (j + k) % N;
                    dp[i + 1][nj] += dp[i][j] / 6;
                }
            }
        }
        printf("%.10f\n", *max_element(dp[T].begin(), dp[T].end()));
    }    
    return 0;
}

Measured memory_bytes: 34316
N = int(input())
s = ''

while N != 0:
#    print(N, s, N % (-2) == 0)
    if N % (-2) == 0:
        s = '0' + s
    else:
        s = '1' + s
        N -= 1
    N /= (-2)

if s =='':
    s = '0'
print(s)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long l;
bool a[111];
int ans=-0;
int main()
{
	int x,k;
	cin>>x>>k;
	for(int i=0;i<k;i++)
	{
		int p;
		cin>>p;
		a[p]=1;
	}
	for(int i=0;;i++)
	{
		if(x-i<0||a[x-i]==0)
		{
			cout<<x-i<<endl;
			return 0;
		}
		if(a[x+i]==0)
		{
			cout<<x+i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
signed main(){
  int A,B,a,b;
  cin>>A>>B>>a>>b;
  cout<<(A-a)*(B-b)<<endl;
}

Measured memory_bytes: 256
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	LL n, A,B;
	cin>>n;
	scanf("%lld %lld",&A,&B);
	if(n==1){
		cout<<(A==B)<<endl;
		return 0;
	}
	if(A>B){
		cout<<0;
		return 0;
	}
	else{
		cout<<A+(n-1)*B-B-(n-1)*A+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
Adj = [[0 for i in range(n)] for i in range(n)]
 
for i in range(n):
    u = list(map(int, input().split()))
    if u[1] > 0:
        for i in u[2: 2 + u[1]]:
            Adj[u[0] - 1][i - 1] = 1
 
color = [0] * n
d = [-1] * n
import queue
Q = queue.Queue()

color[0] = 1
d[0] = 0
Q.put(1)
while not Q.empty():
    u = Q.get()
    for v in range(1, n+1):
        if Adj[u-1][v-1] == 1 and color[v-1] == 0:
            color[v-1] = 1
            d[v-1] = d[u-1] + 1
            Q.put(v)
    color[u-1] = 2

for i in range(n):
    print("{} {}".format(i + 1, d[i]))

Measured memory_bytes: 8724
def main():
    a, b, c, x, y = [int(i) for i in raw_input().strip().split()]
    foo = x * a + b * y
    for k in xrange(max(x, y)+1):
        foo = min(foo, (k * c * 2) + (max(x-k, 0) * a) + (max(y-k, 0) * b))
    print foo
    
if __name__ == '__main__':
    main()

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

#define LL long long
#define ULL unsigned long long

#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) (((l)+(r))>>1)

const int MOD = (int) 1e9 + 7;
const double eps = (double) 1e-8;
const int maxn = (int) 1e5 + 20;
const double pi = (double) acos(-1.0);

int n, m;
int f[maxn];

int find_f(int x)
{
    if(x == f[x]) return x;
    return f[x] = find_f(f[x]);
}


void work()
{
    cin >>n >>m;
    for(int i = 0; i <= n; i++) f[i] = i;
    for(int i = 0; i < m; i++)
    {
        int x, y, z;
        cin >>x >>y >>z;
        f[find_f(x)] = find_f(y);
    }

    int ans = 0;
    for(int i = 1; i <= n; i++)
        if(find_f(i) == i)
            ans++;
    cout <<ans <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r" ,stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416

    int tc = 1;
//    scanf("%d", &tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <regex>
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a;
  int sum=0;
  for(int i=0;i<n;i++){
    int t;
    cin >> t;
	a.push_back(t);
    sum+=t;
  }
  int r = roundf((double)sum/n);
  sum = 0;
  for(auto i:a){
    sum += (i-r)*(i-r);
  }
  cout << sum;
}

Measured memory_bytes: 256
import math
n = int(input())
ai = [int(i) for i in input().split()]

ai.sort()

sqr_max_val = int(ai[n-1]**0.5)
max_val = ai[n-1]
#print(ai)
ai_ex = [0]*(2*10**6)
#ai_ex = [0]*(30)

for i in range(n):
    ai_ex[ai[i]-1] += 1

for i in range(n):
    if ai_ex[ai[i]-1] > 1:
        ai_ex[ai[i]-1] = 0
    """
    if ai[i] > sqr_max_val:
        break
    """
    tmp = ai[i]
    baisu = 2
    #print(ai[i])
    while tmp * baisu <=  max_val:
        ai_ex[tmp*baisu-1] = 0
        #print(tmp*baisu)
        baisu += 1
"""
for i in range(100):
    if ai_ex[i] == 1:
        a = 1
        #print(i)
"""
print(sum(ai_ex))
#print(ai_ex)

Measured memory_bytes: 117500
from math import factorial

n = int(input())
f = factorial(n)

mod = 10 ** 9 + 7

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n ** 0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

ans = 1
for p in primes(n):
    temp = 1
    while f % p == 0:
        temp += 1
        f //= p
    ans = (ans * temp) % mod
print(ans)


Measured memory_bytes: 9360
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define drep(i,cc,n) for(int i=cc;i>n;--i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL <<60;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}

ll choose2(ll n){
    return n*(n-1)/2;
}

int main(){
    int n;
    cin>>n;
    if(n == 1) cout<<"Hello World"<<endl;
    else{
        int a,b;
        cin>>a>>b;
        cout<<a+b<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*
    @uthor: Amit Kumar
    user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define ll    long long
#define ld    long double
#define ull   unsigned long long
#define endl "\n"
ll google_itr = 1;
#define google(x) cout<<"Case #"<<x<<":"
#define pi 3.14159265358979323846264338327950L

const ll mod = 1e9+7;
const ll inf = 1e18;

ll popcount(ll num){
    num = num - ((num >> 1) & 0x55555555);
    num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
    return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}

vector<pair<ll,ll>> factor_arr;

void myfactor(ll num){ 
    ll count = 0;   
    while (!(num % 2)) { 
        num >>= 1; count++; 
    }  
    if (count) factor_arr.push_back({2,count}); 
    for (auto i = 3; i <= sqrt(num); i += 2) { 
        count = 0; 
        while (num % i == 0) { 
            count++; 
            num /= i; 
        } 
        if (count) factor_arr.push_back({i,count}); 
    } 
    if (num > 2) factor_arr.push_back({num,1});
}

void virus(){
        ll len;
        cin>>len;
        vector<ll> arr(len);
        for(auto &i:arr) cin>>i;
        ll sum = 0;
        for(auto i=0;i<len;i++){
            for(auto j=i+1; j<len; j++) sum +=(arr[i]*arr[j]);
        }
        cout<<sum;
}


int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

    ll t=1;
    //cin>>t;
    while(t--){
           auto start = high_resolution_clock::now();
           virus();
           auto stop = high_resolution_clock::now();
           auto duration = duration_cast<seconds>(stop - start);
         //cout << "Time: "<<duration.count()<<endl;
        //your code goes here
    }
    return 0;
}

Measured memory_bytes: 3556
def fin(ok) 
  puts ok.eql?(true) ? 'Yes' : 'No' 
  exit
end

pre = ''
ct = 0
gets.strip.chars do |c|
  if c.eql?(pre)
    ct += 1 
    fin(true) if ct >= 3
  else
    ct = 1
    pre = c
  end 
end
fin(false)


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <bitset>
using namespace std;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	long N;
	cin >> N;
  	long Array[N];
  	int idx = 0;
  	while(cin >> Array[idx]) idx++;
  	for(int i = 1; i< N;i++)
    {
      for(int k=0;k<N -1 ;k++) cout << Array[k] << " ";
      cout << Array[N-1] << endl;

      long key = Array[i];
      for(int j=i-1;j>=0;j--)
      {
        if(key < Array[j])
        {
          Array[j+1] = Array[j];
          Array[j] = key;
        }else
        {
          break;
        }
      }
    }
  	for(int k=0;k<N -1 ;k++) cout << Array[k] << " ";
    cout << Array[N-1] << endl;

  	return 0;
}



Measured memory_bytes: 3224
X=input()
stack=[]
point=0
for i in range(len(X)):
    if X[i]=="S":
        stack.append(X[i])
        point+=1
    else:
        if point==0:
            stack.append(X[i])
            point+=1
        elif stack[point-1]=="T":
            stack.append(X[i])
            point+=1
        elif stack[point-1]=="S":
            del stack[point-1]
            point-=1
print(len(stack))

Measured memory_bytes: 52064
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d;
  	cin >> a >> b >> c >> d ;
  	int n1=(a+d-1)/d, n2=(b+c-1)/b;
  	if(n1>=n2){
    	cout << "Yes" << endl;
    }else{
    	cout << "No" << endl;
    }
}

Measured memory_bytes: 3644
#include <iostream>

using namespace std;
#define ll long long

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

    ll a[100][100];
    ll b[100];
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin >> a[i][j];
        }
    }
    for(int i=0; i<m; i++){
        cin >> b[i];
    }

    for(int i=0; i<n; i++){
        int sum=0;
        for(int j=0; j<m; j++){
            sum += a[i][j] * b[j];
        }
        cout << sum << endl;
    }

    return 0;
}

Measured memory_bytes: 3152
import std.stdio;
import std.array;
import std.math;
import std.conv;

void main(){
	string str;
	while((str = readln()).length != 0){
		string[] input = split(str);
		int a = to!int(input[0]);
		int b = to!int(input[1]);
		writeln(digit(a + b));
	}
}

uint digit(in int num){
	if(num <= 0) return 0;
	else
		return cast(uint)log10(num) + 1;
}

Measured memory_bytes: 1048
#include<stdio.h>
int main()
{
    char x;
    int i=0;
    scanf("%c",&x);
    if(x=='1')i++;
    scanf("%c",&x);
    if(x=='1')i++;
    scanf("%c",&x);
    if(x=='1')i++;
    printf("%d\n",i);
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)

vi a(51,0),b(51,0),c(51,0),d(51,0);
ll M=0,n,m,q;

void dfs(int x,int n,vi arr){
    if(x==0){
        ll sum=0;
        rep(i,q){
            if(arr[a[i]]-arr[b[i]]==c[i])sum+=d[i];
        }
        //for(auto x:arr)cout<<x<<" ";
        //cout<<endl;
        M=max(sum,M);
    }else{
        for(int i=n;i>0;i--){
            vi a=arr;
            a.pb(i);
            dfs(x-1,i,a);
        }
    }
}

int main(){
    cin>>n>>m>>q;
    rep(i,q){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        a[i]--,b[i]--;
    }
    dfs(n,m,vi());
    cout<<M<<endl;
    return 0;
}

//a=97,z=122

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

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

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

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

int main() {
    int n;
    while(cin >> n, n){
        vector<pair<int, int>> v(n);
        for (int i = 0; i < n; ++i) {
            scanf("%d %d", &v[i].first, &v[i].second);
        }
        int m;
        cin >> m;
        v.resize(n+m);
        for (int i = 0; i < m; ++i) {
            scanf("%d %d", &v[n+i].first, &v[n+i].second);
        }
        sort(v.begin(),v.end());
        vector<int> dp(n+m, 1);
        for (int i = 0; i < n+m; ++i) {
            for (int j = 0; j < i; ++j) {
                if(v[j].first < v[i].first && v[j].second < v[i].second){
                    chmax(dp[i], dp[j]+1);
                }
            }
        }
        cout << *max_element(dp.begin(),dp.end()) << "\n";
    }
    return 0;
}


Measured memory_bytes: 3136
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

// #include <unordered_set>
// #include <unordered_map>

#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

#define pb push_back
#define mp make_pair

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

int lcm(int a, int b) {
    int c = gcd(a, b);
    a /= c;
    return a * b;
}

typedef std::pair<int, int> P;
typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI = acos(-1.0);


#define int long long

using namespace std;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {-1, 0, 1, 0};


vector<string> s;

bool used[4000][4000] = {false};
long long black_count;
long long white_count;

void dfs(int y, int x, int w, int h) {
    used[y][x] = true;

    if (s[y][x] == '#') black_count++;
    else if (s[y][x] == '.')white_count++;

    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];

//        cout << ny << ' ' << nx << " " << s[ny][nx] << endl;

        if (used[ny][nx])continue; // already used
        if (nx < 0 || ny < 0 || nx >= w || ny >= h)continue; // invalid area
        if (s[ny][nx] == s[y][x])continue; // '#' => '.' -> '#' ... : not same char

        dfs(ny, nx, w, h);
    }

}


signed main() {
    int h, w;
    int ans = 0;
    cin >> h >> w;

    s.resize(h);

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

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {

//            cout << y << " " << x << " " << s[y][x] << endl;

            if (s[y][x] == '.') continue; // black start, not white
            if (used[y][x])continue; // already used

            black_count = 0;
            white_count = 0;

            dfs(y, x, w, h);
            ans += black_count * white_count;
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 19584
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) a[i] = i+1;
    vector<int> p(n), q(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];
    int pp, qq;
    int loc = 0;
    do {
        loc++;
        if (a==p) pp = loc;
        if (a==q) qq = loc;
    } while (next_permutation(all(a)));

    cout << abs(qq-pp) << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n,m = map(int,input().split())
cnt_pena = 0 # 初めてACが出た時にその時点でのcnt[i] をたす
cnt_ac = 0
cnt = [0]*n # 初めてACが出た時のその問題についてのWA数 ACがすでに出ていたらansに足した後その時点でcnt[i] は負にする
for i in range(m):
    p,s = map(str,input().split())
    if cnt[int(p)-1] >= 0 and s == "WA": 
        cnt[int(p)-1] += 1 
    elif cnt[int(p)-1] >= 0 and s == "AC": 
        cnt_pena += cnt[int(p)-1]
        cnt[int(p)-1] = -1
        cnt_ac += 1
    #print(cnt)
print(cnt_ac,cnt_pena)

Measured memory_bytes: 3828
using System;

public class Program
{
    public static long loop;

    static long n;

    static string output;

    public static void Main(string[] args)
    {
        loop = 0;

        Input();
        Proc();
        Output();
    }

    static void Input()
    {
        string[] input = null;

        // スペース区切りの整数の入力(横、個別)
        input = Console.ReadLine().Split(' ');

        n = long.Parse(input[0]);
    }

    static void Proc()
    {
        long sum = 0;

        for(long i = 1; i <= n; i++)
        {
            sum += i;
        }

        output = sum.ToString();
    }

    static void Output()
    {
        // 出力
        Console.WriteLine(output);
        output = string.Empty;
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int gcd(int a, int b) {
  if (b > a)
    return gcd(b, a);
  if (b == 0)
    return a;
  return gcd(b, (a % b));
}

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

  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, 0, n) cin >> v[i];
  int ans = 1e9 * 2;
  rep(i, 1, n) { ans = min(ans, gcd(v[i], v[i - 1])); }
  cout << ans << endl;
}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

double dist(int d, vi p1, vi p2) {
  int su = 0;
  for(int i=0;i<d;++i) {
    su += (p1[i] - p2[i]) * (p1[i] - p2[i]);
  }
  return sqrt(su);
}

int gcd(int a, int b) {
  if(b == 0) return a;
  else return gcd(b, a%b);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n, d; cin >> n >> d;
  int now = d + 1;
  int cnt = 1;
  while(1) {
    now += 2*d + 1;
    if(now <= n) cnt++;
    else if(now - d <= n) {
      cnt++;
      break;
    } else {
      break;
    }
  }
  cout << cnt << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int ans=0;
		int next=1;
		for(int i=0; i<n; i++) {
			int a=sc.nextInt();
			if(a==next) {
				next++;
			} else {
				ans++;
			}
		}
		if(ans==n) {
			System.out.println(-1);
		} else {
			System.out.println(ans);
		}

		sc.close();
	}
}


Measured memory_bytes: 62492
#include <iostream>

using namespace std;


int main(){
    int sh,sm,ss,eh,em,es;
    for(int i=0;i<3;++i){
        cin>>sh>>sm>>ss>>eh>>em>>es;
        int wt = (eh-sh)*3600+(em-sm)*60+(es-ss);
        cout<<wt/3600<<" "<<wt/60%60<<" "<<wt%60<<endl;
    }
    return 0;
}

Measured memory_bytes: 3072
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int h=sc.nextInt();
    int w=sc.nextInt();
    String str[]=new String[h];
    for(int i=0;i<h;i++){
      str[i]=sc.next();
    }
    sc.close();
    for(int i=0;i<w+2;i++){
      System.out.print("#");
    }
    System.out.println("");
    for(int i=0;i<h;i++){
      System.out.println("#"+str[i]+"#");
    }
    for(int i=0;i<w+2;i++){
      System.out.print("#");
    }
    System.out.println("");
  }
}

Measured memory_bytes: 22996
#include <string>
#include <iostream>

using namespace std;

int main()
{
        string str;
        unsigned int x, sum = 0;

        while (cin >> str) {
                for (string::size_type i = 0; i < str.length(); i++) {
                        x = 0;
                        while (isdigit(str[i])) {
                                x = 10 * x + str[i] - '0';
                                i++;
                        }
                        if (x > 0) {
                                sum += x;
                        }
                }
        }
        cout << sum << '\n';

        return 0;
}



Measured memory_bytes: 2996
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

struct block {
    int x;
    int y;
    int c;
    
    block(int x, int y, int c) : x(x), y(y), c(c) {}
};

int a[200000];

int main() {
    int n, l, r, m, i;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    
    l = 0, r = 200000, m = (l + r) / 2;
    
    while (r - l > 1) {
        vector <block> v;
        
        v.push_back(block(1, a[0], 1));
        
        for (i = 1; i < n; i++) {
            while (v.back().x > a[i]) v.pop_back();
            
            if (v.back().y < a[i]) {
                v.push_back(block(v.back().y + 1, a[i], 1));
            } else {
                int p = -1;
                
                while (!v.empty()) {
                    if (v.back().c < m) {
                        p = min(v.back().y, a[i]);
                        break;
                    } else {
                        v.pop_back();
                    }
                }
                
                if (p == -1) break;
                
                block b = v.back();
                v.pop_back();
                
                if (b.x < p) v.push_back(block(b.x, p - 1, b.c));
                v.push_back(block(p, p, b.c + 1));
                if (p < a[i]) v.push_back(block(p + 1, a[i], 1));
            }
        }
        
        if (i == n) {
            r = m;
            m = (l + r) / 2;
        } else {
            l = m;
            m = (l + r) / 2;
        }
    }
    
    printf("%d\n", r);
    
    return 0;
}


Measured memory_bytes: 6552
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=list(input())
data=[[] for i in range(K)]
for i in range(N):
    zzz=i%K
    u=T[i]
    data[zzz].append(u)
ans=0
for h in data:
    l=len(h)
    dp=[[0,0,0] for i in range(l)]
    u=h[0]
    if u=="r":
        dp[0][2]=P
    elif u=="s":
        dp[0][0]=R
    else:
        dp[0][1]=S
    for i in range(1,l):
        u=h[i]
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])
        dp[i][2]=max(dp[i-1][1],dp[i-1][0])
        if u=="r":
            dp[i][2]+=P
        elif u=="s":
            dp[i][0]+=R
        else:
            dp[i][1]+=S
    ans+=max(dp[-1])
print(ans)

Measured memory_bytes: 73100
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
int k,x;
int main(){
	cin>>k>>x;
	for(int i=x-k+1;i<=x+k-1;i++){
		cout<<i<<" ";
	}
	cout<<endl;	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;

  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    ++mp[x];
  }

  vector<int> freq;
  for (auto e: mp) {
    freq.push_back(e.second);
  }

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

  int res = 0;
  for (int i = 0; i < (int)freq.size() - K; i++) {
    res += freq[i];
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 10748
#include <iostream>
#define ll long long 
using namespace std;
int main() 
{
    int n,c;
    cin>>n>>c;
    ll wt[103],v[103];
    for(int i=0;i<n;i++)
    {
        cin>>wt[i]>>v[i];
    }
    ll dp[103][c+1];
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=c;j++)
        {
            if(i==0 || j==0)
            {
                dp[i][j]=0;
            }
            else if(wt[i-1]<=j)
            {
                dp[i][j]=max(v[i-1]+dp[i-1][j-wt[i-1]], dp[i-1][j]);
            }
            else
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    cout<<dp[n][c];
}


Measured memory_bytes: 82008