akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define MAXWI 100000
 
int gP,gSum,gMaxW;
int gw[MAXWI+1];
int gn,gk;
 
 
void carryPackage( int maxPackage )
{
    int i;
    int tmpk;
    int package;
      
    if( gMaxW <= maxPackage ) {
        tmpk=gk;
        package=i=0;
        while( i < gn ) {
            package+=gw[i];
            if( maxPackage <= package ) {
                if( maxPackage < package ) {
                    i--;
                }
                tmpk--;
                if( tmpk == 0 ) { break; }
                package=0;     
            }
            i++;
        }
        if( 1<=tmpk || (0==tmpk && i == (gn-1)) ) {
            gP=maxPackage;
        } else {
        	if( gMaxW < maxPackage ) {
        		gMaxW=maxPackage;
        	}
        }
    }
    
    return;
}
 
int main( void ) 
{
    int i,j;
    int end;
    int maxPackage;
         
    scanf( "%d%d", &gn, &gk );

    end=gn/gk;
    maxPackage=gMaxW=gSum=0;
   for( i=0; i<end; i++ ) {
        scanf( "%d", &gw[i] );
        maxPackage+=gw[i];
        gSum+=gw[i];
    }   
    for( i=end; i<gn; i++ ) {
        scanf( "%d", &gw[i] );
        gSum+=gw[i];
    }
    for( i=0; i<gn; i++ ) {
		if( gMaxW < gw[i] ) {
			gMaxW=gw[i];
		}
    }
 
    if( 1 == gk ) {
        gP=gSum;    
    } else if( gk < gn ) {
	    gP=gSum;
	  	i=0;
	  	j=end;
       if( gMaxW < gSum/gk ) { gMaxW=gSum/gk; }
        while( i < gn ) {
            while( end < gn ) {
                maxPackage+=gw[end];
                if(  maxPackage < gP ) {
                    carryPackage( maxPackage );
                } else {
                    break;
                }
                j++;
                end=i+j;
            }

            
            maxPackage-=gw[end];
            maxPackage-=gw[end-1];            
	        maxPackage-=gw[i];
           	end--;
            j-=2;
            i++;
            if( end <= i  ) {
                 j=maxPackage=0;
                end=i;
            }
        }
    } else {
		gP=gMaxW;
    }
    printf( "%d\n", gP );
 
    return 0;
}

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

int main()
{
    long long A, B, you2, you, you3;
    bool t = false, Y = false;
    cin >> A >> B;
    vector<long long> akake(1), bkake(1);
    akake.at(0) = 1;
    bkake.at(0) = 1;

    for (int i = 0;; i++)
    {
        if(t==false)
        {
            you = max(A, B);
            you2 = min(A, B);
            t = true;
        }
        if(you==you2)
        {
            cout << (A * B) / you << endl;
            break;
        }
        you3 = max(you, you2)-min(you,you2);
        you2 = max(you, you3);
        you = min(you, you3);
    }
}


Measured memory_bytes: 256
from collections import defaultdict

def paint(v, d, c):
    if color[v] == 0:
        color[v] = c
    if dp[v] >= d or d == 0:
        return
    dp[v] = d
    for nb in graph[v]:
        paint(nb, d-1, c)

N, M = map(int, input().split())
dp = [0] * N
color = [0] * N
graph = defaultdict(set)
for _ in range(M):
    i, j = map(int, input().split())
    graph[i-1].add(j-1)
    graph[j-1].add(i-1)
Q = int(input())
vdcs = []
for _ in range(Q):
    v, d, c = map(int, input().split())
    vdcs.append((v-1, d, c))
vdcs.reverse()

for v, d, c in vdcs:
    paint(v, d, c)

for c in color:
    print(c)

Measured memory_bytes: 60728
#include<bits/stdc++.h>
#define reg(i,a,b) for(int i=a;i<=b;i++)
#define reh(i,a,b) for(int i=a;i>b;i--)
#define in(x) scanf("%d",&x)
#define fro freopen("D:\\testdata.in", "r", stdin)
#define il inline
#define lson(q) q<<1
#define rson(q) q<<1|1
using namespace std;
typedef long long ll;
const int mx=1e5+10;
int a[mx];
int t;
int n,m;
ll res;

int main(){
	string str1,str2;
	cin>>str1;
	cin>>str2;
	int len=str1.length();
	int num=0;
	reg(i,0,len-1){
		if(str1[i]==str2[i])++num;
	}
	cout<<num<<endl;
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
	#define ll long long
	#define f(i,a,b) for(ll i=a;i<b;i++)
	#define fi(i,a,b) for(ll i=b;i>=a;i--)
	using namespace std;
	ll mod(ll a)
	{
	if(a>0)
	return a;
	else
	return -a;
	}
	ll min(ll a,ll b)
	{
	if(a>b)
	return b;
	else
	return a;
	}
	ll gcd(ll a, ll b)
	{
	    if (b == 0)
	        return a;
	    return gcd(b, a % b);

	}
	ll max(ll a,ll b)
	{
	if(a<b)
	return b;
	else
	return a;
	}
	int main()
	{

	ll max=0,i1,n,n1,n2,i,w,j,l=0,k=0,m,t,gcd1;
	cin>>n;
	if(n%1000!=0)
	cout<<(1000-n%1000);
	else
	cout<<0;	
	return 0;
	}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, T, U;
  int A, B;
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  if (S == U) {
    cout << A - 1 << " " << B << endl;
  } else {
    cout << A << " " << B - 1 << endl;
  }
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int N, M;
ll S;

int main()
{
	int i, j;

	scanf("%d%d", &N, &M);
	while(M--)
	{
		ll t; scanf("%lld", &t); S+=t;
	}

	printf("%lld\n", max(-1ll, N-S));
}

Measured memory_bytes: 3828
#include <cstdio>
#include <cctype>
#include <vector>
#include <iterator>
using namespace std;

#define si static inline
#define gcu getchar_unlocked
si int in() {
	int c, n = 0;
	bool minus = false;
	if ((c = gcu()) == '-') minus = true;
	else ungetc(c, stdin);
	while ((c = gcu()) >= '0' && c <= '9') n = 10 * n + (c - '0');
	return minus ? -n : n; }
si void scan(char *s) {while (!isspace(*s++ = gcu()));}
#define pcu putchar_unlocked
#define svo si void out
svo(int n) {
	static char buf[20];
	char *p = buf;
	bool minus = false;
	if(n < 0) minus = true, n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	if (minus) *p++ = '-';
	while (p != buf) pcu(*--p); }
svo(char *s){while(*s)pcu(*s++);}
svo(const char *s){while(*s)pcu(*s++);}
svo(char c){pcu(c);}
template <typename T>
svo(vector<T> v){for(T &x:v)out(' '),out(x);out('\n');}
//svo(vector<T> &v){for(int &x:v)out(&x == &v[0]?"":" ",x);out('\n');}
template <typename head, typename... tail>
svo(head&& h, tail&&... t){out(h);out(move(t)...);}

typedef vector<int> v;

struct bst
{
#define VNI vector<node>::iterator
	struct node {
		int v;
		VNI l = VNI(), r = VNI();
	};
	typedef vector<node> vn;
	typedef vn::iterator vni;
	vn nodes;
	vni root = vni(), i, vnin = root;

	bst(int n)
	{
		nodes.resize(n);
		i = nodes.begin();
	}

	vni insert (vni r, int n)
	{
		if (r == vnin) {
			(*i).v = n;
			r = i++;
		} else if ((*r).v < n)
			(*r).r = insert((*r).r, n);
		else
			(*r).l = insert((*r).l, n);
		return r;
	}
	void insert (int n)
	{
		root = insert(root, n);
	}
	void print(vni r, v &buf)
	{
		if (r == vnin)
			return;
		node n = *r;
		buf.push_back(n.v);
		print(n.l, buf);
		out(' ', n.v);
		print(n.r, buf);
	}
	void print()
	{
		v buf;
		print(root, buf);
		out('\n', buf);
	}
};

int main()
{
	int n = in();
	char s[20];
	bst b(n);

	while (n--) {
		scan(s);
		if (*s == 'i')
			b.insert(in());
		else
			b.print();
	}
}



Measured memory_bytes: 16136
#include"iostream"
using namespace std;

int main()
{
	int n;
	cin >> n;
	int sum = 0;
	int m = n;
	for (int i = 0; i < 12; i++)
	{
		sum += m - (m / 10) * 10;
		m = m / 10;
	}
	cout << (n%sum == 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int a,b,c,d,i,j;
	int data[101][101]={};
	scanf("%d %d",&a,&b);
	for(i=0;i<a;i++){
		for(j=0;j<b;j++){
			scanf("%d",&data[i][j]);
			data[i][b]+=data[i][j];
		}
	}
	for(i=0;i<a;i++){
		for(j=0;j<b+1;j++){
			data[a][j]+= data[i][j];
		}
	}
	for(i=0;i<=a;i++){
		for(j=0;j<=b;j++){
			printf("%d",data[i][j]);
			if(j<b){
				printf(" ");
			}
			else{
				printf("\n");
			}
		}
	}
	return 0;
}

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

#define int long long int
#define ff first
#define ss second
#define pb push_back
#define print(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int bexp(int a, int b, int mod)
{
    int res = 1;

    while (b)
    {
        if (b & 1) res = (res * a) % mod;

        a = (a * a) % mod; 
        b >>= 1;
    }
    return res;
}

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

const int N = 100010;
const int mod = 998244353;

struct comp {
    bool operator() (const pair<int, int> a, const pair<int, int> b) const
    {
        int d1 = a.ss - a.ff, d2 = b.ss - b.ff;
        return ((d1 > d2) || (d1 == d2 && a.ff < b.ff));
    }
};

int32_t main() 
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);

    int n;
    cin >> n;

    string s;
    while (n--) {
        s += "ACL";
    }

    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3576
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		//??????????????°
		Scanner sc;		//??\???
		int a=0;
		int b=0;
		int kotae=0;
		int i=0;

		sc = new Scanner(System.in);

		while(sc.hasNext()){

			a = sc.nextInt();
			b = sc.nextInt();
			kotae = a + b;

			String skotae = String.valueOf(kotae);
			int keta = skotae.length();

			System.out.println(keta);

			if(i >= 200){
				break;
			}
			i= i+1;
		}
	}
}

Measured memory_bytes: 26652
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<math.h>
#include<complex>
#include<queue>

using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; ++i)
using ll = long long;
using ld = long double;
using Point = complex<ld>;
const ld eps = 1e-9;

ld cross(Point a,Point b){
    return imag(conj(a)*b);
}


void solve(int n,int m){
    vector<Point> p(n);
    rep(i,n){
        int x,y;
        cin>>x>>y;
        p[i]=Point(x,y);
    }
    vector<vector<int>> v(m);
    rep(i,m){
        int x,y;
        cin>>x>>y;
        --x;--y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    vector<vector<int>> used(n);
    rep(i,n){
        sort(v[i].begin(),v[i].end(),[&](int x,int y){
            return arg(p[x]-p[i])<arg(p[y]-p[i]);
        });
        used[i].resize(v[i].size());
    }
    vector<vector<int>> pols;
    rep(i,n){
        int s = v[i].size();
        rep(j,s){
            if(used[i][j])continue;
            vector<int> pol;
            pol.push_back(i);
            int cur = i;
            int nxt = v[i][j];
            used[i][j]=true;
            while(nxt!=i){
                pol.push_back(nxt);
                int idx = 0;
                while(v[nxt][idx]!=cur)++idx;
                idx = (idx+1)%v[nxt].size();
                used[nxt][idx]=true;
                cur = nxt;
                nxt = v[cur][idx];
            }
            ld sum = 0;
            rep(k,pol.size()){
                sum += cross(p[pol[k]],p[pol[(k+1)%pol.size()]]);
            }
            if(sum<0)pols.push_back(pol);
        }
    }
    int sz = pols.size();
    vector<vector<int>> vs(sz+1);
    rep(i,sz){
        int s = pols[i].size();
        rep(j,s){
            Point ext = (ld).5*(p[pols[i][(j+1)%s]]+p[pols[i][j]])
                            + Point(0,1)*eps*(p[pols[i][(j+1)%s]]-p[pols[i][j]]);
            int nxt = sz;
            rep(k,sz){
                ld sum = 0;
                rep(t,pols[k].size()){
                    sum += arg((p[pols[k][(t+1)%pols[k].size()]]-ext)/(p[pols[k][t]]-ext));
                }
                if(abs(sum)>3){
                    nxt=k;
                    break;
                }
            }
            vs[nxt].push_back(i);
            vs[i].push_back(nxt);
        }
    }
    vector<int> dist(sz+1,10000);
    dist[sz]=0;
    queue<int> q;
    q.push(sz);
    int ans = 0;
    while(q.size()){
        int cur = q.front();q.pop();
        ans = max(ans,dist[cur]);
        for(auto to : vs[cur]){
            if(dist[to]>dist[cur]+1){
                dist[to]=dist[cur]+1;
                q.push(to);
            }
        }
    }
    cout<<ans<<endl;
}



int main(){
    int n,m;
    while(cin>>n>>m,n!=0)solve(n,m);
    
}


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

ll f(ll n, ll x, ll m){
  ll ref = x;
  ll now = x * x % m;
  int cnt = 1;
  vector<ll> d(m+1);
  d[0] = 0;
  while(now != x){
    d[cnt] = ref;
    ref += now;
    now = now * now %m;
    ++cnt;
  }
  ref = n/cnt *ref + d[n%cnt];
  return ref;
}

int main(){
  ll n, x, m;
  cin >> n >> x >> m;
  vector<bool> ok(m,true);
  ll cnt = 0;
  ll ans = 0;
  while(cnt < n){
    if(!ok[x]) break;
    ans += x;
    ok[x] = false;
    x = x*x % m;
    ++cnt;
  }
  ans += f(n-cnt,x,m);
  cout << ans << endl;
}

Measured memory_bytes: 4048
// Hovalhagh
// Ya Aziz & Hakim
// AliReza Kaboli

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 100;

int a[N], dp[N];

int main() {
	int n, k;
	cin >> n >> k >> a[1];
	dp[1] = 0;
	for (int i = 2; i <= n; ++i) {
		cin >> a[i];
		dp[i] = dp[i - 1] + abs(a[i - 1] - a[i]);
		for (int j = 2; j <= k; ++j)
			if (i - j > 0)
				dp[i] = min(dp[i], dp[i - j] + abs(a[i - j] - a[i]));
	}
	cout << dp[n] << '\n';
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{

    ll sum=0;
    int i,j,k,n;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            for(k=1;k<=n;k++)
            {
                sum+=__gcd(i,__gcd(j,k));
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>

using namespace std;

int main(void) {
	string a, b;
	cin >> a >> b;
	string s = a + b;
	int x = 0;
	for (int i=0;i<s.length();i++){
		x = x * 10 + (s[i] - '0');
	}
	for (int i = 0; i < 1000; i++) {
		if (x == i * i) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll ar[3002],s,dp[3002][3002],n,mod1=998244353;
ll rec(ll i,ll j)
{
    if(j==s)
        return n-i+2;
    if(j>s)
        return 0;
    if(i==n+1)
        return 0;
    if(dp[i][j]!=-1)
        return dp[i][j];
    ll z1=rec(i+1,j);
    ll z2=rec(i+1,j+ar[i]);
    dp[i][j]=(z1%mod1+z2%mod1)%mod1;
    return dp[i][j];
}
int main()
{
    ll i,ans=0;
    cin>>n>>s;
    for(i=1;i<=n;i++)
        cin>>ar[i];
    memset(dp,-1,sizeof dp);
    rec(1,0);
    for(i=1;i<=n;i++)
    {
        ans=((ans%mod1)+(dp[i][0]%mod1))%mod1;
    }
    cout<<ans;
}


Measured memory_bytes: 70784
#include <cstdio>
#include <cstring>
using namespace std;

const int N = 123456*2;
bool prime[N+1];
int sum[N+1];

int main() {
  memset(prime, true, sizeof(prime));
  prime[0] = prime[1] = false;
  for (int i = 2; i*i <= N; ++i) {
    if (prime[i]) {
      for (int j = i*i; j <= N; j += i) { prime[j] = false; }
    }
  }
  sum[0] = 0;
  for (int i = 1; i <= N; ++i) {
    sum[i] += prime[i] + sum[i-1];
  }

  int n;
  while (scanf("%d", &n), n) {
    printf("%d\n", sum[2*n] - sum[n]);
  }
}

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

long long mod = 1000000007;

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

  vector<long long> aa(n);
  vector<long long> ag(n);
  vector<long long> a_g(n);
  vector<long long> ag_(n);
  vector<long long> ac(n);
  vector<long long> ga(n);
  vector<long long> a(n);
  vector<long long> g(n);
  vector<long long> c(n);
  long long ret = 16;
  a[0] = g[0] = c[0] = 1;
  a[1] = g[1] = c[1] = 4;
  aa[1] = ag[1] = ac[1] = ga[1] = 1;
  for(int i = 2;i < n;i++){
    aa[i] = a[i-1];
    ag[i] = a[i-1];

    a_g[i] = a[i-2];

    ag_[i] = (ag[i-1]*2) % mod;

    ac[i] = (a[i-1]-ga[i-1])%mod;
    if(ac[i] < 0)ac[i] += mod;

    ga[i] = g[i-1];

    a[i] = ret;
    c[i] = (ret - ag[i-1] - ga[i-1] - ag_[i-1] - a_g[i-1])%mod;
    if(c[i] < 0)c[i] += mod;
    
    g[i] = (ret - ac[i-1])%mod;
    if(g[i] < 0)g[i] += mod;
    
    ret = (c[i]+g[i]+2*a[i])%mod;
  }

  cout << ret << endl;
}


Measured memory_bytes: 256
//
// Created by 10295 on 27/09/2020.
//

#include <iostream>

using namespace std;
int N;
int M;
int X;
int a[20][20], cost[20], col[20], b[20];
int sum = 1 << 29;
int total;
int kk;

void dfs(int s) {
    if (s == kk + 1) {
        for (int i = 1; i <= M; i++)
            col[i] = 0;
        for (int i = 1; i <= kk; i++)
            for (int j = 1; j <= M; j++) {
                col[j] += a[b[i]][j];
            }
        for (int k = 1; k <= M; ++k) {
            if (col[k] < X) return;
        }
        total = 0;
        for (int j = 1; j <= kk; ++j) total += cost[b[j]];
        sum = min(sum, total);
        return;
    }
    for (int i = b[s - 1] + 1; i <= N; i++) {
        b[s] = i;
        dfs(s + 1);
    }
}

int main() {
    cin >> N >> M >> X;
    for (int i = 1; i <= N; i++) {
        cin >> cost[i];
        for (int j = 1; j <= M; ++j)
            cin >> a[i][j];
    }
    for (kk = 1; kk <= N; ++kk) {
        b[0] = 0;
        dfs(1);
    }
    if (sum == 1 << 29)
        cout << "-1" << endl;
    else cout << sum << endl;
    return 0;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
vector<vector<int>> p;
vector<bool> used;
vector<int> dep;
void dfs(int i, int d) {
  if (used[i])
    return;
  used[i] = true;
  dep[i] = d;
  for (auto &j : p[i])
    dfs(j, d + 1);
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  p.resize(n);
  used.resize(n);
  dep.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    p[a].push_back(b);
    p[b].push_back(a);
  }
  dfs(0, 0);
  int l = 0;
  for (int i = 0; i < n; i++)
    if (dep[l] < dep[i])
      l = i;
  for (int i = 0; i < n; i++)
    used[i] = false;
  dfs(l, 0);
  int maxd = 0;
  for (int i = 0; i < n; i++)
    maxd = max(maxd, dep[i]);
  if (maxd % 3 == 1) {
    cout << "Second" << endl;
  } else {
    cout << "First" << endl;
  }
  return 0;
}


Measured memory_bytes: 18304
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

#define keta setprecision(10) //10桁表示


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n, m;
	cin >> n >> m;
	string s;
	cin >> s;
	reverse(s.begin(), s.end());
	vector<ll> ans;
	ll tmp = 0;
	ll iti = 0;
	ll sum = 0;
	for (int i = 1; i <= n; i++)
	{
		if (ans.size() == iti)
		{
			ans.push_back(0);
		}
		if (s[i] == '0' && tmp<=m)
		{
			tmp++;
			if (ans.size() == iti)
			{
				ans.push_back(tmp);
			}
			ans[iti] = tmp;
		}
		else if (s[i] == '1')
		{
			tmp++;
		}
		if (ans[iti] == 0 && tmp==m)
		{
			cout << -1 << endl;
			ret;
		}
		if (tmp == m)
		{
			sum += ans[iti];
			i = sum;
			tmp = 0;
			iti++;
		}
	}
	reverse(ans.begin(), ans.end());
	for (int i = 0; i < ans.size() - 1; i++)
	{
		cout << ans[i] << " ";
	}
	cout << ans[ans.size() - 1] << endl;
	return 0;
}

Measured memory_bytes: 1480
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>

int main() {
    std::string s;
    int x, y, ptr = 0;
    std::cin >> s >> x >> y;
    std::vector<std::vector<int>> v(2, std::vector<int>(s.size(), 0));

    for (auto c : s) {
        if (c == 'F') v[ptr % 2][ptr / 2]++;
        else ptr++;
    }

    int targetx = std::accumulate(v[0].begin() + 1, v[0].begin() + ptr / 2 + 1, 0) - (x - v[0][0]);
    int targety = std::accumulate(v[1].begin(), v[1].begin() + ptr / 2 + 1, 0) - y;

    if (targetx < 0 || targety < 0) {
        std::cout << "No" << std::endl;
        return 0;
    }

    v[0].erase(v[0].begin());

    std::vector<std::vector<bool>> dpx(ptr / 2 + 1, std::vector<bool>(targetx + 1, false));
    dpx[0][0] = true;
    if (targetx >= 2*v[0][0]) dpx[0][2*v[0][0]] = true;
    for (int i = 1; i < ptr / 2 + 1; i++) {
        for (int j = 0; j <= targetx; j++) {
            if (j >= 2*v[0][i]) dpx[i][j] = dpx[i - 1][j - 2*v[0][i]] || dpx[i - 1][j];
            else dpx[i][j] = dpx[i - 1][j];
        }
    }

    std::vector<std::vector<bool>> dpy(ptr / 2 + 1, std::vector<bool>(targety + 1, false));
    dpy[0][0] = true;
    if (targety >= 2*v[1][0]) dpy[0][2*v[1][0]] = true;
    for (int i = 1; i < ptr / 2 + 1; i++) {
        for (int j = 0; j <= targety; j++) {
            if (j >= 2*v[1][i]) dpy[i][j] = dpy[i - 1][j - 2*v[1][i]] || dpy[i - 1][j];
            else dpy[i][j] = dpy[i - 1][j];
        }
    }

    std::cout << (dpx[ptr / 2][targetx] && dpy[ptr / 2][targety] ? "Yes" : "No") << std::endl;

    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ph push
#define ptc putchar
#define enter putchar('\n')
#define mod 998244353
using namespace std;
typedef pair<int,int> pii;
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef long long lnt;
inline int read(){
	int x = 0;char c = getchar();
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) x = (x << 1) + (x << 3) + c - '0' , c = getchar();
	return x;
}
inline void write(int x){
	if (!x){
       ptc('0');
       return;
	}
	int dg[20] , len = 0;
	while (x) dg[len++] = x % 10 , x /= 10;
	while (len--) ptc(dg[len]+'0');
}
inline void writeln(int x){
	write(x);
	ptc('\n');
}
inline int add(int x,int y){
	x += y;if (x >= mod) x -= mod;
	return x;
}
inline int sub(int x,int y){
	x -= y;if (x < 0) x += mod;
	return x;
}
inline int qpow(int x,int y){
	int res = 1;
	while (y){
		if (y & 1) res = 1ll * res * x % mod;
		x = 1ll * x * x % mod;y >>= 1;
	}
	return res;
}
const int N = 1e5 + 10;
struct Edge{
	int to , nex;
}e[N << 1];int head[N] , ecnt;

void adde(int fr,int to){
	e[++ecnt] = (Edge) {to , head[fr]};
	head[fr] = ecnt;
}

void addedge(int fr,int to){
	adde(fr , to);
	adde(to , fr);
}

bool vis[N];

int dep[N] , mxdep[N] , cnt[N] , mxbrunch[N];
void dfs(int x){
	vis[x] = 1;
	cnt[mxdep[x] = dep[x]]++;
	
	int d = 0;
	for (int j = head[x] ; j ; j = e[j].nex) {
		if (!vis[e[j].to]) {
			dep[e[j].to] = dep[x] + 1;
			dfs(e[j].to);
			mxdep[x] = max(mxdep[x] , mxdep[e[j].to]);
			d++;
		}
	}
	mxbrunch[dep[x]] = max(mxbrunch[dep[x]] , d);
}

int n , colorness;
lnt leastleaves;

int main(){
	cin >> n;
	for (int i = 1;i < n;i++){
		int u , v;scanf("%d%d",&u,&v);
		addedge(u , v);	
	}
	
	if (n == 1) return puts("1 1") , 0;
	if (n == 2) return puts("1 2") , 0;
	colorness = n;
	leastleaves = 0x3f3f3f3f3f3f3f3f;
	
	for (int i = 1;i <= n;i++){
		memset(vis , 0 , sizeof (int) * (n + 1));
		memset(cnt , 0 , sizeof (int) * (n + 1));
		memset(mxbrunch , 0 , sizeof (int) * (n + 1));
		dep[i] = 0;
		vis[i] = 1;
		dfs(i);
		
		int mxd = mxdep[i];
		if (mxd + 1 <= colorness){
			lnt H = 1;
			for (int j = 0;j < mxd;j++){
				H = H * mxbrunch[j];
			}
			
			if (colorness > mxd + 1){
				colorness = mxd + 1;
				leastleaves = H;
			}else{
				leastleaves = min(leastleaves , H);
			
			}
		}
		
	}
	
	
	for (int i = 1;i <= ecnt;i += 2){
		memset(vis , 0 , sizeof (int) * (n + 1));
		memset(cnt , 0 , sizeof (int) * (n + 1));
		memset(mxbrunch , 0 , sizeof (int) * (n + 1));
		int u = e[i].to , v = e[i + 1].to;
		
		dep[u] = dep[v] = 0;
		vis[u] = vis[v] = 1;
		dfs(u);dfs(v);
		
		int mxd = max(mxdep[u] , mxdep[v]);
		if (mxd + 1 <= colorness){
			
			mxbrunch[0] *= 2;
			
			lnt H = 1;
			for (int j = 0;j < mxd;j++){
				H = H * mxbrunch[j];
			}
			
//			printf("[%d %d] %lld %d %d\n",u,v,H,mxd + 1 , cnt[mxd]);
			
			if (colorness > mxd + 1){
				
				colorness = mxd + 1;
				leastleaves = H;
			}else{
//				printf("__ %d %lld\n",colorness,H);
				leastleaves = min(leastleaves , H);
			}
		}
		
	}
	
	printf("%d %lld\n",colorness , leastleaves);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;++i)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;

int main(){
    int h,w,d;cin>>h>>w>>d;
    map <int,P> a;
    int b;
    fol(i,h){
        fol(j,w){
            cin>>b;
            a[b] = P(i+1,j+1);
        }
    }
    int c[h*w+1];
    fol(i,d+1){
        c[i]=0;
    }
    P p1,p2;
    for(int i=1;i<=d;i++){
        int x=i;
        while(x+d<=h*w){
            p1 = a[x];
            p2 = a[x+d];
            c[x+d]= c[x] + abs(p1.first-p2.first)+abs(p1.second-p2.second);
            x += d;
        }
    }
    int q;cin>>q;
    int l,r,ans=0;
    fol(i,q){
        cin>>l>>r;
        ans = c[r]-c[l];
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 7040
suits = ["S", "H", "C", "D"]
card = {}
for s in suits:
    card[s] = list(range(1,14))


N = int(input())
for n in range(N):
    suit, rank = input().split()
    card[suit][int(rank) - 1] = 0

for s in card:
    for r in card[s]:
        if r != 0:
         print("{} {}".format(s, r))


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

using namespace std;

const int N = 1e5 + 7;
int n;

int main()
{

        ios_base::sync_with_stdio(0);
        cin.tie(0);
        //freopen("in.in", "r", stdin);

        long long d ; 
        cin >> n >> d; 
        int ans = 0 ; 
        for(int i=  0 ; i < n;i++){
                long long x ,y ; 
                cin >> x >> y ; 
                ans+= (x * x + y * y <= d * d) ; 
        }
        cout<< ans ;

        return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
long long int max(long long int n, long long int tmp[], long long int *num, long long int *M) {
	long long int max_memo = tmp[0];
	long long int max_num = 0;
	for (int i = 1; i < n; i++) {
		if (max_memo < tmp[i]) {
			max_memo = tmp[i];
			max_num = i;
		}
	}
	*num = max_num;
	*M = max_memo;
	return 0;
}
int main() {
	long long int n;
	long long int num, m;
	int result = 0;
	long long int s[10];
	scanf("%lld", &n);
	for (int i = 0; i < n; i++){
		scanf("%lld", &s[i]);
		result += s[i];
	}
	max(n, s, &num, &m);
	printf("%d",result - (m / 2));
}


Measured memory_bytes: 128
#include <bits/stdc++.h> //C++の機能を「全て」読み込むための命令
#define rep(i,n) for(int i=0; i<(n); ++i)
#define cout(x) cout<<x<<endl
#define all(v) v.begin(), v.end()
using namespace std;
//型エイリアス
using vi = vector<int>;
using ll = long long;
using P = pair<int,int>;
using Mat = vector<vector<int>>;
const ll inf = 1e18;
const int N = 2e5+10;


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

    ll l_0,l_1;
    rep(i,n){
        if(i==0) l_0 = 2,l_1 = 1;
        else{
            ll d = l_1;
            l_1 = l_0 + l_1;
            l_0 = d;
        }
    }
    cout(l_1);
    return 0;
}

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

bool prime(int n)
{
	for(int i=2;i*i<=n;++i)
	{
		if(n%i==0)
			return false;
	}
	return true;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int x;
    cin>>x;
    int ans=-1;
    for(int i=x;;++i)
    {
    	if(prime(i))
    	{
    		ans=i;
    		break;
    	}
    }
    cout<<ans<<endl;


}


Measured memory_bytes: 256
import numpy as np
from collections import defaultdict
import heapq
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=1<<18

from numba import njit, b1, i4, i8, f8
@njit((i8,i8,i8), cache=True)
# @njit(cache=True)
def pos(W,h,w):
    return h * W + w

@njit((i8,i8,i8,i8,i8,i8,b1[:]), cache=True)
# @njit(cache=True)
def main(H,W,Ch,Cw,Dh,Dw,G):
    Ch-=1
    Cw-=1
    Dh-=1
    Dw-=1

    s = (Ch,Cw)
    t = (Dh,Dw)

    hq = [(0,s)]
    heapq.heapify(hq)
    
    dist = [INF] *(H*W) # sからxでの最短距離
    dist[pos(W,*s)] = 0
    while hq: 
        d,x = heapq.heappop(hq) # sからxまでの最短経路を探索する
        if dist[pos(W,*x)] < d: continue

        h,w = x
        normal = set([(h-1,w),(h+1,w),(h,w+1),(h,w-1)])
        for dh in range(-2,3):
            for dw in range(-2,3):
                new_h,new_w = h+dh,w+dw
                e = (new_h,new_w)
                cost = 1

                if dh == 0 and dw == 0: continue
                if not (0<=new_h<H and 0<=new_w<W): continue
                if G[pos(W,*e)] == 1:  continue
                if e in normal:
                    cost -= 1
                
                if dist[pos(W,*e)] > dist[pos(W,*x)] + cost:
                    dist[pos(W,*e)] = dist[pos(W,*x)] + cost
                    heapq.heappush(hq,(dist[pos(W,*e)],e))

    # print(dist)
    if dist[pos(W,*t)] == INF: 
        dist[pos(W,*t)] = -1
        
    return dist[pos(W,*t)]


if __name__ == "__main__":
    H,W=mi()
    Ch,Cw=mi()
    Dh,Dw=mi()

    G = [0] * H*W
    for i in range(H):
        g = []
        for j,s in enumerate(list(input())):
            G[i*W+j] = s == "#"

    ans = main(H,W,Ch,Cw,Dh,Dw,np.array(G))
    print(ans)



Measured memory_bytes: 123540
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

int main() {
	int n, m;
	cin >> n >> m;
	vector<ll> a(n);
	rep (i, n) cin >> a[i];
	vector<pair<ll, ll>> cb(m);
	rep (i, m) cin >> cb[i].se >> cb[i].fi;

	sort(rrng(cb));
	sort(rng(a));

	vector<ll> use;
	bool stop = false;
	rep (i, m) {
		if (stop) break;
		rep (j, cb[i].se) {
			if (stop) break;
			if (use.size() >= n) {
				stop = true;
			}
			use.pb(cb[i].fi);
		}
	}

	sort(rrng(use));
	ll ans = 0;
	rep (k, n) {
		ans += max(a[k], (use.size() > k ? use[k] : 0LL));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3704
import sys
import itertools
# import numpy as np
import time
import math
import heapq
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10 ** 9 + 7

# map(int, input().split())
# list(map(int, input().split()))

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

negs = 0
abs_min = INF
total = 0
for a in A:
    if a < 0:
        negs += 1
    abs_min = min(abs_min, abs(a))
    total += abs(a)

if negs % 2 == 0:
    print(total)
else:
    print(total - abs_min * 2)

Measured memory_bytes: 20484
package main

import (
	"bufio"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	iv, _ := strconv.Atoi(readStr())
	return iv
}

func readStr() string {
	sc.Scan()
	return sc.Text()
}

type poll struct {
	s string
	c int
}
type polls []poll

func (p polls) Len() int           { return len(p) }
func (p polls) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
func (p polls) Less(i, j int) bool { return p[i].c > p[j].c }

func main() {
	n := readInt()
	m := make(map[string]int)
	for i := 0; i < n; i++ {
		s := readStr()
		m[s]++
	}

	ps := polls(make([]poll, 0, len(m)))
	for s, c := range m {
		ps = append(ps, poll{s, c})
	}
	sort.Sort(ps)

	ans := make([]string, 0, len(m))
	pmx := ps[0]
	ans = append(ans, pmx.s)
	for _, p := range ps[1:] {
		if p.c != pmx.c {
			break
		}
		ans = append(ans, p.s)
	}
	sort.Strings(ans)

	var wr = bufio.NewWriter(os.Stdout)
	for _, s := range ans {
		wr.WriteString(s + "\n")
	}
	wr.Flush()
}


Measured memory_bytes: 23808
#include<bits/stdc++.h>
#define int long long
#define loop(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1000000007;
const int INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
using vc = vector <char>;
using vvc = vector <vc>;
using vs = vector <string>;
using vvs = vector <vs>;
//g++ -std==c++14
//setprecision(10)
 
signed main(){
    char c[6];
    rep(i, 6)cin >> c[i];
    cout << (c[0] == c[5] && c[2] == c[3] && c[1] == c[4]? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int X;
	cin >> X;
	if (X == 3 || X == 5 || X == 7) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a,b,c,d,A,B,C,D,all,ALL;
    scanf("%d %d %d %d %d %d %d %d",&a,&b,&c,&d,&A,&B,&C,&D);
    all=a+b+c+d;
    ALL=A+B+C+D;
    if(all<ALL)printf("%d\n",ALL);
    if(ALL<all)printf("%d\n",all);
    if(all==ALL)printf("%d\n",all);

return 0;
}

Measured memory_bytes: 592
import java.util.Scanner;

class Main{
    public static void main(String[] a){
        Scanner scan = new Scanner(System.in);
        int[] data = new int[3];
        int tmp;
        for(int i=0;i<10;i++){
            tmp=scan.nextInt();
            for(int j=0;j<3;j++){
                if(data[j]<=tmp){
                    for(int k=2;k>j;k--){
                        data[k]=data[k-1];
                    }
                    data[j]=tmp;
                    break;
                }
            }
        }
        for(int i=0;i<3;i++){
            System.out.println(data[i]);
        }
    }
}

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


int main() {

  int n;
  cin >> n;

  vector<int> a(n);
  int mx = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mx = max(mx, a[i]); 
  }

  int v;
  double d = mx;

  if (a.size() == 2) {
    if (a[0] < a[1]) {
      cout << a[1] << " " << a[0] << endl;
    } else {
      cout << a[0] << " " << a[1] << endl;
    }
    return 0;
  }

  for (int i = 0; i < n; i++) {
    double d_ = abs((double) (mx / 2) - a[i]);
    if (d_ < d) {
      d = d_;
      v = a[i];
    }
  }
  
  cout << mx << " " << v << endl;
  
  return 0;
}

Measured memory_bytes: 640
using System;
class At_CF
{
    static void Main(string[] args)
    {
        String answer = System.Text.RegularExpressions.Regex.IsMatch(Console.ReadLine(), "C.*F", System.Text.RegularExpressions.RegexOptions.IgnoreCase) ? "Yes":"No";
        Console.Write(answer);
    }
}

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

using namespace std;

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

    for (int i = 0; i < b; ++i) {
        if ((a * (i + 1)) % b == c) {
            cout << "YES" << "\n";
            return 0;
        }
    }
    cout << "NO" << "\n";
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}"<<endl;
  return o;
}



int main() {
  int X,Y;
  cin >> X >> Y;
  rep(i,100) {
    rep(j,100) {
      if (i+j==X&&2*i+4*j==Y) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cmath>

int main()
{
    int N, D;
    int yes = 0;
    std::cin >> N;
    std::cin >> D;

    for (int i=0; i<N; i++) {
        int64_t x, y;
        std::cin >> x;
        std::cin >> y;
        if (std::sqrt(x * x + y * y) <= D) yes++;
    }

    std::cout << yes << std::endl;
    
    return 0;
}

Measured memory_bytes: 3192
N, K = map(int, input().split())
S = list(input())

c = 0
p = 0
for i, s in enumerate(S):
    if i == 0:
        pres = s
        continue
    elif s != pres:
        c += 1
    else:
        p += 1
    pres = s

if c == 0 or c == 1 or c <= 2*K:
    ans = N-1
else:
    ans = p+2*K
print(ans)

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    for(int i=1 ; i<=9 ; ++i)
    {
        if(n%i==0)
        {
            if(n/i<=9 && n/i>=1)
            {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

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

int N;
int store[100007];

int main()
{
    cin >> N;
    for (int i = 0; i < N; i++) scanf("%d", &store[i]);

    int cnt = 0;
    int ans = 0;
    for (int i = N-1; i >= 1; i--) {
        if (store[i-1] >= store[i]) cnt++;
        else {
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    ans = max(ans, cnt);

    cout << ans << endl;
}


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

int main( int argc, char *argv[] )
{
char X;
char Y;

	cin >> X;
	cin >> Y;
	if( X == Y )
		cout << "=" << endl;
	else if( X < Y )
		cout << "<" << endl;
	else
		cout << ">" << endl;

	return 0;
}




Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner inputs = new Scanner(System.in);
		int len = inputs.nextInt();
		int[] vals = new int[len];
		for(int i = 0;i<len;i++) {
			vals[i] = inputs.nextInt();
		}
		int[] stones = new int[len];
		stones[0] = 0;
		stones[1] = Math.abs(vals[0]-vals[1]);
		for(int i=2;i<len;i++) {
			stones[i] = Math.min(Math.abs(vals[i-1]-vals[i])+stones[i-1], Math.abs(vals[i-2] - vals[i])+stones[i-2]);
		}
		System.out.println(stones[len-1]);
	}

}


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

namespace AtCoder.Contest.E
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			Scanner cin = new Scanner();

			int n = cin.NextInt();
			var a = cin.ArrayLong(n);
			long sum = a.Sum();
			bool ok = true;
			if ((sum % ((long)n * (n + 1) / 2)) == 0)
			{
				long k = sum / ((long)n * (n + 1) / 2);
				var diff = new List<long>();
				var sousa = new List<long>();
				for (int i = 0; i < n; i++)
				{
					diff.Add(0);
					sousa.Add(0);
				}
				for (int i = 0; i < n; i++)
				{
					if (i == 0)
					{
						diff[0] = a[0] - a[n - 1];
					}
					else
					{
						diff[i] = a[i] - a[i - 1];
					}
				}
				long ss = 0;
				for (int i = 0; i < n; i++)
				{
					if (((k - diff[i]) % n) != 0) ok = false;
					else
					{
						sousa[i] = (k - diff[i]) / n;
						ss += sousa[i];
						if (sousa[i] < 0) ok = false;
					}
				}
				if (k != ss) ok = false;
			}
			else ok = false;
			if (ok) Console.WriteLine("YES");
			else Console.WriteLine("NO");

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

int N, a[200005];
int dp[200005], ans[200005];
vector<int> adj[200005];

void rec(int v, int p) {
    int i = lower_bound(dp, dp+N, a[v]) - dp;
    int prev = dp[i];

    // 更新
    dp[i] = a[v];
    ans[v] = max(ans[p], i+1);

    // 子へ
    for (int u : adj[v]) if (u != p) rec(u, v);

    // 戻す
    dp[i] = prev;
}

int main() {
    cin >> N;
    for_(i,0,N) cin >> a[i];
    for_(i,0,N-1) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }    

    for_(i,0,N+1) dp[i] = 1L << 30;
    ans[N] = 0;
    rec(0, N);
    for_(i,0,N) cout << ans[i] << endl;
}

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

int N,K;
int DP[100001],A[101];

int solve(int stone){
	if(DP[stone]>=0){
		return DP[stone];
	}
	int ret=0;
	for(int i=0;i<N;i++){
		if(stone-A[i]>=0) ret|=!(solve(stone-A[i]));
	}
	
	return DP[stone]=ret;
}

void reset(){
	for(int i=0;i<100001;i++) DP[i]=-1;
	DP[0]=0;
}

int main(){
	cin>>N>>K;
	reset();
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	if(solve(K)){
		cout<<"First"<<"\n";
	}else{
		cout<<"Second\n";
	}
	return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int n; cin >> n;
    cout << n * n * n << "\n";
}


Measured memory_bytes: 256
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
S = sr()
# マスNからスタート
cur = N
answer = []
while cur > 0:
    for x in range(M, 0, -1):
        if cur - x < 0 or S[cur - x] == '1':
            continue
        answer.append(x)
        cur -= x
        break
    else:
        print(-1)
        exit()

answer = answer[::-1]
print(*answer)
# 53

Measured memory_bytes: 6372
import Data.Traversable
import Data.List

main :: IO ()
main = do
  (n:k:xs) <- ((map read) . words) <$> getLine
  ps <- for [1..n] $ \x ->
    read <$> getLine
  putStrLn . show $ solve k ps

solve :: Int -> [Int] -> Int
solve k xs =
  let sorted = sort xs
  in minimum $ map (\(a,b) -> b - a) $ zip sorted (drop (k-1) sorted)

Measured memory_bytes: 67964
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

int main() {
  string s;
  ll q;
  deque<string> ans;
  cin >> s >> q;
  for (size_t i = 0; i < s.size(); ++i) ans.push_back(s.substr(i, 1));

  bool ord = true;
  rep(i, q) {
    ll t;
    cin >> t;
    if (t == 1) {
      ord = !ord;
    } else {
      ll f;
      cin >> f;
      if (!ord) {
        if (f == 1)
          f = 2;
        else
          f = 1;
      }
      string c;
      cin >> c;
      if (f == 1)
        ans.push_front(c);
      else
        ans.push_back(c);
    }
  }  // i

  if (!ord) Reverse(ans);
  for (auto& c : ans) {
    cout << c;
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 17152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  int n,m,x,y;
  cin >> n >> m >> x >> y;
  vector<int> xs(n+1), ys(m+1);
  xs[0] = x;
  ys[0] = y;
  rep(i,n) cin >> xs[i+1];
  rep(i,m) cin >> ys[i+1];
  sort(all(xs));
  sort(all(ys));
  cout << (xs[n] < ys[0] ? "No War" : "War") << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define FAST ios_base::sync_with_stdio(false);cin.tie(0);
    const double EPS = 1e-9;
    const double PI = acos(-1);
    const int knightDir[8][2] = {{-2,-1},{-2,1},{-1,2},{1,2},{2,-1},{2,1},{-1,-2},{1,-2}};
    //const int dx[]={0,0,0,1,1,1,-1,-1,-1};
    //const int dy[]={-1,0,1,-1,0,1,-1,0,1};
    const int dx[] = {0 , 1 , 0 , -1};
    const int dy[] = {1 , 0 , -1 , 0};
    //#define MOD         1000000007LL
    #define MAX         1000005
    const ll MOD = 1000000000 + 7;
    
    int main()
    {
        FAST
        int t;
        t = 1;

        while(t--)
        {
           ll x , k , d;
           
           cin >> x >> k >> d;
           
           x = abs(x);
           ll steps = x / d;
           
           ll l = abs(0 - (x - (steps * d)));
           ll r = abs(0 - (x - ((steps + 1) * d)));
           
           if(steps >= k)
           {
               cout << abs(0 - (x - (k * d))) << endl;
           }
           else
           {
               if((k - steps) % 2 == 0)cout << l << endl;
               else cout << r << endl;
           }
        }
    }



Measured memory_bytes: 3652
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		String s = sc.next();
		long max = 0;
		for (int i = 1; i < n - 1; i++) {
			Set<Character> x = new HashSet<>();
			Set<Character> y = new HashSet<>();
			for (int j = 0; j < i; j++) {
				x.add(s.charAt(j));
			}
			for (int j = i; j < n; j++) {
				y.add(s.charAt(j));
			}
			long count = x.stream().filter(c -> !y.add(c)).count();
			if (count > max) {
				max = count;
			}
		}

		System.out.println(max);

		sc.close();
	}
}


Measured memory_bytes: 30804