akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n, m;
	cin >> n >> m;
	string s[n];
	for(int i = 0; i < n; i++) {
		cin >> s[i];
	}
	int dp[n][m];
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			if(s[i][j] == '.') {
				if(i) {
					dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
				}
				if(j) {
					dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
				}
			}
		}
	}
	cout << dp[n - 1][m - 1];

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
//const ll mod = 1000000007;

int l, r;
int ans;

signed main() {
    cin >> l >> r;
    ans = INF;
    if (r - l >= 2019) ans = 0;
    else {
        for (int j = l + 1; j <= r; j++) {
            for (int i = l; i < j; i++) {
                int cnd = (i * j) % 2019;
                ans = min(ans, cnd);
            }
        }
    }

    cout << ans << endl;
}


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

using namespace std;

vector<ll> pr3(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
int main() {
  long long n;
  scanf("%lld", &n);

  auto e = pr3(n);

  ll ans = n - 1;

  ll len = e.size();
  for (ll i = 0; i < len - 1; i++) {
    ll a = e[i];
    ll b = n / a;

    ans = min(ans, (a + b - 2));
  }

  cout << ans << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

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

int main(){
  int n;
  cin >> n;
  if(n%10==7 || n/10%10==7 || n/100%10==7){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3596
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[] prime = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997};
		long ans = 1;
		for(int i = 0; i < prime.length; i++) {
			long temp = 0;
			int cnt = 1;
			while(N / (long)Math.pow(prime[i], cnt) > 0) {
				temp += N / (long)Math.pow(prime[i], cnt);
				cnt++;
			}
			if(temp != 0) {
				ans = ans * (temp + 1) % 1000000007;
			}
		}
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 21972
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int main(void){
    int n;
    scanf("%d",&n);
    int m=0,head[n*2],next[n*2],to[n*2],a,b,post[n],count;
    bool visited[n];
    
    for (int i=0; i<n; i++){
        head[i]=-1;
    }
    for (int i=0; i<n-1; i++){
        scanf("%d%d",&a,&b);
        a--;
        b--;
        next[m]=head[a];
        head[a]=m;
        to[m]=b;
        m++;
        next[m]=head[b];
        head[b]=m;
        to[m]=a;
        m++;
    }
    
    for (int i=0; i<n; i++){
        visited[i]=false;
    }
    int costf[n];
    costf[0]=0;
    visited[0]=true;
    count=0;
    post[0]=0;
    for (int i=0; i<count+1; i++){
        for (int e=head[post[i]]; e!=-1; e=next[e]){
            if (visited[to[e]]==false){
                visited[to[e]]=true;
                costf[to[e]]=costf[post[i]]+1;
                count++;
                post[count]=to[e];
            }
        }
    }
    
    for (int i=0; i<n; i++){
        visited[i]=false;
    }
    int costs[n];
    costs[n-1]=0;
    visited[n-1]=true;
    count=0;
    post[0]=n-1;
    for (int i=i=0; i<count+1; i++){
        for (int e=head[post[i]]; e!=-1; e=next[e]){
            if (visited[to[e]]==false){
                visited[to[e]]=true;
                costs[to[e]]=costs[post[i]]+1;
                count++;
                post[count]=to[e];                
            }
        }
    }

    int Fennec=0,Snuke=0;
    for (int i=0; i<n; i++){
        if (costf[i]<=costs[i]){
            Fennec++;
        } else {
            Snuke++;
        }
    }
    
    if (Fennec>Snuke){
        printf("Fennec\n");
    } else {
        printf("Snuke\n");
    }
    

	return 0 ;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define deb(x) cout<<#x<<" = "<<x<<"\n";
#define F first
#define S second
#define mod 1000000007

signed main()
{
	
	int a, b; cin>>a>>b;
	if(a*500 >= b) cout<<"Yes\n";
	else cout<<"No\n";
	
	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <deque>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)
const ll mod = 1e9+7;
int main(){
  int n;
  ll k;
  cin >> n >> k;
  vector<int> v(n);
  ll ans = 0;
  rep(i,n) cin >> v[i];
  rep(i,n){
    for (int j = i+1; j < n;j++){
      if (v[i] > v[j]) ans++;
    }
  }
  ans *= k;
  ans %= mod;
  sort(v.begin(),v.end());
  rep(i,n){
    ll tmp = k*(k-1)/2;
    tmp%=mod;
    ans += (tmp*ll(lower_bound(v.begin(),v.end(),v[i])-v.begin()));
    ans%=mod;
  }
  cout << ans << endl;

  return 0;
  
}


Measured memory_bytes: 3628
using AtCoderBeginnerContest155.Questions;
using AtCoderBeginnerContest155.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest155.Questions
{
    public class QuestionB : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var n = inputStream.ReadInt();
            var a = inputStream.ReadIntArray();

            if (a.Where(i => i % 2 == 0).All(i => i % 3 == 0 || i % 5 == 0))
            {
                yield return "APPROVED";
            }
            else
            {
                yield return "DENIED";
            }
        }
    }
}


namespace AtCoderBeginnerContest155
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionB();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest155.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest155.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;

// http://www.prefield.com/algorithm/misc/dice.html
enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };
class dice {
public:
	dice(int top,int front,int right,int left,int back,int bottom) {
		id[TOP] = top; id[FRONT] = front; id[RIGHT] = right;
		id[LEFT] = left; id[BACK] = back; id[BOTTOM] = bottom;
	}
	int& operator[] (FACE f) { return id[f]; }
	const int& operator[] (FACE f) const { return id[f]; }
	bool operator==(const dice &b) const {
		const dice &a = *this;
		return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] &&
			a[FRONT] == b[FRONT] && a[BACK] == b[BACK] &&
			 a[LEFT] == b[LEFT] && a[RIGHT] == b[RIGHT];
	}
	void roll_north() { roll(TOP, FRONT, BOTTOM, BACK); }
	void roll_south() { roll(TOP, BACK, BOTTOM, FRONT); }
	void roll_east() { roll(TOP, LEFT, BOTTOM, RIGHT); }
	void roll_west() { roll(TOP, RIGHT, BOTTOM, LEFT); }
	void roll_right() { roll(FRONT, LEFT, BACK, RIGHT); }
	void roll_left() { roll(FRONT, RIGHT, BACK, LEFT); }
	void all_rolls(set<long long> &s){
		for (int k = 0; k < 6; (k&1?roll_east():roll_north()),++k)
			for (int i = 0; i < 4; roll_right(), ++i)
				s.insert(((long long)id[TOP]<<40) | ((long long)id[FRONT]<<32) | (id[RIGHT]<<24) | (id[LEFT]<<16) | (id[BACK]<<8) | (id[BOTTOM]<<0));
	}
private:
	void roll(FACE a, FACE b, FACE c, FACE d){
		int tmp = id[a];
		id[a] = id[b]; id[b] = id[c];
		id[c] = id[d]; id[d] = tmp;
	}
	int id[6];
};

int main(){
	string str;
	int d[6];
	int n,i,j,r;
	for(;cin>>n,n;){
		set<long long>s;
		for(r=i=0;i<n;i++){
			for(j=0;j<6;j++)cin>>str,d[j]=str[0];
			long long x=((long long)d[0]<<40) | ((long long)d[1]<<32) | (d[2]<<24) | (d[3]<<16) | (d[4]<<8) | (d[5]<<0);
			if(s.find(x)!=s.end())r++;
			else{
				dice di(d[0],d[1],d[2],d[3],d[4],d[5]);
				di.all_rolls(s);
			}
		}
		cout<<r<<endl;
	}
}

Measured memory_bytes: 1228
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;

    int sum = 0;
    if (a >= b)
    {
        sum += a--;
    } else sum += b--;
    if (a >= b)
        sum += a--;
    else sum += b--;
    cout << sum;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <utility>
using namespace std;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int k = s.size();  
  int ans = 0;
  for(int i = 0; i < k - 1; i++){
    int cnt = 0;
    vector<char> s1(i + 1);
    vector<char> s2(k - i - 1);
    vector<int> v1(26);
    vector<int> v2(26);

    for(int j = 0; j < i + 1; j++){
      s1[j] = s[j];
      for(int l = 0; l < 26; l++){
        if(s1[j] == l + 97){v1[l] = 1; break;}
      }
    }
    for(int j = 0; j < k - i - 1; j++){
      s2[j] = s[j + i + 1];
      for(int l = 0; l < 26; l++){
        if(s2[j] == l + 97){v2[l] = 1; break;}
      }
    }

    for(int j = 0; j < 26; j++){
      if(v1[j] == v2[j] && v1[j] == 1){cnt++;}
    }
    if(cnt > ans){ans = cnt;}
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#define MN 201000

struct xxx{
	int x, y, k;
}d[MN]; 

int fa[MN], s[MN];

bool cmp(xxx a, xxx b) {return a.k > b.k;}

int Find(int x) {return fa[x] == x ? x : fa[x] = Find(fa[x]);}

int main()
{
	int n, h, w; scanf("%d%d%d", &n, &h, &w);
	for(int i = 1; i <= n; i++) scanf("%d%d%d", &d[i].x, &d[i].y, &d[i].k);
	std::sort(d + 1, d + n + 1, cmp);
	for(int i = 1; i <= h + w; i++) fa[i] = i, s[i] = 1; 
	long long Ans = 0;
	for(int i = 1; i <= n; i++)
	{
		int dx = Find(d[i].x), dy = Find(d[i].y + h);
		if(dx == dy)
		{
			if(s[dx] >= 1)
			{
				s[dx]--;
				Ans += d[i].k;
			}
		}
		else
		{
			if(s[dx] + s[dy] >= 1)
			{
				fa[dx] = dy;
				s[dy] += s[dx] - 1;
				Ans += d[i].k;
			}
		}
	}
	printf("%lld\n", Ans);
}

//从大往小贪心加入每个卡片，用Hall定理依次判断 

Measured memory_bytes: 3072
N = int(input())
INF = 10**9
dp = [INF]*(N+1)
dp[0] = 0
num6 = [6**i for i in range(1, 10)]
num9 = [9**i for i in range(1, 7)]
S = sorted([1] + num6 + num9)

for i in range(1, N+1):
    for j in S:
        if j > i:
            break
        else:
            dp[i] = min(dp[i], dp[i-j]+1)

print(dp[N])

Measured memory_bytes: 3828
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long 
using namespace std;
int main(){
  ll x,t;
  cin >>x>>t;
  if(t>x)cout <<0<<endl;
  else cout <<x-t<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/

int main() {
	int l,r,d;
	std::cin >> l >> r >> d;
	int count=0;
	for(int i=l;i<=r;i++) {
		if(i%d==0) count++;
	}
	print(count);
}


Measured memory_bytes: 3564
#include<iostream>
#include<cmath>
#include<vector>
#include<bitset>
#include<bitset>
#include<string>
#include<utility>
#include<queue>

using namespace std;

int main(){
    int n,k;
    cin >> n >>k;
    long long int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int j=k;j<n;j++){
        if(a[j-k]<a[j]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4724
#include <stdio.h>
#include <math.h>

int main(void)
{
  long long int N, P, Q, p, k, ans;

  scanf("%lld%lld",&N,&P);

  if(N == 1) {
    printf("%lld\n",P);
    return 0;
  }
  else if (N>=40) {
    printf("%lld\n",1);
    return 0;
  }
  
  ans = 1;
  p = 2;
  while(1) {
    Q = pow(p,N);
    if(P < Q) {
      break;
    } else if(P == Q) {
      ans *= p;
      break;
    }

    k = 0;
    while(P % p == 0) {
        P /= p;
        k ++;
    }
    ans *= pow(p, k/N);
    p += 1;
  }

  printf("%lld\n",ans);
  return 0;
}


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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);


// ABC074C - Sugar Water
int main(){
  int A, B, C, D, E, F;
  // 1 <= A < B <= 30
  // 1 <= C < D <= 30
  // 1 <= E <= 100
  // 100A <= F <= 3000
  cin >> A >> B >> C >> D >> E >> F;

  vector<int> waterList;
  vector<int> sugerList;
  waterList.reserve(F);
  sugerList.reserve(F);
  for (int i = 0; i <= F; ++i) {
    for (int j = 0; j <= F; ++j) {
      int x = 100 * (A * i + B * j);
      if (x <= F) {
        waterList.push_back(x);
      }
      int y = C * i + D * j;
      if (y <= F) {
        sugerList.push_back(y);
      }
    }
  }
  int maxWater = 0;
  int maxSuger = 0;
  long double maxNoudo = -1;
  rep(i, waterList.size()) {
    const int x = waterList[i];
    rep(j, sugerList.size()) {
      const int y = sugerList[j];
      if (x + y > F) {
        continue;
      }
      if (x / 100 * E < y) {
        continue;
      }
      if (x == 0 && y == 0) {
        continue;
      }
      //cout << "x:" << x << ",y:" << y << endl;
      const long double noudo = 100 * y / (long double)(x + y);
      if (noudo >= maxNoudo) {
        maxWater = x;
        maxSuger = y;
        maxNoudo = noudo;
      }
    }
  }

  cout << (maxWater + maxSuger) << " " << maxSuger << endl;
  return 0;
}


Measured memory_bytes: 1420
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;

int main(){
	int n;
	while(cin >> n && n){
		int y;
		cin >> y;
		vector< pair<double,int> > S;
		for(int i = 0 ; i < n ; i++){
			double b,r,t;
			cin >> b >> r >> t;
			
			if( t == 1 ){
				S.push_back(make_pair(1+y*r/100.0,(int)b));
			}else{
				S.push_back(make_pair(pow(1+r/100.0,y),(int)b));
			}
		}
		sort(S.rbegin(),S.rend());
		cout << S[0].second << endl;
	}
}

Measured memory_bytes: 0
/*
 * You Siki
 * Born to be King!
 */

#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>

//using namespace std;

const int LIMIT = 10000000;

char in[LIMIT], *p = in;

__inline int nextInt(void) {

    register int res = 0;
    register bool neg = false;

    while (*p < '0' || *p > '9')
        if (*p++ == '-')neg ^= 1;

    while (*p >= '0' && *p <= '9')
        res = res * 10 + *p++ - '0';

    return neg ? -res : res;

}

__inline long long nextLong(void) {

    register long long res = 0;
    register bool neg = false;

    while (*p < '0' || *p > '9')
        if (*p++ == '-')neg ^= 1;

    while (*p >= '0' && *p <= '9')
        res = res * 10 + *p++ - '0';

    return neg ? -res : res;

}

int max(int x, int y) {
	return x > y ? x : y;
}

const int N = 100005;

int n, m, num[N];

signed main(void) {

	fread(p, 1, LIMIT, stdin);
	
	n = nextInt();
	m = nextInt();
	
	for (register int i = 1; i <= n; ++i)
		num[i] = nextInt();
		
	for (register int t = 1; t <= m; ++t) {
		long long q = nextLong(), ans = 0, sum = 0;
		for (register int i = 1, j = 0; i <= n; ++i) {
			while (j < n && sum + num[j + 1] <= q)
				sum += num[++j];
			ans += (j - i + 1); sum -= num[i];
		}
		printf("%lld\n", ans);
	}

}

Measured memory_bytes: 2464
N, M = map(int, input().split())

B = [tuple(map(int, input().split())) for _ in range(N)]
B.sort(reverse=True)

import heapq

hq = []
ans = 0
for i in range(1, M+1):
    while B and B[-1][0] == i:
        heapq.heappush(hq, B.pop()[1]*(-1))
    if hq:
        ans -= heapq.heappop(hq)

print(ans)








Measured memory_bytes: 17240
#include<stdio.h>
#define ST_SIZE ((1 << 18) - 1)
typedef long long int LL;
LL dat[ST_SIZE], lazy[ST_SIZE];
LL input(void);
void eval(LL k, LL l, LL r);
void add(LL a, LL b, int x, LL k, LL l, LL r);
LL sum(LL a, LL b, LL k, LL l, LL r);
int main (void) {
  int command, x;
  LL i, n, q, s, t, n2 = 1;
  n = input();
  q = input();
  while (n2 < n) n2 *= 2;
  n = n2;
  for (i = 0; i < q; i++) {
    command = input();
    if (!command) {
      s = input();
      t = input();
      x = input();
      add(s - 1, t, x, 0, 0, n);
    } else {
      s = input();
      t = input();
      printf("%lld\n", sum(s - 1, t, 0, 0, n));
    }
  }
}
LL input(void)
{
  LL n = 0;
  int c = getchar_unlocked();
  if (c == '-') {
    c = getchar_unlocked();
    do {
      n = 10 * n + c - '0';
      c = getchar_unlocked();
    } while (c >= '0' && c <= '9');
    return -n;
  } else {
    do {
      n = 10 * n + c - '0';
      c = getchar_unlocked();
    } while (c >= '0' && c <= '9');
    return n;
  }
}
void eval(LL k, LL l, LL r)
{
  if (lazy[k] != 0) {
    dat[k] += lazy[k];
    if (r - l > 1) {
      lazy[k*2+1] += lazy[k] / 2;
      lazy[k*2+2] += lazy[k] / 2;
    }
    lazy[k] = 0;
  }
}
void add(LL a, LL b, int x, LL k, LL l, LL r)
{
  eval(k, l, r);
  if (a >= r || b <= l) return;
  else if (a <= l && b >= r) {
    lazy[k] = (r - l) * x;
    eval(k, l, r);
  }
  else {
    add(a, b, x, k * 2 + 1, l, (l + r) / 2);
    add(a, b, x, k * 2 + 2, (l + r) / 2, r);
    dat[k] = dat[k*2+1] + dat[k*2+2];
  }
}
LL sum(LL a, LL b, LL k, LL l, LL r)
{
  eval(k, l, r);
  if (a >= r || b <= l) return 0;
  else if (a <= l && b >= r) return dat[k];
  else {
    LL vl, vr;
    vl = sum(a, b, k * 2 + 1, l, (l + r) / 2);
    vr = sum(a, b, k * 2 + 2, (l + r) / 2, r);
    return (vl + vr);
  }
}


Measured memory_bytes: 5032
<?php
	$n=fgets(STDIN);
	fscanf(STDIN,"%d%d",$t,$a);
	$s=1000000000;
	$h=explode(' ',fgets(STDIN));
	for($i=1;$i<=$n;$i++){
		$now=($t-$a)*1000-$h[$i-1]*6;
		$now=abs($now);
		if($s>$now)
		{
			$s=$now;
			$id=$i;
		}
	}
	echo $id;


Measured memory_bytes: 3828
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

string s;
vector<int> vi;

int main() {
	cin >> s;
	ll n;
	stringstream ss;
	ss << s;
	ss >> n;
	ss.clear();
	rep(i, 10)vi.push_back(i);
	sort(ALL(vi));
	ll g = 0;
	ll ans = 0;
	ll p = pow(10, s.size());
	do {
		ll num = 0;
		rep(i, s.size()) {
			num *= 10;
			num += vi[i];
		}
		if (g < min((ll)abs(num - n), (ll)(p - abs(num - n)))) {
			g = min((ll)abs(num - n), (ll)(p - abs(num - n)));
			ans = num;
		}
	} while (next_permutation(ALL(vi)));
	string a;
	ss << ans;
	ss >> a;
	reverse(ALL(a));
	while (a.size() != s.size())a += "0";
	reverse(ALL(a));
	rep(i, a.size())cout << a[i];
	cout << endl;
}


Measured memory_bytes: 3396
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

#define x first
#define y second

using namespace std;

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

const int maxn = 2e5 + 10;

int t,n,m;

int main(void) {
	string str;
	cin >> n;
	cin >> str;
	if(str.length() > n) {
		for(int i = 0; i < n; i ++) {
			cout << str[i];
		}
		cout << "..." << endl;
	} else {
		cout << str << endl;
	}

	return 0;	
}
 

Measured memory_bytes: 3620
import itertools

def main() :
    N, M, R = map(int, input().split())
    r = [a-1 for a in list(map(int, input().split()))]
    d = [[float('inf')]*N for _ in range(N)]

    for _ in range(M):
        a, b, c = map(int, input().split())
        d[a-1][b-1] = c
        d[b-1][a-1] = c

    for i in range(N):
        d[i][i] = 0

    for k in range(N):
        for i in range(N):
            for j in range(N):
                dd = d[i][k] + d[k][j]
                if dd < d[i][j]:
                    d[i][j] = dd

    ans = float("inf")

    for perm in itertools.permutations(r):
        a = 0
        for i in range(len(perm)-1):
            a += d[perm[i]][perm[i+1]]
        ans = min(a, ans)

    print(ans)
    
main()

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

#define long long long

using namespace std;

const int N = 1e5 + 10;

int d[N];

int main() {
    int n; cin >> n;
    set <pair <int, int> > S;
    for (int i = 0; i < n; ++i) d[i] = (int)2e9;
    for (int i = 1; i < 10; ++i) if (d[i % n] == (int)2e9)
        S.insert({i, i % n}), d[i % n] = i;
    while (S.size()) {
        int w = S.begin() -> first;
        int x = S.begin() -> second; S.erase(S.begin());
        // cout << w << " " << x << endl;
        for (int digit = 0; digit < 10; ++digit) {
            int nx = (x * 10 + digit) % n;
            if (d[nx] > d[x] + digit) {
                S.erase({d[nx], nx});
                d[nx] = d[x] + digit;
                S.insert({d[nx], nx});
            }
        }
    }
    cout << d[0] << endl;
    return 0;
}

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

#define int long long
signed main(){
	string s; int num; cin >> s >> num; bool flg = 1;
	for(int i = 1 ; i < s.size() ; ++i) flg &= s[i] == s[1];
	if(flg){cout << s.size() * num / 2; return 0;}
	vector < int > len; int pre = 0 , ans = 0;
	for(int i = 1 ; i < s.size() ; ++i)
		if(s[i] != s[pre]){len.push_back(i - pre); pre = i;}
	len.push_back(s.size() - pre);
	for(int i = 1 ; i + 1 < len.size() ; ++i) ans += len[i] / 2 * num;
	if(*s.begin() != *--s.end()) ans += (*len.begin() / 2 + *--len.end() / 2) * num;
	else ans += *len.begin() / 2 + *--len.end() / 2 + ((*len.begin() + *--len.end()) / 2) * (num - 1);
	cout << ans; return 0; 
}


Measured memory_bytes: 764
import itertools

def solve(S):
    '''
    数字の間に+を入れるパターンと入れないパターンを全てチェックする
    125であれば、 125, 1+25, 12+5, 1+2+5
    +が入る可能性のある場所は右の通り、 1  |ここ!| 2  |ここ!| 5
    よって、組み合わせは 2 ** (文字列数 - 1)
    '''
    
    if len(S) == 1:
        print(int(S))
    else:
        count = 0
        bit_list = list(itertools.product([0, 1], repeat=len(S)-1))
        for pattern in bit_list:
            '''
            ビットの値が1の時に+が入ると考えて、0の時は入らない
            文字列を先頭から調べていき、次の文字との間に+が入る場合、そこまでの文字列をint型に変換して変数「count」に加算する
            +が入る場所の次の文字をstartに記録する
            
            '''
            start = 0
            for end in range(len(pattern)):
                if pattern[end] == 1:
                    count += int(S[start:end+1])
                    start = end + 1
    
            count += int(S[start:])

        print(count)


if __name__ == '__main__':
    S = input()
    solve(S)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoderProg {
    class A_Product {
        static void Main(string[] args) {
            int a, b;

            string[] str = Console.ReadLine().Split(' ');
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);

            if ((a * b) % 2 == 0) {
                Console.WriteLine("Even");
            } else {
                Console.WriteLine("Odd");
            }
        }
    }
}


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

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

  vector<uint64_t> B(Q);
  vector<uint64_t> C(Q);
  for (uint64_t i = 0; i < Q; i++) {
    cin >> B[i];
    cin >> C[i];
  }

  uint64_t total = 0;
  unordered_map<uint64_t, uint64_t> Amap;
  for (auto a : A) {
    if (Amap.count(a) == 0) {
      Amap[a] = 0;
    }
    Amap[a]++;
    total += a;
  }
  for (uint64_t i = 0; i < Q; i++) {
    auto b = B[i];
    auto c = C[i];
    if (Amap.count(b) > 0) {
      auto num = Amap.at(b);
      Amap.erase(b);
      if (Amap.count(c) == 0) {
        Amap[c] = 0;
      }
      Amap[c] += num;
      total = total + (num * c) - (num * b);
    }
    cout << total << endl;
  }
}


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

int main()
{
    int c = 0;
    string s;
    cin >> s;
    for(int i = 0; i < 3; i++)
    {
        if(s[i] == '1')
        {
            c = c + 1;
        }
    }
    cout << c << endl;
}

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

int main()
{
	char k;
	int x,y,z,w;
	k=' ';
	cin >> x >> y >> z ;
	w=x;
	x=y;
	y=w;

	w=x;
	x=z;
	z=w;

	cout << x <<k << y << k << z ;

	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0,nn=(intl)(n);i<nn;++i)
#define Rep1(i,n) for(intl i=1,nn=(intl)(n)+1;i<nn;++i)
#define vec vector
#define fi first
#define se second
#define eb emplace_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(),v.rend())
#define All(a) (a).begin(),(a).end()
#define Input(a) for(intl ii=0,nn=(intl)(a.size());ii<nn;ii++){cin>>(a).at(ii);}
#define Input2(a,b) for(intl ii=0,nn=(intl)(a.size());ii<nn;ii++){cin>>(a).at(ii);cin>>(b).at(ii);}
#define mp make_pair
#define mt make_tuple
using intl = int64_t;
using vi = vec<intl>;
using vb = vec<bool>;
using vvi = vec<vi>;
using pi = pair<intl,intl>;
using vpi = vec<pi>;
using si = set<intl>;
using vsi = vec<si>;
using mii = map<intl,intl>;
using vmii = vec<mii>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr intl INF = 9223372036854775807;

/*
intl sum( vec<vec<bool>> &mat){
  intl ans=0
  for(auto&& n :mat){
    for(auto&& m : mat){
      if(m) ++ans;
    }
  }
  return ans;
}
*/

int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  
  intl H,W,K;
  
  cin >> H>>W>>K;
  
  vec<vec<bool>> bw(H,vec<bool>(W,0));
  char sign;
  Rep(i,H){
    Rep(j,W){
      cin >>sign;
      if(sign=='#'){bw[i][j] = 1;}
    }
  }
  
  /*
  Rep(i,H){
    Rep(j,W){
      cout << bw[i][j];
    }
    cout <<endl;
  }
  */
  
  intl sum;
  intl ans=0;
  for(intl i =0; i != 1<<H ; ++i){
    for(intl j = 0; j != 1<<W; ++j){
      sum =0;
      
      bitset<6> ho(i);
      bitset<6> ve(j);
      
      Rep(k,H){
        if(!ho.test(k)){continue;}
        Rep(l,W){
          if(!ve.test(l)){continue;}
          if(bw[k][l])++sum;
        }
      }
      
      if(sum==K){
        ++ans;
        //cout<<ho<<" "<<ve<<endl;
      }

    }
  }
  
  cout <<ans;
}
        
  
  
  

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

#ifdef ARTEM
	#define deb(x) x
#else
	#define deb(x)
	const int LIMIT = 2 * int(1e5) + 123;
#endif

void solve();

int main() {
	solve();
}

/* ================ actual code starts here ================ */

void solve() {
	int l, r, d;
	scanf("%d%d%d", &l, &r, &d);
	printf("%d\n", r / d - (l - 1) / d);
}

Measured memory_bytes: 3824
let () =
  Scanf.scanf "%d %d" (fun x y ->
    [ if x <= y then y - x else max_int;
      if -x <= y then 1 + x + y else max_int;
      if x <= -y then 1 - x - y else max_int;
      if -x <= -y then 2 + x - y else max_int ])
  |> List.fold_left min max_int
  |> Printf.printf "%d\n"



Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

const uint64_t MOD = 1e+9 + 7;

class ModuloOps
{
private:
  std::vector<uint64_t> _fact, _fact_inv;

  void _calc_fact(uint64_t n)
  {
    for (uint64_t i = 2; i <= n; ++i) {
      _fact[i] = (_fact[i - 1] * i) % MOD;
      _fact_inv[i] = inv(_fact[i]);
    }
  }

public:
  ModuloOps(uint64_t n)
  {
    _fact     = std::vector<uint64_t>(n + 1);
    _fact_inv = std::vector<uint64_t>(n + 1);

    _fact[0] = _fact[1] = 1;
    _fact_inv[0] = _fact_inv[1] = 1;

    _calc_fact(n);
  }

  uint64_t power(uint64_t x, uint64_t y) const
  {
    if (y <= 1) {
      return (y == 0) ? 1 : (x % MOD);
    }

    uint64_t w = power(x, y >> 1);
    uint64_t z = (w * w) % MOD;

    if (y % 2 == 1) {
      z = (x * z) % MOD;
    }

    return z;
  }

  uint64_t inv(uint64_t n) const { return power(n, MOD - 2); }

  uint64_t fact(uint64_t n) const { return _fact[n]; }
  uint64_t fact_inv(uint64_t n) const { return _fact_inv[n]; }

  uint64_t perm(uint64_t n, uint64_t k) const {
    return (_fact[n] * _fact_inv[n - k]) % MOD;
  }

  uint64_t comb(uint64_t n, uint64_t k) const {
    return (perm(n, k) * _fact_inv[k]) % MOD;
  }

  uint64_t prem_rep(uint64_t k, uint64_t l) const
  {
    uint64_t x = _fact[k + l];
    x = (x * _fact_inv[k]) % MOD;
    x = (x * _fact_inv[l]) % MOD;
    return x;
  }

  uint64_t prem_rep(const std::vector<uint64_t> &a) const
  {
    uint64_t n = std::accumulate(a.begin(), a.end(), 0);
    uint64_t x = _fact[n];
    for (uint64_t y : a) {
      x = (x * _fact_inv[y]) % MOD;
    }
    return x;
  }

  uint64_t comb_rep(uint64_t n, uint64_t k) const {
    return comb(n + k - 1, k);
  }
};

uint64_t subtract_abs(uint64_t a, uint64_t b)
{
  return a > b ? a - b : b - a;
}

int main(int argc, char **argv)
{
  uint64_t N;
  std::cin >> N;
  
  std::vector<uint64_t> A(N);
  N_TIMES(n, N) { std::cin >> A[n]; }
  
  ModuloOps mod_ops(N + 1);
  
  std::vector<uint64_t> S(N + 1);
  N_TIMES(n, N) { 
    S[n + 1] = mod_ops.inv(n + 1) + S[n];
  }
  
  uint64_t fact_N = mod_ops.fact(N);
  
  uint64_t T = 0;
  
  for (uint64_t j = 0; j < N; ++j) {
    uint64_t P = ((S[j + 1] - S[0]) + (S[N - j] - S[1])) % MOD;
    uint64_t Q = (A[j] * ((fact_N * P) % MOD)) % MOD;
    T = (T + Q) % MOD;
  }
  
  std::cout << T << std::endl;
  
  return 0;
}

Measured memory_bytes: 3328
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let m: usize = read();
    let mut ss = vec![];

    for _ in 0..m {
        let k: usize = read();
        let s: Vec<usize> = (0..k).map(|_| read()).collect();
        ss.push(s);
    }
    let p: Vec<usize> = (0..m).map(|_| read()).collect();

    let mut switchs = vec![];
    let switch = vec![];
    make_switch_pattern(&mut switchs, &switch, n);

    let ans = switchs
        .iter()
        .filter(|switch| {
            ss.iter()
                .zip(p.iter())
                .filter(|&(s, p_i)| s.iter().filter(|s_i| !switch[**s_i - 1]).count() % 2 == *p_i)
                .count()
                == m
        })
        .count();

    println!("{}", ans);
}

// true: on, false: off
fn make_switch_pattern(switchs: &mut Vec<Vec<bool>>, switch: &Vec<bool>, count: usize) {
    if count == 0 {
        switchs.push(switch.clone());
    } else {
        let mut switch1 = switch.clone();
        switch1.push(true);
        make_switch_pattern(switchs, &switch1, count - 1);
        let mut switch2 = switch.clone();
        switch2.push(false);
        make_switch_pattern(switchs, &switch2, count - 1);
    }
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() int {
	n, k := scanInt(sc), scanInt(sc)
	for i := 0; i < n; i++ {
		_ = scanInt(sc)
	}
	return (n-k+k-2)/(k-1) + 1
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 2416
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int A,B;
    cin >> A >> B;
    if(B%A==0) cout << A+B << endl;
    else cout << B-A << endl;
}

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

typedef int32_t i32;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i32 p[4];
  for (i32 i = 0; i < 4; ++i) {
    scanf ("%" SCNi32, p + i);
  }
  const i32 m = 200;
  i32 *dp = ALLOC (m + 1, i32);
  for (i32 i = 1; i <= m; ++i) dp[i] = i * 101;
  for (i32 i = 0; i < 4; ++i) {
    i32 t;
    scanf ("%" SCNi32, &t);
    for (i32 j = t; j <= m; ++j) {
      dp[j] = MIN (dp[j], dp[j - t] + p[i]);
    }
  }
  i32 ans = dp[n];
  for (i32 i = n + 1; i <= m; ++i) {
    ans = MIN (ans, dp[i]);
  }
  printf ("%" PRIi32 "\n", ans);
}

int main (void) {
  run();
  return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <queue>
#include <utility>

using namespace std;

vector<vector<char>> field;
vector<vector<int>> d;
vector<vector<int>> used;
int n, m, asd = 1, ans = 0;

bool can(int i, int j)
{
    return i >= 0 && j >= 0 && i < n && j < m && field[i][j] == '.' && used[i][j] != asd;
}

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

    cin >> n >> m;

    field.resize(n, vector<char>(m));
    d.resize(n, vector<int>(m));
    used.resize(n, vector<int>(m, 0));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> field[i][j];

    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
        {
            if (field[i][j] == '#') continue;
            pair<int, int> u = {i, j};
            queue<pair<int, int>> s;
            s.push({u.first, u.second});
            d[u.first][u.second] = 0;
            while (!s.empty())
            {
                auto cur = s.front();
                //cout << cur.first << "!" << cur.second << "\n";
                used[cur.first][cur.second] = asd;
                s.pop();
                ans = max(ans, d[cur.first][cur.second]);
                if (can(cur.first - 1, cur.second)) s.push({cur.first - 1, cur.second}), d[cur.first - 1][cur.second] = d[cur.first][cur.second] + 1, used[cur.first - 1][cur.second] = asd;
                if (can(cur.first + 1, cur.second)) s.push({cur.first + 1, cur.second}), d[cur.first + 1][cur.second] = d[cur.first][cur.second] + 1, used[cur.first + 1][cur.second] = asd;
                if (can(cur.first, cur.second - 1)) s.push({cur.first, cur.second - 1}), d[cur.first][cur.second - 1] = d[cur.first][cur.second] + 1, used[cur.first][cur.second - 1] = asd;
                if (can(cur.first, cur.second + 1)) s.push({cur.first, cur.second + 1}), d[cur.first][cur.second + 1] = d[cur.first][cur.second] + 1, used[cur.first][cur.second + 1] = asd;
            }
            asd++;
        }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long 
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int n;
ll a[110000],b[110000];
ll ans;

int main(){
  cin>>n;
  rep(i,n){
    cin>>a[i]>>b[i];
  }

  for(int i=n-1;i>=0;i--){
    a[i]+=ans;
    if(a[i]%b[i]!=0)
      ans += b[i]- a[i]%b[i];
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long int n; cin >> n;
	long long int a[100005];
	long long int m = -1;
	long long int mi = -1;
	for(long long int i=0;i<n;i++){
		cin >> a[i];
		if(m<=a[i]){
			m = a[i];
			mi = i;
		}
	}
	long long int ms = LLONG_MAX;
	long long int ans = -1;
	long long int d = -1;
	long long int e = -1;
	if(m%2==0){
		d = m/2;
		e = m/2;
	}else{
		d = m/2;
		e = (m/2)+1;
	}
	for(long long int i=0;i<n;i++){
		if(i==mi){
			continue;
		}else{
			if(ms>=min(abs(a[i]-d), abs(a[i]-e))){
				ms = min(abs(a[i]-d), abs(a[i]-e));
				ans = a[i];
				//cout << ms << endl;
			}
		}
	}
	cout << m << ' ' << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
use std::io::*;
use std::str::FromStr;

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(stderr(), "Process terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(104_857_600)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}

fn solve() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    loop {
        let s: String = sc.read();
        println!("{}8{}", &s[0..3], &s[4..]);
    }
}


Measured memory_bytes: 8572
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int left, right;
    left = a+b;
    right = c+d;
    if(left<right){
        cout << "Right" << endl;
    }else if(left == right){
        cout << "Balanced" << endl;
    }else{
        cout << "Left" << endl;
    }
}




Measured memory_bytes: 256
from math import sqrt
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        d = 0
        for p1, p2 in zip(x[i], x[j]):
            d += (p1 - p2) ** 2
        if int(sqrt(d)) ** 2 == d:
            ans += 1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	vector<int> v(n);
	for(int& x : v)
		scanf("%d",&x);
	int k = v[0];
	long long ans = 0;
	for(int i = 1; i < n; i++){
		if(v[i] > k)
			k = v[i];
		else
			ans += k-v[i];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4028
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    string S; cin >> S;
    res = (int)count(S.begin(),S.end(),'1');
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 256