akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int max(VI a){
    int ma = -1e9;
    REP(i,a.size()) ma = max(ma, a[i]);
    return ma;
}

int min(VI a){
    int mi = 1e9;
    REP(i,a.size()) mi = min(mi, a[i]);
    return mi;
}

int main() {
    int n, d;
    while (cin >> n >> d && n){
        vector<stack<int> > a(n);
        VI s(n);
        REP(i,n){
            int m;
            cin >> m;
            while (m--){
                int x;
                cin >> x;
                s[i] += x;
                a[i].push(x);
            }
        }
        while (1){
            bool change = false;
            REP(i,n){
                if (a[i].empty()) continue;
                int x = a[i].top();
                s[i] -= x;
                int ma = max(s), mi = min(s);
                s[i] += x;
                if (ma - mi <= d){
                    s[i] -= x;
                    a[i].pop();
                    change = true;
                }
            }
            if (!change) break;
        }
        bool zero = true;
        REP(i,n) if (s[i] > 0) zero = false;
        cout << (zero ? "Yes" : "No") << endl;
    }

    return 0;
}

Measured memory_bytes: 3120
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});

    let N = parseInt(input[0][0], 10);
    let v_h = input[1].map(e => parseInt(e, 10));

    let DP = [0, Math.abs(v_h[1] - v_h[0])];

    let x1, x2;
    for(let i = 2; i < N; i++){
        x1 = DP[i - 2] + Math.abs(v_h[i] - v_h[i - 2]);
        x2 = DP[i - 1] + Math.abs(v_h[i] - v_h[i - 1]);
        DP.push(Math.min(x1, x2));
    }

    console.log(DP[N - 1]);

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 41404
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define UN unsigned int
#define mod 1000000007
#define F first
#define S second
#define mk make_pair
#define B(v) v.begin(), v.end()
#define BS binary_search

int main()
{
	int n,k;
	cin>>n>>k;
	n--;
	for(int i=k-n;i<=(k+n);i++)
	{
		cout<<i<<" ";
	}
	cout<<endl;
}

Measured memory_bytes: 256
n, x, y = map(int, input().split())

ans = [0]*(n-1)

for i in range(1, n):
	for j in range(i+1, n+1):
		a1 = abs(j-i)
		a2 = abs(y-j)+1+abs(x-i)
		#a3 = abs(x-j)+1+abs(y-i)
		#ans[min(a1, min(a2, a3))-1] += 1
		ans[min(a1, a2)-1] += 1
		
for i in ans:
	print(i)

Measured memory_bytes: 3444
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
int main(void){
 int A=0;
  int B=0;
  cin >> A;
  cin >> B;
  int C;
  C=A*B;
  if(A<10 && B<10){
    printf("%d", C);
  }else{
    printf("-1");
  }
  
  
 
 return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll n;
  cin >> n;
  
  vector<ll> a(n);
  ll count = 0;
  REP(i, n){
    cin >> a[i];
    while(a[i] % 2 == 0){
      a[i] /= 2;
      count++;
    }
  }
  
  cout << count << endl;
  
}

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

A = [""] * N
for _ in range(N):
    A[_] = input()

B = [""] * M
for _ in range(M):
    B[_] = input()

import sys
ans = True

for nvi in range(N-M+1):
    for nhi in range(N-M+1):
        ok = True

        for vi in range(M):
            for hi in range(M):
                if A[nvi+vi][nhi+hi] == B[vi][hi]:
                    pass
                else:
                    ok = False
                    break
        
        if ok:
            print("Yes")
            sys.exit()

print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <time.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
const int inf = 1e+9+10;
const ll linf = 1e+18;

const int MAXN = 2e+5 + 5;
ll t[MAXN];

void solve()
{
    int n, m;
    cin >> n;
    ll sum = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> t[i];
        sum += t[i];
    }
    
    cin >> m;
    for(int i = 0; i < m; i++)
    {
        int p;
        ll x;
        cin >> p >> x;
        p--;
        sum += x - t[p];
        cout << sum << "\n";
        sum += t[p] - x;
    }
}

int main()
{
    //ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0);
    //freopen(FILE ".in", "r", stdin);freopen(FILE ".out", "w", stdout);
    int t = 1;
    //cin >> t;
    
    while(t--)
    {
        solve();
    }
    
    return 0;
}


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

int main(){
  int n,a,ans=1000000,j;
  cin>>n;
  for (int i=0;i<n;i++){
    cin>>a;
    j=0;
    while (a%2==0){
      a/=2;
      j++;
    }
    if (ans>j){
      ans=j;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

const int NUM = 26;

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int cons[NUM] = {}, cont[NUM] = {};
	vector<vector<int>> hoge(NUM);
	int ans = 0;
	string s, t;
	
	cin>>s>>t;
	
	
	for(int i = 0; i < s.size(); i++){
		cons[s[i] - 'a']++;
		hoge[s[i] - 'a'].push_back(i);;
	}
	
	for(int i = 0; i < t.size(); i++){
		cont[t[i] - 'a']++;
	}
	
	for(int i = 0; i < NUM; i++){
		if(!cons[i] && cont[i]){
			cout<<-1<<endl;
			return 0;
		}
	}
	
	for(int i = 0, now = -1; i < t.size(); i++){
		
		int next = upper_bound(hoge[t[i] - 'a'].begin(), hoge[t[i] - 'a'].end(), now) - hoge[t[i] - 'a'].begin();
		
		// cout<<"i = "<<i<<" t = "<<t[i]<<" now = "<<now<<" next = "<<next<<" ans = "<<ans<<endl;
		
		if(next == hoge[t[i] - 'a'].size()){ //cout<<"Xnext = "<<hoge[t[i] - 'a'][0]<<endl;
			ans += s.size() - now + hoge[t[i] - 'a'][0];
			now = hoge[t[i] - 'a'][0];
		} else { //cout<<"Tnext = "<<hoge[t[i] - 'a'][next]<<endl;
			ans += hoge[t[i] - 'a'][next] - now;
			now = hoge[t[i] - 'a'][next];
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 1736
import java.util.*;

class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        double N = sc.nextDouble();
                        System.out.printf("%.10f %.10f\n", N * N * Math.PI, 2. * N * Math.PI);
                }
        }
}

Measured memory_bytes: 28384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned int ui;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
#define All(v) (v).begin(),(v).end()
#define Rep(i,n) for(int i = 0; i < (int)n; i++)
#define Reps(i,n) for(int i = 1; i <= (int)n; i++)
#define For(i,m,n) for(int i = m; i < n; i++)
#define Fors(i,m,n) for(int i = m; i <= n; i++)
#define Inf 2e9
#define F first
#define S second
#define pb push_back
#define mp make_pair
struct speed{speed(){cin.tie(); ios::sync_with_stdio(false); cout << fixed << setprecision(18);}}speed;

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

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

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


int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    Rep(i,n){
        cin >> p[i];
    }
    vector<int> tmp(3);
    int ans = 0;
    For(i,1,n-1){
        tmp[0] = p[i-1];
        tmp[1] = p[i];
        tmp[2] = p[i+1];
        sort(All(tmp));
        if(tmp[1] == p[i]) ans++;
    }
    cout << ans << endl;
}

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

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

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    if(a == b){
        cout << 0 << endl;
    }else{
        if(abs(a) + abs(b) > 1e18) cout << "Unfair" << endl;
        ll ans = a - b;

        if(k % 2){
            ans = -ans;
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
		int i=0,length=0,dam=0;
		boolean first=true;

		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            while ((line = br.readLine()) != null ) {
            	if(first){
            		length=Integer.parseInt(line);
            		first=false;
            		line = br.readLine();
            		dam=Integer.parseInt(line);
            	}else{
            		String[] tokens=line.split(" ");
            		int a=Integer.parseInt(tokens[0]);
            		int b=Integer.parseInt(tokens[1]);
            		if(length%2==0){
            			a=length/2<a?length-a+1:a;
            			b=length/2<b?length-b+1:b;
            		}else{
            			if(length/2+1!=a){
            				a=length/2<a?length-a+1:a;
            			}
            			if(length/2+1!=b){
            				b=length/2<b?length-b+1:b;
            			}
            		}
            		System.out.println(Integer.min(a,b)%3==0?3:Integer.min(a,b)%3);

            		i++;
            		if(i==dam){
            			break;
            		}
            	}
            }
		}
	}

}

Measured memory_bytes: 26184
#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;
const int NMAX = 10000;

void print(int* A, int N)
{
   cout << A[0]; 
   for (int k = 1; k < N;k++) {
     cout << " " << A[k] ; 
   }
   cout << endl;
}

bool isPrime(int n)
{
  int k = 2;
  while (k * k < n + 1) {
    if (n % k == 0) {
      return false;
    }
    k += 1; 
  }
  return true;
}


int main()
{
  int n = 10;
  for (int i = 1; i < n;i++) {
    for (int j = 1; j < n;j++) {
      cout << i << "x" << j << "=" << i*j << endl;  
    }
  } 
  return 0;
}

Measured memory_bytes: 1116
///*Bismillahir Rahmanir Rahim***///
/***Stay_Home_Stay_Safe***/
///**Author Thasin Sheikh**///
#include<bits/stdc++.h>
using namespace std;
#define MAX 35000
#define MOD 1000000007
#define PI 3.14159265359
#define makefast__  ios_base::sync_with_stdio(false);
using ll=long long int  ;
using dl =double;
const int N = 2e5 + 10;
ll aarray[300000+10];
ll magic[101][101];
vector<ll>primes;
bool prime[1000001];
ll chkbit(ll n,ll k)
{
    return n&(1LL<<k);
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    makefast__
    string str;
    ll a,b,c,d,e,f,x,y,k,t,A=0,mod,B=0,L,j,i,l,r,m,n,C=0,ans=0,sum=0,sum1=0;
    vector<ll>v,v1;
    queue<ll>qu;
    cin>>n;
    for(i=0; i<n; i++)
        cin>>aarray[i];
    for(i=0; i<64; i++)
    {
        ll cnt=0;
        for(j=0; j<n; j++)
        {
            if(chkbit(aarray[j],i))
                cnt++;
        }
        ll ad=((cnt*(n-cnt))%MOD)*((1LL<<i)%MOD);
        ans=(ans+ad)%MOD;

    }
    cout<<ans<<endl;


    return 0;
}



Measured memory_bytes: 5976
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);

    String s;
    String sl[];

    int c[][] = new int[3][3];

    for(int i = 0; i < 3; i++)
    {
      sl = r.readLine().split(" ");
      for(int j = 0; j < 3; j++)
      {
        c[i][j] = Integer.parseInt(sl[j]);
      }
    }

    int a[] = new int[3];
    int b[] = new int[3];

    boolean f = true;

    for(int i = 0; i < 2; i++)
    {
      int z = c[i][0] - c[i + 1][0];
      for(int j = 0; j < 3; j++)
      {
        if(c[i][j] - c[i + 1][j] != z)
        {
          //System.out.printf("%d %d\n", i, j);
          f = false;
        }
      }
    }

    for(int i = 0; i < 2; i++)
    {
      int z = c[0][i] - c[0][i + 1];
      for(int j = 0; j < 3; j++)
      {
        if(c[j][i] - c[j][i + 1] != z)
        {
          //System.out.printf("%d %d\n", i, j);
          f = false;
        }
      }
    }

    System.out.println(f ? "Yes" : "No");


  }

}

Measured memory_bytes: 21716
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debugg cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll ans,n;
double t,a,aa,mini;
void solve()
{
    cin>>n>>t>>a>>aa;
    mini=abs(a-(t-aa*0.006));
    ans=1;
    for(int i=2;i<=n;i++)
    {
        cin>>aa;
        if(mini>abs(a-(t-aa*0.006)))
        {ans=i;mini=abs(a-(t-aa*0.006));}
    }
    debug(ans);return;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#085-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n,y=IL()
f=True
for i in range(n+1):
    for j in range(n+1):
        if n-i-j>=0:
            if (10*i+5*j+(n-i-j))*1000==y:
                if f:
                    print(i,j,n-i-j)
                    f=False
if f:
    print(-1,-1,-1)

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

using namespace std;

#define N 800

int n,m,x,y,ans,c[N],sum[2];
bool fl,f[N][N],g[N][N];

void dfs(int u){
	for (int v=1;v<=n;++v)
		if (g[u][v]){
			if (c[v]==c[u]){puts("-1"); exit(0);}
			if (c[v]==-1){++sum[c[v]=c[u]^1]; dfs(v);}
		}
}

int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i)
		for (int j=1;j<=n;++j)
			if (i!=j) g[i][j]=1;
	for (int i=1;i<=m;++i){
		scanf("%d%d",&x,&y);
		g[x][y]=g[y][x]=0;
	}
	memset(c,-1,sizeof c);
	f[0][0]=1;
	for (int i=1;i<=n;++i)
		if (c[i]==-1){
			sum[0]=1; sum[1]=0;
			c[i]=0; dfs(i);
			for (int i=n;i>=0;--i)
				for (int j=n;j>=0;--j){
					if (i>=sum[0]&&j>=sum[1])
						f[i][j]|=f[i-sum[0]][j-sum[1]];
					if (i>=sum[1]&&j>=sum[0])
						f[i][j]|=f[i-sum[1]][j-sum[0]];
				}
		}
	ans=n*n*2;
	for (int i=1;i<=n;++i)
		if (f[i][n-i]) ans=min(ans,i*(i-1)/2+(n-i)*(n-i-1)/2);
	printf("%d\n",ans);
	
	return 0;
}
			

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
using vb = vector<bool> ;
using pll = pair<ll, ll> ;

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;


vector<int> fact[maxs];

void pre(){

    for(int i=2;i<maxs;i++){
        if(fact[i].size()==0){
            for(int j=i;j<maxs;j+=i){
                fact[j].push_back(i);
            }
        }
    }


}

void solve(){

    int n;
    cin >> n;
    int a[n+1];
    int g=0;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        g  = __gcd(g,a[i]);
    }
    if(g > 1){
        cout << "not coprime";
    }else{
        map<int,int> cache;
        int flg=0;
        for(int i=1;i<=n;i++){
            int val = a[i];
            for(auto it : fact[val]){
                cache[it]++;
            }
        }
      	for(auto it : cache){
          	if(it.ss > 1){
              	flg = 1;
              	break;
            }
        }
        if(flg){
            cout << "setwise coprime";
        }else{
            cout << "pairwise coprime";
        }
    }

}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}


Measured memory_bytes: 66444
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
vector<int> v[2000];
int ans[2000],ch[2000],n,a,b;
void dfs(int n){
    for(auto x:v[n]){
        cout<<x<<" "<<n<<endl;
        if(ch[x]==0){
            ans[ch[n]-1]++;
            ch[x]=ch[n]+1;
            dfs(x);
        }
    }
    return ;
}
int main(void){
    cin>>n>>a>>b;
    for(int i=1;i<n-1;i++){
        v[i].push_back(i+1);
        v[i].push_back(i-1);
    }
    v[0].push_back(1);
    v[n-1].push_back(n-2);
    v[a-1].push_back(b-1);
    v[b-1].push_back(a-1);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)ch[j]=0;
        ch[i]=1;
        queue<int> que;
        que.push(i);
        while(que.size()){
            int q=que.front();
            que.pop();
            for(auto x:v[q]){
                if(ch[x]==0){
                    ans[ch[q]-1]++;
                    ch[x]=ch[q]+1;
                    que.push(x);
                }
            }
        }
    }
    for(int i=0;i<n-1;i++){
        cout<<ans[i]/2<<endl;
    }
}


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

using namespace std;
#define BUF (8005)
#define ll long long 

char s[BUF];
int x,y;
vector<int> A[2];

bool dp[BUF][2*BUF];

int main(void){
	cin >> s;
	cin >> x >> y;
	int axis=1;
	int cnt=0;
	int n=strlen(s);
	s[n]='T';
	for(int i=0; i<=n; i++){
		if(s[i]=='T'){
			axis=(axis+1)%2;
			if(cnt!=0)A[axis].push_back(cnt);
			cnt = 0;
		}else cnt++;
	}
	
	//for(auto z:A[0]) cout << z ;
	//for(auto z:A[1]) cout << z ;



	//dp
	memset(dp,0,2*BUF*BUF);
	dp[0][0+BUF]=true;
	cnt = 0;
	for(auto z:A[0]){
		cnt++;
		for(int i=0;i<2*BUF;i++){
			if(dp[cnt-1][i]){
				if(cnt==1&&s[0]=='F'){
					dp[cnt][i+z]=true;
				}else{
					dp[cnt][i+z]=true;
					dp[cnt][i-z]=true;
				}
			}
		}
		//for(int i=-10;i<=10;i++)cout << (int)dp[cnt][i+BUF];
		//cout << "\n";	
	}

	//for(int i=-10;i<10;i++) cout << (int)dp[cnt][i+BUF] << "a\n";
	bool tmp = dp[cnt][x+BUF];

	memset(dp,0,2*BUF*BUF);
//	for(int i=0;i<BUF;i++) for(int j=0;j<2*BUF;j++) dp[i][j]=0; 
	dp[0][0+BUF]=true;
	cnt = 0;
	for(auto z:A[1]){
		cnt++;
		for(int i=0;i<2*BUF;i++){
			if(dp[cnt-1][i]){
					dp[cnt][i+z]=true;
					dp[cnt][i-z]=true;
			}
		}	
	}

	if(tmp && dp[cnt][y+BUF]) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}


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

int const MAX = 200010;
int cnt[MAX];

int main() {
    int n, k;
    cin >> n >> k;

    rep(i, n) {
        int a;
        cin >> a;
        cnt[a]++;
    }
    sort(cnt, cnt + n + 1, greater<int>());

    int ans = 0, kind = 0;
    rep(i, n) {
        if (cnt[i] != 0) kind++;
    }

    while (kind > k) kind--, ans += cnt[kind];

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


Measured memory_bytes: 1024
#include <cstdint>
#include <iostream>
#include <sstream>
#include <string>

using Pos = uint64_t;

int main(int argc, char* argv[]) {
    size_t size = 0;
    size_t unit = 0;
    size_t warp = 0;

    std::string paramLine;
    std::getline(std::cin, paramLine);
    std::istringstream is1(paramLine);
    is1 >> size >> unit >> warp;

    std::string posLine;
    std::getline(std::cin, posLine);
    std::istringstream is2(posLine);

    Pos dist = 0;
    Pos prevPos = 0;
    is2 >> prevPos;

    for(size_t i=1; i<size; ++i) {
        Pos pos = 0;
        is2 >> pos;
        dist += std::min((pos - prevPos) * unit, warp);
        prevPos = pos;
    }

    std::cout << dist;
    return 0;
}


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

int main(){
    int n, q; cin >> n >> q;
    fenwick_tree<long long> data(n);
    for (int i = 0; i < n; i++) {
        long long a; cin >> a;
        data.add(i,a);
    }
    while (q--) {
        int t; cin >> t;
        if (t) {
            int l, r; cin >> l >> r;
            cout << data.sum(l,r) << "\n";
        }
        else {
            int p; long long x; cin >> p >> x;
            data.add(p,x);
        }
    }
    return 0;
}

Measured memory_bytes: 8204
using System;
using System.Runtime.CompilerServices;

namespace rensyuu1
{
    class Program
    {
        static void Main(string[] args)
        {
            int num = int.Parse(Console.ReadLine());
            int[] b = new int[num];
            int[] f = new int[num];
            int[] r = new int[num];
            int[] v = new int[num];
            //箱の用意
            int[,,] kanri = new int[4, 3, 10];
            for (int k1 = 0; k1 < 4; k1++)
            {
                for (int k2 = 0; k2 < 3; k2++)
                {
                    for (int k3 = 0; k3 < 10; k3++)
                        kanri[k1, k2, k3] = 0;
                }
            }
            //読み取り
            for (int i1 = 0; i1 < num; i1++)
            {
                string[] line = Console.ReadLine().Split(new char[] { ' ' });
                b[i1] = int.Parse(line[0]) - 1;
                f[i1] = int.Parse(line[1]) - 1;
                r[i1] = int.Parse(line[2]) - 1;
                v[i1] = int.Parse(line[3]);
                kanri[b[i1], f[i1], r[i1]] = kanri[b[i1], f[i1], r[i1]] + v[i1];
            }
            //出力
            for (int o3 = 0; o3 < 4; o3++)
            {
                for (int o1 = 0; o1 < 3; o1++)
                {
                    for (int o2 = 0; o2 < 10; o2++)
                    {
                        Console.Write($" {kanri[o3, o1, o2]}");
                    }
                    Console.WriteLine();
                }
                if (o3 < 3)
                {
                    Console.WriteLine("####################");
                }
            }


        }
    }
}


Measured memory_bytes: 18004
// B - Sum of Three Integers
#include <bits/stdc++.h>
using namespace std;

int main(){
	int k,s; cin>>k>>s;
	int ans = 0;
	int e = min(k,s);//単にkを使うより、x,y,zの範囲を縮める効果あり
	for(int x=0; x<=e; ++x)
		for(int y=0; y<=e; ++y){
			int z = s-x-y;
			if(0<=z && z<=e)ans++;
		}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>

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

    vpl ab(n);rep(i,n)ab[i]=make_pair(a[i],b[i]);

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

    ll sum=0;ll cnt=0;
    rep(i,n){
        if(cnt+ab[i].second>=m){
            sum+=(m-cnt)*ab[i].first;break;
        }

    sum+=ab[i].first*ab[i].second;
    cnt+=ab[i].second;

    }

cout<<sum<<endl;


}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll n , m , cnt , a;
string s;
int main(){
    cin >> n;
    ll arr[n];
    for( int i = 0;i < n;i ++ )
        cin >> arr[i];
    for( int i = 0;i < n - 1;i ++ ){
        if( arr[i] > arr[i + 1] )
            cnt+=arr[i] - arr[i + 1] , arr[i + 1] += arr[i] - arr[i + 1];
    }
    cout << cnt << endl;
}


Measured memory_bytes: 5164
# -*- coding: utf-8 -*-
n = int(input())
w = list(map(int, input().split()))
deltas = []
for i in range(n):
    s1 = sum(int(j) for j in w[:i]) 
    s2 = sum(int(j) for j in w[i:]) 
    deltas.append(abs(s1 - s2))
print(min(deltas))


Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, k;
    scanf("%d %d", &n, &k);
    int ans = 1;
    while(n--){
        if(ans > k){
            ans += k;
        } else {
            ans *= 2;
        }
    }
    printf("%d", ans);
    return 0;
}


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



int main()
{
	int a, b, c, d, f;
	double e;
	cin >> a >> b >> c >> d >> e >> f;
	bool water[3050], suger[3050];
	for (int i = 0; i <= f; i++) {
		water[i] = suger[i] = false;
	}
	water[0] = suger[0] = true;
	for (int i = 0; i <= f; i++) {
		if (water[i]) {
			if (i + a * 100 <= f) {
				water[i + a * 100] = true;
			}
			if (i + b * 100 <= f) {
				water[i + b * 100] = true;
			}
		}
	}
	for (int i = 0; i <= f; i++) {
		if (suger[i]) {
			if (i + c <= f) {
				suger[i + c] = true;
			}
			if (i + d <= f) {
				suger[i + d] = true; 
			}
		}
	}
	double dens = static_cast<double>(e / (100 + e));
	int ansW = 0, ansS = 0;
	double max = -1;
	for (int i = 100; i <= f; i = i + 100) {
		for (int j = 0; j <= f; j++) {
			double temp = 1.0*j / (1.0*j + 1.0*i);
			if (water[i] && suger[j] && temp <= dens && i + j <= f) {
				if (temp > max) {
					max = temp;
					ansW = i;
					ansS = j;
				}
			}
		}
	}
	cout << ansW + ansS << " " << ansS << endl;
	return 0;
}



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

int n, a, b, m, q, r, sum, total=0;
int main(){
	cin >> n >> a >> b;
	for(int i = 1; i <= n; i++){
		m = i;
		sum = 0;
		while(m > 0){
			q = m / 10; r = m % 10;
			sum += r;
			m = q;
		}
		if(a<=sum && sum <= b){
//			cout << i << endl;
			total += i;
		}
	}
//	cout << "total" << endl;
	cout << total << endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define pi 3.141592653589793
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define sz size()
#define cu cout<<
#define en endl
#define sp " "
#include<cstdio>
#include<cstring>
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll modd = (ll)1e9 + 7;
const int mod = 10000007;
/*#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{

    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {
        if (prime[i] == true)
        {
            prm.pb(i);
            for (ll j=i*i; j<=N; j += i)
                pe[j] = false;
        }
    }
}*/
void pr (int f)
{
    if(f==1)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}
bool isprime(ll n)
{
    if(n<2) return 0;
    if(n==2) return 1;
    else
    {
        for(int i=2; i*i<=n; i++)
            if(n%i==0) return 0;
    }
    return 1;
}
map<int , int >mp;
set<int  > st;
multiset<string> :: iterator it;
deque <char> q ;
int vis [10000000];
pair<int,int> a[2020];
int main()
{
    fast ;
    int n;
    int k;
    cin >> n >> k;
    int ar[n];
    for ( int i=0;i<n;i++) cin >> ar[i];
    sort(ar,ar+n);
    int sum = 0;
    for ( int i=0;i<k;i++)
        sum+=ar[i];
    cout << sum <<endl;
}





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

using namespace std;

int main() {
    int K, A, B;
    cin >> K;
    cin >> A >> B;
    if(B/K > A/K || A%K == 0 || B%K == 0) {
        cout << "OK" << endl;
    }else{
        cout << "NG" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>
#include <cstdint>

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

using namespace std;
typedef long long ll;

const int INF = 1 << 30;
const int MOD = 1e9 + 7;


bool dp[81][81][25610];

int main() {
    int h, w; cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w, 0));
    vector<vector<int>> b(h, vector<int>(w, 0));
    rep(i, h) rep(j, w) cin >> a[i][j];
    rep(i, h) rep(j, w) cin >> b[i][j];
    vector<vector<int>> c(h, vector<int>(w, 0));
    rep(i, h) rep(j, w) c[i][j] = abs(a[i][j] - b[i][j]);

    int base = 80 * (h+w-1);

    dp[0][0][c[0][0] + base] = true;
    dp[0][0][-c[0][0] + base] = true;
    rep(i, h) rep(j, w) rep(v, 25601){
        if (i+1 < h) {
            if (v + c[i+1][j] < 25610) dp[i+1][j][v + c[i+1][j]] |= dp[i][j][v];
            if (v - c[i+1][j] > 0) dp[i+1][j][v - c[i+1][j]] |= dp[i][j][v];
        }
        if (j+1 < w) {
            if (v + c[i][j+1] < 25610) dp[i][j+1][v + c[i][j+1]] |= dp[i][j][v];
            if (v - c[i][j+1] > 0) dp[i][j+1][v - c[i][j+1]] |= dp[i][j][v];
        }
    }

    int ans = INF;
    rep(v, 25610) {
        if (dp[h-1][w-1][v]) ans = min(ans, abs(v-base));
    }
    cout << ans << endl;
 


    return 0;
}

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

typedef long long ll;

int main() {
	int N;
	cin>>N;
	vector<ll> A(3*N);
	rep(i,3*N)cin>>A[i];

	//最小値がtop,pop;
	priority_queue<ll,vector<ll>, greater<ll>> ql;
	//最大値がtop,pop;
	priority_queue<ll> qr;

	ll suml = 0,sumr = 0;
	rep(i,N){
		suml += A[i];
		ql.push(A[i]);
		sumr += A[2*N+i];
		qr.push(A[2*N+i]);
	}
	//境界を左側i個までとしたときの、左側の和の最大値
	//境界を右側i個としたときの、右側の和の最小値
	vector<ll> L(N+1), R(N+1);
	L[0] = suml;
	R[0] = sumr;
	rep1(i,N+1){
		suml += A[N-1+i];
		ql.push(A[N-1+i]);
		suml -= ql.top();
		L[i] = suml;
		ql.pop();

		sumr += A[2*N-i];
		qr.push(A[2*N-i]);
		sumr -=qr.top();
		R[i] = sumr;
		qr.pop();
	}
	ll ans = L[0] - R[N];
	rep(i,N+1){
		ans = max(ans,L[i] - R[N-i]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 5996
#include <stdio.h>
 
int main(void){
    int n,a,minv,maxv,i,b;
    scanf("%d",&n);
    scanf("%d",&b);
    minv=b;
 
    for(i=2;i<=n;i++){
        scanf("%d",&a);
        if(i==2)
            maxv = a-b;
        if(maxv < a-minv)
            maxv = a-minv;
        if(minv > a)
            minv =a;
    }
    printf("%d\n",maxv);
    return 0;
}


Measured memory_bytes: 2104
#include<stdio.h>
#include<algorithm> 
#define PI 3.1415927
//using namespace std;
int a[105];
int main()
{
	int n,ans=1;
	scanf("%d",&n);
	for(int i=0;i<n;i++)  scanf("%d",&a[i]);
	for(int i=1;i<n;i++)
	{
		int flast=1;
		for(int j=0;j<i;j++) 
		{
			if(a[i]<a[j])
			{
				 flast=0;
				 break;
			}
		}
		if(flast)  ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3212
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
	int ans = -intMAX;
	int N;
	cin >> N;
	vector<int> V(N);
	vector<int> C(N);
	for(int i=0; i<N; ++i) cin >> V[i];
	for(int i=0; i<N; ++i) cin >> C[i];
	for(int bit=0; bit < (1<<N); ++bit){
		int value = 0;
		int cost = 0;
		for(int i=0; i<N; ++i){
			if(bit & (1<<i)){
				value += V[i];
				cost += C[i];
			}
		}
		ans = max(ans, value-cost);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    n, a, b = map(int, input().split())
    x = tuple(map(int, input().split()))
    r = 0
    for i1 in range(1, n):
        dis = x[i1] - x[i1-1]
        if dis * a > b:
            r += b
        else:
            r += dis * a
    print(r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14352
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N],b[N];
int main()
{
    int n,r=0;
    cin>>n;
    for(int i=0; i<n; i++)cin>>a[i];
    for(int i=0; i<n; i++)cin>>b[i];
    if(n&1)
    {
        for(int i=0; i<n; i++)r^=a[i]^b[i];
    }
    for(int i=1<<29; i; i>>=1)
    {
        for(int j=0; j<n; j++)a[j]&=i-1;
        sort(a,a+n);
        for(int j=0; j<n; j++)
        {
            int t=lower_bound(a,a+n,i-(b[j]&(i-1)))-a;
            if((t&1)!=(n&1))r^=i;
        }
    }
    cout<<r;
    return 0;
}

Measured memory_bytes: 1920
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
//#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define PB push_back
#define MP make_pair
#define INF 1073741824
#define inf 1152921504606846976
#define pi 3.14159265358979323846
//#pragma comment(linker,"/STACK:10240000,10240000")
//mt19937 rand_(time(0));
const int N=3e5+7,M=2e6;
const long long mod=1e9+7;
inline int read(){int ret=0;char ch=getchar();bool f=1;for(;!isdigit(ch);ch=getchar()) f^=!(ch^'-');for(;isdigit(ch);ch=getchar()) ret=(ret<<1)+(ret<<3)+ch-48;return f?ret:-ret;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}//逆元
//int head[N],NEXT[M],ver[M],tot;void link(int u,int v){ver[++tot]=v;NEXT[tot]=head[u];head[u]=tot;}

char s[N],t[N];
int dp[3300][3300];
int pre[10000000];
int main(){
    //freopen("1.txt","r",stdin);
    //ios::sync_with_stdio(false);
    scanf("%s",s);
    scanf("%s",t);
    int n=strlen(s);
    int m=strlen(t);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(s[i-1]==t[j-1]){
                dp[i][j]=dp[i-1][j-1]+1;
                pre[i*m+j]=(i-1)*m+j-1;
                //pre[(i-1)*m+j]=MP(i-1,j-1);
            }
            if(dp[i][j]<dp[i-1][j]){
                pre[i*m+j]=(i-1)*m+j;
                //pre[MP(i,j)]=MP(i-1,j);
                dp[i][j]=dp[i-1][j];
            }
            if(dp[i][j]<dp[i][j-1]){
                pre[i*m+j]=i*m+j-1;
                //pre[MP(i,j)]=MP(i,j-1);
                dp[i][j]=dp[i][j-1];
            }
        }
    }
//    for(int i=1;i<=n;i++){
//        for(int j=1;j<=m;j++) cout<<dp[i][j]<<' ';
//        cout<<endl;
//    }
    int ans=dp[n][m];
//    cout<<ans<<endl;
    int now=n*m+m;
    stack<char>ss;
    int x,y;
    while(ans){
        if(now%m==0) {
            x=now/m-1;
            y=m;
        }
        else {
            x=now/m;
            y=now%m;
        }

        if(s[x-1]==t[y-1]){
            ss.push(s[x-1]);
            ans--;
        }
        now=pre[now];
    }
    while(!ss.empty()){
        printf("%c",ss.top());
        ss.pop();
    }
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}




Measured memory_bytes: 78080
#include <bits/stdc++.h>
using namespace std;
int main () {
	int N;cin >> N;
	int a[N];
	int count = 0;
	for (int i = 0; i < N; ++i)
	{
		int tmp;
		cin >> tmp;
		while(tmp % 2 == 0){
			tmp /= 2;
			count++;
		}
	}
	cout << count << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  return res;
}

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> divs = divisor(M);
  ll ans = 1;
  for (int i = 0; i < divs.size(); i++) {
    if (M / divs[i] >= N) ans = max(ans, divs[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

ll dp[105][4][4][4];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	rep(j,4)rep(k,4)rep(l,4){
		if(j==0&&k==1&&l==2)continue;
		if(j==1&&k==0&&l==2)continue;
		if(j==0&&k==2&&l==1)continue;
		dp[3][j][k][l]=1;
	}
	range(i,2,n){
		rep(l,4){
			rep(k,4){
				rep(j,4){
					rep(z,4){
						if(k==1&&l==0&&z==2)continue;
						else if(k==0&&l==1&&z==2)continue;
						else if(k==0&&l==2&&z==1)continue;
						else if(j==0&&k==1&&z==2)continue;
						else if(j==0&&l==1&&z==2)continue;
						dp[i+1][k][l][z]+=dp[i][j][k][l];
						dp[i+1][k][l][z]%=MOD;
					}
				}
			}
		}
	}
	ll ans=0;
	rep(j,4)rep(k,4)rep(l,4)ans+=dp[n][j][k][l];
	cout<<ans%MOD<<endl;

	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define AB_BHI_NI_DEGI                \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
#define int long long
#define pb push_back
#define N 100009
#define inf 1e18
const double PI = 3.141592653589793238462643383279;
int mod = 1e9 + 7;
//int mod = 998244353;
#define P pair<int, int>
#define F first
#define S second
#define ll long long
#define all(v) v.begin(), v.end()
#define vi vector<int>
#define ld long double

#define ordered_set tree<P, null_type, less<P>, rb_tree_tag, tree_order_statistics_node_update>

void end(int n = -1)
{
	cout << n << "\n";
	exit(0);
}
int n;
int a[101];
int dp[101][N];

int32_t main()
{
	AB_BHI_NI_DEGI
	cin >> n;
	int k;
	cin >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	dp[0][0] = 1;
	for (int i = 0; i < n; i++)
	{
		vector<int> sum(k + 2, 0);
		for (int j = 0; j <= k; j++)
			sum[j + 1] = sum[j] + dp[i][j];
		for (int j = 0; j <= k; j++)
		{
			dp[i + 1][j] += (sum[j + 1] - sum[max(0LL, j - a[i])]);
			dp[i + 1][j] %= mod;
		}
	}
	cout << dp[n][k] << "\n";

	return 0;
}

Measured memory_bytes: 79220
# include <iostream>
# include <vector>
# include <limits>
# include <algorithm>
# include <map>
# include <string>
# include <functional>
using namespace std;

int main() {
	int n;
	int k;
	cin >> n >> k;
	int x, y, ans;
	for (int i = 0; i < k; i++) {
		cin >>x >> y;
		x = min(x, abs(n - x) + 1);
		y = min(y, abs(n - y) + 1);
		ans = min(x, y) % 3;
		if (ans == 0) {
			ans = 3;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int maxM = 3e5+7;
const int maxV = 90010;
 
const int MOD = 1e9+7;
 
int T;
const int maxN = 1e5+8;
const ll INF = 1000000000000000010LL;
const int K = 15;
ll a[maxN];
ll b[maxN];
int n;

int f[1010][1010];
int main() {
	int x,y,z;
	 
	scanf("%d%d%d",&x,&y,&z);
	int ans = max(0,z - (x - y));
	cout<<ans<<endl;

    return 0;
}

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

int n;
int p[20];
int mind;

void dfs(int a=0, int b=0, int i=0)
{
  if (i == n){
    mind = min(mind, abs(a - b));
    return;
  }
  dfs(a + p[i], b, i + 1);
  dfs(a, b + p[i], i + 1);
}

int main()
{
  while (cin >> n, n){
    for (int i = 0; i < n; i++){
      cin >> p[i];
    }
    mind = INT_MAX;
    dfs();
    cout << mind << endl;
  }
}

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

using namespace std;
vector<int>v(3),dp(3);
int i,j,k,n,maxim;
const int inf=1e9+5;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie();
    cin>>n;
    for(i=1; i<=n; i++)
    {
        vector <int>aux(3,0);
        cin>>v[0]>>v[1]>>v[2];
        for(j=0;j<3;j++)
            for(k=0;k<3;k++)
            if(j!=k)
            aux[j]=max(aux[j],dp[k]+v[j]);
            dp=aux;
    }
    maxim=max(dp[0],dp[1]);
    maxim=max(maxim,dp[2]);
    cout<<maxim;
            return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
 
int main() {
    ll N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        A[i]--;  // 0-indexed に変更
    }
 
    set<int> used;     // 探索済みの町を保存
    vector<int> path;  // 探索の順番を格納
    int now = 0;
    while (used.count(now) == 0) {  // 探索済みの町に到達するまで
        path.push_back(now);
        used.insert(now);
        now = A[now];
    }
 
    int s = find(path.begin(), path.end(), now) - path.begin();  // s: ループする最初の部分に到達するまで
    int r = (int)path.size() - s;                                // 周期
 
    if (K < s) {  // ループ部分に到達しない時
        cout << path[K] + 1 << endl;
        return 0;
    } else {  // ループ部分に到達する時
        cout << path[(K - s) % r + s] + 1 << endl;
        return 0;
    }
}
 

Measured memory_bytes: 14012
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;

int cnt = 0;
int n, A[1000000], G[1000000];

void cout_array(int n,int arr[]){
    for(int i = 0; i < n; i++){
        cout << arr[i];
        if(i < n-1) cout << ' ';
    }
    cout << endl;
}

//間隔gだけ離れた要素のみを対象に挿入ソート
void insertion_sort(int N, int A[], int g){
    //挿入ソート 計算量 O(N**2)
    for(int i = g; i < N; i++){
        int v = A[i];
        int j = i - g;
        //i番目の要素とi-g to 0番目 => (j)の要素を比較していく
        while(j >= 0 && A[j] > v){
            //gだけ後ろにずらしていく
            A[j+g] = A[j];
            j -= g;
            cnt++;
        }
        A[j+g] = v;
    }
}

void sell_sort(int n, int A[]){
    int m = 0, h = 0;
    //Gを作成 3n+1
    for (int i = 0; i < 100; i++){
        h = 3*h + 1;
        if (h > n) {
            m = i;
            break;
        }
        G[i] = h;
    }

    cout << m << endl;
    for(int i = m-1; i >= 0; i--){
        cout << G[i];
        if(i > 0) cout << ' ';
    }
    cout << endl;

    for (int i = m-1; i >= 0; i--){
        insertion_sort(n, A, G[i]);
    }

}

int main(){
    cin >> n;
    for (int i = 0; i < n; i++) cin >> A[i];
    
    sell_sort(n, A);

    cout << cnt << endl;
    //配列を表示
    for(int i = 0; i < n; i++){
        cout << A[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 6992
N , K = map(int,input().split())
Rosoku_list = list(map(int,input().split()))

Sum_list = []
for i in range (N-K+1):
    Sum_list.append(Rosoku_list[i+K-1]-Rosoku_list[i])
    
for index , current_sum in enumerate(Sum_list):
    
    if Rosoku_list[index]*Rosoku_list[index+K-1] >  0:
        if Rosoku_list[index] > 0 :
            Sum_list[index] += abs(Rosoku_list[index])
        elif Rosoku_list[index] < 0 :
            Sum_list[index] += abs(Rosoku_list[index + K -1])
            
    elif Rosoku_list[index]*Rosoku_list[index+K-1] <  0:
        if abs(Rosoku_list[index]) <= abs(Rosoku_list[index+K-1]):
            Sum_list[index] +=abs(Rosoku_list[index])
        else:
            Sum_list[index] +=abs(Rosoku_list[index+K-1])
        
    #elif Rosoku_list[index]*Rosoku_list[index+K-1] ==  0:
        
print(min(Sum_list))

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

typedef int32_t i32;
typedef int64_t i64;

typedef struct line {
  i64 a, b;
} line;

i64 eval (line l, i64 x) {
  return l.a * x + l.b;
}

int cond (line p, line q, line r) {
  return -(p.b - q.b) * (q.a - r.a) < -(q.b - r.b) * (p.a - q.a);
}

#define ALLOC(size,type) ((type*) calloc ((size), sizeof (type)))

void run (void) {
  i32 n;
  i64 c;
  scanf ("%" SCNi32 "%" SCNi64, &n, &c);
  i32 *h = ALLOC (n, i32);
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, h + i);
  }
  i64 *dp = ALLOC (n, i64);
  line *d = ALLOC (n, line);
  i32 front = 0;
  i32 last = 0;
  d[last++] = (line) {-2 * h[0], (i64)h[0] * h[0] + c};
  for (i32 i = 1; i < n; ++i) {
    i32 x = h[i];
    for (; front < last - 1 && eval (d[front], x) >= eval (d[front + 1], x); ++front);
    dp[i] = eval (d[front], x) + (i64) x * x;
    line l = {-2 * h[i], dp[i] + (i64) x * x + c};
    for (; front + 1 < last && !cond (d[last - 2], d[last - 1], l); --last);
    d[last++] = l;
  }
  printf ("%" PRIi64 "\n", dp[n - 1]);
}

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


Measured memory_bytes: 5632