akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main()
{
	int n, t[101], v[101];
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> t[i];
	for (int i = 0; i < n; i++)
		cin >> v[i];
	t[n] = 1, v[n] = 0;
	int x = 1, s = 0, d = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < t[i] * 2; j++, x++) {
			int m = 10000;
			for (int k = 0, T = 0; k <= n; T += t[k++]) {
				int l = k == i ? v[k] * 2 : k < i ? v[k] * 2 + x - T * 2 - t[k] * 2 : v[k] * 2 - x + T * 2;
				if (l < m) m = l;
			}
			if (m == s)
				d += s * 2;
			else if (m < s)
				d += s * 2 - 1, s--;
			else
				d += s * 2 + 1, s++;
		}
	}
	cout.precision(18);
	cout << d / 8. << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>

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

using namespace std;
using ll = long long;
#define max(a,b) a > b ? a : b
#define min(a,b) a < b ? a : b

const int mod = 1e9+7;

ll gcd(ll x,ll y){
    ll M,m;
    M = max(x,y);
    m = min(x,y);
    if(m == 0) return M;
    return gcd(m, M % m);
}

ll lcm(ll x,ll y){
    return x / gcd(x,y) * y;
}

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll cnt_c,cnt_d,cnt_cd;
    cnt_c = (b/c) - (a/c);
    if(a%c==0)cnt_c++;
    
    cnt_d = (b/d) - (a/d);
    if(a%d==0)cnt_d++;
    
    ll lcm_cd = lcm(c,d);
    cnt_cd = (b/lcm_cd) - (a/lcm_cd);
    if(a%lcm_cd==0)cnt_cd++;
    
    ll ans = (b-a+1) - cnt_c - cnt_d + cnt_cd;
    
    cout << ans << endl;
    return 0;
}


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

using namespace std;

vector<long long> accum[2];
int N[2];

int main(void)
{
    long long tmp, prev = 0LL, K;
    scanf("%d %d %lld", &N[0], &N[1], &K);
    accum[0].resize(N[0]);
    accum[1].resize(N[1]);
    for(int a = 0; a < 2; a++) {
        prev = 0;
        for(int i = 0; i < N[a]; i++) {
            scanf("%lld", &tmp);
            prev += tmp;
            accum[a][i] = prev;
        }
    }
    
    auto other = upper_bound(accum[1].begin(), accum[1].end(), K);
    int ans = other - accum[1].begin(), possible;
    for(int i = 0; i < N[0]; i++)
    {
        if(accum[0][i] > K) break;

        auto other = upper_bound(accum[1].begin(), accum[1].end(), K - accum[0][i]);
        possible = other - accum[1].begin();
        ans = max(ans, i + 1 + possible);
    }

    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 5868
N = int(input())
A = input()
B = input()
C = input()

ans = 0
for i in range(N):
    if A[i] == B[i]:
        if B[i] == C[i]:
            pass
        else:
            ans += 1
    else:
        if B[i] == C[i]:
            ans += 1
        elif A[i] == C[i]:
            ans += 1
        else:
            ans += 2

print(ans)

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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

  int N;
  cin >> N;
  vector<ll> v1(N);
  vector<ll> v2(N);
  ll ans;
  rep (i, N) {
    cin >> v1[i] >> v2[i];
  }
  sort(all(v1));
  sort(all(v2));
  if (N % 2) {
    int t = (N-1)/2;
    ans = v2[t]-v1[t]+1;
  }
  else {
    int t1 = N/2-1;
    int t2 = N/2;
    ans = v2[t1]+v2[t2]-v1[t1]-v1[t2]+1;
  }
  cout << ans << endl;
}


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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,N,j) for(int i = (N-1);i >= (j);i--)
#define _rec(i,N,j) for(int i = (N);i >=(j);i--)
#define ALL(x) x.begin(),x.end()
#define MEM(a,n) memset(a,n,sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define PTR2(a,j,N,k,L) for(int i = (j); i <= (N);i++) see(a[i],k,L);

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

int get_int(){int x;scanf("%d",&x);return x;}
LL get_ll(){LL x;scanf("%lld",&x);return x;}
double get_db(){double x;scanf("%lf",&x);return x;}

template<typename T> int chmin(T &a,T b){if(a > b){a = b;return 1;}else return 0;}
template<typename T> int chmax(T &a,T b){if(a < b){a = b;return 1;}else return 0;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {_for(i,0,v.size()) os << v[i] << " ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){for(auto a:v) os << a <<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){os << v.fst <<" "<<v.scd << " ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& v){for(auto a:v) cout << a << endl;return os;}
template<typename T> void see(T a[],int from,int to){ _rep(i,from,to) cout << a[i]<<" ";cout << endl;}

static const int dx[8] = { -1,  0, 1, 0,  1, -1,  1, -1};
static const int dy[8] = {0,  1, 0,  -1,  1, -1, -1,  1};
const double pi  = acos(-1.0);
const double eps = 1e-8;
const LL  INF  = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;

map<pll,int> mp;

pll depo(LL i){
    LL a = i%10;
    while(i/10){
        i/=10;
    }
    return MP(i,a);
}

int main()
{
    int N;
    cin >> N;
    _rep(i,1,N){
        pll k = depo(i);
        mp[k]++;
    }
    LL ans = 0;
    for(auto a:mp){
        pll n = MP(a.first.second,a.first.first);
        ans += a.second * mp[n];
    }
    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
std::string a,b;
int main()
{
	std::getline(std::cin,a);
	std::getline(std::cin,b);
	std::sort(a.begin(),a.end());
	std::sort(b.begin(),b.end(),std::greater<char>());
	puts(a<b?"Yes":"No");
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
using namespace std;
int main()
{
	int n, a;
	cin >> n >> a;

  	n %= 500;
  	if(a>=n){
		cout << "Yes" << endl;
    }else{
		cout << "No" << endl;
    }
	return 0;
}

Measured memory_bytes: 256
/*{{{*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
using namespace std;
typedef pair<int, int> PP;
typedef long long LL;
#define pb push_back
#define fr first
#define sc second
#define bitcnt __builtin_popcount
#define all(x) x.begin(), x.end()
inline int ri() {int x; scanf("%d", &x); return x;}
#define rep2(i, n, ...) for (int i = 0; i < (n); i ++) 
#define rep3(i, a, b, ...) for (int i = (a); i < (b); i ++)
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define drep2(i, n, ...) for (int i = (n) - 1; i >= 0; i --)
#define drep3(i, a, b) for (int i = (a) - 1; i >= (b); i --)
#define drep(...) GET_MACRO(__VA_ARGS__, drep3, drep2)(__VA_ARGS__)
template<typename T>inline bool smax(T&a, T b){if(a<b){a=b;return true;}return false;} 
template<typename T>inline bool smin(T&a, T b){if(a>b){a=b;return true;}return false;} 
/*}}}*/


int p[500 * 500], a[500], n, m;
void no() {
  cout << "No" << endl;
  exit(0);
}
int main() {
  #ifdef _TEST_
  freopen("input.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
  #endif

  cin >> n; m = n * n;
  rep(i, n) cin >> a[i], p[-- a[i]] = i + 1;
  vector<int> v;
  rep(i, m) if (p[i] != 0) a[v.size()] = i, v.pb(p[i]);
  //cout << v.size() << endl;
  for (int i = 0, c = 0; c < n; c ++) {
    for (int j = v[c] - 1; j > 0 && i < m; i ++) {
      if (i >= a[c]) no();
      if (p[i] == 0) {
        p[i] = v[c]; j --;
      }
    }
  }
  //rep(i, m) cout << p[i] << ' '; cout << endl;
  for (int i = m - 1, c = n - 1; c >= 0; c --) {
    for (int j = (n - v[c]); j > 0 && i >= 0; i --) {
      if (i <= a[c]) no(); 
      if (p[i] == 0) {
        p[i] = v[c]; j --;
      }
    }
  }
  cout << "Yes" << endl;
  rep(i, m) cout << p[i] << ' '; cout << endl;
  return 0;
}


Measured memory_bytes: 2176
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

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

using namespace std;

bool solve(vector<int> X,int tar,bool first){
	bool dp[2][20000]={};
	int from=0,to=1;
	dp[from][10000]=true;
	for(int a:X){
		rep(i,20000) if(0<=i+a && i+a<20000 && dp[from][i]) dp[to][i+a]=true;
		if(!first){
			rep(i,20000) if(0<=i-a && i-a<20000 && dp[from][i]) dp[to][i-a]=true;
		}
		first=false;
		fill(dp[from],dp[from]+20000,false);
		swap(from,to);
	}
	return dp[from][tar+10000];
}

int main(){
	string s;
	int tx,ty;
	cin>>s>>tx>>ty;
	s+='T';
	int n=s.length();

	int pre=0;
	bool par=true;
	vector<int> X,Y;
	rep(i,n) if(s[i]=='T') {
		if(par) X.emplace_back(i-pre);
		else    Y.emplace_back(i-pre);
		pre=i+1;
		par=!par;
	}

	cout<<(solve(X,tx,true)&&solve(Y,ty,false)?"Yes":"No")<<endl;

	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define N 510
int n,c,a[N],ct;
double r,f[N][(1<<7)];
int main(){
	cin>>n>>c;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	do{
		memset(f,0,sizeof(f));
		f[a[n-1]*n][0]=1;
		for(int i=0;i<=n*c;i++)
			for(int j=i;j<=n*c;j++)
				for(int s=0;s<(1<<(n-1));s++)
					if(i%n&&!(s&(1<<(i%n-1)))&&f[j][s]){
						f[min(n*c,max(j,i+a[i%n-1]*n))][s+(1<<(i%n-1))]+=f[j][s];
					}
		r+=f[n*c][(1<<(n-1))-1];
		ct++;
	}while(next_permutation(a,a+n-1));
	printf("%.15lf",(double)r/ct/pow(c,n-1));
}

Measured memory_bytes: 768
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		String k = in.next();
		int d = in.nextInt();
		long r = solve(k, d);
		System.out.println(r);
		in.close();
	}

	private static long solve(String k, int d) {
		int l = k.length();
		long[][] dp = new long[l + 1][d];
		dp[0][0] = 1;
		for (int i = 1; i <= l; i++) {
			for (int j = 0; j < d; j++) {
				for (int m = 0; m < 10; m++) {
					dp[i][j] = add(dp[i][j], dp[i - 1][(j + d - m % d) % d]);
				}
			}
		}
		long r = 0;
		int offset = 0;
		for (int i = 0; i < l; i++) {
			int v = Integer.parseInt(k.charAt(i) + "");
			for (int j = 0; j < v; j++) {
				r = add(r, dp[l - i - 1][(d - (j + offset) % d) % d]);
			}
			offset = (offset + v) % d;
		}
		if (offset == 0) {
			return r;
		} else {
			return add(r, -1);
		}

	}

	static long mod = 1000000007;

	static long add(long a, long b) {
		long r = a + b;
		if (r < 0) {
			r += mod;
		}
		return r % mod;
	}

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

	static String str(int[] a) {
		String[] str = new String[a.length];
		for (int i = 0; i < a.length; i++) {
			str[i] = a[i] + "";
		}
		return String.join(" ", str);
	}

	static int[] getIntArr(Scanner in, int size) {
		int[] arr = new int[size];
		for (int i = 0; i < size; i++) {
			arr[i] = in.nextInt();
		}
		return arr;
	}

	static int[][] getIntArr(Scanner in, int row, int col) {
		int[][] arr = new int[row][];
		for (int i = 0; i < row; i++) {
			arr[i] = getIntArr(in, col);
		}
		return arr;
	}

	static char[] getCharArr(Scanner in, int size) {
		char[] arr = in.next().toCharArray();
		return arr;
	}

	static String[] getStringArr(Scanner in, int size) {
		String[] arr = new String[size];
		for (int i = 0; i < size; i++) {
			arr[i] = in.next();
		}
		return arr;
	}

	static Map<Integer, List<Integer>> getEdges(Scanner in, int size, boolean directed) {
		Map<Integer, List<Integer>> edges = new HashMap<>();
		for (int i = 0; i < size; i++) {
			int from = in.nextInt();
			int to = in.nextInt();
			if (!edges.containsKey(from)) {
				edges.put(from, new ArrayList<Integer>());
			}
			edges.get(from).add(to);
			if (!directed) {
				if (!edges.containsKey(to)) {
					edges.put(to, new ArrayList<Integer>());
				}
				edges.get(to).add(from);
			}

		}
		return edges;
	}
}


Measured memory_bytes: 30796
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int N, X;
    cin >> N >> X;

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

    int x = 0;
    int count = 1;
    for(int i = 0; i < N; i++){
        x += l[i];
        if(x <= X){
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  int a, b, c;
  cin >> a >> b >> c;

  int x = a - b;
  int ans = c - x;
  cout << (ans >= 0 ? ans : 0) << "\n";

  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

'''
4
10 30 40 20
'''

N = int(input())
h = list(map(int, input().split()))

dp = [None] * N

dp[0] = 0
dp[1] = abs(h[0] - h[1])

for i in range(2, N):
    dp[i] = min(dp[i-2] + abs(h[i]-h[i-2]),
                    # dp[i-2] + abs(h[i]-h[i-2]) + abs(h[i]-h[i-1])),
                dp[i-1] + abs(h[i]-h[i-1]))

print(dp[N-1])


Measured memory_bytes: 52208
// inputに入力データ全体が入る
function Main(input) {
  var a,b,c,d,e,k;
  a = Number(input.split('\n')[0]);
  b = Number(input.split('\n')[1]);
  c = Number(input.split('\n')[2]);
  d = Number(input.split('\n')[3]);
  e = Number(input.split('\n')[4]);
  k = Number(input.split('\n')[5]);

  if(Math.max(e-a,e-b,d-a,e-c,d-b,c-a,e-d,d-c,c-b,b-a) > k){
    console.log(':(');
  }else{
    console.log('Yay!');
  }
  
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
if __name__ == '__main__':
    h, w = map(int, input().split())
    cost_graph = []
    field = []
    for i in range(10):
        cost_graph.append(list(map(int, input().split())))

    for i in range(h):
        field.append(list(map(int, input().split())))

    for k in range(10):
        for i in range(10):
            for j in range(10):
                cost_graph[i][j] = min(cost_graph[i][j], cost_graph[i][k] + cost_graph[k][j])

    ans = 0
    for y in range(h):
        for x in range(w):
            if field[y][x] == -1 or field[y][x] == 1:
                pass
            else:
                ans += cost_graph[field[y][x]][1]

    print(ans)


Measured memory_bytes: 3444
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<unordered_set>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 5 * 1000 * 100 + 47;

int A[MAX];
int H[MAX];
vector<int> g[MAX];
int res = 0;
int n, k;

void dfs(int v, int d)
{
	H[v] = 0;
	FOR(i, 0, SZ(g[v]))
	{
		int to = g[v][i];
		dfs(to, d + 1);
		H[v] = max(H[v], H[to] + 1);
	}

	if (H[v] == k - 1 && d > 1)
	{
		res++;
		H[v] = -1;
	}
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);

	cin >> n >> k;
	FOR(i, 0, n)
	{
		int a;
		cin >> a;
		a--;
		A[i] = a;
		if (i)
		{
			g[a].push_back(i);
		}
	}

	if (A[0] != 0) res++;
	dfs(0, 0);
	cout << res << endl;
}

Measured memory_bytes: 23680
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        int y = scanner.nextInt();

        boolean sameSign = (x>>>31)==(y>>>31);

        int result = Math.abs(Math.abs(x) - Math.abs(y)) + (sameSign ? (x > y ? 2 : 0) : 1);

        if (y == 0 && x <= 0)
            System.out.println(Math.abs(x));
        else if (y==0&&x>0)
            System.out.println(x+1);
        else
            System.out.println(result);
    }
}

Measured memory_bytes: 9684
#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d %d",&a,&b);
	if(a<=b){
		c=b;
		b=b-1;
		if(a<=b){
			printf("%d\n",c+b);
		}
		else{
			printf("%d\n",c+a);
		}
	}
	else{
		c=a;
		a=a-1;
		if(a<=b){
			printf("%d\n",c+b);
		}
		else{
			printf("%d\n",c+a);
		}
	}
	return 0;
}


Measured memory_bytes: 128
N, K = map(int, input().split())
Sunuke = [0 for i in range(N)]
S = 0
for i in range(K):
    d = int(input())
    d_list = list(map(int, input().split()))
    # print(d_list)
    for j in range(d):
        Sunuke[d_list[j]-1] += 1
for i in range(N):
    if Sunuke[i] == 0:
        S += 1
print(S)

Measured memory_bytes: 9244
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
int64 gcd(int64 a, int64 b) {
	return b != 0 ? gcd(b, a %b) : a; 
}

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

void solve() {
	int64 a, b; cin >> a >> b;
	int64 ans = lcm(a, b);
	cout << ans << endl;
	return;
}

int main() {
	solve();
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define EPS 1e-8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = (j); i < (k); i++)
typedef long long ll;
typedef pair < int , int > Pii;
int main(){
	int n,m;
	int list[12800];
	while(scanf("%d%d",&n,&m),m){
		memset(list,0,sizeof(list));
		Pii p[12800];
		rep(i,m){
			scanf("%d%d",&p[i].first,&p[i].second);
		}
		stable_sort(p,p+m);
		int index = 0;
		while(p[index].first==1){
			list[p[index++].second] = 1;
		}
		list[1] = 1;
		reps(i,1,m+1){
			if(list[p[i].first]==1 && list[p[i].second] == 0)list[p[i].second] = 2;
			if(list[p[i].second]==1 && list[p[i].first] == 0)list[p[i].first] = 2;
		}
		int ans = 0;
		reps(i,2,m+1){
			if(list[i] == 1 || list[i] == 2)ans++;
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

typedef long long int ll;

vector <ll> a;
ll freq[100005];


int main()
{
	ll i,j,k,l,m,n,u,v;

	cin >> n;

	ll sum = 0;

	for(i=0;i<n;i++)
	{
		cin >> k;
		a.push_back(k);
		freq[k]++;
		sum += k;
	}

	ll q;

	cin >> q;

	ll b,c;



	while(q--)
	{
		cin >> b >> c;

		l = freq[b];
		freq[b] = 0;
		freq[c] += l;

		sum -= l*b;
		sum += l*c;

		cout << sum << '\n';


	}

	
	
	


}

Measured memory_bytes: 5096
N, D = map(int, input().split())
coordinates = []

for _ in range(N):
    line = tuple(map(int, input().split()))
    coordinates.append(line)

count = 0
for i in range(N):
    for j in range(i+1, N):

        total = 0
        for y, z in zip(coordinates[i], coordinates[j]):
            total += abs(y - z) ** 2
    
        for k in range(1, total+1):
            if k * k == total:
                count += 1

print(count)

Measured memory_bytes: 9032
import java.util.Scanner;

public class Main{

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

		Scanner sc = new Scanner(System.in);

		while (sc.hasNext()) {
			String S = sc.next();

			if (S.equals("-")) {
				break;
			}

			int K = sc.nextInt();

			for (int i = 0; i < K; i++) {
				int M = sc.nextInt();
				//１文字目からMの手前まで
				String A = S.substring(0, M);
				//指定したところ(M)から最後まで
				String Z = S.substring(M);

				S = Z + A;
			}
			System.out.println(S);
		}

	}
}



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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion

int MAX = 7368791;

int main()
{
    int n, m;
    while(cin>>m>>n, m) {
        vector<bool> v(MAX+1, false);
        for(int i=m;;++i) {
            if(v[i]) continue;
            if(n) {
                n--;
                for(int j=i; j<=MAX; j+=i) v[j] = true;
            }
            else {
                cout << i << endl;
                break;
            }
        }
    }
    return 0;
}

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

int main(){
    int n;
    int result = 0;

    while(cin >> n){
        for(int i=0; i<10; i++){
            for(int j=0; j<10; j++){
                for(int k=0; k<10; k++){
                    for(int l=0; l<10; l++){
                        if(i+j+k+l == n){
                            result++;
                            break;
                        }
                    }
                }
            }
        }
        cout << result << endl;
        result = 0;
    }
    return 0;
}

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

int main(){

    int n; cin >> n;
    int A = 0;
    int B;

    for(int i = 0; i < n; i++){
        int a, b; cin >> a >> b;
        if(A < a){
            A = a;
            B = b;
        }
    }

    cout << A + B << endl;
    return 0;
}

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

int main() {
  long int L0 = 2, L1 = 1;
  long int L = 0;
  int i = 0;
  int N;
  cin >> N;
  if(N == 0){
    L = L0;
  }
  else if (N == 1){
    L = L1;
  }
  else{    
  while(i<N-1){
    L = L1 + L0;
    L0 = L1;
    L1 = L;
    i++;
//  cout << L << endl; 

  }
  }
  cout << L << endl; 

}


Measured memory_bytes: 256
mod = 10**9+7
s = int(input())
dp = [0]*(s+1)
dp[0] = 1
for i in range(s):
  for j in range(3, s+1):
    if i+j>s:
      break
    dp[i+j] += dp[i]
    dp[i+j] %= mod
print(dp[s])


Measured memory_bytes: 66212
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int N;
	string S, T;

	cin >> N;
	cin >> S >> T;
	for (int i = 0; i < N; i++)
	{
		cout << S[i] << T[i];
	}
	cout << endl;
}



Measured memory_bytes: 256
package main
 
import (
	"fmt"
)
 
func main() {
	var n, x int
	fmt.Scan(&n, &x)
 
  var l = make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&l[i])
  }
  
  var sum int
  c := 1
  for _, v := range l {
    sum = sum + v
    if sum <= x {
	    c++
    }
  }
  fmt.Println(c)
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    ll a, b; cin >> a >> b;
    if (a % b == 0) {
        cout << -1 << endl;
    } else {
        for (ll i = 2 * a;; i += a) {
            if (i % b != 0) {
                cout << i << endl;
                return 0;
            }
        }
    }
}

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

#define INF (1LL<<60)
typedef pair<long long, long long> P;

int N;
long long D;
long long X[30], Y[30];
int n2;
long long seg[1<<25];
vector<P> M1, M2;

void dfs(int i, int until, vector<P> &p, long long a, long long b) {
  if (i >= until) {
    p.push_back(P(a, b));
    return;
  }
  dfs(i+1, until, p, a, b);
  dfs(i+1, until, p, a-X[i], b-Y[i]);
  dfs(i+1, until, p, a+X[i], b+Y[i]);
}

void update(int k, long long a) {
  k += n2 - 1;
  seg[k] = a;
  while (k > 0) {
    k = (k-1) / 2;
    seg[k] = max(seg[k*2+1], seg[k*2+2]);
  }
}

long long query(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l) return -INF;
  if (a <= l && r <= b) return seg[k];
  return max(query(a, b, k*2 + 1, l, (l+r) / 2),
             query(a, b, k*2 + 2, (l+r) / 2, r));
}

int main() {
  cin >> N >> D;
  for (int i=0; i<N; i++) {
    cin >> X[i] >> Y[i];
  }
  dfs(0, N/2, M1, 0, 0);
  dfs(N/2, N, M2, 0, 0);
  sort(M1.begin(), M1.end());
  sort(M2.begin(), M2.end());

  long long ans = 0;
  n2 = 1;
  while (n2 < M2.size()) n2 *= 2;
  for (int i=0; i<2*n2; i++) seg[i] = -INF;
  for (int i=0; i<M2.size(); i++) update(i, M2[i].second);

  for (auto p : M1) {
    long long x = p.first, y = p.second;
    int lo = lower_bound(M2.begin(), M2.end(), P(-x-D, -INF)) - M2.begin();
    int hi = lower_bound(M2.begin(), M2.end(), P(-x+D,  INF)) - M2.begin();
    if (lo > hi) continue;
    ans = max(ans, y+query(lo, hi, 0, 0, n2));
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 713356
/*
* welcome to my code!
* ------------------------------------------
* author : lynmisakura(twitter : @andoreiji11)
*/

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

using ll = long long;

// macro templates

#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define rep(i,n) for(int i = 0;i < n;i++)
#define dv(TYPE,VAL) TYPE VAL;cin >> VAL;
#define vi(TYPE,NAME,SIZE,INIT) vector<TYPE> NAME(SIZE,(INIT))
#define vin(TYPE,NAME,SIZE) vector<TYPE> NAME(SIZE);rep(i,SIZE)cin >> NAME[i]
#define vout(ARRAY) for(auto i : ARRAY)cout << i << ' ';cout << '\n'
#define vvi(TYPE,NAME,LOW,COL,INIT) vector<vector<TYPE>> NAME(LOW,vector<TYPE>(COL,INIT))
#define vpi(T1,T2,NAME,SIZE,I1,I2) vector<pair<T1,T2>> NAME(SIZE,make_pair(I1,I2))
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define dup(x,y) (x + y - 1)/y
#define sz(v) (int64_t)v.size()
#define CUM(arr,cum) vector<ll> cum(sz(a)+1,0); rep(i,sz(a)) cum[i+1] = cum[i] + 1
#define PY(COND) if(COND){cout << "YES" << '\n';return;}
#define PN(COND) if(COND){cout << "NO" << '\n';return;}
#define PYN(COND) cout << ((COND) ? "YES" : "NO") << '\n';
#define Py(COND) if(COND){cout << "Yes" << '\n';return;}
#define Pn(COND) if(COND){cout << "No" << '\n';return;}
#define Pyn(COND) cout << ((COND) ? "Yes" : "No") << '\n';return

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pi acos(-1)
#define fi first
#define se second
#define pq priority_queue

#define MULTITEST; int t;cin >> t;rep(_,t)main2();
#define IOB; cin.tie(0);ios::sync_with_stdio(false);

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

// templates end

void main2(){

}

int main(void){
    IOB;
    //MULTITEST

    int64_t a,v,b,w,t;cin >> a >> v >> b >>w >> t;
    PYN(abs(b - a) <= t * (v - w));
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define MODB 998244353
#define INF 9223372036854775807
signed main()
{
  int x=0,y=0,z=0,w=0,n=0,m=0;
  std::cin >> x>>y;
  if(x==1)z+=300000;
  else if(x==2)z+=200000;
  else if(x==3)z+=100000;

  if(y==1)z+=300000;
  else if(y==2)z+=200000;
  else if(y==3)z+=100000;

  if(x==1&&y==1)z+=400000;

  std::cout << z << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define ll long long
#define rep(i,n) for (int i=0; i<(int)(n); i++)
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a >= 13) {
		cout << b << endl;
	}
	else if (a >= 6 && a <= 12) {
		cout << b / 2 << endl;
	}
	else {
		cout << "0" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
#include <queue>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    int ans = 1;
    bool up = false;
    bool down = false;
    bool equal = false;

    for (int i = 0; i < n-1; ++i) {
        if (!up && !down && !equal) {
            if (a[i] < a[i+1]) up = true;
            else if (a[i] == a[i+1]) equal = true;
            else down = true;
        }
        if (equal && (!up && !down)) {
            if (a[i] < a[i+1]) {
                up = true;
                equal = false;
            }
            else if (a[i] > a[i+1]) {
                down = true;
                equal = false;
            }
            else continue;
        }
        if (up) {
            if (a[i] < a[i+1]) continue;
            else if (a[i] == a[i+1]) equal = true;
            else {
                ans++;
                up = false;
                down = false;
                equal = false;
            }
        }
        else {
            if (a[i] > a[i+1]) continue;
            else if (a[i] == a[i+1]) equal = true;
            else {
                ans++;
                up = false;
                down = false;
                equal = false;
            }
        }
    }
    cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 640
import sys
def main():
    input = sys.stdin.readline
    N,M,P=map(int, input().split())
    E=[]
    G=[[] for _ in range(N)]
    H=[[] for _ in range(N)]
    for _ in range(M):
        a,b,c=map(int, input().split())
        a,b=a-1,b-1
        E.append((a,b,c-P))
        G[b].append(a)
        H[a].append(b)

    R1=[False]*N
    R1[0]=True
    stk=[0]
    while stk:
        v=stk.pop()
        for to in H[v]:
            if R1[to]: continue
            R1[to]=True
            stk.append(to)

    R2=[False]*N
    R2[N-1]=True
    stk=[N-1]
    while stk:
        v=stk.pop()
        for to in G[v]:
            if R2[to]: continue
            R2[to]=True
            stk.append(to)

    INF=10**10
    d=[-INF]*N
    d[0]=0
    for i in range(N):
        for a,b,c in E:
            if R1[a]==False: continue
            if R2[b]==False: continue
            if d[a]==-INF: continue
            if d[b] < d[a] + c:
                d[b] = d[a] + c
                if i==N-1:
                    print(-1)
                    return
    print(max(0,d[N-1]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 45424
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace AtCoder124
{
    class Program
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            int K = int.Parse(Console.ReadLine());
            char s = S[K-1];
            char[] res = new char[N];
            for (int i = 0; i < N; i++)
            {
                res[i] = (S[i] != s)? '*': S[i];
            }
            string resS = new string(res);
            Console.WriteLine(resS);
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(int argc, char * argv[]) {
    double a, b, x;
    cin >> a >> b >> x;

    double half = a * a * b / 2;
    cout.precision(10);
    if (x < half) {
        double c = x * 2 / b / a;
        cout << 90 - atan(c / b) / M_PI * 180 << endl;
    } else {
        double h = (a * a * b - x) * 2 / a / a;
        cout << atan(h / a) / M_PI * 180 << endl;
    }

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int fund[131072];
int p[16][2];
int main(void)
{
  int n,d,x;
  cin >> n >> d >> x;
  REP(i,n) cin >> p[i][0];
  REP(i,d-1){
    REP(j,131072) fund[j]=j;
    REP(i,n){
      cin >> p[i][1];
      REP(j,100001) if(j>=p[i][0]) fund[j]=max(fund[j],fund[j-p[i][0]]+p[i][1]);
      p[i][0]=p[i][1];
    }
    x=fund[x];
  }
  cout << x << endl;
  
  return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;
public class Main {
  public static void main( String[] args ) {
	  Scanner scan = new Scanner(System.in);
	  int N = scan.nextInt();
	  int A = scan.nextInt();
	  int B = scan.nextInt();
	  int ans = 0;
	  int i_tmp = 0;
	  for( int i = 1; i <= N; i++ ) {
		  i_tmp = i;
		  int divide = 10;
		  int sum = 0;
		  int digit = 1;
		  while( true ) {
			  if( i_tmp / divide >= 10 ) {
				  digit++;
				  divide *= 10;
			  }else {
				  divide /= 10;
				  break;
			  }
		  }
		  divide = (int)Math.pow( 10, digit );
		  while( true ) {
			  sum += i_tmp / divide;
			  if( i_tmp < 10 ) {
				  sum += i_tmp % 10;
				  break;
			  }
			  i_tmp = i_tmp % divide;
			  divide /= 10;
			  if( divide <= 10 ) {
				  sum += i_tmp / 10;
				  sum += i_tmp % 10;
				  break;
			  }
		  }
		  if( A <= sum && sum <= B ){
			  ans += i;
		  }
	  }
	  System.out.println( ans );
  }
}


Measured memory_bytes: 21844
//AtCoder
//2655 Fennec VS. Snuke

#include<iostream>
#include<vector>
#include<queue>

using namespace std;

const int MAXN=1000000+10;
vector<int> edge[MAXN];
queue<int> q;
int tree[MAXN],cnt[3];
int n;

void bfs()
{
	q.push(1),q.push(n);
	
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		
		++cnt[tree[u]];
		
		for(int i=0;i<edge[u].size();++i)
		{
			int v=edge[u][i];
			
			if(tree[v])continue;
			else tree[v]=tree[u];
			
			q.push(v);
		}
	}
}

int main()
{
	ios::sync_with_stdio(false);
	
	cin>>n;
	
	for(int i=1;i<n;++i)
	{
		int x,y;
		cin>>x>>y;
		
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	
	tree[1]=1,tree[n]=2;
	
	bfs();
	
	if(cnt[2]>=cnt[1])
		cout<<"Snuke"<<endl;
	else
		cout<<"Fennec"<<endl;
	
	return 0;
}

Measured memory_bytes: 29184
#include <bits/stdc++.h>
#define ls (x<<1)
#define rs (x<<1|1)
#define ll long long
using namespace std;
const int N=1e5+50,mo=1e9+7;
int tr[N<<2][2],n;
ll s[N];
struct len{
  int l[N]; ll w;
  void main(){
    l[1]=1;
    for (int i=2; i<=n; ++i)
      if (s[i]-s[i-1]>=w) l[i]=l[i-1];
      else l[i]=i;
  }
}g[2];
void add(int x,int l,int r,int y,int t,int s){
  (tr[x][t]+=s)%=mo;
  if (l==r) return;
  int mid=(l+r)>>1;
  if (y<=mid) add(ls,l,mid,y,t,s);
  else add(rs,mid+1,r,y,t,s);
  return;
}
int query(int x,int l,int r,int ql,int qr,int t){
  if (ql<=l&&r<=qr) return tr[x][t];
  int mid=(l+r)>>1,ans=0;
  if (ql<=mid) ans+=query(ls,l,mid,ql,qr,t);
  if (qr>mid) ans+=query(rs,mid+1,r,ql,qr,t);
  return ans%mo;
}
int main(){
  ll a,b; cin>>n>>a>>b;
  for (int i=1; i<=n; ++i) scanf("%lld",&s[i]);
  s[n+1]=2e18,g[0].w=a,g[1].w=b;
  g[0].main(),g[1].main();
  int la=0,lb=0,l,r,s1,s2;
  add(1,0,n,0,0,1),add(1,0,n,0,1,1);
  for (int i=1; i<=n; ++i){
    while(s[i+1]-s[la+1]>=a) ++la;
    while(s[i+1]-s[lb+1]>=b) ++lb;
    r=lb,l=g[0].l[i]-1,s1=0; if (l<=r) s1=query(1,0,n,l,r,0);
    r=la,l=g[1].l[i]-1,s2=0; if (l<=r) s2=query(1,0,n,l,r,1);
    add(1,0,n,i,1,s1),add(1,0,n,i,0,s2);
  }
  cout<<(query(1,0,n,n,n,0)+query(1,0,n,n,n,1))%mo;
  return 0;
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
	int H, W;
	int i, j;

	while (1)
	{
		cin >> H >> W;
		if (H == 0 && W == 0) break;
		for (i = 0; i < H; i++) {
			for (j = 0; j < W; j++) {
				cout << '#';
			}
			cout << endl;
		}
		cout << endl;
	}

	return (0);
}

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

using namespace std;

int a[100000], N, T;

int main() {
    scanf("%d %d", &N, &T);
    for(int i = 0; i<N; ++i) scanf("%d", a+i);
    int mn = a[0], best = 0;
    for(int i = 1; i<N; ++i) {
        best = max(best, a[i]-mn);
        mn = min(mn, a[i]);
    }
    int ans = 0;
    mn = a[0];
    for(int i = 1; i<N; ++i) {
        if( a[i]-mn == best ) ++ans;
        mn = min(mn, a[i]);
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 640
ENV[Z='RUBY_THREAD_VM_STACK_SIZE']||exec({Z=>'50000000'},'ruby',$0)

N = gets.to_i
@hh = gets.chomp.split.map(&:to_i)

@dparr = Array.new(N)

def dp(to, cost)
  return cost if to == 0
  return @dparr[to] if @dparr[to]

  if to - 2 < 0
    @dparr[to] = dp(to - 1, cost) + (@hh[to] - @hh[to - 1]).abs
  else
    @dparr[to] = [dp(to - 1, cost) + (@hh[to] - @hh[to - 1]).abs, dp(to - 2, cost) + (@hh[to] - @hh[to - 2]).abs].min
  end
  return @dparr[to]
end

puts dp(N- 1, 0)

Measured memory_bytes: 27884
#include <iostream>

using namespace std;

int main(void) {

	int A, B, C, X;
	cin >> A >> B >> C >> X;

	int num = 0;
	for (int a = 0; a <= A; a++) {
		int aX = 500 * a;
		for (int b = 0; b <= B; b++) {
			int bX = 100 * b;
			for (int c = 0; c <= C; c++) {
				int total = aX + bX + 50 * c;
				if (total == X) {
					++num;
				}
			}
		}
	}

	cout << num << endl;

	return 0;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    csf = []
    for _ in range(N - 1):
        csf.append([int(x) for x in input().split()])

    for i in range(N - 1):
        total = 0
        total = csf[i][0] + csf[i][1]
        for j in range(i + 1, N - 1):
            if total <= csf[j][1]:
                total = csf[j][1] + csf[j][0]
                continue
            else:
                if (total - csf[j][1]) % csf[j][2] != 0:
                    total += csf[j][2] - (total - csf[j][1]) % csf[j][2]
                total += csf[j][0]
        print(total)
    print(0)



if __name__ == '__main__':
    main()



Measured memory_bytes: 3188
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<math.h>
using namespace std;

int main()
{
	
	vector<int> x;
	int i;
	for(i=0;i<5;i++)
	{
		int k;
		cin>>k;
		x.push_back(k);
		
		
	}
	
	int count=1;
	for(auto it=x.begin();it!=x.end();it++)
	{
		
		if(*it==0)
		{
			
		    cout<<count<<endl; 
		    break;
			
		}
		
	    count++;
		
	}
	
	

	return 0;
	
}

Measured memory_bytes: 3552
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils,Classes;
var
  a,h,w,i,j,count,x,y,sw,m,n,b,c,soeji,sum,max,k,min:Integer;
  l:array[0..6] of Integer = (1,2,4,8,16,32,64);
  s,s123,s1,s2,s3:string;
  tf:Boolean;
  nyu:TStringList;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Readln(n);

    for I := 0 to 6 do begin
      if n>=l[6-i] then begin
        Writeln(l[6-i]);
        break;
      end;
    end;
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	vi a(n), b(m);
	REP(i, n)cin >> a[i];
	REP(i, m)cin >> b[i];
	int c = -INF, d = INF;
	REP(i, n)c = max(c, a[i]);
	REP(i, m)d = min(d, b[i]);
	for (int i = x + 1; i <= y; ++i) {
		if (i > c&&i <= d) {
			cout << "No ";
			break;
		}
	}
	cout << "War" << endl;

}


Measured memory_bytes: 256
#include<iostream>

using namespace std;
#define MAX 100000

int parent(int i){return i/2;}
int left(int i){return i*2;}
int right(int i){return i*2+1;}


int main(){
    int n;
    int heap[MAX+1];
    int p, l, r;

    cin >> n;
    for(int i=1;i<=n;i++) cin >> heap[i];
    for(int i=1;i<=n;i++){
        p = parent(i); l = left(i); r = right(i);

        cout << "node " << i <<": ";
        cout << "key = " << heap[i] << ", ";
        if(p >0) cout << "parent key = " << heap[p] <<", ";
        if(l<=n) cout << "left key = " << heap[l] <<", ";
        if(r<=n) cout << "right key = " << heap[r] <<", ";
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 3096
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>

using namespace std;
typedef long long int ll;

int n;

int dsm(int target){
    int da=target,db=10,dc=0,dd,sum=0,repeat=0,value=1;
    while(value!=0){
        dd=dc;dc=da;da/=db;da*=db;
        if(repeat>0){
            value=(dd-dc)*100/db;
            sum+=(value==2);
            
        }
        db*=10;
        repeat++;
    }
    return sum;
}
int main(){
    scanf("%d",&n);
    printf("%d\n",dsm(n));
}

Measured memory_bytes: 256
# coding: utf-8

def main():
    _, x = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()

    ans = 0

    for i in a:
        x -= i
        if x < 0:
            break
        else:
            ans += 1

    if x > 0 and ans > 0:
        ans -= 1

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9188
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>

using namespace std;

long long MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<bool> noterased(n, true);

    char prev = '1';
    for (int i = 1; i < n; ++i) {
        if (s[i-1] == s[i]) {
            noterased[i] = false;
        }
    }
    int count = 0;
    for (int e : noterased) {
        count += e;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
signed main(){
  string a; 
  string b="CODEFESTIVAL2016";
  int c=0;
  cin>>a;
  for(int i=0;i<a.size();i++){
    if(a[i]!=b[i]) c++;
  }
  cout<<c<<"\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string u;
  cin>>N;
  double x,sum=0;
  for(int i=0;i<N;i++){
    cin>>x>>u;
    if(u=="JPY")
      sum+=x;
    if(u=="BTC")
      sum+=x*380000;
    }
  cout<<sum<<endl;
}

Measured memory_bytes: 256