akhauriyash/Code-Regression huggingface dataset:
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    loop {
        let n: usize = sc.get();
        if n == 0 {
            break;
        }
        let w: Vec<i64> = sc.vec(n);
        let mut dp = vec![vec![0; n+1]; n+1];
        for l in 0..n-1 {
            let r = l + 2;
            if (w[l] - w[r-1]).abs() < 2 {
                dp[l][r] = 2;
            }
        }
        for width in 3..n+1 {
            for l in 0..n {
                let r = min(l + width, n);
                if (w[l] - w[r-1]).abs() < 2 && dp[l+1][r-1] == width-2 {
                    dp[l][r] = max(dp[l][r], width);
                }
                for i in l+1..r {
                    dp[l][r] = max(dp[l][r], dp[l][i] + dp[i][r]);
                }
            }
        }
        println!("{}", dp[0][n]);
    }
}



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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, w;
    cin >> n >> w;
    vector<array<int, 2>> a(n);
    for (auto& it : a)
        cin >> it[0] >> it[1];
    // sort(a.begin(), a.end());
    vector<long long> dp(w + 1, -1);
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = w; j >= a[i][0]; j--) {
            if (dp[j - a[i][0]] != -1) {
                dp[j] = max(dp[j], dp[j - a[i][0]] + a[i][1]);
            }
        }
    }
    cout << *max_element(dp.begin(), dp.end());
    return 0;
}

Measured memory_bytes: 3980
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> q(n);
    for (int i = 0; i < m; ++i)
    {
        int l, r;
        cin >> l >> r;
        q[l - 1]++;
        if (r < n)
        {

            q[r]--;
        }
    }
    int ct = 0;
    for (int i = 0; i < n - 1; ++i)
    {
        q[i + 1] += q[i];
        if (q[i] == m)
        {
            ++ct;
        }
    }
    cout << (q[n - 1] == m ? ct + 1 : ct) << endl;
}

Measured memory_bytes: 3780
n = int(input())
*a, = map(int, input().split())
b1 = b2 = b4 = 0
for i in a:
    if i%4==0:
        b4 += 1
    elif i%2==0:
        b2 += 1
    else:
        b1 += 1
b1 += b2>0
print('Yes' if b1<=b4+1 else 'No')

Measured memory_bytes: 15020
#include <iostream>
using namespace std;
 
int main() {
    int N;

    cin >> N;

    int ans[10100];

    for (int i = 0; i < 10100; i++) {
        ans[i] = 0;
    }

    int v;

    for (int x = 1; x <= 101; x++) {
        for (int y = 1; y <= 101; y++) {
            for (int z = 1; z <= 101; z++) {
                v = x*x + y*y + z*z + x*y + y*z + z*x;

                if (v < 10100) {
                    ans[v] += 1;
                }
            }
        }
    }

    for (int i = 1; i <= N; i++) {
        cout << ans[i] << endl;
    }
}

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

using namespace std;

int main(){
string s1,s2,s3;
cin >> s1 >> s2 >> s3;

s1[0] = toupper(s1[0]);
s2[0] = toupper(s2[0]);
s3[0] = toupper(s3[0]);

cout << s1[0] << s2[0] << s3[0] << endl;

    return 0;
}

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

int main() {
  int n;ll a, S = 0;
  cin >> n;
  map<int, ll> v;
  vector<int> A(n);
  REP(i, n) {
    cin >> A[i];
    v[A[i]]++;
  }
  for(auto p : v) {
    a = p.first;
    S += v[a] * (v[a] - 1) / 2;
  }
  REP(i, n) cout << S - v[A[i]] + 1 << endl;
}

Measured memory_bytes: 11856
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d", &n);
    int arr[n];
    double arr2[n];
    for(int i=0; i<n; i++)
        cin >> arr[i];
    sort(arr, arr+n);
    for(int i=0; i<n; i++)
        arr2[i]=(double)arr[i];
    for(int i=0; i<n; i++)
    {
        double x=(arr2[i]+arr2[i+1])/2.0;
        arr2[i+1]=x;
    }
    cout << arr2[n-1] << endl;
    return 0;
}


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

using namespace std;

using ll = long long;

const int N = 105, W = 1e5 + 5, INF = 1e9 + 5;

ll dp[N][W];

int main(){
	ios_base::sync_with_stdio(0); cin.tie();
	int n, w;	cin >> n >> w;
	for(int i = 1; i <= n; i++){
		int wi, vi;	cin >> wi >> vi;
		for(int j = 0; j < wi; j++)	dp[i][j] = dp[i - 1][j];
		for(int j = wi; j <= w; j++)	dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wi] + vi);
	}
	ll ans = 0;
	for(int i = 0; i <= w; i++)	ans = max(ans, dp[n][i]);
	cout << ans << "\n";
}


Measured memory_bytes: 81752
from heapq import *

n,m,s,t=map(int,input().split())
s-=1
t-=1
INF=10**19
Gyen=[[]for i in range(n)]
Gsnu=[[]for i in range(n)]
for i in range(m):
  u,v,a,b=map(int,input().split())
  u-=1
  v-=1
  Gyen[u].append([v,a])
  Gyen[v].append([u,a])
  Gsnu[u].append([v,b])
  Gsnu[v].append([u,b])

def dijkstra(G,s):
  d=[INF]*n
  d[s]=0
  visited={s}
  que=[(0,s)]
  while(que):
    p=heappop(que)
    v=p[1]
    visited.add(v)
    if d[v]<p[0]:
      continue

    for node,cost in G[v]:
      if (node not in visited) and d[node]>d[v]+cost:
        d[node]=d[v]+cost
        heappush(que,(d[node],node))
  return d

yen=dijkstra(Gyen,s)
snu=dijkstra(Gsnu,t)
ans=10**15
ans_list=[]
for i in reversed(range(n)):
  ans=min(ans,yen[i]+snu[i])
  ans_list.append(10**15-ans)
print(*ans_list[::-1], sep='\n')


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

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    int r = 0;
    ll sum = 0;
    ll ans = 0;
    rep(l,n){
        while(r<n && (sum+a[r])==(sum^a[r])){
            sum += a[r];
            r++;
        }
        ans += r-l;
        if(l==r)r++;
        sum -= a[l];
    }
    cout << ans << endl;
    return 0;
}

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

killed = 0
for i in range(N):
  if (A[i] + A[i + 1]) >= B[i]:
    if A[i] > B[i]:
      killed += B[i]
    else:
      killed += B[i]
      A[i + 1] -= (B[i] - A[i])
  else:
    killed += A[i] + A[i + 1]
    A[i + 1] = 0
    
print(killed)

Measured memory_bytes: 19156
#include<bits/stdc++.h>
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define show(x) std::cerr << #x << "=" << x << std::endl
using namespace std;
typedef long long ll;
const double eps=1e-8;
const int maxn = 2e5+5;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
int t;
int n,m;
int a[maxn];
    map<int,int>mp;
int factor[maxn];
bool solve(int n)
{
    if(n==1) return mp[1]==1;
    m = 0;
    for(int i=2;i<=(int)sqrt(n);++i)
    {
        if(n%i==0)
        {
            factor[++m] = i;
            if(i != n/i) factor[++m] = n/i;
        }
    }
    for(int i=1;i<=m;++i)
    {
        if(mp.count(factor[i])) return false;
    }
    if(mp.count(1)) return false;
    if(mp[n]>1) return false;
    return true;
}
int main()
{
    scanf("%d",&n);
    mp.clear();
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&a[i]);
        mp[a[i]]++;
    }
    bool bo = 0;
    int ans = 0;
    for(int i=1;i<=n;++i)
    {
        if(solve(a[i]))
        {
           ++ans;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 13864
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  100005
ll vis[N],cnt[N];
int main()
{
	ios
	ll n,m,i,j=0,x,y;
	cin>>n>>m;
	vis[1]=1;
	for(i=1;i<=n;i++)cnt[i]=1;
	for(i=0;i<m;i++){
		cin>>x>>y;
		cnt[x]--;
		cnt[y]++;
		if(vis[x])vis[y]=1;
		if(cnt[x]<=0)vis[x]=0;
	}
	for(i=1;i<=n;i++)
		if(vis[i])j++;
	cout<<j;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
long long int n,p[100005],a[100005],b[100005];
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&p[i]);
	}
	for(int i=1;i<=n;i++)
	{
		a[i]=i*20005;
		b[i]=(n-i+1)*20005;
	}
	int k=n;
	for(int i=1;i<=n;i++)
	{
		a[p[i]]-=k;
		b[p[i]]-=k;
		k--;
	}
	for(int i=1;i<=n;i++)
	{
		printf("%lld ",a[i]);
	}
	printf("\n");
	for(int i=1;i<=n;i++)
	{
		printf("%lld ",b[i]);
	}
	
	
}


Measured memory_bytes: 1152
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
#include <algorithm>
//#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
#include <math.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
//#define cocount cout << count << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define Cinint(n) int n;\
cin >> n;
#define Cinvecint(a, n) vector<int> a(n);\
for (int i = 0; i < (int)(n); i++) {\
  int num;\
  cin >> num;\
  a.at(i) = num;\
}
#define Cinstring(s) string s;\
cin >>s;

  

int main() {
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  if (s.at(0) == '3') {
    cout << "bon" << endl;
  }
  else if ((s.at(0) == '0') || (s.at(0) == '1') || (s.at(0) == '6') || (s.at(0) == '8')) {
    cout << "pon" << endl;
  }
  else {
    cout << "hon" << endl;
  }
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
template<class T> inline istream& operator >> (istream & c, vector<T> & A) {rep(i, A.size()) c >> A[i];return c;}
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

ll comb(int n, int k) {
	if (n - k < k) k = n - k;
	ll ret = 1;
	rep(i, k) ret = ret * (n - i) / (i + 1);
	return ret;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, p;
	cin >> n >> p;
	vector<int> a(n);
	cin >> a;
	int odd = 0, even = 0;
	rep(i, n) {
		if (a[i] % 2 == 0) even++;
		else odd++;
	}
	if (p == 0) {
		ll ans = 0;
		rep(i, even + 1) {
			rep(j, odd + 1) {
				if (j % 2 != 0) continue;
				ans += comb(even, i) * comb(odd, j);
			}
		}
		cout << ans << endl;
	}
	else {
		ll ans = 0;
		for (int i = 1; i <= odd; i += 2) {
			ans += comb(odd, i);
		}
		ll res = (1LL << even);
		ans *= res;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3624
N = int(input())
list1 = []
for i in range(N):
  aa = input().split()
  a = aa[0]
  b = -int(aa[1])
  xxx = [a,b,i]
  list1.append(xxx)
list1.sort()

for i in range(N):
  list1[i].append(i)

for i in range(N):
  for j in list1:
    if j[3] == i:
      print(j[2]+1)

Measured memory_bytes: 9040
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int K = scan.nextInt();
		String S = scan.next();
		String ans;

		if (S.length() <= K) {
			System.out.println(S);
		} else {
			ans = S.substring(0, K);
			ans = ans.concat("...");
			System.out.println(ans);

		}

		scan.close();

	}
}


Measured memory_bytes: 35760
#include<iostream>
#include<math.h>
using namespace std;
typedef long long ll;
inline ll keta(ll a){
   ll x=0;
	while(a>0){
       x++;
       a /= 10;
    }
  return x;
}
  ll n;
  ll ans = 20;
  ll tmp;
int main(){
  cin >> n;
  for(ll i=1;i<sqrt(n)+1;++i){
    if(n%i != 0)continue;
     ll b = n/i;
     tmp = max(keta(i),keta(b));
     if(ans > tmp) ans = tmp;
  }
  cout << ans;
}

Measured memory_bytes: 256
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N, M, X, Y = get_ints
XX = get_ints
YX = get_ints

XX.sort!
YX.sort!

x_max = XX.last
y_min = YX.min

if x_max < y_min && ([*(x_max+1)..y_min] & [*(X+1)..Y]).length > 0
  puts 'No War'
else
  puts 'War'
end


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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    int cnt[h][w] = {};
    rep(i,h) {
        vector<int> done(w);
        rep(j,w) {
            if (s[i][j] == '#') continue;
            if (done[j]) continue;
            int l = 0;
            while (j+l < w) {
                if (s[i][j+l] == '#') break;
                l++;
            }
            rep(k,l) {
                cnt[i][j+k] += l;
                done[j+k] = 1;
            }
        }
    }
    rep(j,w) {
        vector<int> done(h);
        rep(i,h) {
            if (s[i][j] == '#') continue;
            if (done[i]) continue;
            int l = 0;
            while (i+l < h) {
                if (s[i+l][j] == '#') break;
                l++;
            }
            rep(k,l) {
                cnt[i+k][j] += l;
                done[i+k] = 1;
            }
        }
    }
    int ans = 0;
    rep(i,h)rep(j,w) ans = max(ans,cnt[i][j]-1);
    cout << ans << endl;
}

Measured memory_bytes: 19968
#include <iostream>
#include <iomanip>
#include <utility>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
#include <map>
#include <climits>
#include <bitset>

#define ll long long
const ll MOD = 1e9 + 7;
const ll INF = 1 << 29;

std::vector<int> ZAlgorithm(const std::string& S)
{
    std::vector<int> Z(S.size());
    Z[0] = S.size();

    // 現在の探索位置
    auto idx = 1;

    // 一致した文字数
    auto matched = 0;

    while (idx < S.size())
    {
        // S[i]の位置から何文字がSの共通接頭辞か
        while (idx + matched < S.size() && S[matched] == S[idx + matched])
            matched++;

        Z[idx] = matched;

        if (matched == 0)
        {
            idx++;
            continue;
        }

        // 一致した分だけ既存のZ値をコピーできる
        // ただし k + Z[k] が 一致した文字数 j 以上になると Z[i+k] = Z[k] が成り立たなくなる可能性がある
        auto k = 1;
        while (k + Z[k] < matched)
        {
            Z[idx + k] = Z[k];
            k++;
        }

        // コピーした分を飛ばす
        idx += k;
        matched -= k;
    }

//    for (auto z : Z)
//        std::cout << z << std::endl;

    return Z;
}

int main()
{
    std::ios::sync_with_stdio(false);

    ll N;
    std::string S;
    std::cin >> N >> S;

    auto result = 0;
    for (auto i=0; i<N; ++i)
    {
        auto subStr = S.substr(i, N - i);
        auto zResult = ZAlgorithm(subStr);

        //j文字目までの最長共通接頭辞
        for (auto j=0; j < subStr.size(); ++j)
            result = std::max(result, std::min(j, zResult[j]));
    }

    std::cout << result << std::endl;
}


Measured memory_bytes: 3704
using System;
using System.Collections;
using System.Collections.Generic;
 
class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		while(true){
			var d=ria();
			int N=d[0];int P=d[1];
			if(N==0 && P==0)return;
			int[] A=new int[N];
			int ptr=0;
			int p=P;
			while(true){
				if(p>0){
					p--;
					A[ptr]++;
					if(A[ptr]==P){
						Console.WriteLine(ptr);
						break;
					}
				}else{
					p=A[ptr];
					A[ptr]=0;
				}
				ptr++;
				if(ptr==N)ptr-=N;
			}
		}
		
	}

	public Sol(){
	}




	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}

Measured memory_bytes: 5644
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();
        int sum = (x - 2 * z) / (y + z);
        if ((x - 2 * z) - sum * (y + z) >= y)
            System.out.println(sum + 1);
        else
            System.out.println(sum);

    }
}


Measured memory_bytes: 21844
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a %2 == 0 && a == b && b == c) {
            System.out.println(-1);
            return;
        }

        int count = 0;
        while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
            int disA = a / 2;
            int disB = b / 2;
            int disC = c / 2;
            a = disB + disC;
            b = disA + disC;
            c = disB + disA;
            count++;
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 23124
import sys 

sys.setrecursionlimit(10**6)

N, M = map(int, input().split())
G = [list(map(int, input().split())) for _ in range(M)]
visited = [True if v == 0 else False for v in range(N)]
adj = {i+1:[] for i in range(N)}

# init
for g in G:
  adj[g[0]].append(g[1])
  adj[g[1]].append(g[0])
  
def dfs(adj, visited, x):
  if all(visited):
    return 1
  count = 0
  for v in adj[x]:
    if visited[v-1]:
      continue
    visited[v-1] = True
    count += dfs(adj, visited, v)
    visited[v-1] = False
  return count

print(dfs(adj, visited, 1))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>

using namespace std;

#define li long long int
#define FOR(i, a, b) for (li (i) = (a) ; (i) < (b) ; ++(i))
#define REP(i, n) FOR(i, 0, n)

int main(void) {
    li N;
    string S;

    cin >> N >> S;

    char increment = 'I';
    char decrement = 'D';

    li x = 0;
    li maxNum = 0;
    FOR(i, 0, S.size()) {
        if (S[i] == increment) {
            x += 1;
            maxNum = max(x, maxNum);
        } else {
            x -= 1;
        }
    }
    cout << maxNum;

    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<unordered_set>
#include<vector>

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]
#define GI(name) int (name);scanf("%d",&(name))
#define GI2(name1,name2) int (name1),(name2);scanf("%d %d",&(name1),&(name2))
#define GI3(name1,name2,name3) int (name1),(name2),(name3);scanf("%d %d %d",&(name1),&(name2),&(name3))
#define GVI(name,size) vector<int> (name)(size);FOR(i,(size))scanf("%d",&(name)[i])
#define MOD 1000000007

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=n;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug_print(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug_print(Head head,Tail... tail){
    cerr<<to_string(head)<<" ";
    debug_print(tail...);
}

template<class... T>
void debug(T... args){
    cerr<<"["<<__LINE__<<"]: ";
    debug_print(args...);
}

void print(){
    cout<<endl;
}

template<class Head,class... Tail>
void print(Head head,Tail... tail){
    cout<<to_string(head);
    print(tail...);
}

int main(){
    GI3(X,A,B);
    print((X-A)%B);
    return 0;
}

Measured memory_bytes: 256
/*痛みを受け取れ，痛みを知れ*/
#include<bits/stdc++.h>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 1000007;
const int inf = 0x3f3f3f3f;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const int N = 6e5 + 5;

int main()
{
	//freopen("in.txt", "r", stdin);
	int n;
	ll a, b;
	while (cin >> a >> b)
	{
		cout << a * b / gcd(a, b) << endl;
	}
	return 0;
}


Measured memory_bytes: 3600
#include <iostream>

using namespace std;

const int maxn = 1e3 + 10;
const int MOD = 1e9+7;

int n , m , x = -1;
char a[maxn][maxn];
long long dp[maxn][maxn];

int main() {
    cin >> n >> m;
    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++)
        if (a[0][i] == '#') {
            x = i;
            break;
        }
    if (x == -1)
        for (int i = 0; i < m; i++)
            dp[0][i] = 1;
    else
        for (int i = 0; i < x; i++)
            dp[0][i] = 1;
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (a[i][j] == '#'){
                continue;
            }
            if (j == 0)
                dp[i][j] = dp[i-1][j] % MOD;
            else{
                dp[i][j] = dp[i-1][j] % MOD;
                dp[i][j] = (dp[i][j] + dp[i][j-1]) % MOD;
            }
            //cout << dp[i][j] << " ";
        }
    }
    cout << dp[n-1][m-1] << endl;
    return 0;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1e18)
#define MOD (1000000007)

/////////////////////////////////////////////////////////

void Main(){
  int N, M; cin >> N >> M;
  if(abs(N - M) > 1){
    cout << 0 << endl;
    return;
  }
  ll res = 1;
  rep(i, 1, N + 1){
    res *= i;
    res %= MOD;
  }
  rep(i, 1, M + 1){
    res *= i;
    res %= MOD;
  }
  if(N == M){
    res *= 2;
    res %= MOD;
  }
  cout << res << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

using graph = vector<vector<ll>>;
pair<pair<ll,ll>,ll> p[100010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,a,b;
    cin>>n>>a>>b;
    if(a>b){
        cout<<0<<endl;
        return 0;
    }
    if(n==1){
        if(a==b) cout<<1<<endl;
        else cout<<0<<endl;
        return 0;
    }
    cout<<(b-a)*(n-2)+1<<endl;
    return 0;
}

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

bool check(int n){
    set<int> s;
    while(n){
        s.insert(n%10);
        n/=10;
    }
    return s.size() == 1;
}

signed main(){

    int n;  cin >> n;

    for(int x=n; ; x++){
        if(check(x)){
            cout << x;
            return 0;
        }
    }
    


    return 0;
}

Measured memory_bytes: 256
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr ll INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld PI = acos(-1);
constexpr ld EPS = 1e-11;

int main(void){
	ll n, m;
	cin >> n >> m;
	ll ans = 0;

	ans += n * (n - 1) / 2;
	ans += m * (m - 1) / 2;
	co(ans);

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,f[1000][1000];
int main(){
	scanf("%d",&m); n=2;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j){
			int x; scanf("%d",&x);
			f[i][j]=max(f[i-1][j],f[i][j-1])+x;
		}
	printf("%d",f[n][m]);
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
	int n;
	int min = 9999999;
	int sa, sum, tmp;

	scanf("%d", &n);
	for (int i = 1; i <= n / 2; i++) {
		sum = 0;
		sa = n - i;
		while (sa > 0) {
			sum += sa % 10;
			sa /= 10;
		}
		tmp = i;
		while (tmp > 0) {
			sum += tmp % 10;
			tmp /= 10;
		}
		if (min > sum) {
			min = sum;
		}
	}
	printf("%d\n", min);
	return 0;
}

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

using namespace std;

int main()
{
    #ifdef LOCAL_EXEC
    #else
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #endif // LOCAL_EXEC
    long long int n,i,j,k,x=0,sum=0;
    map<long long int,long long int>mt;
    cin>>n;
    long long int A[n+1];
    for(i=1;i<=n;i++){
        cin>>A[i];
    }
    for(i=1;i<=n;i++){
        sum+=max(0ll,x-A[i]);
        x=max(x,A[i]);
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 5172
#include <stdio.h>

int main(void) {
  int  N;
  int a, b, c;
  int t;

  scanf("%d", &N);

  while (N--) {
    scanf("%d %d %d", &a, &b, &c);
    
    if (a > b) {
      t = a;
      a = b;
      b = t;
    }
    if (b > c) {
      t = b;
      b = c;
      c = t;
    }
    if (a > b) {
      t = a;
      a = b;
      b = t;
    }

    if(a * a + b * b == c * c)
      printf("YES\n");
    else
      printf("NO\n");
  }

  return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
	int main()
	{
		int a[105],i;
		int n,cnt1=0,cnt2=0;
		cin>>n;
		for(i=0;i<n;i++)
		{
			cin>>a[i];
			if(a[i]%2==0)
			{
				cnt1++;
				if(a[i]%3==0 || a[i]%5==0)
				{
					cnt2++;
				}
			}
		}
		if(cnt1==cnt2)
			cout<<"APPROVED"<<endl;
		else
			cout<<"DENIED"<<endl;
		return 0;
	}

Measured memory_bytes: 256
#AtCorder Beginner Contest 085  C Otoshidama
n, y = map(int, input().split())

a = -1
b = -1
c = -1

for i in range(n + 1):
    if 10000*i == y and i == n:
        a = i
        b = 0
        c = 0
        break
    else:
        for j in range(n - i + 1):
            if i+j == n and 10000*i + 5000*j == y:
                a = i
                b = j
                c = 0
                break
            elif 10000*i + 5000*j + 1000*(n - i -j) == y:
                a = i
                b = j
                c = n - i - j
                break


print(str(a) + " " + str(b) + " " + str(c))

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
	int n,f=0,i,g=0;
	scanf("%d",&n);
	if(n<105)printf("0\n");
	else
	{
		for(i=105;i<=n;i=i+2)
		{
			f=0;
			for(int j=1;j<=i;j++)
			{
				if(i%j==0)f++;
			}
			if(f==8)g++;
		}
		printf("%d\n",g);
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a,b,sum;
  int i;

  while(scanf("%d %d",&a,&b)!=EOF){
    sum=a+b;
    for(i=0;sum!=0;i++){
      sum/=10;
    }
    printf("%d\n",i);
  
}
return 0;

}

Measured memory_bytes: 600
#include <iostream>
#include <bits/stdc++.h>
#define ll long long

using namespace std;
int n,k;
vector < int > v;

int main()
{
    cin >> n >> k;
    string s;  cin >> s;
    int p1 = 0 , p2 = 0;
    bool one = false;
    int Ans = 0;
    while(p1 < s.size()){
        if(s[p1] == '1')  p1++ , one = true;
        else if(s[p1] == '0' && (k || !one))  {
                if(one || !p1)  k--;
                p1++ , one = false;
        }
        else {
            if(s[p2] == '1')  p2++;
            else  {
                while(s[p2] == '0')  p2++;
                k++;
            }
        }
        Ans = max(Ans , p1 - p2);
    }
    cout << Ans;
    return 0;
}


Measured memory_bytes: 512
while 1:
    n,w = map(int,raw_input().split())
    if n == 0: break
    v = [0.]*11
    m = 0
    for i in range(n):
        p = int(raw_input())/w
        v[p] += 1.
        m = max(m,p)
    vm = max(v)
    ans = 0.01+sum((v[i]/vm)*(1-i*1.0/m) for i in range(m))
    print ans

Measured memory_bytes: 4256
#include<iostream>
using namespace std;
int fabs(int x){
    if(x<0) return -x;
    return x;
}
int main(){
    int n; cin>>n;
    int data[1001];
    for(int i=1;i<=n;++i) cin>>data[i];
    int maxv=0,minv=1000000000;
    for(int i=1;i<=2000;++i){
	maxv=0;
	for(int j=1;j<=n;++j)
	    maxv=max(maxv,fabs(i-data[j]));
	minv=min(minv,maxv);
    }
    cout<<minv<<endl;
    return 0;
}


Measured memory_bytes: 3112
#include <string>
#include <vector>
#include <iostream>
using namespace std;
const int mod = 1000000007;
int main() {
	string S;
	cin >> S;
	vector<int> dp(13);
	dp[0] = 1;
	for (char ch : S) {
		vector<int> ndp(13);
		for (int i = 0; i < 13; ++i) {
			for (int j = 0; j < 10; ++j) {
				if (ch == '?' || ch == char(j + '0')) {
					ndp[(10 * i + j) % 13] += dp[i];
					if (ndp[(10 * i + j) % 13] >= mod) ndp[(10 * i + j) % 13] -= mod;
				}
			}
		}
		dp = ndp;
	}
	cout << dp[5] << endl;
	return 0;
}

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

int main(void) {
  int n, m;
  cin >> n >> m;
  if (n == m) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product
from bisect import bisect_left, bisect_right
def inpl(): return list(map(int, input().split()))


N, K = map(int, input().split())
x = inpl()

all_time = []
for ind in range(N-K+1):
    l = x[ind]
    r = x[ind+K-1]
    all_time.append(min(abs(l)+abs(r-l), abs(r)+abs(l-r)))

print(min(all_time))

Measured memory_bytes: 23084
#include<iostream>

using namespace std;

int main(){
  long long a,b; cin >> a >> b;
  
  if( a > 0 && b > 0){ cout << "Positive" << endl;}
  else if( a < 0 && b < 0){
    if( abs( a - b ) % 2 == 0){ cout << "Negative" << endl;}
    else{ cout << "Positive" << endl;}
  }
  else{cout << "Zero" << endl;}
  
  return 0;}

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

int main() {
    int n,k;
    cin >> n >> k;
    long long ar[n];
    long long ans[n];
    
    
    for (int i=0;i<n;i++){
        cin >> ar[i];
        ans[i]=100000000000;
    }
    
    ans[0]=0;
    ans[1]=abs(ar[1]-ar[0]);
    
    for (int i=2;i<n;i++){
        for (int j=1;j<=min(k,i);j++)
            ans[i]=min(ans[i],ans[i-j]+abs(ar[i]-ar[i-j]));
    }
    
   // cout << 1;
    cout << ans[n-1] << endl;
    return 0;
}

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

// {{{
#define PI pair<int, int>
#define mk make_pair
#define reg register
#define ll long long
#define rep(i, a, b) for(reg int i = a; i <= b; ++i)
#define per(i, a, b) for(reg int i = a; i >= b; --i)
// }}}

using namespace std;

inline int min(reg int a, reg int b) { return a < b ? a : b; }
inline int max(reg int a, reg int b) { return a > b ? a : b; }
inline int read() {
  reg int s = 0; reg char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
  return s;
}

int main() {
  ll n = read(), m = read(), x = read(), y = read();
  long double S = 1.0 * n * m / 2;
  long double midx = 1.0 * n / 2, midy = 1.0 * m / 2;
  int res = 0;
  if (1.0 * x == midx && 1.0 * y == midy) res = 1;
  printf("%Lf %d\n", S, res);
  return 0; 
}


/*******************************************
 _________________________________________
< C.cpp is created by zrz who is weak >
 -----------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
********************************************/

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
struct segtree{
private:
  int siz;
  vector<ll> node,lazy;
  ll seg_inf;
public:
  segtree(ll n){
    siz=1;
    while(siz<=n) siz*=2;
    node.resize(siz*2-1,0);
    lazy.resize(siz*2-1,0);
    seg_inf=17441744174417;
  }
  void eval(ll k){
    node[k]+=lazy[k];
    if(k<siz-1){
      lazy[2*k+1]+=lazy[k];
      lazy[2*k+2]+=lazy[k];
    }
    lazy[k]=0;
  }
  void plus(ll a,ll b,ll x,ll k,ll l,ll r){
    eval(k);
    if(r<=a||b<=l) return;
    if(a<=l&&r<=b){
      lazy[k]+=x;
      eval(k);
    }
    else{
      plus(a,b,x,2*k+1,l,(l+r)/2);
      plus(a,b,x,2*k+2,(l+r)/2,r);
      node[k]=min(node[2*k+1],node[2*k+2]);
    }
  }
  void add(ll a,ll b,ll x){
    plus(a,b,x,0,0,siz);
  }
  ll get_min(ll a,ll b,ll k,ll l,ll r){
    eval(k);
    if(r<=a||b<=l) return seg_inf;
    if(a<=l&&r<=b) return node[k];
    else return min(get_min(a,b,2*k+1,l,(l+r)/2),get_min(a,b,2*k+2,(l+r)/2,r));
  }
  ll min_q(ll s,ll t){
    return get_min(s,t,0,0,siz);
  }
  void debug(int f){
    if(f==0){
      cout<<"node:";
      for(int i=0;i<node.size();i++) cout<<node[i]<<" ";
    }
    else{
      cout<<"lazy:";
      for(int i=0;i<lazy.size();i++) cout<<lazy[i]<<" ";
    }
    cout<<endl;
  }
};
int main(){
  ll n,d,a;
  cin>>n>>d>>a;
  vector<P> comp;
  vector<P> vec;
  for(int i=1;i<=n;i++){
    ll x,h;
    cin>>x>>h;
    vec.push_back(P(x,h));
  }
  vec.push_back(P(1744174417441744,0));
  sort(vec.begin(),vec.end());

  ll ans=0;
  vector<ll> atacked;
  vector<ll> rsum;
  atacked.push_back(-999999999999);
  rsum.push_back(0);
  for(int i=0;i<n;i++){
    ll xi=vec[i].first,hi=vec[i].second;
    ll lb=lower_bound(atacked.begin(),atacked.end(),xi-d)-atacked.begin();
    ll zan=rsum[rsum.size()-1]-rsum[lb-1];
    hi-=zan;

    if(hi>0){
      ll mns=(hi+a-1)/a;
      ans+=mns;
      atacked.push_back(xi+d);
      rsum.push_back(rsum[rsum.size()-1]+mns*a);
    }
  }
  cout<<ans<<endl;
}


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



int main()
{
    int a,b,i,j=0;
    cin>>a>>b;
    char s[100];
    cin>>s;
    if(s[a]!='-')
    {
        cout<<"No";return 0;
    }

        for(i=0;i<strlen(s);i++)
        {   if(i==a)continue;
            if((s[i]-'0')>=0 && (s[i]-'0')<=9)
            {
                j++;
            }
        }

    if(j==a+b)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";return 0;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int X; cin >> X; int A[X+1]={};
A[100]=A[101]=A[102]=A[103]=A[104]=A[105]=1;
for(int i=200; i<=X; i++){
if(A[i-100]||A[i-101]||A[i-102]||A[i-103]||A[i-104]||A[i-105]){A[i]=1;}
}
cout << A[X] << "\n";
}

Measured memory_bytes: 640
#include<iostream> 
using namespace std; 
int main(){ 
  int h,n,s=0; 
  cin>>h>>n;
  int a[n]; 
  for(int i=0;i<n;i++) {
    cin>>a[i]; 
    s+=a[i]; 
  } 

  if(s>=h)
    cout<<"Yes"<<endl; 
  else 
    cout<<"No"<<endl; 
  }
  


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int n, k, x, y; cin >> n >> k >> x >> y;
    if(n <= k) cout << n * x << endl;
    else cout << k * x + (n-k) * y << endl;
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

/*
必ず三角形に分割される
*/
long long max(long long a,long long b){
    if(a>b){
        return a;
    }else{
        return b;
    }
}

int main(void){
    long long n,x;
    scanf("%lld %lld",&n,&x);
    long long counter = 0;
    long long len1,len2,val;
    counter += n;
    len1 = n-max(x,n-x);
    len2 = max(x,n-x);
    while(1){
            if(len2%len1 == 0){
                counter +=(len2/len1)*2*len1 - len1;
                break;
            }else{
                counter +=(len2/len1)*2*len1;
                val = len1;
                len1 = len2 - (len2/len1)*len1;
                len2 = val;
            }
    }
    printf("%lld\n",counter);


    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <list>
#include <set>
using namespace  std;

#define int long long int

constexpr int INF = std::numeric_limits<int>::max();
constexpr int MAGIC = 753;

int ctoi(char c) {
    return c - '0';
}

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

    string s;
    cin >> s;

    int a = ctoi(s[0]) * 100 + ctoi(s[1]) * 10 + ctoi(s[2]);
    int ans = abs(MAGIC - a);
    for (int i = 3; i < s.size(); i++) {
        a = (a % 100) * 10 + ctoi(s[i]);
        ans = min(ans, abs(MAGIC - a));
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/* 変数名を被らせない
   デバッグコードを取り除く 
　　提出する問題を間違えない */
#define ANSWER(x) cout<<x<<endl
#define debug(x) cout<<#x<<": "<<x
int main(){
  bool ball[3] = {true,false,false};
  char receive[3];
  while(1){
    cin >> receive;
    if(cin.eof())break;
    swap(ball[receive[0]-'A'],ball[receive[2]-'A']);
  }
  for(int i=0;i<3;i++){
    if(ball[i])cout << (char)(i+'A') << endl;
  }
}

Measured memory_bytes: 1136
def main():
    import math
    import sys

    input = sys.stdin.readline

    n = int(input())
    c = 0
    for i in range(n):
        if (i+1) % 3 == 0:
            continue
        elif (i+1) % 5 == 0:
            continue
        else:
            c += i+1
    print(c)


if __name__ == '__main__':
    main()

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define FILL(c, v) fill((c).begin(),(c).end(), v)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long LL;
typedef unsigned long long ULL;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
int gcd(int a,int b){return b ? gcd(b, a%b) : a;}

void solve()
{
  LL A, B; cin >> A >> B;
  cout << A*B/gcd(A, B);
}

int main(int argc, char const *argv[])
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout<<std::fixed<<std::setprecision(10);
  solve();
  return 0;
}

Measured memory_bytes: 256