akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;

int main() {
  int w,h,n;cin >> w >> h>>n;
  vector<tuple<int, int, int>> vt;
  for(int i=0;i<n;++i){
  	int x,y,a;cin >> x >> y>>a;
    vt.push_back(make_tuple(x,y,a));
  }
  int area = h*w;
  int x1 =0;int y1 =0;
  int x2 =w;int y2 =0;
  int x3 =w;int y3 =h;
  int x4 =0;int y4 =h;
  for(int i=0;i<n;++i){
  	int x = get<0>(vt[i]);
    int y = get<1>(vt[i]);
    int a = get<2>(vt[i]);
    if(a == 1){
      	x1 =max(x1,x);
      	x4 =max(x4,x);
    } else if(a == 2){
      	x2 =min(x2,x);
      	x3 =min(x3,x);
    } else if(a == 3){
      	y1 =max(y1,y);
      	y2 =max(y2,y);
    } else if(a == 4){
      	y3 =min(y3,y);
      	y4 =min(y4,y);
    }
  }
  if(x2 - x1>=0 && y3 - y2>=0){
    cout << (x2 - x1)*(y3 - y2) << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}


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

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: u32,
        a: u32,
        b: u32,
    }
    println!("{}", std::cmp::min( a*n, b));
}


Measured memory_bytes: 4352
from bisect import bisect_left
import sys
input=sys.stdin.readline
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
bc=[]
for i in b:
  for j in c:
    bc.append(i+j)
bc.sort()
yz=y*z
ng=10**12
ok=1
while ng-ok>1:
  mid=(ok+ng)//2
  cnt=0
  for j in a:
    cnt+=yz-bisect_left(bc,mid-j)
  #print(cnt)
  if cnt>=k:
    ok=mid
  else:
    ng=mid
ans=[]
#print(ok)
for i in a:
  idx=bisect_left(bc,ok-i)
  for j in range(idx,yz):
    ans.append(i+bc[j])
ans.sort(reverse=True)
#print(len(ans))
for i in ans[:k]:
  print(i)

Measured memory_bytes: 196752
import java.util.*;

// UVa 11504

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		char[] c = in.next().toCharArray();
		
		int index = 0;
		char[] answer = new char[10];
		
		for (int i = 0; i < c.length; i++) {
			if (c[i] == '0' || c[i] == '1') {
				answer[index] = c[i];
				index++;
			} else if (index > 0) {
				index--;
			}
		}
		
		for (int i = 0; i < index; i++) {
			System.out.printf("%c", answer[i]);
		}
	}
}

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

const ll MOD = 1000000007;


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

  int x = 0, y = 0, z = 0;
  ll ans = 1;
  rep(i, n) {
    int a;
    cin >> a;

    ll product = 0;
    int idx = -1;
    if (a == x) {product++; idx = 0;}
    if (a == y) {product++; idx = 1;}
    if (a == z) {product++; idx = 2;}

    if (idx == -1) {
			cout << "0" << endl;
			return 0;
		}

    if (idx == 0) x++;
    if (idx == 1) y++;
    if (idx == 2) z++;

    ans *= product;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
int main() {
  int n;cin>>n;
  int target=1;
  int broken=0;
  REP(i,n){
    int a;cin>>a;
    if(a==target){
      target++;
    }else{
      broken++;
    }
  }
  int ans=(target==1)?-1:broken;
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

// https://atcoder.jp/contests/abc156/tasks/abc156_c
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int c = sc.nextInt();
		int[] arrayB = new int[m];
		for(int i=0;i<m;i++) {
			arrayB[i] = sc.nextInt();
		}

		int ans = 0;
		for(int i=0;i<n;i++) {
			int tmp = c;
			for(int j=0;j<m;j++) {
				int a = sc.nextInt();
				tmp = tmp + arrayB[j]*a;
			}
			if(tmp>0) {
				ans++;
			}
		}
		sc.close();
		System.out.println(ans);
	}
}


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

int main() {
int a,b,c,d,e;
cin >> a >> b >> c >> d >> e;
if(a == 0) cout << 1 << endl;
else if(b == 0) cout << 2 << endl;
else if(c == 0)cout << 3 << endl;
else if(d == 0)cout << 4 << endl;
else cout << 5 << endl;
}

Measured memory_bytes: 3592
/*
██████╗  ███████╗  
██╔══██╗ ██╔════╝ 
██████╔╝ ███████╗ 
██╔══██╗ ╚════██║  
██║  ██║ ███████║      
╚═╝  ╚═╝ ╚══════╝                                                                                                             
*/

#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define haha(j,a,n) for(int j=a;j<n;j++)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define endl "\n"
#define bc(v) v.begin(),v.end()
#define vl vector<ll>
#define vi vector<int>
#define mod 1000000007
#define NUM 100005
#define F first
#define S second
#define bhar(a) rep(i,a.size()) cin>>a[i];
#define show(a) rep(i,a.size()) cout<<a[i]<<" ";
#define sott(a) sort(bc(a))
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define mapp map<ll,ll>
#define dkac cout<<fixed<<setprecision(15);
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define yeah(n) while(n--)
ll gcd(int a, int b){if(b==0) return a; else return gcd(b,a%b);}
ll bitfun(ll x){
  return (x&(-x));
}
void solve(){
  ll s,w; cin>>s>>w;
  if(w>=s) cout<<"unsafe";
  else cout<<"safe";
  
}
int main(){
    ios
    int t=1; 
    //cin>>t;
    yeah(t){
      solve();
    }
}

Measured memory_bytes: 3604
#include"bits/stdc++.h"
using namespace std;

int main() {
	int a, b, c;
	cin >> a;
	cin >> b;
	cin >> c;
	if(a==b && a!=c){
		cout << "Yes" << endl;
	} else if (a==c && a!=b) {
		cout << "Yes" << endl;
	} else if (b==c && b!=a) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
const lines=readlines(open("/dev/fd/0"))
let
    state=0
    global input
    input()=lines[state+=1]
end
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
intLine()=map(intSub,split(input()))
function main()
    t,x=intLine()
    println(t/x)
end
main()

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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

// I/O Asynchronizing
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

int main() {
    ll a, b;
    cin >> a >> b;
    if((a + b) % 2 == 0) {
        cout << (a + b) / 2 << endl;
    }
    else {
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	int n; cin >> n;
	vector<vector<pair<int, int>>> edg(n);
	for (int i = 0; i < n - 1; i++) {
		int a, b; cin >> a >> b;
		a--; b--;
		edg[a].push_back({ b, i });
		edg[b].push_back({ a, i });
	}
	vector<int> ans(n, -1);
	deque<pair<int, int>> que;
	int ma = 0;
	que.push_back({ n / 2, -1 });
	while (!que.empty()) {
		int pos = que.front().first;
		int c = que.front().second;
		que.pop_front();

		int cnt = 1;
		for (const auto &p : edg[pos]) {
			if (ans[p.second] != -1) continue;
			if (cnt == c) cnt++;
			ans[p.second] = cnt;
			que.push_back({ p.first, cnt });
			cnt++;
		}
	}
	for (int i = 0; i < n - 1; i++) ma = max(ma, ans[i]);
	cout << ma << endl;
	for (int i = 0; i < n - 1; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

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


int main(void){
    int n, q;
    while(1){
        cin >> n >> q;
        if(n == 0) break;
        
        vector<int> array(110, 0);

        for(int i = 0; i < n; i++){
            int m; cin >> m;
            for(int j = 0; j < m; j++){
                int input; cin >> input;
                array[input]++;
            }
        }

        int idx = 0;
        int max = 0;

        for(int i = 0; i < 110; i++){
            if(max < array[i]){
                idx = i;
                max = array[i];
            }
        }

        if(max < q) cout << "0" << endl;
        else cout << idx << endl;

    }

    return 0;
    
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
#pragma target("avx")

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> a >> b;
  if (a <= 9 && b <= 9)
    Cout(a * b);
  else
    Cout(-1);
  return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    i32 n,m, a,b; cin >> n >> m;
    vi h(n); rep(i,n) cin >> h[i];
    vec<bool> highests(n, 1);
    rep(i,m) {
        cin >> a >> b;
        --a, --b;
        if(h[a] < h[b]) highests[a] = 0;
        if(h[b] < h[a]) highests[b] = 0;
        if(h[a] == h[b]) highests[a] = highests[b] = 0;
    }

    i32 cnt = 0;
    rep(i,n) if(highests[i]) ++cnt;

    cout << cnt << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int k; cin >> k;
    int a,b; cin >> a >> b;
    if(b/k-(a-1)/k > 0) cout << "OK" << endl;
    else cout << "NG" << endl;
}

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

/*動的計画法で解く*/
int main(){
	int n;
	std::cin >> n;
	//dp[i][j]はi+1項まで計算した結果がj(0≦j≦20)である数
	std::vector<std::vector<long long int> > dp(n, std::vector<long long int>(21, 0));
	//入力の数値保存用
	std::vector<int> num(n, 0);
	//数値入力
	for(int i = 0; i < n; ++i){
		int x;
		std::cin >> x;
		num[i] = x;
	}
	//初期値
	dp[0][num[0]] = 1;
	//処理
	for(int i = 1; i < n - 1; ++i){ //2項からN-1項までの計算
		for(int j = 0; j < 21; ++j){ //
			//もし1つ前の計算結果がjの場合の数があればその加減を求める
			if(dp[i - 1][j] > 0){
				//それがもし0以上20以下なら
				if((j + num[i]) >= 0 && (j + num[i]) <= 20){
					dp[i][j + num[i]] += dp[i - 1][j];
				}
				if((j - num[i]) >= 0 && (j - num[i]) <= 20){
					dp[i][j - num[i]] += dp[i - 1][j];
				}
			}
		}
	}
	//必要な結果はn - 1項まで計算した結果がnum[n-1]である数
	std::cout << dp[n - 2][num[n - 1]] << std::endl;
	return 0;
}

Measured memory_bytes: 1232
#include<stdio.h>
int main()
{
   int n,m,res,r,a,b,d,i;
    scanf("%d%d",&n,&m);
        a=n;
        b=m;
        while(a!=0)
        {
            res=b%a;
            b=a;
            a=res;
        }
        printf("%d\n",b);


    return 0;
}

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

const int N = 100 * 1000 + 10;

int n;
long long ans;
int arr[N];

void input() {
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    return;
}

void solve() {
    int rate = 2;
    for (int i = 1; i < n; i++)
        if (arr[i] == rate)
            rate++;
        else
            ans += (arr[i] - 1) / rate;
    return;
}

int main() {
    input() ;
    solve() ;
    cout << ans + arr[0] - 1 << endl;
    return 0;
}


Measured memory_bytes: 640
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		long X=sc.nextLong();
		long A=sc.nextLong();
		long B=sc.nextLong();
		System.out.println(A-B>=0?"delicious":B-A<=X?"safe":"dangerous");
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
	
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
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> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }


int main() {
  int n,r; cin >>n >>r;
  int res = 0;
  if (n >= 10){
    res = r;
  }else{
    res = r + 100 * (10 - n);
  }
  cout <<res <<endl;
}

Measured memory_bytes: 764
#include<stdio.h>
using namespace std;
int main()
{
    int A, B, ad, time;
    scanf("%d %d", &A, &B);
    if(A>=0 && B >=0 && A <=23 && B <= 23){
        ad=A+B;
        if(ad >= 24){
            time=ad - 24;
        }
        else{
            time = ad;
        }
        printf("%d\n", time);
    }
   return 0;
}


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

int main(){
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << H*W - (H*w + W*h - h*w) << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
#define rep1(i,n) for (ll i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
const ll mod = 998244353;
const double e = 0.000000001;
int main(){
  ll l,r,d; cin >> l >> r >> d;
  ll ans = 0;
  for(ll i=l; i<r+1; i++){
    if(i%d==0) ans++;
  }
  cout << ans;
  return 0;
}

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

bool check(const string &s, const string &t){
	int m = s.size(), n = t.size();
	for(int k = 1; k < n; ++k){
		for(int i = 0; i + k * (m - 1) < n; ++i){
			int j;
			for(j = 0; j < m && i + j * k < n && s[j] == t[i + j * k]; ++j);
			if(j == m) return true;
		}
	}
	return false;
}

int main(){
	int n, c = 0;
	string s, t;
	cin >> n >> s;
	for(int i = 0; i < n; ++i){
		cin >> t;
		if(check(s, t)) ++c;
	}
	cout << c << '\n';
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii  = pair<int,int>;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define MOD 1000000007
#define EPS 10e-8
int gcd(int a,int b){return b?gcd(b,a%b):a;}    //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

int main(){
    int n,a,b;
    int count = 0;
    cin >> n >> a >> b;
    
    rep2(i,1,n+1){
        string s = to_string(i);
        int co = 0;
        rep(j, s.length())
        {
            co += s[j]-'0';
        }
        if(a<=co&&co<=b){
            count += i;
        }
    }
    cout << count << endl;
}


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

l = b-a
if l %2 == 0:
  print(l//2)
  
else:
  mi = b-1
  ma = n-a
  
  x1 = min(mi,ma)
  t1 = a-1
  c = b-(t1+1)
  t1 += (c-1)//2+1
  
  t2 = n-b
 
  a += (t2+1)

  t2 += (n-a)//2+1

  print(min(x1,t1,t2))
  

Measured memory_bytes: 3060
#include <iostream>
#include <unordered_map>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  
  int result = max(a+b, max(a-b, a*b));

  cout << result << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define ALL(A) A.begin(),A.end()
const long long mod=1000000007;
int main(){
    int n,ans=0;
    string s;
    cin>>n>>s;
    int blc[n+1],whc[n+1];blc[0]=0;whc[n]=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='#')
        blc[i+1]=blc[i]+1;
        else
        blc[i+1]=blc[i];
    }
    for(int i=n;i>0;i--)
    {
        if(s[i]=='.')
        whc[i-1]=whc[i]+1;
        else
        whc[i-1]=whc[i];
    }
    int k=0;
    ans=blc[0]+whc[0];
    while(k<n)
    {
        while(s[k]==s[k+1])
        k++;
        k++;
        ans=min(ans,blc[k]+whc[k]);
    }
    ans=min(ans,blc[n]+whc[n]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2180
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define ll unsigned long long int
#define test long int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
#define mmmm4 3


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int binaryExponentiation(int x, int n) //function to calculate x raise to power n
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x;
		x = x * x;
		n = n / 2;
	}
	return result;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-______________________________________________________________________________

	int n, m;
	cin >> n >> m;
	int h[n];
	//map<int, int>mm;
	rep(i, 1, n)
	{
		cin >> h[i];
		//mm[i] = 1;
	}

	map<int, int>m2;
	int cnt = 0;
	rep(i, 1, m)
	{
		int a, b;
		cin >> a >> b;

		/*m2[a]++;
		m2[b]++;
		if (h[a] > h[b])
		{
			mm[b] = -1;
		}
		else if (h[b] < h[a])
		{
			mm[a] = -1;
		}*/

		if (h[a] == h[b] && m2[a] <= 0 && m2[b] <= 0)
		{

			m2[a]--;
			m2[b]--;
		}
		else if (h[b] > h[a]  && m2[a] <= 0)
		{

			m2[a]--;
		}
		else if (h[a] > h[b] && m2[b] <= 0 )
		{
			m2[b]--;
		}
	}
	rep(i, 1, n)
	{
		if (m2[i] >= 0)
		{
			cnt++;
		}
	}
	cout << cnt << en;
	return 0;

}


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

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    set<int> st;
    FOR(i, A, A + K) {
        if (A <= i && i <= B) st.insert(i);
    }
    FOR(i, B - K + 1, B + 1) {
        if (A <= i && i <= B) st.insert(i);
    }
    for (auto itr = st.begin(); itr != st.end(); ++itr) cout << *itr << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;

template<typename T>
struct BIT{
  int n;
  vector<T> d;
  BIT(int n = 0):n(n),d(n+1){}
  void add(int i,T x=1){
    for(i++;i<=n;i += i&-i){
      d[i] += x;
    }
  }
  T sum(int i){
    T x = 0;
    for(i++;i>0;i -= i&-i){
      x += d[i];
    }
    return x;
  }
};
 
int main(){
  int n,c;cin >> n >> c;
  vector<vector<int>> prog(30,vector<int>(100005));
  rep(i,n){
    int s,t,ci;cin >> s >> t >> ci;
    --ci;
    --s;
    --t;
    prog[ci][s]++;
    prog[ci][t]--;
  }
  rep(j,c)rep(i,100005) prog[j][i+1] += prog[j][i];
  //rep(i,20) cout << prog[2][i] << endl;
  int ans = 0;
  for(int i = 1;i < 100003;i++){
    int cnt = 0;
    int lcnt = 0;
    rep(j,c){
      if(prog[j][i]==1) cnt++;
      else if(prog[j][i-1]==1) lcnt++;
    }
    if(cnt > 0) cnt += lcnt;
    ans = max(ans,cnt);
  }
  cout << ans << endl;
}

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

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

int main(){

    string key="keyence";
    string aa;

    cin >> aa ;

    string t=aa;

    for(int i=0;i<aa.size();i++){
        for(int j=i;j<=aa.size();j++){
            t=aa;
            t.erase(t.begin()+i,t.begin()+j);
            if(t==key){
                cout << "YES" << endl;
                return 0;
            }
        }
    }

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

Measured memory_bytes: 256
N,M=map(int,input().split())
list_n=[]
for i in range(N):
    list_n.append(0)
for i in range(M):
    a,b=map(int,input().split())
    list_n[a-1]+=1
    list_n[b-1]+=1
    
for i in range(N):
    print(list_n[i])

Measured memory_bytes: 3060
import sys

def print_board(board):
    for y in xrange(8):
        for x in xrange(8):
            if x == board[y]:
                sys.stdout.write("Q")
            else:
                sys.stdout.write(".")
        print ""

# y = x - col + row
# y = - x + col + row

def check_threat(board, col, row):
    for y in xrange(8):
        if board[y] == col:
            return True

    for y in xrange(8):
        if board[y] < 0:
            continue

        is_on_line = (row - y == col - board[y])
        is_on_line = is_on_line or (row - y == -col + board[y])
        if is_on_line:
            return True

    return False

def can_place(pos, idx, col):
    for i in range(8):
        if pos[i] >= 0 and pos[i] == col: return True
    for i in range(8):
        if pos[i] >= 0 and abs(pos[i] - col) == abs(i - idx): return True
    return False


def place(board, row):
    if row == 8:
        print_board(board)
        return

    if board[row] >= 0:
        place(board, row + 1)
        return

    for i in xrange(8):
        if check_threat(board, i, row):
            continue

        board[row] = i
        place(board, row + 1)
        board[row] = -1


def solve():
    board = [-1 for i in xrange(8)]

    num_qs = int(raw_input())
    for _ in xrange(num_qs):
        x, y = map(int, raw_input().split())
        board[x] = y

    place(board, 0)


if __name__ == "__main__":
    solve()

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

int main(void) {
	int h,w,i,j,**visit,np;
	char **Table,c,num[10];

	while (1) {
		np = 0;
		while ((c = fgetc(stdin))!=' ') {
			num[np++] = c;
		}
		num[np] = '\0';
		h = atoi(num);
		np = 0;
		while ((c = fgetc(stdin))!='\n') {
			num[np++] = c;
		}
		num[np] = '\0';
		w = atoi(num);

		if (h==0&&w==0) break;

		Table = (char **)calloc(h,sizeof(char *));
		visit = (int **)calloc(h,sizeof(int *));
		for (i=0;i<h;i++) {
			Table[i] = (char *)calloc(w,sizeof(char));
			visit[i] = (int *)calloc(w,sizeof(int));
			j = 0;
			while ((c = fgetc(stdin))!='\n') {
				visit[i][j] = 0;
				Table[i][j++] = c;
			}
		}

		i = j = 0;
		while (visit[i][j]==0&&Table[i][j]!='.') {
			visit[i][j] = 1;
			if (Table[i][j]=='>') {
				j++;
			} else if (Table[i][j]=='<') {
				j--;
			} else if (Table[i][j]=='^') {
				i--;
			} else if (Table[i][j]=='v') {
				i++;
			}
		}

		if (visit[i][j]==1) puts("LOOP");
		else printf("%d %d\n",j,i);

		for (i=0;i<h;i++) {
			free(Table[i]);
			free(visit[i]);
		}
		free(Table);
		free(visit);
	}

	return 0;
}

Measured memory_bytes: 632
program prob3
    implicit none
    integer::n, i
    integer(16),allocatable::a(:)
    integer(16)::s, c, cnt, re, c2, re2
    read(*,*) n
    allocate(a(n))
    read(*,*) a
    s = sum(a)
    c = 0
    c2 = 0
    cnt = 0

    do i = 1, n
        c = c+a(i)
        c2 = c2+a(i)
        cnt = cnt + 1
        if(c >= s/2)then
            c2 = c-a(i)
            exit
        end if
        if(i == n-1) then
        	exit
        end if
    end do

    re = s - c
    re2 = s - c2

    write(*,*) min(abs(c-re),abs(c2-re2))

    stop
end program

Measured memory_bytes: 6172
#include <bits/stdc++.h>
#define SZ(x) (int)x.size()
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define RALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int l=0, r=n-1;
    int ans=0;
    while ( l<r ) {
        if ( s[l]=='W' ) {
            while ( l<r && s[r]!='R' ) r--;
            if ( s[r]=='R' ) {
                swap(s[l],s[r]);
                ans++;
            }
        }
        l++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3732
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
#include <stack>
#include <queue>
#include <cassert>
#include <forward_list>
#include <chrono>
#include <deque>
#include <list>
#include <random>
#include <cstdio>
#include <sstream>

using namespace std;

//最大公約数
template<class T>
inline T GCD(T m, T n)
{
	T temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

//最小公倍数
template<class T>
inline T LCM(T m, T n)
{
	return m * n / GCD(m, n);
}

long long int sum = 0;
long long int n = 0;

void DFS(long long int ans, int bit, long long int& count)
{
	if (ans > n) { return; }

	if (bit == 0b111) { count++; }

	DFS(ans * 10 + 7, bit|0b001, count);

	DFS(ans * 10 + 5, bit|0b010, count);

	DFS(ans * 10 + 3, bit|0b100, count);
}

int main()
{
	cin >> n;
	
	DFS(0, 0, sum);

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    s = input()
    t = input()
    cnt = 0
    for i in range(len(s)):
        if s[i] != t[i]:
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9476
# -*- 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 numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
import math

def main():
	N, K = map(int, input().split(" "))
	A = input().split(" ")
	A = [int(s) for s in A]
	
	DP = [100000000000000000000000000000000 for _ in range(N)]
	DP[0] = 0
	
	for i, val in enumerate(A):
		if i == 0:
			continue
		tmp = 100000000000000000000000000000000
		
		for j in range(K):
			index = j+1
			if i >= index:
				tmp1 = DP[i-index] + abs(A[i-index] - val)
				tmp = min(tmp, tmp1)
			else:
				break
		DP[i] = min(DP[i], tmp)
		
	#print(DP)
	print(DP[N-1])
	
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 58336
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        if (str.length() == 4) {
            System.out.println("ABD");
        } else {
            System.out.println("ABC");
        }
    }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

int n,t,a;
ll ans[mx];
vector<int> v[mx];
vector<int> d(mx,0);
vector<int> e(mx,0);
vector<int> ne(mx,0);
int me=0;

void dfs(int x,int p){
  for(auto to : v[x]){
    if(to == p){  continue; }
    d[to] = d[x]+1;
    ne[to]=x;
    dfs(to,x);
  }
}

struct UnionFind {  
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  UnionFind(int n) : par(n) { //最初は全てが根であるとして初期化
    for(int i=0; i<n; i++){ par[i]=i; }  
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if(par[x]==x){ return x; }
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if(rx == ry){ return; }//xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool check(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
};


int main() {
  cin >> n;
  vector<int> a(n),b(n);
  for(int i=0; i<n-1; i++){ 
    cin >> a[i] >> b[i]; a[i]--; b[i]--;
    v[a[i]].push_back(b[i]);
    v[b[i]].push_back(a[i]);
  }
  d[0]=0;
  dfs(0,-1);
  int md = d[n-1]/2;

  int nxtt = n-1, safe=n-1;
  while(d[nxtt]>md){
    safe=nxtt;
    nxtt = ne[nxtt];//oya?
  }
  
  UnionFind snk(n);
  rep(i,n-1){
    if((a[i]==nxtt&&b[i]==safe)||(b[i]==nxtt&&a[i]==safe)){ continue; }
    snk.unite(a[i],b[i]);
  }
  
  int snkp=0, fenp=0;
  rep(i,n){
    if(snk.check(n-1,i)){ snkp++; }else{ fenp++; }
  }
  if(fenp>snkp){
    cout << "Fennec" <<endl; 
  } else {
    cout << "Snuke" <<endl; 
  }
  return 0;
}  


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

int main(){
    
    int n;
    cin >> n;
    long double num=n;
    num=2/num;

    vector<int> x(n),y(n);
    for(int i=0; i<n; i++){
        cin >> x.at(i) >> y.at(i);
    }

    long double dist=0;
    for(int i=0; i<n-1; i++){
        for(int j=n-1; j>i; j--){
            dist+=sqrt((x.at(i)-x.at(j))*(x.at(i)-x.at(j))+(y.at(i)-y.at(j))*(y.at(i)-y.at(j)));
            //cout << dist << endl;
        }
    }
    cout << fixed << setprecision(15)<< num*dist << endl;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int dp[200010][2];

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

    string s;
    cin >> s;
    int n = s.size();
    dp[0][0] = 1;
    dp[1][1] = 1;
    Rep(i, 1, n)
    {
        if (s[i] != s[i - 1])
            dp[i][0] = max(dp[i][0], dp[i - 1][0] + 1);
        dp[i][0] = max(dp[i][0], dp[i - 1][1] + 1);
        if (i > 1)
            dp[i][1] = dp[i - 2][0] + 1;
    }
    cout << max(dp[n - 1][0], dp[n - 1][1]) << endl;
}


Measured memory_bytes: 3732
#include <iostream>
	using namespace std;
	
	int main()
	{
		int start, end, num;
		cin >> start >> end >> num;
		int cnt = 0;
		for (int i=start; i<=end; i++)
		{
			if (num % i == 0)		
			{
				cnt++;
			}
		}
		cout << cnt << endl;
		
		return 0;
	}

Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define ALL(v) v.begin(),v.end()
#define mod 1000000007

vector<ll> p_id[100010];

ll dig(ll x){
  ll d=0;
  while(x>0){
    x/=10;
    d++;
  }
  return d;
}

int main(){
  ll n,m;
  cin >> n >> m;
  ll p[100100]={0},y[100100]={0};
  rep(i,m){
    cin >> p[i] >> y[i];
    p_id[p[i]].push_back(y[i]);
  }
  rep(i,100010)sort(ALL(p_id[i]));
  ll ans=0,res,tmp;

  rep(i,m){
    res=dig(p[i]);
    rep(j,6-res)cout << 0;
    cout << p[i];
    /*
    rep(j,p_id[p[i]].size()){
      if(p_id[p[i]][j]==y[i]){
        rep(k,6-dig(j+1))cout << 0;
        cout << j+1;
      }
    }*/
    auto pos = lower_bound(p_id[p[i]].begin(),p_id[p[i]].end(),y[i]);
    tmp=distance(p_id[p[i]].begin(),pos);
    rep(k,6-dig(tmp+1))cout << 0;
    cout << tmp+1;
    //cout << endl << "tmp:" << tmp;
    cout << endl;

  }
}


Measured memory_bytes: 8576
/*
 * AGC024_A.cpp
 *
 *  Created on: May 20, 2018
 *      Author: 13743
 */
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}



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

	lng a, b, c, k;
	cin >> a >> b >> c >> k;
	if(k%2==0) {
		cout << a-b << endl;
	}
	else {
		cout << b-a << endl;
	}
}






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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll D,N;
    string S;
    cin >> D>>N;

    if(N==100){
        N++;
    }

    if(D==0){
        cout << N << endl;
    }
    else if(D==1){
        cout << N * 100 << endl;
    }
    else{
        cout << N * 10000 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b&&b==c){
    cout << "1" << endl;
  }else if(a==b||b==c||c==a){
    cout << "2" << endl;
  }else{
    cout << "3" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#define INF 10000

int t[50002];
int mini(int x,int y){
	return (x<y)?x:y;
}
int main(void){
	int n,m,c[20],i,j;
	scanf("%d %d",&n,&m);
	for(i=0;i<m;++i){
		scanf("%d",&c[i]);
	}
	
	for(i=0;i<=n;++i){
		t[i]=INF;
	}
	t[0]=0;
	
	for(i=0;i<m;++i){
		for(j=c[i];j<=n;++j){
			t[j] = mini(t[j],t[j-c[i]]+1);
		}
	}
	printf("%d\n",t[n]);
	return 0;
}

Measured memory_bytes: 788
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
	ll T1, T2, A1, A2, B1, B2;
	cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;

	ll A = T1 * (A1 - B1);
	ll B = T2 * (A2 - B2);

	if (A < 0) { A *= -1; B *= -1; }

	if (A + B == 0) { cout << "infinity" << endl; return 0; }
	if (A + B > 0) { // 上に移動
		cout << 0 << endl;
		return 0;
	}

	ll N = A / (- A - B);

	if (N * (A + B) + A == 0) {
		cout << N * 2 << endl;
	}
	else {
		cout << N * 2 + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 384
l = map(int, raw_input().split());
ans = 0;

if (l[0] == l[1]):
	ans = l[0] + l[1];

elif(l[0] > l[1]):
	if (l[0] == 1):
		ans = l[0];
	else:
		ans = l[0] + l[0] - 1;

else:
	if (l[1] == 1):
		ans = l[1];
	else:
		ans = l[1] + l[1] - 1;

print ans;

Measured memory_bytes: 2568
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int n, a, b;

    cin >> n;

    if (n == 1) {
        cout << "Hello World" << endl;
    }
    else {
        cin >> a >> b;

        cout << a + b << endl;
    }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int N,W,w,v;
    
    cin>>N>>W;
    vector<pair<long long int,long long int>>vp;
    vp.push_back(make_pair(0,0));
    for(int i=0;i<N;i++)
    {
        cin>>w>>v;
        vp.push_back(make_pair(w,v));
    }
    long long int dp[N+1][W+1];
    for(int i=0;i<=N;i++)
        for(int j=0;j<=W;j++)
        dp[i][j]=0;
        
    sort(vp.begin(),vp.end());
    for(int i=1;i<=N;i++)
    {
        for(int j=1;j<=W;j++)
        {
           
            dp[i][j]=max(dp[i][j],dp[i][j-1]);
            if (j-vp[i].first>=0)
            dp[i][j]=max(dp[i][j],dp[i-1][j-vp[i].first]+vp[i].second);
            dp[i][j]=max(dp[i][j],dp[i-1][j]);
    
            
            
        }
        
    }

    cout<<dp[N][W];
    
    
    
    
    
   
    
}

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

#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define setbits(x) __builtin_popcount(x)
#define zerobits(x) __builtin_ctz(x)
#define setbitsll(x) __builtin_popcountll(x)
#define zerobitsll(x) __builtin_ctzll(x)
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef map<int,int> mii;

const int MOD = 1e9+7;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	cout << (1000-n%1000)%1000 << '\n';
	return 0;
}



Measured memory_bytes: 3604
// finish date: 2019/06/03

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 998244353;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    string S;
    cin >> S;
    bool isreachedA = true;
    bool isreachedB = true;
    FOR(i, A, C - 1) if ((S[i] == S[i + 1]) && (S[i + 1] == '#')) isreachedA = false;
    FOR(i, B, D - 1) if ((S[i] == S[i + 1]) && (S[i + 1] == '#')) isreachedB = false;
    bool caseCD = false;
    if (C > D) {
        FOR(i, B - 1, D) {
            if ((S[i - 1] == S[i]) && (S[i] == S[i + 1]) && (S[i + 1] == '.')) caseCD = true;
        }
    } else {
        caseCD = true;
    }
    if (isreachedA && isreachedB && caseCD) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


    return 0;
}


Measured memory_bytes: 640
n = int(input())
a = [0] * n
d = {}
ans = 0
for i in range(n):
    d[i] = []
for i in range(n):
    a[i] = int(input())
    for j in range(a[i]):
        d[i].append([int(_) for _ in input().split()])
for i in range(0, 2**n):
    fool = 'yes'
    bin_str = format(i, '0' + str(n) + 'b')
    # print(bin_str)
    res = {}
    for j in range(n):
        res[j] = bin_str[j]
    # print(res)
    for k in range(n):
        if res[k] == '1':
            for l in d[k]:
                x = l[0] - 1
                y = l[1]
                # print(x, y)
                if res[x] != str(y):
                    fool = 'no'
    # print(fool)
    if fool == 'yes':
        tem = 0
        for i in range(n):
            if res[i] == '1':
                tem += 1
        ans = max(ans, tem)
print(ans)


Measured memory_bytes: 43996
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    while True:
        n, x = map(int, input().split())
        if n==0 and x==0:
            break
        else:
            ans = 0
            for i in range(1, n-1):
                for j in range(i+1, n):
                    for k in range(j+1, n+1):
                        if i+j+k==x:
                            ans += 1
            print(ans)

if __name__ == '__main__':
    resolve()



Measured memory_bytes: 5600
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;

int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	ll n,k;
 	cin>>n>>k;
 	ll a[n];
 	bool vis[n]={false};
 	for(ll i=0;i<n;i++)
 	{
 		cin>>a[i];
 		--a[i];
 	}
 	vector<ll>cyc;
 	map<ll,ll>lvl;
 	ll cur=0;
 	ll level=0;
 	while(!vis[cur])
 	{
 		cyc.push_back(cur);
 		lvl[cur]=level++;
 		vis[cur]=true;
 		cur=a[cur];
 	}
 	ll total=cyc.size();
 	ll cyclen =total - lvl[cur];
 	//cout<<total<<" "<<cyclen<<endl;
 	if(k<cyc.size())
 	{
 		cout<<cyc[k]+1<<endl;
 	}
 	else
 	{
 		k-=lvl[cur];
 		// cout<<lvl[cur]<<endl;
 		// cout<<k<<endl;
 		k%=cyclen;
 		cout<<cyc[lvl[cur]+k]+1<<endl;
 	}
    return 0;
}

Measured memory_bytes: 18728
# https://atcoder.jp/contests/abc134/tasks/abc134_e

n = gets.to_i
b_ary = [gets.to_i]

(n-1).times do
  v = gets.to_i
  index = b_ary.bsearch_index { |x| x < v }
  if index
    b_ary[index] = v
  else
    b_ary << v
  end
end
puts b_ary.size


Measured memory_bytes: 2996
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>

using namespace std;

static const int MAX = 10000;
static const int INFTY = (1<<20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector <pair<int,int>> adj[MAX];

void dijkstra(){
    priority_queue <pair<int,int>> PQ;
    int color[MAX],d[MAX];
    for (int i=0;i<n;i++){
        d[i] = INFTY;
        color[i] = WHITE;
    }

    d[0] = 0;
    PQ.push(make_pair(0,0));
    color[0] = GRAY;

    while (!PQ.empty()){
        pair <int,int> f = PQ.top();
        PQ.pop();
        int u = f.second;
        color[u] = BLACK;

        if(d[u] <f.first * (-1)){
            continue;
        }
        for (int j=0;j<adj[u].size();j++){
            int v = adj[u][j].first;
            if(color[v] == BLACK){
                continue;
            }
            if(d[v] > d[u] + adj[u][j].second) {
                d[v] = d[u] + adj[u][j].second;

                PQ.push(make_pair(d[v] * (-1), v));
                color[v] = GRAY;
            }
        }
    }
    for (int i=0;i<n;i++){
        cout << i << " " << (d[i] == INFTY ? -1:d[i]) << endl;
    }
}

int main(){
    
    int k,u,v,c;
    cin >> n;
    for (int i=0;i<n;i++){
        cin >> u >> k;
        for (int j=0;j<k;j++){
            cin >> v >> c;
            adj[u].push_back(make_pair(v,c));
        }
    }
    dijkstra();
}


Measured memory_bytes: 8016