akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i = 0;i<n;i++)
using ll = long long;
using P = pair<ll,ll>;

int main(){
  ll R,G,B,n;
  cin>>R>>G>>B>>n;
  ll r = n/R,g = n/G,b = n/B,sum = 0;
  rep(i,r+1){
    rep(j,g+1){
      ll a = n - (i*R + j*G);
      if (i*R + j*G + a == n && a>=0 && a%B == 0){
          sum++;
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n+1];
    for(int i=0;i<=n;i++)cin>>a[i];
    long long b[n+1],wa[n+1];
    b[0]=1-a[0];
    if(b[0]<0){
        cout<<"-1"<<endl;
        return 0;
    }
    wa[0]=a[0];
    for(int i=1;i<=n;i++)wa[i]=wa[i-1]+a[i];
    for(int i=1;i<=n;i++){
        b[i]=min(2*b[i-1]-a[i],wa[n]-wa[i]);
        if(b[i]+a[i]<b[i-1] || b[i]<0){
            cout<<"-1"<<endl;
            return 0;
        }
    }
    long long x=0;
    for(int i=0;i<=n;i++)x+=a[i]+b[i];
    cout<<x<<endl;
    return 0;
}


Measured memory_bytes: 5548
#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>

using namespace std;

typedef long long ll;
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 = (1LL << 60) - 1;
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
#define MAX_N 100100 * 3

int n;
int a[100100 * 3]; 
priority_queue<int, vector<int>, greater<int> > q1;
priority_queue<int> q2;
ll sum[2][100100];
ll ssum[2];

int main() {
	cin >> n;
	rep(i, n * 3) {
		cin >> a[i];
		if (i < n) {
			ssum[0] += a[i];
			q1.push(a[i]);
		}
		else if (i >= 2 * n) {
			ssum[1] += a[i];
			q2.push(a[i]);
		}
	}
	sum[0][0] = ssum[0];
	sum[1][n] = ssum[1];
	rep(i, n) {
		q1.push(a[n + i]);
		q2.push(a[2 * n - 1 - i]);
		ssum[0] -= q1.top();
		ssum[1] -= q2.top();
		ssum[0] += a[n + i];
		ssum[1] += a[2 * n - 1 - i];
		q1.pop();
		q2.pop();
		sum[0][i + 1] = ssum[0];
		sum[1][n - 1 - i] = ssum[1];
	}
	ll ans = -INF;
	rep(i, n + 1) {
		//cout << sum[0][i] << " " << sum[1][i] << endl;
		ans = max(ans, sum[0][i] - sum[1][i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3832
n,k,q = map(int,input().split())
point = [k] * n
counter = [0] * n
for i in range(q):
    a = int(input())
    a-=1
    counter[a]+=1
for i in range(n):
    diff = q - counter[i]
    point[i] -= diff
for i in range(n):
    if point[i] <= 0: print('No')
    else: print('Yes')

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


void solve_t()
{
    int N;
    std::cin >> N;
    std::vector<int> count(N + 1, 0);
    for(int i = 2; i <= N; ++i) {
        int a;
        std::cin >> a;
        ++count[a];
    }

    for(int i = 1; i <= N; ++i) {
        std::cout << count[i] << '\n';
    }
}

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

Measured memory_bytes: 4036
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=0,p;cin>>n>>p;
  string s;cin>>s;
  if(p==2||p==5) {
    for(ll pos=n-1;pos>-1;pos--)
      if((s[pos]-'0')%p==0) ans+=pos+1;
  }
  else {
    ll digit=1,val=0;
    lvector mods(p,0);
    for(ll pos=n-1;pos>-1;pos--) {
      val=(val+(s[pos]-'0')*digit)%p;
      digit=(digit*10)%p;
      mods[val]++;
    }
    ans+=mods[0];
    for(ll i:mods) ans+=i*(i-1)/2;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 720
/*
    ????????°??§???????????¨????????????
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <float.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <vector>
#include <map>
#include <utility>
#define LLU unsigned long long int
#define LL long long int
#define LD long double
using namespace std;
#define Lfmax DBL_MAX
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define vd vector<int>
#define vLL vector<long long int>
#define vLLU vector<unsigned long long int>
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define debug printf("asd\n")
#define debugd(a) printf("--%d\n",a)
#define debugdd(a,b) printf("--%d %d\n",a,b)
#define debugarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i]);printf("\n")
#define newline printf("\n")
#define forin(a,b,c) for(int a=b ; a<c ; a++)
#define forde(a,b,c) for(int a=b ; a>=c ; a--)
#define UPC(a) (a>='A' && a<='B')
#define LWC(a) (a>='a' && a<='b')

inline void scd(int &a){scanf("%d",&a);}
inline void scdd(int &a,int &b){scanf("%d %d",&a,&b);}
inline void sctd(int &a,int &b,int &c){scanf("%d %d %d",&a,&b,&c);}
inline void sctlld(LL &a,LL &b,LL &c){scanf("%I64d %I64d %I64d",&a,&b,&c);}
inline void scdlld(LL &a,LL &b){scanf("%I64d %I64d",&a,&b);}
inline void sclld(LL &a){scanf("%I64d",&a);}

inline void prd(int a){printf("%d",a);};
inline void prdd(int a,int b){printf("%d %d",a,b);};
inline void prtd(int a, int b, int c){printf("%d %d %d",a,b,c);};
inline void prtlld(LL a, LL b, LL c){printf("%I64d %I64d %I64d",a,b,c);};
inline void prdlld(LL a, LL b){printf("%I64d %I64d",a,b);};
inline void prtlld(LL a){printf("%I64d",a);};

#define scarrd(a,b) for(int index=0 ; index<b ; index++)scanf("%d",&a[index])
#define prarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i])
#define iniarr(a,b) for(int i=0 ; i<b ;i++)a[i]=0
#define arr(a,b) int *a=(int *)malloc(b*sizeof(int))
#define llarr(a,b) long long int *a=(long long int *)malloc(b*sizeof(long long int))
#define st(a,b) char *a=(char *)malloc(b*sizeof(char))
#define grav 9.8
#define pi 3.14159265


int a[200][200],spos[2000],epos[2000],visit[2000],pos;


void dfs(int now,int n)
{
	//debugd(now);
	spos[now]=pos;
	visit[now]=1;
	pos++;
	for(int i=1 ; i<=n ; i++)
	{
		if(a[now][i]==1 && visit[i]==0)
		dfs(i,n);
	}
	//debugd(now);
	epos[now]=pos;
	pos++;
}

int main()
{
	int c,n,m,b;
	pos=1;
	scd(n);
	forin(i,0,n)
	{
		scdd(c,m);
		forin(j,0,m)
		{
			scd(b);
			a[c][b]=1;			
		}
	}
	
	for(int i=1 ; i<=n ; i++)
	{
		if(visit[i]==0)
		dfs(i,n);
	}
	
	for(int i=1 ; i<=n ; i++)
	printf("%d %d %d\n",i,spos[i],epos[i]);
	return 0;
}

Measured memory_bytes: 3296
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/10;
    public static final int inf = Integer.MAX_VALUE/10;

    static void solve(InputReader in, PrintWriter out){
        long s = in.nl();
        long x = 0, y = 0;
        if(s ==(long)1e18){
            x = 0;
            y = 1000000000;
        }else{
            x = 1000000000-s%1000000000;
            y = s/1000000000+1;
        }
        out.printf("0 0 1000000000 1 %d %d", x, y);
    }

    public static void main(String[] args) throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 21204
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=15,SN=1<<N,O=1000000007;
inline int fpow(int x,int n){
	int a=1;
	for(;n;n>>=1,x=(lint)x*x%O){
		if(n&1){
			a=(lint)a*x%O;
		}
	}
	return a;
}
int to[N];
int bitcnt[SN];
int f[SN];
inline int Main(){
	int n=ni,m=ni;
	for(int i=1;i<=m;i++){
		int u=ni,v=ni;
		to[u]|=1<<(v-1);
	}
	bitcnt[0]=0;
	for(int s=1,ts=1<<n;s<ts;s++){
		bitcnt[s]=bitcnt[s^(s&-s)]+1;
	}
	memset(f,0,sizeof(f));
	for(int s=0,ts=1<<n;s<ts;s++){
		if((s&1)!=((s>>1)&1))continue;
		lint ans=1;
		for(int t=s;t=s&(t-1),t;){
			if((t&1)!=((t>>1)&1))continue;
			lint tmp=1;
			for(int i=1;i<=n;i++){
				if((s>>(i-1))&1){
					if((t>>(i-1))&1){
						tmp*=(1<<bitcnt[to[i]&(((t>>(i-1))&1)?s^t:t)])-1;
					}else{
						tmp*=(1<<bitcnt[to[i]&t]);
					}
				}
			}
			ans+=tmp%O*f[t]%O;
		}
		f[s]=ans%O;
	}
	return (fpow(2,m)-f[(1<<n)-1]+O)%O;
}
int main(){
	printf("%d\n",Main());
	return 0;
}

Measured memory_bytes: 640
import numpy as np
n,m =map(int,input().split())


A = np.array([list(input()) for i in range(n)])
B = np.array([list(input()) for i in range(m)])
P = np.zeros(B.shape,str)
a = 0
for i in range(n-m+1):
   for j in range(n-m+1):
      P= A[i:i+m,j:j+m]
      if np.all(B==P):
         a = 1
         break

if a ==0:
   print("No")
else:
   print("Yes")

Measured memory_bytes: 12404
#! /usr/bin/env python
# -*- coding: utf-8 -*-

P = [0]*(1000100)
P[0] = 1
P[1] = 1
for i in range(2, 1000100):
    if P[i]==0:
        j = i
        for j in range(i+i, 1000100, i):
            P[j] = 1

(a, d, n) = map(int, raw_input().split())
while a!=0:
    cnt = 0
    for i in range(a, 1000100, d):
        if P[i] == 0:
            cnt += 1
        if cnt == n:
            print i
            break

    (a, d, n) = map(int, raw_input().split())

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,a,b;
    cin >> n >> a >> b;
    if((b-a)%2==0) cout << "Alice" << endl;
    else cout << "Borys" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template< typename G >
struct LCA{
    const int LOG;
    vector< int > depth;
    const G &g;
    vector< vector< int > > table;

   LCA(const G &g) : g(g), depth(g.size()), LOG(32 - __builtin_clz(g.size())) {
        table.assign(LOG, vector< int >(g.size(), -1));
    }

    void dfs(int idx, int par, int d) {
        table[0][idx] = par;
        depth[idx] = d;
        for(auto &to : g[idx]) {
            if(to != par) dfs(to, idx, d + 1);
        }
    }

    void build() {
        dfs(0, -1, 0);
        for(int k = 0; k + 1 < LOG; k++) {
            for(int i = 0; i < table[k].size(); i++) {
                if(table[k][i] == -1) table[k + 1][i] = -1;
                else table[k + 1][i] = table[k][table[k][i]];
            }
        }
    }

    int get(int u, int v) {
        if(depth[u] > depth[v]) swap(u, v);
        for(int i = LOG - 1; i >= 0; i--) {
            if(((depth[v] - depth[u]) >> i) & 1) v = table[i][v];
        }
        if(u == v) return u;
        for(int i = LOG - 1; i >= 0; i--) {
            if(table[i][u] != table[i][v]) {
                u = table[i][u];
                v = table[i][v];
            }
        }
        return table[0][u];
    }

    int dist(int u, int v) {
		int lca_ = get(u, v);
		return depth[u] + depth[v] - 2 * depth[lca_];
	}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, u, v;
    cin >> N >> u >> v;
    --u, --v;
    vector<vector<int>> G(N);
    REP(i,N-1){
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    LCA<vector<vector<int>>> lca(G);
    lca.build();

    int ans = 0;
    REP(i,N){
        int t = lca.get(i, u);
        if(lca.dist(t, u) < lca.dist(t, v)) chmax(ans, lca.dist(i, v) - 1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 15352
ABCD = input()

def bit_cal(n):
    return_list = [''] * (2**n)
    for i in range(2**n):
        for j in range(n):
            if ((i >> j) & 1):
                return_list[i] = return_list[i] + '1'
            else:
                return_list[i] = return_list[i] + '0'
    return return_list

ope_candidates = bit_cal(3)

flag = False
for ope in ope_candidates:
    tmp_ans = int(ABCD[0])
    tmp_str = ABCD[0]
    for i in range(3):
        if ope[i] == '0':
            tmp_ans += int(ABCD[i+1])
            tmp_str = tmp_str + '+' + str(ABCD[i+1])
        else:
            tmp_ans -= int(ABCD[i+1])
            tmp_str = tmp_str + '-' + str(ABCD[i+1])
    if tmp_ans == 7:
        break
print(tmp_str + '=7')

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    int a,b,c,x=0;
    scanf("%d %d %d",&a,&b,&c);
    while(1)
    {
        if(a<b && c<b || a==c && a!=b && b!=c && a<b && c<b)
        {
            a=a+1;
            c=c+1;
            x++;
        }
        else if(a<c && b<c || a==b && a!=c && b!=c && a<c && b<c)
        {
            a=a+1;
            b=b+1;
            x++;
        }
        else if(b<a && c<a || b==c && b!=a && c!=a && b<a && c<a)
        {
            b=b+1;
            c=c+1;
            x++;
        }
        if(a<b && a<c)
        {
            a=a+2;
            x++;
        }
        else if(b<a && b<c)
        {
           b=b+2;
           x++;
        }
        else if(c<a && c<b)
        {
            c=c+2;
            x++;
        }
        if(a==b && b==c && c==a)
        {
            break;
        }
    }
    printf("%d\n",x);

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;
//printf("%.10f\n", n);

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}

signed main() {
	ll n, m, a = 0, b = 0, c = 0, d = 0; cin >> n; string s;
	rep(h, n) {
		cin >> s;
		if (s == "AC") { a++; }
		if (s == "WA") { b++; }
		if (s == "TLE") { c++; }
		if (s == "RE") { d++; }
	}
	cout << "AC x " << a << endl;
	cout << "WA x " << b << endl;
	cout << "TLE x " << c << endl;
	cout << "RE x " << d << endl;
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>

using namespace std;

long long GetGCD(long long a, long long b) 
{
	if (a < b) {
		swap(a, b);
	}

	while(true) 
	{
		long long mod = a % b;
		if (mod == 0) {
			return b;
		}
		a = b;
		b = mod;
	}

	return -1;
}
long long GetLCM(long long a, long long b)// 最小公倍数
{
	long long gcd = GetGCD(a, b);
	long long pA = a / gcd;

	return pA * b;
}

int main()
{
	int N = 0;
	cin >> N;
	vector<long long> T(N, 0);

	for (int i = 0; i < N; ++i) {
		cin >> T[i];
	}
	// sort(T.rbegin(), T.rend());

	// 端から最小公倍数を求めてゆく。
	long long res = T[0];
	for (int i = 0; i < N; ++i) {
		long long cur0 = T[i];
		res = GetLCM(res, T[i]);
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

//using namespace __gnu_pbds;
using namespace std;

typedef  long long ll;
typedef long double ld;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define endl "\n"
#define ioss ios::sync_with_stdio(0);cin.tie(0);
#define pb push_back
#define eb emplace_back



double startTime;
double gct()//get_current_time
{
    return ((double)clock()-startTime)/CLOCKS_PER_SEC;
}

void suraj();

int main()
{
    startTime=(double)clock();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt,"w",stdout);
    //ioss
    //int t;cin>>t;while(t--)
    suraj();
    //suraj2();
    //suraj3();
    //suraj4();
    return 0;
}

































int dp[100001];


void suraj(){
int n,k;cin>>n>>k;
vector<int>h(n);for(int &i:h)cin>>i;
dp[0]=0;
dp[1]=abs(h[1]-h[0]);
for(int i=2;i<n;i++){
    dp[i]=1e12;
    for(int j=1;j<=k;j++){
        if(i-j>=0)
        dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
    }
}
cout<<dp[n-1]<<endl;
}













Measured memory_bytes: 4108
import java.util.ArrayList;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int n = sc.nextInt();
			final int m = sc.nextInt();
			
			if(n == 0 && m == 0){
				break;
			}
			
			
			int[][] map = new int[n][n];
			
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					map[i][j] = sc.nextInt();
				}
			}
			
			int[][] pict = new int[m][m];
			for(int i = 0; i < m; i++){
				for(int j = 0; j < m; j++){
					pict[i][j] = sc.nextInt();
				}
			}
			
			int[][] pict90 = new int[m][m];
			for(int i = 0; i < m; i++){
				for(int j = 0; j < m; j++){
					pict90[i][j] = pict[(m - 1) - j][i];
				}
			}
			
			int[][] pict180 = new int[m][m];
			for(int i = 0; i < m; i++){
				for(int j = 0; j < m; j++){
					pict180[i][j] = pict90[(m - 1) - j][i];
				}
			}
			
			int[][] pict270 = new int[m][m];
			for(int i = 0; i < m; i++){
				for(int j = 0; j < m; j++){
					pict270[i][j] = pict180[(m - 1) - j][i];
				}
			}
			
			int count = 0;
			int[][][] order = new int[4][][];
			boolean p = false,p_90 = false,p_180 = false,p_270 = false;
			END_O:
			for(int i = 0; i < m; i++){
				for(int j = 0; j < m; j++){
					if(count >= 4){
						break END_O;
					}
					
					if(!p && pict[i][j] != -1){
						p = true;
						order[count] = pict;
						count++;
					}
					
					if(!p_90 && pict90[i][j] != -1){
						p_90 = true;
						order[count] = pict90;
						count++;
					}
					
					if(!p_180 && pict180[i][j] != -1){
						p_180 = true;
						order[count] = pict180;
						count++;
					}
					
					if(!p_270 && pict270[i][j] != -1){
						p_270 = true;
						order[count] = pict270;
						count++;
					}
				}
			}
			
			boolean flag = false;
			END_2:
			for(int i = 0; i < (n - m + 1); i++){
				for(int j = 0; j < (n - m + 1); j++){
					
					for(int[][] window : order){
						boolean found = true;
						
						END:
						for(int k = 0; k < m; k++){
							for(int l = 0; l < m; l++){
								if(window[k][l] == -1){
									continue;
								}
								
								if(window[k][l] != map[i+k][j+l]){
									found = false;
									break END;
								}
							}
						}
						
						if(found){
							flag = true;
							for(int k = 0; k < m; k++){
								for(int l = 0; l < m; l++){
									if(window[k][l] == -1){
										continue;
									}
									
									System.out.println((j+l+1) + " " + (i+k+1));
									break END_2;
								}
							}
							
						}
						
					}
					
				}
			}
			
			if(!flag){
				System.out.println("NA");
			}
			
		}
		
	}

}

Measured memory_bytes: 13000
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        input: [(f64, String); n],
    }

    let rate = 380000.0;

    let mut ans = 0.0;

    for &(v, ref cur) in input.iter() {
        if cur == "JPY" {
            ans += v;
        } else {
            ans += v * rate;
        }
    }

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


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

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

    while( cin >> n )
    {
        if( n == 0 )
            break;
        
        for( int i = 0; i < n; i++ )
        {
            cin >> a >> b >> c;
            if( ( a == 100 || b == 100 || c == 100 ) || ( a + b ) / 2 >= 90 || ( a + b + c ) / 3 >= 80 )
                cout << 'A' << endl;
            else if( ( a + b + c ) / 3 >= 70 || ( ( a + b + c ) / 3 >= 50 ) && ( a >= 80 || b >= 80 ) )
                cout << 'B' << endl;
            else
                cout << 'C' << endl;
        }
    }
    return 0;
}


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

int main() {
    using namespace std;
    constexpr long double quarter = 4.292036732051033807686783083602485579014153003124470895125, half = 11.41592653589793238462643383279502884197169399375105820974;
    unsigned long sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;
    if(sx > gx){swap(sx, gx); swap(sy, gy);}
    unsigned long N;
    cin >> N;
    vector<pair<long, long>> f;
    unsigned long tapi = (gx - sx + max(sy, gy) - min(sy, gy)) * 100;
    for(unsigned long i = 0, x, y; i < N; ++i){
        cin >> x >> y;
        if(sx <= x && x <= gx && min(sy, gy) <= y && y <= max(sy, gy))f.emplace_back(x, y * (1 - 2 * (sy > gy)));
    }
    if((sx ^ gx) && (sy ^ gy)){
        sort(begin(f), end(f));
        vector<long> y(N, numeric_limits<long>::max());
        for(const auto& i : f)*lower_bound(begin(y), end(y), i.second) = i.second;
        unsigned long n = lower_bound(cbegin(y), cend(y), 893921037921) - cbegin(y);
        cout << printf("%.15Lf", tapi - n * quarter + (half + quarter) * (n == min(gx - sx, max(sy, gy) - min(sy, gy)) + 1));
    }else printf("%.15Lf", tapi + half * f.size());
    return 0;
}

Measured memory_bytes: 6384
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  int t, a;
  cin >> t >> a;
  vector<int> h(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  int id = 0;
  double mindiff = 11000000;
  for (int i = 0; i < n; i++) {
    double tt = t - 0.006 * h[i];
    double fs = fabs(tt - a);
    if (mindiff > fs) {
      mindiff = fs;
      id = i;
    }
  }
  cout << id + 1 << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
aaa = list(map(int, input().split()))
mod = 1000000007
c_sum = [0] * n
c_sum[n - 1] = aaa[n - 1]
ans = 0

for i in range(n - 2, 0, -1):
    c_sum[i] = (c_sum[i + 1] + aaa[i]) % mod

for i in range(n - 1):
    ans += aaa[i] * c_sum[i + 1] % mod
    ans %= mod

print(ans)

Measured memory_bytes: 31528
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
using vl=vector<ll>;
using vb=vector<bool>;
using vs=vector<string>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
const ll oo =0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(0) cerr << "TR: " << (#X) << " = " << (X) << endl; })
ll N;

map<pll, ll> cnt;
ll C = 0;
ll pToI(ll i, ll j) {

	pll key = {min(i,j), max(i,j)};

	if (cnt.count(key)) return cnt[key];
	else return cnt[key] = C++;
}

int main(){ cin.sync_with_stdio(0);
	cin >> N;
	const ll MAX_N = (N*(N-1)) / 2;

	vvl adj(MAX_N);
	ll last;
	vl indeg(MAX_N);
	ll edges = 0;
	FOR(i, 0, N) FOR(j, 0, N-1) {
		ll a; cin >> a;
		a --;

		if (j == 0) {
			last = a;
			continue;
		}

		edges++;
		TR(i);TR( last);
		TR(pToI(i,last));

		TR(i);TR(a);
		TR(pToI(i,a));

		adj[pToI(i, last)].pb(pToI(i, a));
		indeg[pToI(i,a)]++;
		last = a;
	}

	TR(edges);
	queue<ll> todo; 
	vl finished(MAX_N);
	FOR(i, 0, MAX_N) if (indeg[i] == 0) {
		todo.push(i);
		finished[i] = 1;
	}

	TR(sz(todo));
	ll ans = 0;
	queue<ll> nxt;
	while (sz(todo)) {
		ll cur = todo.front();
		todo.pop();

		TR(cur);
		TR(sz(adj[cur]));
		for (ll nei : adj[cur]) {
			indeg[nei] --;
			if (indeg[nei] == 0) {
				TR(nei);
				nxt.push(nei);
				finished[nei] = finished[cur] + 1;
			}
		}

		if (todo.empty()) {
			TR(sz(nxt));
			swap(nxt, todo);
			ans ++;
		}
	}

	FOR(i, 0, MAX_N) {
		if (finished[i] == 0) {
			cout << -1 << endl;
			return 0;
		}
	}

	cout << *max_element(all(finished)) << endl;

} //cin.tie(0) bei schnellem Wechseln


Measured memory_bytes: 66560
// https://atcoder.jp/contests/abc086/tasks/arc089_a

#include <iostream>
#include <vector>
using namespace std;

bool is_reachable_at_shortest_path(int t, int x, int y) {
    if (abs(x)+abs(y) != t) {
        return false;
    }
    return true;
}

bool is_travelable(int t, int x, int y) {
    if (t < 0) {
        return false;
    }
    if (t == 0) {
        return x == 0 && y == 0;
    }
    return is_reachable_at_shortest_path(t, x, y) || is_travelable(t-2, x, y);
}
int main() {
    int N;
    cin >> N;
    int t{}, x{}, y{};
    int tt{}, xx{}, yy{};
    for (int i=0; i < N; ++i) {
        cin >> tt;
        cin >> xx;
        cin >> yy;
        if (!is_travelable(tt-t, xx-x, yy-y)) {
            cout << "No" << endl;
            return 0;
        }
        t = tt;
        x = xx;
        y = yy;
    }
    cout << "Yes" << endl;
}


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

pair<int,int> a[55];
int f;
int p[55][55];
int c[55];
int n, m;
void sl(int x)
{
    if(c[x]) return ;
    c[x] = 1;
    for(int i = 1; i <= n; i++)
    {
        if(p[x][i] && !c[i])
        {
            sl(i);
        }
    }
}

int main()
{

    cin >> n >> m;
    for(int i = 1; i <= m; i++)
    {
        int x, y;
        cin >> x >> y;
        p[x][y] = p[y][x] = 1;
        a[i] = make_pair(x,y);
    }
    int sum = 0;
    for(int i = 1; i <= m; i++)
    {
        memset(c, 0, sizeof(c));
        f = 0;
        int x = a[i].first, y = a[i].second;
        p[x][y] = p[y][x] = 0;
        sl(x);
        for(int i = 1; i <= n; i++)
            if(!c[i])
            {
                f = 1; break;
            }
        if(f) sum++;
        p[x][y] = p[y][x] = 1;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
import numpy as np

n, m = map(int, input().split())
A = [0] + list(map(int, input().split()))

csA = np.cumsum(A)
csA_mod = csA % m
dict = defaultdict(int)

for mod in csA_mod:
    dict[mod] += 1

counts = list(dict.values())
ans = [(count * (count-1))//2 for count in counts]

print(sum(ans))

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

// [               1              ]
// [       2      ][       3      ]
// [   4  ][   5  ][   6  ][   7  ]
// [ 8][ 9][10][11][12][13][14][15]
// - root が 1 の完全二分木
// - ある頂点の番号を k とすると左の子は 2*k, 右の子は 2*k+1, 親は k/2 
// - 最下段の左端の番号 == 最下段の長さ == n
// 区間に一様に足すという操作のためにその区間に一様に足されている値を持つ
const ll INF = 1LL << 61;
struct RangeMinRangeAdd {
  typedef ll Val;
  int n;
  vector<Val> vs;
  vector<Val> ws; // 区間に一様に足されている値

  void clear(int N) {
    for (n = 1; n < N; n <<= 1);
    vs.assign(n * 2, 0);
    ws.assign(n * 2, 0);
  }

  // [l, r) の最小値
  Val getMin(int l, int r) {
    if (r - l <= 0) return INF;
    return getMin(0, n, 1, l, r);
  }
  Val getMin(int nl, int nr, int k, int l, int r) {
    if (r <= nl || nr <= l) return INF;
    if (l <= nl && nr <= r) return vs[k] + ws[k];
    Val x = getMin(nl, (nl+nr)/2, 2*k  , l, r);
    Val y = getMin((nl+nr)/2, nr, 2*k+1, l, r);
    return min(x, y) + ws[k];
  }

  // [l, r) の全てに val を加算
  void addRange(int l, int r, Val val) {
    addRange(0, n, 1, l, r, val);
  }
  void addRange(int nl, int nr, int k, int l, int r, Val val) {
    if (r <= nl || nr <= l) return ;
    if (l <= nl && nr <= r) { ws[k] += val; return ; }
    addRange(nl, (nl+nr)/2, 2*k  , l, r, val);
    addRange((nl+nr)/2, nr, 2*k+1, l, r, val);
    vs[k] = min(vs[2*k]+ws[2*k], vs[2*k+1]+ws[2*k+1]);
  }

  // pos の値を強制的に val にする
  void update(int pos, Val val) {
    Val now = getMin(pos, pos + 1);
    addRange(pos, pos+1, val - now);
  }
};


const int MAX_N = 212345;
struct Item {
  int l, r, a;
};
vector<Item> is[MAX_N];

int main2() {
  REP(i, MAX_N) is[i].clear();

  int N = nextInt();
  int M = nextInt();
  REP(i, M) {
    int l = nextInt();
    int r = nextInt();
    int a = -nextInt(); // スコアの最小値を求める問題に変えておく
    Item item = {l, r, a};
    is[r].push_back(item);
  }

  RangeMinRangeAdd dp;
  dp.clear(N+10);
  dp.update(0, 0);

  for (int i = 1; i <= N; i++) {
    ll best = dp.getMin(0, i);
    dp.update(i, best);
    for (Item item : is[i]) {
      dp.addRange(item.l, item.r + 1, item.a);
    }
  }
  ll ans = dp.getMin(0, N+1);
  cout << -ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 19712
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.function.IntToDoubleFunction;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = getInt(sc);
		int y = getInt(sc);
		System.out.println(x+y/2);
	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}


Measured memory_bytes: 35740
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

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

  int n; cin >> n;
  ll a;

  ll norm = 0;
  rep(i, n) {
    cin >> a;
    norm ^= a;
  }

  if( !norm ) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define endl '\n'
#define maxN 100
#define maxW 10000
using namespace std;
int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1};
typedef pair<ll, ll> P;

int dp[maxN + 1][maxW + 1];
int n, W;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> W;
    vector<int> v(n);
    vector<int> w(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i] >> w[i];
    }
    memset(dp, 0, sizeof(dp));
    int ans;
    for (int x = 0; x < n; x++) {
        for (int y = 0; y <= W; y++) {
            if (y < w[x]) {
                dp[x + 1][y] = dp[x][y];
            } else {
                dp[x + 1][y] = max(dp[x][y], dp[x][y - w[x]] + v[x]);
            }
        }
    }
    ans = dp[n][W];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7160
#include<bits/stdc++.h>
using namespace std;
long long N=23333333333333333;
int main()
{
	int k,a,b;
	scanf("%d%d%d",&k,&a,&b);
	int sum=b/k;
	sum=sum*k;
	if(sum>=a&&sum<=b)
	printf("OK");
	else
	printf("NG");
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define REP(i, n) for (LL i = 0; i < (LL)(n); i++)
#define REP2(i, n) for (LL i = 1; i <= (LL)(n); i++)
#define FOR(i, m, n) for (LL i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define SUM(x) accumulate(x.begin(), x.end(),0LL)
#define vLL(v,n) vector<LL> v(n); REP(i,n)cin>>v[i];
#define vstr(v,n) vector<string> v(n); REP(i,n)REP(i,n)cin>>v[i];
LL INF = 1e9 + 1;
LL MOD = 1e9+7;
  LL zero,a,b,c,d,e,n,m,l,k,r,x,y,z,odd,ans=INF,ans2=0,h,w;
string s,S,t;
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> y;
REP(i,2001){
    REP(j,2001){
    if(n-i-j>=0&&(10000*i+5000*j+1000*(n-i-j))==y){
            cout <<i << " " << j << " " << (n-i-j);
            return 0;
    }
   }
  }
cout << -1 << " " << -1 << " " << -1;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h, n; cin >> h >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    vector<long long> dp(h+1, 1e12);
    dp[h] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = h; j >= 0; j--) {
            int t = max(0, j-a[i]);
            dp[t] = min(dp[t], dp[j]+b[i]);
        }
    }
    cout << dp[0] << "\n";
    return 0;
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

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

pair<int, int> pas[100005];

signed main() {
	int N, D;
	cin >> N >> D;
	REP(i, N) {
		cin >> pas[i].first >> pas[i].second;
	}

	sort(pas, pas + N);

	int ns = 1;
	int nt = 0;
	int d = 0;
	int ans = 0;
	REP(i, N) {
		if (pas[i].second - ns > pas[i].first - nt) {
			cout << -1 << endl;
			return 0;
		}
		
		
		
		
		ans += d * (pas[i].first - nt);

		ns = pas[i].second;
		nt = pas[i].first;

		d++;

		//cout << ns << " " << nt << " " << d << " " << ans << " " << endl;

		if (ns - 1 + pas[i + 1].second - 1 <= pas[i + 1].first - nt) {
			ans += d * (ns - 1);

			nt += (ns - 1);
			ns = 1;

			d = 0;
		}

		if (d >= D) {
			ans += d * (ns - 1);

			nt += (ns - 1);
			ns = 1;

			d = 0;
		}

		//cout << ns << " " << nt << " " << d  << " " << ans << " " << endl;
	}

	ans += d * (ns - 1);

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4676
#include<iostream>
#include<stack>
#include<map>
#include<cstdio>
#include<utility>
#include<vector>
#include<algorithm>

using namespace std;

pair<string,int> split(string s){
  char t[99];
  int d;
  sscanf(s.c_str(),"%[a-z]%d",t,&d);
  return make_pair(string(t),d);
}

int main(){
  for(int N;cin>>N,N;){
    int cnt=0;
    stack<int> s;
    string m[10001];
    map<pair<string,int>,vector<int> > mmap;
    for(int i=1;i<=N;i++){
      cin>>m[i];
      if(m[i].back()=='v'){
      }else if(m[i].size()>1){
	auto p=split(m[i]);
	if(p.second==1){
	  s.push(i);
	}else{
	  mmap[p].push_back(i);
	}
      }else{
	s.push(i);
      }
      while(!s.empty()){
	int x=s.top();
	s.pop();
	if(x>0){
	  cout<<x<<endl;
	  cnt++;
	  if(m[x].size()>1){
	    s.push(-x);
	  }
	  if(x&&m[x-1].back()=='v'){
	    s.push(x-1);
	  }
	}else{
	  x=-x;
	  auto p=split(m[x]);
	  p.second++;
	  if(!mmap[p].empty()){
	    auto it=upper_bound(begin(mmap[p]),end(mmap[p]),x);
	    if(it!=begin(mmap[p])){
	      s.push(*--it);
	      mmap[p].erase(it);
	    }
	  }
	}
      }
    }
    //    cerr<<cnt<<' '<<N<<endl;
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, k;
    cin >> n >> k;
    int arr[n];
    int i, j;
    int dp[n];
    for (i = 0; i < n; i++) {
        dp[i] = 0;
        cin >> arr[i];
    }
    for (i = 1; i < n; i++) {
        dp[i] = INT_MAX;
        for (j = i - 1; j >= i-k && j>=0; j--) {
        
            int a1 = abs(arr[i] - arr[j]) + dp[j];
            dp[i] = min(dp[i], a1);
        }
    }
    cout << dp[n - 1];

    return 0;
}

Measured memory_bytes: 1024
n,k=map(int,input().split())
a=list(map(int,input().split()))
mod=10**9+7
dp=[0]*(k+1)
for i in range(a[0]+1):
    dp[i]=1
for i in range(1,n):
    u=a[i]
    h=dp[:]
    for j in range(u+1,k+1):
        h[j]=(dp[j]-dp[j-u-1])%mod
    for j in range(1,k+1):
        h[j]=(h[j]+h[j-1])%mod
    dp=h
print(dp[k])

Measured memory_bytes: 73260
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

char buf[1600000];
int bufi = 0;
template<typename T>
void readi(T &n) {
    int c;
    n = 0;
    c = buf[bufi++];
    for (; '0' <= c; c = buf[bufi++])
        n = 10 * n + c - '0';
}

// End of template.

int main(){
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin.read(buf, sizeof buf); // 注意: ./a.out < in か pbp | ./a.out で入力すること

    int n;
    readi(n);

    int t = 1;
    for (int i = n; i; --i) {
        int a;
        readi(a);
        t += t == a;
    }

    if (t == 1)
        print(-1);
    else
        print(n - t + 1);

    return 0;
}



Measured memory_bytes: 1664
fun main(args: Array<String>) {
    val n = readLine()!!.toLong()
    var sqrt = Math.sqrt(n.toDouble()).toLong() + 1
    while (sqrt > 1) {
        if (n % sqrt == 0L) {
            val size1 = sqrt.toString().toCharArray().size
            val size2 = (n / sqrt).toString().toCharArray().size
            println(Math.max(size1, size2))
            return
        }
        sqrt--
    }
    println(n.toString().toCharArray().size)
}

Measured memory_bytes: 31740
package main

import "fmt"

func main() {
	var n, m, c int
	fmt.Scan(&n, &m, &c)
	bs := make([]int, m)
	for i := range bs {
		fmt.Scan(&bs[i])
	}
	ass := make([][]int, n)
	for i := range ass {
		ass[i] = make([]int, m)
		for j := range ass[i] {
			fmt.Scan(&ass[i][j])
		}
	}

	ans := 0
	for _, as := range ass {
		sum := 0
		for j, a := range as {
			sum += a * bs[j]
		}
		if sum+c > 0 {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll pow(ll x,ll y){
  if(y==0) return 1;
  ll res=pow(x,y/2);
  res*=res;
  res%=mod;
  if(y%2==1) res*=x;
  return res%mod;
}
ll gyaku(ll x){
  return pow(x,mod-2);
}
vector<ll> frac,gfrac;
void set_frac(ll n){
  frac.push_back(1);
  gfrac.push_back(1);
  for(ll i=1;i<=n;i++){
    frac.push_back(frac[i-1]*i%mod);
    gfrac.push_back(gyaku(frac[i]));
  }
}
ll nCr(ll n,ll r){
  ll res=frac[n]*gfrac[r]%mod;
  res*=gfrac[n-r];
  return res%mod;
}
ll solve(vector<ll> vec,ll k){
  ll ans=0;
  for(int i=k-1;i<vec.size();i++){
    ans+=nCr(i,k-1)*vec[i];
    ans%=mod;
  }
  return ans;
}
int main(){
  ll n,k;
  cin>>n>>k;
  set_frac(n+100);
  vector<ll> vec;
  for(int i=0;i<n;i++){ll a;cin>>a;vec.push_back(a);}
  sort(vec.begin(),vec.end());
  ll ans=solve(vec,k)%mod;
  ans+=mod;
  sort(vec.begin(),vec.end(),greater<ll>());
  ans-=(solve(vec,k)%mod);
  ans%=mod;
  cout<<ans<<endl;
}


Measured memory_bytes: 4196