akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n,d,a;
  cin >> n >> d >> a;
  vector<pair<ll,ll>> mon(n);
  for(int i = 0;i < n;i++){
    int pos,hp;
    cin >> pos >> hp;
    mon[i] = make_pair(pos,hp);
  }
  sort(mon.begin(),mon.end());
  vector<ll> posmemo(n);
  for(int i = 0;i < n;i++)posmemo[i] = mon[i].first;
  vector<ll> range(n);
  for(int i = 0;i < n;i++){
    range[i] = upper_bound(posmemo.begin(),posmemo.end(),posmemo[i] + 2 * d) - posmemo.begin() - 1;
  }
  //for(auto item:range)cout << item << endl;
  ll res = 0;
  vector<ll> ruiseki(n);
  vector<ll> now(n);
  for(int i = 0;i < n;i++)ruiseki[i] = 0,now[i] = 0;
  for(int i = 0;i < n;i++){
    if(i >= 1)now[i] = now[i - 1] + ruiseki[i];
    if(now[i] < mon[i].second){
      ll add = 0;
      add = (mon[i].second - now[i]) / a;
      if((mon[i].second - now[i]) % a != 0)add++;
      now[i] += add * a;
      ruiseki[i] += add * a;
      if(range[i] < n - 1)ruiseki[range[i] + 1] -= add * a;
      res += add;
    }
      /*for(auto item:ruiseki)cout << item << " ";
    cout << endl;
    for(auto item:now)cout << item << " ";
    cout << endl;*/
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 9600
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	private static Scanner in;
	
	private static int n;
	private static HashMap<Integer, ArrayList<Integer>> g;
	private static long[][] dp;
	private static final int MOD = (int)1e9+7;
	
	public static void main(String[] args) {
		in = new Scanner(System.in);
		n = in.nextInt();
		g = new HashMap<>();
		for(int i=0; i<n; i++) {
			g.put(i, new ArrayList<>());
		}
		
		dp = new long[n][2];
		
		for(int i=0; i<n; i++)
			Arrays.fill(dp[i], -1);
		
		for(int i=0; i<n-1; i++) {
			int p = in.nextInt()-1;
			int q = in.nextInt()-1;
			g.get(p).add(q);
			g.get(q).add(p);
		}
		
		
//		System.out.println(dfs(0, -1, 0));
//		System.out.println(dfs(0, -1, 1));
		System.out.println((dfs(0, -1, 0)+dfs(0, -1, 1))%MOD);
	
	}
	
	private static long dfs(int i, int p, int c) {
		
		if (dp[i][c]!=-1) return dp[i][c];
		
		long ans = 1;
		for(int v: g.get(i)) {
			if (v==p) continue;
			
			if (c==0) {
				//white
				ans = (ans*(dfs(v, i, 0)+dfs(v, i, 1)))%MOD;
			} else {
				//black
				ans = (ans*dfs(v, i, 0))%MOD;
			}
		}
		
		return dp[i][c]=ans;
	}

}


Measured memory_bytes: 132556
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e5 + 5, M = 1e5 + 5;


int main(){
    int n, d;
    scanf("%d%d", &n, &d);
    d = (2 * d + 1);
    printf("%d\n", (n + d - 1) / d);
}

Measured memory_bytes: 256
from collections import Counter
def solve(n, m, a, b):
    parents = list(range(n+1))
    def root(x):
        if parents[x] != x:
            parents[x] = root(parents[x])
        return parents[x]
    for u, v in zip(a, b):
        u = root(u)
        v = root(v)
        if u > v:
            u, v = v, u
        if u != v:
            parents[v] = u
    return max(Counter(map(root, parents)).values())

n, m = map(int, input().split())
if m > 0:
    a, b = zip(*[map(int, input().split()) for i in range(m)])
else:
    a, b = [], []
print(solve(n, m, a, b))

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n, k, x, y;
    cin >> n >> k >> x >> y;
    cout << x*min(n,k)+y*max(n-k, 0ll) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int n, t;
    cin >> n >> t;
    long long int sum = 0;
    long long int finishtime = 0;
    int temp;
    cin >> temp;
    sum = t;
    finishtime = temp + t;
    rep(i, n - 1)
    {
        cin >> temp;
        if (finishtime > temp) // 終わる前に押した
        {
            sum -= finishtime - temp;
            sum += t;
            finishtime = temp + t;
        }
        else
        {
            finishtime = temp + t;
            sum += t;
        }
        if (DEBUG)
            cout << sum << endl;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int A[20], N;

bool exhaustiveSearch(int m, int s, int n){
    if(n==N+1) return false;//it's over
    if(s==m) return true;

    if (exhaustiveSearch(m,s,n+1)) {
        return true;
    }else
    {
        return exhaustiveSearch(m,s+A[n],n+1);
    }
}

int main(){
    int i,q;
    cin >> N;
    for(i=0;i<N;i++) cin>>A[i];
    cin>>q;
    for(i=0;i<q;i++){
        int m;
        cin >> m;
        exhaustiveSearch(m,0,0)?cout<<"yes":cout<<"no";
        cout<<endl;
    }
}


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

int d[1001][200]; int n,m;

int main(){
	int z[200]; scanf("%d%d",&n,&m);
	for(int i=1;i<=2*n;i++) d[0][i-1]=i;
	for(int j=1;j<=m;j++){
		int k; scanf("%d",&k);
		if(k==0){
			for(int i=0;i<n;i++){ d[j][2*i]=d[j-1][i]; d[j][2*i+1]=d[j-1][i+n]; }
		}else{
			for(int i=k;i<2*n;i++) d[j][i-k]=d[j-1][i];
			for(int i=0;i<k;i++) d[j][i+2*n-k]=d[j-1][i];
		}
	}
	for(int i=0;i<2*n;i++) printf("%d\n",d[m][i]);
}

Measured memory_bytes: 1968
package main

import "fmt"

var (
	n  int
	as []int
)

func main() {
	fmt.Scan(&n)
	as = make([]int, n)
	us := make(map[int]int)
	for i := range as {
		fmt.Scan(&as[i])
		us[as[i]]++
	}
	all := 0
	for _, v := range us {
		all += v * (v - 1) / 2
	}
	for k := range as {
		fmt.Println(all - us[as[k]] + 1)
	}

}


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

int main() {

	string s;
	cin >> s;

	
	

	for (int i = 0; i < s.size(); i++) {

		if (i==s.size()-1){
			if (s.at(i) == 's') {
				cout << s << "es";
			}
			else {
				cout << s << "s";

			}
			
		      

		}
	}
}

Measured memory_bytes: 3628
// Package main provides
//
// File:  a.go
// Author: ymiyamoto
//
// Created on Sun Dec 16 19:33:27 2018
//
package main

import "fmt"

func main() {
	var S string
	fmt.Scan(&S)

	number := 0
	for _, c := range S {
		if c == '+' {
			number++
		} else {
			number--
		}
	}

	fmt.Println(number)
}


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

int main() {
    int H, W;  cin >> H >> W;
    vector<vector<int>> c(10, vector<int>(10));
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            cin >> c[i][j];
        }
    }

    // warshall_floyd
    for (int k = 0; k < 10; ++k) {
        for (int i = 0; i < 10; ++i) {
            for (int j = 0; j < 10; ++j) {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }

    vector<int> cnt(11);
    for (int i = 0; i < H * W; ++i) {
        int a;  cin >> a;
        ++cnt[a + 1];
    }

    int ans = 0;
    for (int i = 0; i < 10; ++i) {
        ans += cnt[i + 1] * c[i][1];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;


int main() {
    cin>>H>>W>>K;
    vec bit2(10,1);
    reps(i,1,10){
        bit2[i] = bit2[i-1] << 1;
    }
    vec comb(10,1);
    reps(i,2,10){
        comb[i] = (comb[i-1] + comb[i-2])%MOD;
    }
    mat dp(H+1,vec(W,0));
    dp[0][0] = 1;
    reps(i,1,H+1){
        rep(j,W){
            ll left = j, right = W - j - 1;
            ll temp;
            temp = (comb[left] * comb[right])%MOD;
            (temp *= dp[i-1][j])%=MOD;
            (dp[i][j] += temp)%=MOD;
            if(j != 0){
                temp = (comb[left-1] * comb[right])%MOD;
                (temp *= dp[i-1][j-1])%=MOD;
                (dp[i][j] += temp)%=MOD;
            }
            if(j != W - 1) {
                temp = (comb[left] * comb[right - 1])%MOD;
                (temp *= dp[i-1][j+1])%=MOD;
                (dp[i][j] += temp)%=MOD;
            }
        }
    }
    cout<<dp[H][K-1]<<endl;
}


Measured memory_bytes: 768
// finish date: 2019/2/22

#include <bits/stdc++.h>

using namespace std;

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


int main() {
    string s, t;
    cin >> s >> t;
    int n = s.length(), m = t.length();
    vvi dp(n + 1, vi(m + 1, 0));
    FOR(i, 1, n + 1) {
        FOR(j, 1, m + 1) {
            dp[i][j] = max({dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1] + (s[i - 1] == t[j - 1])});
        }
    }
//    cout<<dp[n][m]<<endl;
    string ans = "";
    int i = n, j = m;
    while (dp[i][j] != 0) {
        if (s[i-1]==t[j-1]) {
            i--, j--;
            ans = s[i] + ans;
        } else if (dp[i - 1][j] == dp[i][j]) i--;
        else j--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 35584
#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <cmath>

using namespace std;
#define PI 3.14159265359

// 約数の数
int divisor_count(int n)
{
    int ans = 0;
    for(int i = 1; i <= n; i++){
        if(n % i == 0) ans++;
    }

    return ans;
}

// 公約数
void common_divisor(int a, int b, int *array)
{
    int k = 0;
    for(int i = min(a, b); i >= 1; i--){
        if(a % i == 0 && b % i == 0){
            array[k] = i;
            k++;
        }
    }
}

// 桁数
int digit_count(long long n)
{
    int ans = 0;
    while(1){
        n /= 10;
        ans++;
        if(n == 0) break;
    }

    return ans;
}



int main()
{
    long long N;
    cin >> N;
    int ans = 30000;

    for(long long A = 1; A <= sqrt(N); A++){
        long long B;
        if(N % A == 0) B = N / A;
        ans = min(ans, digit_count(max(A, B)));
    }

    cout << ans << endl;

    
    return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

// Read editorial
class DAOrorBProblem {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      ll a, b; cin >> a >> b;
      if (a==b) {
        cout << 1 << endl;
        return;
      }
      for(int k=61; k>=0; k--) {
        ll t = 1LL<<k;
        if (b < t) continue;
        if (a >= t && b >= t) {
          a -= t;
          b -= t;
          continue;
        }
        if (b >= t && a < t) {
          ll c = t|a;
          ll d = t*2-1;
          bool find = false;
          for(int p=k-1; p>=0; p--) {
            ll r = 1LL<<p;
            if (b&r) {
              find = true;
            }
            if (find) {
              b |= r;
            }
          }
          ll ret = -1;
          if (b >= c) {
            ret = d-a+1;
          } else {
            ret = d-c+1 + b-a+1;
          }
          cout << ret << endl;
          return;
        }
      }
    }
};

signed main() {
  DAOrorBProblem solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3624
const main = (input) => {
  const [, s] = input.trim().split('\n')
  const str = Array.from(s)

  let wh = 0
  let rd = 0
  let change = 0

  let lastRed = str.length - 1

  for (let v of str) v === 'W' ? wh++ : rd++

  for (let i=0; i<lastRed; i++) {
    if (str[i] === 'W') {
      while (str[lastRed] === 'W') lastRed--
      if (i>=lastRed) break

      ;[str[i], str[lastRed]] = ['R', 'W']
      change++
      lastRed--
    }
  }
  
  return console.log(Math.min(change, Math.min(wh, rd)))
}

process.env.MYTEST ? test() : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 37628
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace boost::multiprecision;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
int main () {
  cpp_int n;
  cpp_int result = 1;
  cin >> n;

  REP(i, n) {
    result = (result * (i+1)) % MOD;
  }

  cout << result << endl;

  return 0;
}


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

int main()
{
	string s;
	cin >> s;
	bool check = true;
	int ccount = 0;
	int smallcount = 0;
	for (int i = 0; i < s.size(); i++) {
		
		if (i == 0) {
			if (s[i] != 'A') {
				check = false;
				break;
			}
		}
		if (i >= 2 && i <= s.size() - 2) {
			if (s[i] == 'C')
				ccount++;
		}
		if (s[i] >= 'a' && s[i] <= 'z')
			smallcount++;
	}
	if (check && ccount == 1 && smallcount == s.size() - 2) {
		cout << "AC" << endl;
	}
	else
		cout << "WA" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 1e5+5;

int main()
{
    ll x;
    cin >> x;
    ll c = (x / 500) * 1000;
    x %= 500;
    c += (x / 5) * 5;
    cout << c << endl;
}


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

using ll    = long long;
using ull   = unsigned long long;
using veci  = vector<int>;
using vecll = vector<ll>;
#define EPS (1e-7)
#define INF (1e9)
#define PI  (acos(-1))
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define REP(i,n) for(int i= 0;i<(int)(n);++i)
#define pb push_back

veci enum_div(int n){
	veci ret;
	ret.pb(1);
	for(int i=1;i*i<n;i++){
		if(n%i==0){
			ret.pb(i);
			if(i != n/i){ret.pb(n/i);}
		}
	}
	ret.pb(n);
	return ret;
}
int gcb(int a,int b){return ((b == 0)? a : gcb(b,a%b));}
int gcd(int a,int b){return (a*b) / gcb(a,b);}

int main(){
    string c1,c2;
    cin >> c1 >> c2;
    if(c1[0]!=c2[2] || c1[1]!=c2[1] || c1[2]!=c2[0]){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
    return 0;
}



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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 22;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  string s; cin >> s;
  map<char, int> m;
  map<char, int> ma;
  REP(i, SZ(s)) {
    ma[s[i]] = max(ma[s[i]], i+1 - m[s[i]]);
    m[s[i]] = i+1;
  }

  REP(i, SZ(s)) {
    ma[s[i]] = max(ma[s[i]], SZ(s)+1 - m[s[i]]);
  }

  int mi = INF;
  MFOR(i, ma) {
    mi = min(mi, i->se - 1);
  }
  cout << mi << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll n,i,j,k,s1=0,s2=0;
	cin>>n;
	ll a[n],b[n];
	for (i=0;i<n;i++)
	{
		cin>>a[i];
		s1+=a[i];
	}
	for (i=0;i<n;i++)
	{
		cin>>b[i];
		s2+=b[i];
	}
	if (s1<s2)
	cout<<-1<<endl;
	else
	{
		ll c[n];
		for (i=0;i<n;i++)
		c[i]=a[i];
		vector<pair<ll,ll> > v;
		for (i=0;i<n;i++)
		{
			if (a[i]>b[i])
			v.push_back(make_pair(a[i]-b[i],i));
		}
		sort(v.begin(),v.end());
		j=v.size()-1;
		for (i=0;i<n;i++)
		{
			if (c[i]<b[i])
			{
				ll d=b[i]-c[i];
				while (d)
				{
					if (d>v[j].first)
					{
						d-=v[j].first;
						a[v[j].second]=b[v[j].second];
						v[j].first=0;
						j--;
					}
					else
					{
						v[j].first-=d;
						a[i]=b[i];
						if (v[j].first==0)
						j--;
						d=0;
					}
				}
			}
			
		}
		for (i=0;i<v.size();i++)
		{
			a[v[i].second]=b[v[i].second]+v[i].first;
		}
		ll count=0;
		for (i=0;i<n;i++)
		if (a[i]!=c[i])
		count++;
		cout<<count<<endl; 
	}
}

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()

#define EACH(i, c) \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#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)
const double PI = acos(-1.0);
#define CLR(a) memset((a), 0, sizeof(a))



//map<string,string> d;

void takakuwa(int n){
	int hidari=0;
	int migi = n-1;
	vector<int> kuwa;
	REP(i,n){
		int j;
		cin >> j;
		kuwa.push_back(j);
	}
	int mokuteki;
	cin >> mokuteki;
	int ans=0;
	while(migi >= hidari){
		int chushin = (hidari+migi)/2;
		ans++;
		if (kuwa.at(chushin) == mokuteki) break;
		if (kuwa.at(chushin) < mokuteki) hidari= chushin+1;
		if (kuwa.at(chushin) > mokuteki) migi = chushin-1;
		
	}
	cout << ans << "\n";

}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while (cin >> n  &&n ) {
    takakuwa(n);
  }
  return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int h,w;
  cin>>h>>w;
  int data[50][50];
  for(int i=0;i<h;i++){
    string s;
    cin>>s;
    for(int j=0;j<w;j++){
      data[i][j]=0;
      if(s[j]=='#')data[i][j]=-1;
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(data[i][j]==-1)continue;
      if(i!=0){
        if(data[i-1][j]==-1)data[i][j]++;
        if(j!=0){
          if(data[i-1][j-1]==-1)data[i][j]++;
        }
        if(j!=(w-1)){
          if(data[i-1][j+1]==-1)data[i][j]++;
        }
      }
      if(j!=0){
        if(data[i][j-1]==-1)data[i][j]++;
      }
      if(i!=(h-1)){
        if(data[i+1][j]==-1)data[i][j]++;
        if(j!=(w-1)){
          if(data[i+1][j+1]==-1)data[i][j]++;
        }
        if(j!=0){
          if(data[i+1][j-1]==-1)data[i][j]++;
        }
      }
      if(j!=(w-1)){
        if(data[i][j+1]==-1)data[i][j]++;
      }
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(data[i][j]==-1){
        cout<<'#';
      }else{
        cout<<data[i][j];
      }
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
INF = 10**15
dp = [INF for _ in range(n)]
dp[0] = 0
for i in range(n):
    if i+1 <= n-1 :
        dp[i+1] = min(dp[i]+ abs(a[i+1] - a[i]) , dp[i+1])
    if i+2 <= n-1:
        dp[i+2] = min(dp[i]+ abs(a[i+2] - a[i]) , dp[i+2])
print(dp[-1])

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

const ll mod = 1e9 + 7;

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

	ll n, k;	cin >> n >> k;

	ll final = 0;

	for (int i = k; i <= n + 1; i++)
		final += (i * (n - i + 1) + 1) % mod;

	cout << final % mod << endl;

	return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<set>
#include<queue>
#include<algorithm>
using namespace std;
int vis[200];
int main(){
	int t;
	string a;
	cin>>t;
	cin>>a;
	set<char> left;
	set<char> right;
	set<char> final;
	queue<char> q;
	queue<char> p;
	int n=a.length();
	for(int i=0;i<n;i++){
		q.push(a[i]);

	}

	for(int i=0;i<n-1;i++){
		left.insert(a[i]);
		q.pop();
		p=q;
		right.clear();
		while(!p.empty()){
			right.insert(p.front());
			p.pop();
		}
		
		set<char>::iterator it1;
		set<char>::iterator it2;
		for(it1=left.begin();it1!=left.end();it1++){
			final.insert(*it1);
		}
		for(it2=right.begin();it2!=right.end();it2++){
			final.insert(*it2);
		}
		int an=left.size()+right.size()-final.size();
		vis[i]=an;
	
	}
	sort(vis,vis+n-1);
	cout<<vis[n-2]<<endl;

	return 0;
}

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

// ll n,w;
ll dp[101][100005]={0};

ll knapsack(ll *wt, ll *val, ll w, ll n){
    if(w==0 || n==0) return 0;
    
    if(dp[n][w]!=0) return dp[n][w];
    
    ll op1 =INT_MIN , op2= INT_MIN;
    if(w-wt[n-1]>=0) {op1= knapsack(wt, val, w-wt[n-1], n-1) + val[n-1];}
    op2 = knapsack(wt, val, w, n-1) ;
    
    dp[n][w] = max(op1,op2);
    return dp[n][w];
}

int main() {
    ll n,w;
    cin>>n>>w;
    ll wt[n], val[n];
    for(ll i=0;i<n;i++) cin >> wt[i] >> val[i];

    cout << knapsack(wt, val, w, n);
}


Measured memory_bytes: 77312
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

ll bfs1(ll n, vector<vll> &nx, ll u, ll v) {
	queue<ll> task;
	task.push(u);
	vector<bool> seen(n, false);
	seen[u] = true;

	ll depth = 1;
	while (task.size()) {
		ll sz = task.size();
		while (sz--) {
			ll x = task.front();
			task.pop();
			for (ll i = 0; i < nx[x].size(); i++) {
				if (nx[x][i] == v) return depth;
				if (!seen[nx[x][i]]) {
					task.push(nx[x][i]);
					seen[nx[x][i]] = true;
				}
			}
		}
		depth++;
	}
}

vll bfs2(ll n, vector<vll> &nx, ll u, ll v, ll dist) {
	queue<ll> task1, task2;
	task1.push(u);
	task2.push(v);
	vector<bool> seen1(n, false), seen2(n, false);
	seen1[u] = true;
	seen2[v] = true;

	ll depth = 1;
	while (1) {
		ll sz = task2.size();
		while (sz--) {
			ll x = task2.front();
			task2.pop();
			for (ll i = 0; i < nx[x].size(); i++) {
				if (!seen2[nx[x][i]]) {
					task2.push(nx[x][i]);
					seen2[nx[x][i]] = true;
				}
			}
		}
		if (depth == dist / 2) break;
		depth++;
	}

	while (1) {
		ll x = task1.front();
		task1.pop();
		for (ll i = 0; i < nx[x].size(); i++) {
			if (seen2[nx[x][i]]) return {x, nx[x][i]};
			if (!seen1[nx[x][i]]) {
				task1.push(nx[x][i]);
				seen1[nx[x][i]] = true;
			}
		}
	}
}

ll bfs3(ll n, vector<vll> &nx, ll mid, vector<bool> &seen) {
	queue<ll> task;
	task.push(mid);
	seen[mid] = true;

	ll depth = 1;
	while (task.size()) {
		ll sz = task.size();
		while (sz--) {
			ll x = task.front();
			task.pop();
			for (ll i = 0; i < nx[x].size(); i++) {
				if (!seen[nx[x][i]]) {
					task.push(nx[x][i]);
					seen[nx[x][i]] = true;
					//cout << nx[x][i] + 1 << " " << depth << endl;
				}
			}
		}
		depth++;
	}
	return depth - 2;
}

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

	ll n, u, v;
	cin >> n >> u >> v;
	u--;
	v--;
	vector<vll> nx(n, vll(0));
	for (ll i = 0; i < n - 1; i++) {
		ll a, b;
		cin >> a >> b;
		nx[a - 1].push_back(b - 1);
		nx[b - 1].push_back(a - 1);
	}

	ll dist = bfs1(n, nx, u, v);

	ll ans = (dist - 1) / 2, mid1, mid2;
	if (dist <= 2) {
		mid1 = u;
		mid2 = v;
		if (nx[mid1].size() == 1) {
			cout << dist - 1 << endl;
			return 0;
		}
	}
	else {
		vll w = bfs2(n, nx, u, v, dist);
		mid1 = w[0];
		mid2 = w[1];
	}

	vector<bool> seen(n, false);
	seen[mid2] = true;
	ll escape = bfs3(n, nx, mid1, seen);
	ans += escape;
	if (dist % 2 == 0) ans++;
	cout << ans << endl;
}


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

int INF = 1e9;
vector<int> color(1e5,INF);
vector<vector<P>> edge(1e5);

void dfs(int i){
    for(int j = 0;j < edge[i].size();++j){
        int ni = edge[i][j].first;
        int nd = edge[i][j].second;
        if(color[ni] == INF){
            if(nd%2 == 0) color[ni] = color[i];
            else color[ni] = 1- color[i];
            dfs(ni);
        }
    }
}

int main(){
    int n; cin >> n;
    rep(i,n-1){
        int u,v,w; cin >> u >> v >> w;
        u--;v--;
        edge[u].push_back(P(v,w));
        edge[v].push_back(P(u,w));
    }
    color[0] = 0;
    dfs(0);
    rep(i,n) cout << color[i] << endl;
}

Measured memory_bytes: 8448
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, M = getNM()
S = getList()
N_s = len(S)
T = getList()
N_t = len(T)

dp = [[0] * (N_s + 1) for i in range(N_t + 1)]
dp[0][0] = 0

for i in range(N_t):
    for j in range(N_s):
        # 基礎 dp[i][j] + Sを伸ばして増えた分 + Tを伸ばして増えた分
        dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1] - dp[i][j]) % mod
        if S[j] == T[i]:
            # dp[i][j]の通りのそれぞれの末尾に(S[i], T[i])をつけることで
            # dp[i][j]通り（と空に(S[i], T[i])をつけた）分新しいのが作れる
            dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j] + 1) % mod
print((dp[N_t][N_s] + 1) % mod)

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

int main()
{
    lli n;
    cin>>n;
    lli a[n];
    map<lli,lli> m;
    for(lli i=0;i<n;i++)
    {
        cin>>a[i];
        m[a[i]]++;
    }
    lli ans=0;
    for(auto it=m.begin();it!=m.end();it++)
    {
        if(it->first>it->second)
        ans+=it->second;
        if(it->first<it->second)
        ans+=(it->second - it->first);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 7040
#include <stdio.h>
#include <iostream>

using namespace std;

#define MAX_NUM	1000000

int solist[MAX_NUM] = { 0 };

int main(int argc, char* argv[])
{
	int i; 
	int num;
	int count;
	int val;

	solist[0] = 1;
	solist[1] = 1;

	for (num = 2; num < MAX_NUM; num++) {
		if (solist[num]) continue;
		for (i = num * 2; i < MAX_NUM; i += num) {
			solist[i] = 1;
		}
	}

	while (cin >> val) {
		count = 0;
		for (i = 1; i <= val; i++) {
			if (solist[i] == 0) {
				count++;
			}
		}
		cout << count << endl;
	}
	
	return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll m;
    cin >> m;
    vector<pair<ll, ll>> dc(m);
    rep(i, m) cin >> dc[i].first >> dc[i].second;
    ll sum = 0, ans = 0;
    rep(i, m) {
        sum += dc[i].first * dc[i].second;
        ans += dc[i].second;
    }
    cout << (ans + ((sum - 1) / 9) - 1) << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <chrono>
#include <vector>
#include <iostream>

using namespace std;
using namespace std::chrono;

const vector<int> di = {-1, -1, -1, 0,  0, 1, 1,  1};
const vector<int> dj = { 1,  0, -1, 1, -1, 1, 0, -1};
const int dirs = di.size();

int main() {
  auto start = high_resolution_clock::now();

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int h, w;
  cin >> h >> w;
  vector<string> vs(h);
  for (int i = 0; i < h; ++i)
    cin >> vs[i];

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (vs[i][j] == '#')
        continue;
      int cnt = 0;
      for (int k = 0; k < dirs; ++k) {
        int ni = i + di[k];
        int nj = j + dj[k];
        cnt += 0 <= ni && ni < h && 0 <= nj && nj < w && vs[ni][nj] == '#';
      }
      vs[i][j] = to_string(cnt)[0];
    }
  }

  for (const string& it : vs)
    cout << it << endl;

  cerr << "Total execution time : " << duration_cast<milliseconds>(high_resolution_clock::now() - start).count() << " ms" << endl;

  return 0;
}


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

using namespace std;

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

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl



int N, Z, W;
int a[2345];

signed main(){

	cin >> N >> Z >> W;
	rep(i, N){
		cin >> a[i];
	}

	if (N == 1)
		cout << abs(W - a[0]) << endl;
	else
	cout << max(abs(W - a[N - 1]),
		abs(a[N - 2] - a[N - 1])) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

int main()
{
	int N, M;
	cin >> N;
	vector<string> s(N);
	for (auto i = 0; i < N; ++i)
	{
		cin >> s[i];
	}
	cin >> M;
	vector<string> t(M);
	for (auto i = 0; i < M; ++i)
	{
		cin >> t[i];
	}

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

	auto result = 0;
	for (auto i = 0; i < N;)
	{
		auto temp = 0;
		auto current = i;
		while (i < N && s[current] == s[i])
		{
			++temp;
			++i;
		}
		for (auto j = 0; j < M; ++j)
		{
			if (s[current] == t[j])
			{
				--temp;
			}
		}
		result = max(result, temp);
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b;
    cin>>a>>b;
    int ans=0;
    if(a<=5){
        ans=0;
    }else if(a>5&&a<13){
        ans=b/2;
    }else{
        ans=b;
    }
    cout<<ans<<endl;
    
    return 0;
    
}



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

int main(void)
{
	int n,cnt=1;
	scanf("%d",&n);
	char s[n][11];
	for(int i=0;i<n;i++){
		scanf("%s",s[i]);
	}
	
	qsort(s,n,11,strcmp);
	for(int i=0;i<n-1;i++){
		if(strcmp(s[i],s[i+1])!=0)
			cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}
		

Measured memory_bytes: 5736
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>

using namespace std;
using ll =long long;
const int mod = 1000000007;
int gcd(ll a, ll b) {

	if (b == 0) {

		return a;
	}
	else {
		a = a%b;
		gcd(b, a);
	}
}
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
void ini_func(vector<ll> & a, vector<ll> & b, ll N) {
	ll k, c;
	for (ll i = 0; i < N; i++) {
		cin >> k >> c;
		a.push_back(k);
		b.push_back(c);
	}


}
int GCD(vector<ll> a) {

	int ans = a[0];
	for (int i = 1; i < a.size(); i++) {

		ans = gcd(ans, a[i]);
	}
	return ans;

}
int main() {
	ll N;
	cin >> N;
	vector<ll>A(N);
	for (int i = 0; i < N; i++) {
		cin>>A[i];
	}
	cout << GCD(A);
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

struct UnionFind {
	int s, num; // [0, s) の s 個の要素がある。num は非空集合の個数。
	vector<vector<int>> v;
	vector<int> find;
	
	UnionFind() { s = 0; }
	UnionFind(int s) { init(s); }
	void init(int arg_s) {
		num = s = arg_s;
		v.clear();
		find.clear();
		inc(i, s) { v.PB({i}); find.PB(i); }
	}
	bool unite(int x, int y) {
		assert(inID(x, 0, s) && inID(y, 0, s));
		if(find[x] == find[y]) { return false; }
		num--;
		if(v[find[x]].size() > v[find[y]].size()) { swap(x, y); }
		int fx = find[x];
		for(auto && e: v[find[x]]) { v[find[y]].PB(e); find[e] = find[y]; }
		v[fx].clear();
		return true;
	}
};

// ----

LL n, m, a[100000], b[100000];

int main() {
	cin >> n >> m;
	UnionFind uf(n);
	inc(i, m) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		uf.unite(a[i], b[i]);
	}
	
	LL x = uf.v[uf.find[0]].size();
	LL y = uf.v[uf.find[1]].size();
	LL z = min(x, y);
	
	cout << (n * (n - 1) / 2 - z * (n - z) - m) << endl;
	
	return 0;
}


Measured memory_bytes: 9520
import bisect
import collections
import heapq
import itertools
import operator
import sys


def main():
    int_max = 2 ** 31 - 1
    n, q = map(int, sys.stdin.readline().split())
    n = 1 << (n - 1).bit_length()
    dat = [int_max] * 131072 * 2

    def update(i, x):
        i += n - 1
        dat[i] = x
        while i > 0:
            i = (i - 1) // 2
            dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2])

    def query(a, b, k, l, r):
        if r <= a or b <= l:
            return int_max
        if a <= l and r <= b:
            return dat[k]
        else:
            vl = query(a, b, k * 2 + 1, l, (l + r) // 2)
            vr = query(a, b, k * 2 + 2, (l + r) // 2, r)
            return min(vl, vr)

    for _ in range(q):
        com, x, y = map(int, sys.stdin.readline().split())
        if com == 0:
            update(x, y)
        elif com == 1:
            print(query(x, y + 1, 0, 0, n))


if __name__ == "__main__":
    main()



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

using namespace std;

const int Maxn = 100010;

int x[Maxn], y[Maxn];

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        cin >> x[i];
    }

    sort(x, x + m);

    for (int i = 0; i < m - 1; ++i) {
        y[i] = x[i + 1] - x[i];
    }

    sort(y, y + m - 1);
    reverse(y, y + m - 1);

    int ans = x[m - 1] - x[0];
    for (int i = 0; i < n - 1; ++i) {
        ans -= y[i];
    }

    cout << ans << endl;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, x;
    cin >> n >> x;
    vector<int> L(n+1);
    for(int i=0;i<n;i++){
        cin >> L[i];
    }
    int ans=0,count=1;
    for(int i=1;i<=n;i++){
        ans+=L[i-1];
        //cout<< "d=" << ans<<endl;
        if(ans>x) break;
        ++count;
    }
    cout << count << endl;
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
typedef long long ll;
using namespace std;

//素数判定
inline bool IsPrime(int p) {
	if (p == 1) return false;
	for (int i = 2; i <= sqrt(p); i++) {
		if (p%i == 0) return false;
	}
	return true;
}

//10進数の自然数の桁数を返す
inline int GetDigit(int num) {
	return (int)log10(num) + 1;
}

//各位の和を返す
int GetDigitsSum(int num) {
	int N = 0;
	while (num > 0) {
		N += num % 10;
		num /= 10;
	}
	return N;
}

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



//異なるn個からr個の整数を取り出す組合せの数を求める
int combination(int n, int r) {
	if (r == 0 || n == r) {
		return 1;
	}
	else if (r == 1) {
		return n;
	}
	else {
		return combination(n - 1, r - 1) + combination(n - 1, r);
	}

}

int main() {
	ll N; cin >> N;
	vector<ll> a(N + 100);
	for (ll i = 0; i < N; i++)
		cin >> a[i];
	map<ll, ll>mp;
	vector<ll>v;
	for (ll i = 0; i < N; i++) {
		mp[a[i]]++;
		if (mp[a[i]] >= 2)
		{
			v.push_back(a[i]);
			mp[a[i]] = 0;
		}
	}
	ll ans = 0;
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	if (v.size() >= 2)ans = v[0] * v[1];
	cout << ans << endl;
}

Measured memory_bytes: 7296
#include<iostream>
#include<algorithm>
using namespace std;
int a[2000];
int main() {
	int n,k,sum=0;
	cin>>n>>k;
	for(int i=0; i<n; i++) cin>>a[i];
	sort(a,a+n);
	for(int i=0; i<k; i++) sum+=a[i];
	cout<<sum;
}

Measured memory_bytes: 3616
input = gets.chomp.split
a = input[0].to_i
b = input[1].to_i
c = input[2].to_i
d = input[3].to_i

result = true
loop do
    c -= b
    break if c <= 0
    a -= d
    if a <= 0
        result = false
        break
    end
end

puts result ? "Yes" : "No"

Measured memory_bytes: 14248
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
#include<cassert>
#define ll long long
#define fi first
#define se second
using namespace std;

int n,m;
string s;
                   
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  cin>>s;
  for(int i=0;i<(int)s.length()-1;i++){
    if(s[i]=='A' && s[i+1]=='C'){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1,0);
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    map<ll,int> pl,mi;
    for(int i=1;i<=n;i++){
        pl[i+a[i]]++;
        mi[i-a[i]]++;
    }
    ll ans = 0;
    for(int i=1;i<=n;i++){
        ll p = i + a[i];
        ans += mi[p];
    }
    cout << ans << endl;

}

Measured memory_bytes: 38156
import java.util.Scanner;

public class Main{
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);

		long n = sc.nextLong();
		long k = sc.nextLong();
		int a,b,c;
		long total =0;

		long k2= k/2;
		if (k%2 == 1){
			total = (n/k)*(n/k)*(n/k);
		}
		else {
			if ((n/k2)%2 == 1){
				total = ((n/k2)/2)*((n/k2)/2)*((n/k2)/2) + ((n/k2)/2+1)*((n/k2)/2+1)*((n/k2)/2+1);
			}
			else total =((n/k2)/2)*((n/k2)/2)*((n/k2)/2)*2;
		}


/*
		if (k%2 == 1){
			a=k;
			for(int i=1;a*i<=n;++i){
				for (int j=i;a*j<=n;++j){
					for (int m=j;a*m<=n;++m){
						if (i==j && j==m)++total;
						else {
							if (i==j || j==m || i==m) total = total +3;
							else total = total +6;

						}
					}
				}
			}
		}

		else {
			a=k/2;
			for(int i=1;a*i<=n;++i){
				for (int j=i;a*j<=n;j=j+2){
					for (int m=j;a*m<=n;m=m+2){

						if (i==j && j==m)++total;
						else {
							if (i==j || j==m || i==m) total = total +3;
							else total = total +6;
						}
					}
				}
			}
		}
*/
		System.out.println(total);


	}

}

Measured memory_bytes: 23124
# import bisect
# from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    s = input()
    ss = set(s)

    print('Yes') if len(ss) == 2 else print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 38496
#include <iostream>

void PrintCheckFirstSharp( int length ){
    using namespace std;

    for( int i = 0; i < length; ++i ){
        if( i % 2 == 0 ){
            cout << '#';
        } else {
            cout << '.';
        }
    }
    cout << endl;
}

void PrintCheckFirstDot( int length ){
    using namespace std;
    
    for( int i = 0; i < length; ++i ){
        if( i % 2 == 0 ){
            cout << '.';
        } else {
            cout << '#';
        }
    }
    cout << endl;
}

void PrintArea( int H, int W ){
    using namespace std;

    for( int i = 0; i < H; ++i ){
        if( i%2 == 0){
            PrintCheckFirstSharp( W );
        } else {
            PrintCheckFirstDot( W );
        }
    }
    cout << endl;
}

int main(){
    using namespace std;

    while( true ){
        int H = 0;
        int W = 0;
        cin >> H >> W;

        if( H == 0 && W == 0 ){ break; }

        PrintArea( H, W );
    }

    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#include<iomanip>
#include<cmath>
#define lld long long int
#define ld long double
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b)  for(lld i=a;i<=b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define endl '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vector<vector<lld> > dp(101,vector<lld>(100001,1e18));
int main()
{
     ios;
     lld n,we;
     cin>>n>>we;
     vector<lld> v(n+1),w(n+1);
     rep(i,1,n)
     {
         cin>>w[i]>>v[i];
     }
     lld ans=0;
     dp[0][0]=0;
     rep(i,1,n)
     {
         dp[i]=dp[i-1];
         rep(j,0,100000)
         {
             if(j==0)
                dp[i][j]=0;
             else if(j-v[i]>=0)
             {
                 dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
             }
         }
     }
     rep(i,1,100000)
     {
         if(dp[n][i]<=we)
         {
             ans=i;
         }
     }
     cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 80256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>

using namespace std;

typedef long long int ll;
typedef long int li;

int main(void){
    int ans=0;
    int n,m;
    cin >> n >> m;
    int box[m+1];
  	for(int i=0;i<m+1;i++)box[i]=0;
    for(int i=0;i<n;i++){
        int k;
        cin >> k;
        for(int j=0;j<k;j++){
            int x;
            cin >> x;
        box[x]++;
        }
    }
    for(int i=1;i<m+1;i++){
        if(box[i]==n)ans++;
    }
    
    cout << ans << endl;
}



Measured memory_bytes: 256
n  = int(input())
x = [0]*n
y = [0]*n
for i in range(n):
    x[i],y[i] = map(int,input().split())


ans = "No"
count = 0
for i in range(n):
    if x[i]== y[i]:
        count +=1
    else:
        count =0
    if count == 3:
        ans = "Yes"

print(ans)


Measured memory_bytes: 62616
def main():
    N = int(input())
    W = [input() for _ in range(N)]
 
    if len(set(W)) != len(W):
        print("No")
        return
    W = [list(a) for a in W]
 
    for i in range(len(W) - 1):
        if W[i][-1] != W[i + 1][0]:
            print("No")
            return
    print("Yes")
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <map>
#include <queue>

using namespace std;

int dire[4] = {1,-1,4,-4};
map<string,int> dp;
queue<string> q;
char data[10];
string now,after;//now保存当前状态。after则是移动后的
int zs;//zs用来记录0所在的位置

void bfs(){
    now = "01234567";
    dp[now] = 0;
    q.push(now);

    while(!q.empty()){
        now = q.front();
        q.pop();

        //找到0的位置
        for(int i = 0; i < 8; i++){
            if(now[i] == '0'){
                zs = i;
                break;
            }
        }

        for(int i = 0; i < 4; i++){

            int nx = zs + dire[i];
            if(nx >= 0 && nx <= 8 && !(zs == 3 && nx == 4) && !(zs == 4 && nx == 3)){
                //先保存现在的状态
                after = now;
                swap(after[zs],after[nx]);
                //如果map里面没有出现这个情况，加入；
                if(dp.count(after) == 0){
                    dp[after] = dp[now] + 1;
                    q.push(after);
                }
            }
        }
    }
}

int main(void){

    bfs();
    while(~scanf("%c",&data[0])){

        for(int i = 1; i <= 7; i++){
            getchar();//吃掉空格
            scanf("%c",&data[i]);
        }
        getchar();//吃掉换行符

        cout << dp[data] << endl;
    }

    return 0;
}


Measured memory_bytes: 43632