akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>

int CalculateGreatestCommonFactor(int a,int b){
	int small,large;
	if(a<b){
		small=a;
		large=b;
	} else{
		small=b;
		large=a;
	}
	//ユークリッドの互除法を行う
	while(true){
		const int remainder=large%small;
		if(remainder==0){
			//あまりが0ならsmallが最大公約数
			break;
		} else{
			//あまりが0でないなら、次のループではsmallとremainderの最大公約数を求める
			large=small;
			small=remainder;
		}
	}
	return small;
}

int main(){
	//入力機構
	size_t N;
	int X;
	std::cin>>N>>X;
	std::vector<int> x(N,0);//|x[i]|<10^9なのでintで表現できる
	for(size_t i=0;i<N;i++){
		std::cin>>x[i];
	}

	//処理機構
	int ans;
	//x[0],x[1],...,x[N-1]それぞれについて、Xとの差の絶対値を求めて、最大公約数を求める
	//ユークリッドの互除法はO(log x)、その個数がNなのでO(Nlogx)。なんとかなるかな？
	ans=std::abs(x[0]-X);//ansはx[0]-Xで初期化。答えはこれより必ず小さくなる。
	for(size_t i=0;i+1<N;i++){
		//X[1],X[2],...,X[N-1]について最大公約数を求めて更新
		//最大公約数の性質より、ansに次々と格納していってそれを利用すればよい
		ans=CalculateGreatestCommonFactor(std::abs(x[i+1]-X),ans);
	}

	//出力機構
	std::cout<<ans<<std::endl;

	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(){
   int data[5];
   scanf("%d%d%d%d%d",&data[0],&data[1],&data[2],&data[3],&data[4]);

   for(int i=0;i<5;i++){
      if(data[i]==0){
         printf("%d",i+1);
      }
   }
   return 0;
}

Measured memory_bytes: 1688
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn = 2e5 + 5;
const ll mod = 1e9 + 7;
ll n, k;
ll a[maxn], sum[maxn];
int main(){
	ll ans = 0, ant = 0;
	sum[1] = 0;
	for(ll i = 2; i <= 2e5 + 5; i++){
		sum[i] = sum[i - 1] + i - 1;
	}
	scanf("%lld%lld", &n, &k);
	for(ll i = k; i <= n + 1; i++){
		ant = (sum[n + 1] - sum[n + 1 - i]) - (sum[i] - sum[0]) + 1;
		ans += ant;
		ans = ans % mod;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 5392
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define mod 1000000007
#define MOD 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 2e9

vector<vector<int> >v;  
vector<int>c;
vector<string>books;
int n,m,kn;

string dtob(int num,int rlen)
{
    string r="";
    while(num>0)
    {
        r=to_string(num%2)+r;
        num/=2;
    }
    int rem=rlen-r.length();
    string t(rem,'0');
    return t+r;
}

int func(string s)
{
    vector<int>u(m,0);
    int cost=0;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='1')
        {
            cost+=c[i];
            for(int j=0;j<m;j++)
                u[j]+=v[i][j];
        }
    }
    for(int i=0;i<m;i++)
    {
        if(u[i]<kn)
            return -1;
    }
    return cost;
}

int main()
{
    cin >> n >> m >> kn;
    v.resize(n);
    c.resize(n);
    for(int i=0;i<n;i++)
    {
        cin >> c[i];
        for(int j=0;j<m;j++)
        {
            int x;
            cin >> x;
            v[i].push_back(x);
        }
    }
    for(int i=1;i<=pow(2,n)-1;i++)
        books.push_back(dtob(i,n));
    int ans=1e9;
    for(int i=0;i<books.size();i++)
    {
        int t=func(books[i]);
        if(t!=-1)
            ans=min(ans,t);
    }
    if(ans!=1e9)
        cout << ans << endl;
    else
        cout << "-1" << endl;
}

Measured memory_bytes: 4300
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', v => {
    var tmp = Number(v.split("\n")[0]);
    if(tmp % 1 === 0 && 0<tmp<100 && tmp % 2 !== 0 ) {
        console.log((tmp + 1) / 2);
    }
    else if(tmp % 2 === 0 && 0<tmp<100 && tmp % 2 === 0) {
        console.log(tmp / 2);
    } else {
        console.log();
    }
});

Measured memory_bytes: 21192
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
int main(){
    int i,j,length,index=0;
    char t[200020]={};
    scanf("%s",t);
    length=strlen(t);
    for(i=0; i<length; i++){
        if (t[i]=='?')t[i]='D';
    }
    printf("%s",t);
    return 0;
}

Measured memory_bytes: 1920
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll gcd(ll p,ll q){while(q){ll t=p%q;p=q;q=t;}return p;}
int main(){
	ll a,b;
	scanf("%lld%lld",&a,&b);
	printf("%lld",a*b/gcd(a,b));
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

const int mod = 1e9 + 7;
const int mod2 = 998244353;

void fact_init(int n);
ll exp(ll taban, ll us, ll md);
ll ebob(ll a, ll b);
ll ekok(ll a, ll b);
ll komb(ll a, ll b);

vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n){
    fact.resize(n+5);
    inv_fact.resize(n+5);
    fact[0] = inv_fact[0] = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = (fact[i-1] * i) % mod;
        inv_fact[i] = exp(fact[i], mod-2, mod);
    }
}
ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
    if(carpan == 0) return 0;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

ll komb(ll a, ll b){
    if(a < b) return 0;
    return fact[a] * (inv_fact[a-b] * inv_fact[b] % mod) % mod;
}

const int N = 2e5 + 5;

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
	ll k; cin>>k;
	bool seen[k] = {};
	bool check = false;
	ll res = 0;
	ll cnt = 0;
	ll carp = 1;
	while(1){
		res = (res + carp * 7) % k;
		carp = carp * 10 % k;
		cnt++;
		if(res == 0) break;
		if(cnt > 1e8){
			check = true;
			break;
		}
		seen[carp] = true;
	}
	if(check){
		cout<<-1;
	}else cout<<cnt;
}

Measured memory_bytes: 4580
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
bool square[1000005];
int main(){
    for(ll i=0;i*i<1000005;i++){
        square[i*i]=true;
    }
    string a,b;
    cin>>a>>b;
    a.append(b);
    ll num =0;
    for(ll i=0;i<a.size();i++){
        num = num*10+a[i] - '0';
    }
    if(square[num]){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
    
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

typedef pair<int,int> P;

// グラフ
vector<int> G[21], rG[21];
// memo[v] := 頂点 v を調べたかどうか
bool memo[21] = {false};
// 出次数 0 の頂点(部屋に入ったのが遅い人)
vector<int> leaf;
// d[v] := 出次数 0 の頂点からの距離の最大値
int d[21] = {0};

// 出次数 0 の頂点を列挙する
void dfs(int v){
	if( memo[v] ) return;
	memo[v] = true;
	
	if( G[v].size() == 0 ){
		leaf.push_back(v);
	}else{
		for(int i = 0; i < G[v].size(); i++){
			dfs( G[v][i] );
		}
	}
}

// 出自数 0 の頂点からたどる
void solve(int v, int cost){
	for(int i = 0; i < rG[v].size(); i++){
		int to = rG[v][i];
		if( d[to] < cost + 1 ){
			d[to] = cost + 1;
			solve(to, cost + 1);
		}
	}
}

int main(){
	int n, m;
	cin >> m >> n;
	for(int i = 0; i < n; i++){
		int x, y;
		cin >> x >> y;
		G[x].push_back(y);
		rG[y].push_back(x);
	}
	
	for(int v = 1 ; v <= m; v++){
		dfs(v);
	}
	fill(memo, memo + 21, false);
	for(int i = 0; i < leaf.size(); i++){
		solve(leaf[i], 0);
	}
	
	vector<P> ans;
	for(int i = 1; i <= m; i++){
		ans.push_back( P(d[i], i) );
	}
	sort(ans.rbegin(), ans.rend());
	for(int i = 0; i < ans.size(); i++){
		cout << ans[i].second << endl;
	}
}

Measured memory_bytes: 1220
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ii> P;
typedef unsigned long long int ull;
const int MOD=1e9+7;
int dy[]={1,0};
int dx[]={0,1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e18;

int h,w;
vector<vector<char> > G(100,vector<char>(100));
vector<vector<ll> > d(100,vector<ll>(100,INF));

ll dijkstra(){
    priority_queue<P,vector<P>,greater<P> > que;
    que.push(P(0,ii(0,0)));
    d[0][0]=1;
    while(!que.empty()){
        P p=que.top();que.pop();
        ll cst=p.first;
        int y=p.second.first;
        int x=p.second.second;
        if(d[y][x]<cst) continue;
        for(int i=0;i<2;i++){
            int ny=y+dy[i];
            int nx=x+dx[i];
            if(ny>=0&&ny<h&&nx>=0&&nx<w&&d[ny][nx]>d[y][x]+(G[y][x]==G[ny][nx]?0:1)){
                d[ny][nx]=d[y][x]+(G[y][x]==G[ny][nx]?0:1);
                que.push(P(d[ny][nx],ii(ny,nx)));
            }
        }
    }
    return d[h-1][w-1];
}
int main(){
    cin>>h>>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>G[i][j];
        }
    }
    ll ans=dijkstra()/2+((G[0][0]=='#'&&G[h-1][w-1]=='#')?1:0);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3736
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define get0(x)     (get<0>(x))
#define get1(x)     (get<1>(x))
#define get2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       9223372036854775807LL
#define LLMIN       -9223372036854775808LL
#define IMAX        2147483647
#define IMIN        -2147483648
typedef long long LL;
using namespace std;

LL N,L;
LL A[100000];

int main(void){
    cin>>N>>L;
    REP(i,N)
        cin>>A[i];
    REP(i,N-1)
        if(A[i]+A[i+1]>=L){
            cout<<"Possible"<<endl;
            REP(j,i)
                cout<<j+1<<endl;
            for(int j=N-2;i<j;j--)
                cout<<j+1<<endl;
            cout<<i+1<<endl;
            return 0;
        }
    cout<<"Impossible"<<endl;
     return 0;
}

Measured memory_bytes: 1536
import copy
def main():
    n, a, b, c, d = map(int, input().split())
    step = list(input())

    sn = a - 1
    fn = b - 1

    sn_goal = False
    fn_goal = False
    jump = -1
    
    while True:
        if d < c:
                if (step[fn - 1] == ".") and (step[fn + 1] == "."):
                    jump = copy.deepcopy(fn)
                    
        if fn == d - 1:
            fn_goal = True
            break

        if step[fn + 1] == ".":
            fn += 1
        elif step[fn + 2] == ".":
            fn += 2
        else:
            break

       

    if d < c:
        if jump == -1:
            print("No")
            exit()

        step[jump] = "#"

    while True:
        if sn == c - 1:
            sn_goal = True
            break

        if step[sn + 1] == ".":
            sn += 1
        elif step[sn + 2] == ".":
            sn += 2
        else:
            break
    
    if sn_goal and fn_goal:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 10820
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,v,p,s,mx,c,r,b,a[100005];
signed main()
{
	scanf("%lld%lld%lld%lld",&n,&m,&v,&p);
	for(int i=1;i<=n;i++) scanf("%lld",a+i);
	sort(a+1,a+n+1),c=a[n-p+1],b=0,r=p,v=n-v,s=0,mx=0;
	for(int i=n;i>=1;i--) if(a[i]<c) break;else b++;
	for(int i=n-p;i>=1;i--)
	{
		s+=(a[i+1]-a[i])*(n-p+1-i);
		if(s<=min(n-p,v)*m&&a[n-p+1]-a[i]<=m) r++;else break;
	}
	return printf("%lld\n",r),0;
}


Measured memory_bytes: 4604
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	int n;

	while(scanf("%d\n", &n)==1)
	{
		int ab=0, b_front=0, a_back=0, bf_ab=0;
		for(int i=0;i<n;i++)
		{
			char s[10+2];
			scanf("%10s", s);

			int l=strlen(s);
			if(s[0]=='B') b_front++;
			if(s[l-1]=='A') a_back++;
			if(s[0]=='B' && s[l-1]=='A') bf_ab++;
			for(int j=1;j<l;j++)
			{
				if(s[j]=='B')
				{
					if(s[j-1]=='A') ab++;
				}
			}
		}
//		printf("ab=%d a_back=%d b_front=%d\n", ab, a_back, b_front);
		int ans=ab+min(a_back, b_front);
		if(bf_ab>0 && bf_ab==a_back && bf_ab==b_front) ans--;
		printf("%d\n", ans);
	}
	return 0;
}


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

void solve(long long N, std::vector<std::string> S) {
    ll m = 0, a = 0, r = 0, c = 0, h = 0;
    rep(i, N) {
        if (S[i][0] == 'M') {
            m++;
        } else if (S[i][0] == 'A') {
            a++;
        } else if (S[i][0] == 'R') {
            r++;
        } else if (S[i][0] == 'C') {
            c++;
        } else if (S[i][0] == 'H') {
            h++;
        }
    }
    cout << m * a * r + m * a * c + m * a * h + m * r * c + m * r * h + m * c * h + a * r * c + a * r * h + a * c * h +
                r * c * h
         << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<std::string> S(N);
    for (int i = 0; i < N; i++) {
        std::cin >> S[i];
    }
    solve(N, std::move(S));
    return 0;
}


Measured memory_bytes: 6428
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


class Info:
    def __init__(self,arg_id,arg_score):
        self.id = arg_id
        self.score = arg_score
        self.float_score = float(self.score)

    def __lt__(self,another):
        return self.float_score < another.float_score


rest = []

for loop in range(3):

    work = []

    for row in range(8):
        tmp_id,score = input().split()
        work.append(Info(int(tmp_id),score))

    work.sort()
    print("%d %s"%(work[0].id,work[0].score))
    print("%d %s"%(work[1].id,work[1].score))

    for row in range(2,len(work)):
        rest.append(work[row])

rest.sort()
print("%d %s"%(rest[0].id,rest[0].score))
print("%d %s"%(rest[1].id,rest[1].score))


Measured memory_bytes: 13892
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

template< typename T >
struct Compress {
  vector< T > xs;

  Compress() = default;

  Compress(const vector< T > &vs) {
    add(vs);
  }

  Compress(const initializer_list< vector< T > > &vs) {
    for(auto &p : vs) add(p);
  }

  void add(const vector< T > &vs) {
    copy(begin(vs), end(vs), back_inserter(xs));
  }

  void add(const T &x) {
    xs.emplace_back(x);
  }

  void build() {
    sort(begin(xs), end(xs));
    xs.erase(unique(begin(xs), end(xs)), end(xs));
  }

  vector< int > get(const vector< T > &vs) const {
    vector< int > ret;
    transform(begin(vs), end(vs), back_inserter(ret), [&](const T &x) {
      return lower_bound(begin(xs), end(xs), x) - begin(xs);
    });
    return ret;
  }

  int get(const T &x) const {
    return lower_bound(begin(xs), end(xs), x) - begin(xs);
  }

  const T &operator[](int k) const {
    return xs[k];
  }
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,Q; cin >> N >> Q;
    vector<pll> S(N),T(N),X(N);
    vector<ll> D(Q);
    rep(i,N) {
        cin >> S[i].first >> T[i].first >> X[i].first;
        S[i].second = T[i].second = X[i].second = i;
        S[i].first -= X[i].first;
        T[i].first -= X[i].first;
    }
    rep(i,Q) cin >> D[i];

    Compress<ll> com(D);
    rep(i,N) {
        com.add(S[i].first);
        com.add(T[i].first);
    }
    com.build();

    sort(all(S)); sort(all(T));
    int nowS = 0;
    int nowT = 0; 
    int nowD = 0;
    int M = com.xs.size();
    vector<ll> ans(Q,-1);
    set<pll> dic;
    rep(i,M) {
        while (nowT < N && com.get(T[nowT].first) == i) {
            dic.erase(X[T[nowT].second]);
            nowT++;
        }
        while (nowS < N && com.get(S[nowS].first) == i) {
            dic.emplace(X[S[nowS].second]);
            nowS++;
        }
        while (nowD < Q && com.get(D[nowD]) == i) {
            if (!dic.empty()) ans[nowD] = dic.begin()->first;
            nowD++;
        }
    }

    rep(i,Q) cout << ans[i] << endl;
} 


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, ma, mb;
  cin >> n >> ma >> mb;
  
  int dp[n + 1][401][401];
  for(int i = 0; i < n + 1; i++){
    for(int j = 0; j < 401; j++){
      for(int k = 0; k < 401; k++){
        dp[i][j][k] = 1e9;
        if(j == 0 && k == 0) dp[i][j][k] = 0;
      }
    }
  }
  
  int a, b, c;
  for(int i = 0; i < n; i++){
    cin >> a >> b >> c;
    for(int j = 0; j < 401; j++){
      for(int k = 0; k < 401; k++){
        if(dp[i][j][k] != 1e9){
          dp[i + 1][j + a][k + b] = min(dp[i + 1][j + a][k + b], dp[i][j][k] + c);
          dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
        }
      }
    }
  }
  
  int ans = 1e9;
  for(int i = 1; i < (int) 401 / max(ma, mb); i++){
    ans = min(ans, dp[n][ma * i][mb * i]);
  }
  
  if(ans == 1e9) cout << -1 << '\n';
  else cout << ans << '\n';
}

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

void warfl(vector<vector<int> > &dist, int n){
  for(int k=0; k<n; k++){
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
      }
    }
  }
  return;
}

int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<int> > C(10, vector<int>(10));
  for(int i=0; i<10; i++){
    for(int j=0; j<10; j++){
      cin >> C[i][j];
    }
  }
  warfl(C,10);
  int ans =0;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      int A; cin >> A;
      if(A!=-1) ans+=C[A][1];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;
using ll = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    int diff = 0;
    REP(i, n-1)  if (s[i] != s[i+1]) diff++;
    diff = max(diff-2*k, 0); // s内のdiffを消せるだけ消す
    cout << n-1-diff; // sの端のいずれかでdiffが必ず存在するから 最大でn-1 それからdiffを引くと答え
    return 0;
}

Measured memory_bytes: 512
import java.math.BigInteger;
import java.util.*;
public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		

		String s = sc.next();
		
		char[] cs = s.toCharArray();
		
		for(int i=1; i<cs.length ; i++ ) {
			if(cs[i-1] == cs[i]) {
				System.out.println("Bad");
				return;
			}
		}
		
		System.out.println("Good");

		
		
	}
	
}

Measured memory_bytes: 21844
# coding: utf-8
while 1:
    n,m=map(int,input().split())
    if n==0:
        break
    d=list(map(int,input().split()))
    mx=-1
    for i in range(n):
        for j in range(i+1,n):
            if d[i]+d[j]<=m:
                mx=max(d[i]+d[j],mx)
    print(mx if mx!=-1 else 'NONE')


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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<string>a(n);
  rep(i,0,n)cin>>a[i];
  vector<ll>t(n);
  rep(i,0,n)rep(j,0,n){
    if(a[i][j]=='#')t[j]=1;
  }

  rep(j,0,n){
    judge=true;
    rep(i,0,n)if(a[i][j]=='.')judge=false;
    if(judge)buf++;
  }
  res=INF;
  rep(i,0,n){
    ll tmp=0;
    rep(j,0,n){
      if(a[i][j]=='#')tmp++;
    }
    if(tmp==n)chmin(res,n-buf);
    else if(t[i])chmin(res,n-buf+n-tmp);
    else chmin(res,n-buf+n-tmp+1);
  }
  judge=false;
  rep(i,0,n)if(t[i])judge=true;
  ans(!judge,-1,res);
  return 0;
}

Measured memory_bytes: 512
fun main(args: Array<String>) {
    val (H, W, M) = readLine()!!.split(' ').map { it.toInt() }
    val arrH = IntArray(H+1)
    val arrW = IntArray(W+1)
    val arr = mutableSetOf<Pair<Int, Int>>()

    arrH[0] = 0
    arrW[0] = 0

    var maxH = 0
    var maxW = 0

    repeat(M) {
        val (h, w) = readLine()!!.split(' ').map { it.toInt() }

        arrH[h]++
        if (arrH[h] > arrH[maxH]) maxH = h

        arrW[w]++
        if (arrW[w] > arrW[maxW]) maxW = w

        arr.add(h to w)
    }

    val ans = arrH[maxH] + arrW[maxW]
    if (maxH to maxW !in arr) println(ans)
    else {
        val lstH = arrH.withIndex().filter { it.value == arrH[maxH] }.map { it.index}
        val lstW = arrW.withIndex().filter { it.value == arrW[maxW] }.map { it.index}

        lstH.forEach { i ->
            lstW.forEach { j ->
                if (i to j !in arr) {
                    println(ans)
                    return
                }
            }
        }
        println(ans - 1)
    }
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int mod = 1000000007;

ll rep_square(ll a, ll b) {
    // return a^b
    ll ans = 1;
    ll base = a;
    while (b != 0) {
        if (b & 1) {
            ans *= base;
            ans %= mod;
        }
        base *= base;
        base %= mod;
        b >>= 1;
    }
    return ans;
}

template <std::uint_fast64_t Modulus> class modint {
    using u64 = std::uint_fast64_t;

  public:
    u64 a;

    constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept {
        return modint(*this) += rhs;
    }
    constexpr modint operator-(const modint rhs) const noexcept {
        return modint(*this) -= rhs;
    }
    constexpr modint operator*(const modint rhs) const noexcept {
        return modint(*this) *= rhs;
    }
    constexpr modint operator/(const modint rhs) const noexcept {
        return modint(*this) /= rhs;
    }
    constexpr modint &operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr modint &operator-=(const modint rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr modint &operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr modint &operator/=(modint rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
    modint pow(modint m) {
        modint ans = 1, base = a;
        while (m.a != 0) {
            if (m.a & 1) {
                ans *= base;
            }
            base *= base;
            m.a /= 2;
        }
        return ans;
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) { cin >> a[i]; }

    sort(a.begin(), a.end(), greater<ll>());

    using m = modint<mod>;
    m ans = 0;
    rep(i, n) { ans += m(a[i]) * m(2).pow(2 * n - 2) * m(2 + i); }
    cout << ans.a << endl;
    return 0;
}



Measured memory_bytes: 4788
let () =
  let rec read l p =
    try let n = read_int () in
        if n != 0 then read (n::l) p
        else read (List.tl l) ((List.hd l)::p)
    with End_of_file ->
      List.rev p |> List.iter (fun x -> Printf.printf "%d\n" x)
  in read [] [];;

Measured memory_bytes: 2300
import scala.io.StdIn._

object Main extends App {

  val n = readLong()
  val A = Array.fill(5)(readLong())

  def solve() = {
    val bottleneck = A.min
    if(n <= bottleneck) 5L
    else 4 + (n + bottleneck - 1)/bottleneck
  }
  println(solve())

}



Measured memory_bytes: 54968
n = int(input())

a0 = 1
a1 = 1

aList = [a0, a1]

if n == 0:
    print(a0)
    exit()
elif n == 1:
    print(a1)
    exit()
else:
    for i in range(2, n+1):
        aList.append(aList[i-1] + aList[i-2])

    print(aList[n])


Measured memory_bytes: 5600
#include<iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
const long long int mod1=1000000007;
const long long int mod2 = -1;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back                                       
#define ff first
#define ss second
#define ll long long int
#define ull unsigned long long int
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define ordered1 tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define inf mod1
#define all(x) x.begin(),x.end()
ll gcd(ll a, ll b){
    ll c;
     while(b){
        c = b;
        b = a % b;
        a = c;
     }
     return a;
}
ll power1(ll a, ll b){
     if(b == 0) return 1;
     else if(b % 2) return a * power1(a, b - 1);
     else {
        ll temp = power1(a, b / 2);
        return temp * temp;
     }
}
ll power2(ll a, ll b, ll m){
     a %= m;
     if(b == 0) return 1;
     else if(b % 2) return (a * power2(a, b - 1, m)) % m;
     else{
        ll temp = power2(a, b / 2, m);
        return (temp * temp) % m;
     }
}
ll mod(ll x, ll p){
return (x % p + p) % p;
}
ll lcm(ll x, ll y){
return (x * y)/gcd(x, y);
}
int main(){
    fast;
    ll h = 1;
    //scanf("%lld", &h);
    while(h--){
        ll k;
        cin >> k;
        ll out = 0;
        for(int i = 1; i <= k; i++){
            for(int j = 1; j <= k; j++){
                for(int l = 1; l <= k; l++){
                    out += gcd(gcd(i, j), l);
                }
            }
        }
        cout << out << endl;
}
}

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

typedef long long ll;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    ll n;
    cin >> n;

    string ans = "";
    unordered_map<int,char> umap;
    umap[0]='z';
    char c = 'a';
    for(int i=1; i<=25; i++){
        umap[i]=c;
        c++;
    }

    while(n){
        ans+=umap[n%26];
        n-=1;
        n/=26;
    }

    reverse(ans.begin(),ans.end());
    cout<<ans<<'\n';

    return 0;
}


Measured memory_bytes: 3656
n = int(input())
cards = [[0 for i in range(14)] for j in range(4)]
for i in range(n):
    suit, rank = list(map(str, input().split()))
    if suit == 'S':
        cards[0][int(rank)] = 1
    elif suit == 'H':
        cards[1][int(rank)] = 1
    elif suit == 'C':
        cards[2][int(rank)] = 1
    else:
        cards[3][int(rank)] = 1

for i in range(4):
    for j in range(1,14):
        if cards[i][j] == 0:
            if i == 0:
                print("S",end = " ")
            elif i == 1:
                print("H",end = " ")
            elif i == 2:
                print("C",end = " ")
            else:
                print("D",end = " ")
            print(j)


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

int main() {
        int n, W;
        scanf("%d%d", &n, &W);
        vector<long long> cur(W + 1);
        rep(i, n) {
                vector<long long> next = cur;
                int w, v;
                scanf("%d%d", &w, &v);
                rep(j, W + 1) if (j + w <= W) {
                        next[j + w] = max(next[j + w], cur[j] + v);
                }
                cur.swap(next);
        }
        long long ans = 0;
        rep(i, W + 1) {
                ans = max(ans, cur[i]);
        }
        printf("%lld\n", ans);
        return 0;
}


Measured memory_bytes: 1804
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
using namespace std; 
int main()
{ 
	//cout<<'X'-'A'<<"\n";
	int d;
	cin>>d;
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++)
	{
		cout<<char((s[i]-'A'+1+d-1)%26+'A'-1+1);	
	}
	cout<<endl;
	//system("pause");
	return 0;
}

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

public class Main{
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0 )break;
			
			HashSet<Integer> map = new HashSet<Integer>();
			for(int i = 1; i * i <= (1 << 15); i++){
				map.add(i * i);
			}
			
			int count = 0;
			for(int i = 0; i * i <= n; i++){
				for(int j = i; j * j <= n; j++){
					for(int k = j; k * k <= n; k++){
						int temp = (i * i + j * j + k*k);
						int l = n - temp;
						if(l + temp > n){
							break;
						}
						
						if(l >=k * k && map.contains(l)){
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
	}

	public static void main(String [] args){
		new Main().doit();
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <string>
using namespace std;
int dp[100][1000];
int main(){
	int a,b,c;
	int n;
	int ax[1000],bx[1000],cx[1000],r[1000];
	int w[500];
	while(true){
	for(int i=0;i<500;i++)
		w[i]=2;
	cin>>a>>b>>c;
	if(a==0&&b==0&&c==0)
		break;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>ax[i]>>bx[i]>>cx[i]>>r[i];
	for(int i=0;i<n;i++){
		if(r[i]==1){
			w[ax[i]-1]=1;
			w[bx[i]-1]=1;
			w[cx[i]-1]=1;
		}
	}
	for(int i=0;i<n;i++){
		if(r[i]==0){
			if(w[ax[i]-1]==1&&w[bx[i]-1]==1&&w[cx[i]-1]!=1)
				w[cx[i]-1]=0;
			if(w[ax[i]-1]==1&&w[cx[i]-1]==1&&w[bx[i]-1]!=1)
				w[bx[i]-1]=0;
			if(w[bx[i]-1]==1&&w[cx[i]-1]==1&&w[ax[i]-1]!=1)
				w[ax[i]-1]=0;
		}
	}
	for(int i=0;i<a+b+c;i++)
		cout<<w[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1176
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void) {
	char S[5];
	scanf("%s", &S);
	int count = 0;
	for (int i = 0; i < 4; i++) {
		if (S[i] == S[i + 1]) {
			count++;
		}
	}
	if (count == 0) {
		printf("Good");
	}
	else {
		printf("Bad");
	}


	return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define fr(i, n) for (i = 0; i < n; i++)
#define rep(i, n) for (i = 1; i <= n; i++)
#define lcm(x, y) ((x) * (y) / __gcd((x), (y)))
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#include <iostream>
#define intCeil(a, b) ((a) + (b)-1) / (b)

#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

int main()
{
    fastinput;
    LL n, i, j, k, t, temp, tc;
    cin >> n;
    vector<LL> v(n);
    for (i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    LL cnt = 0;
    for (i = 0; i < n; i++)
    {
        for (j = i + 1; j < n; j++)
        {
            for (k = j + 1; k < n; k++)
            {
                LL arr[3] = {v[i], v[j], v[k]};
                sort(arr, arr + 3);
                if (arr[0] != arr[1] && arr[1] != arr[2])
                {

                    if (arr[2] < arr[1] + arr[0])
                    {
                        cnt++;
                    }
                }
            }
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, N, a, b) for(int i = a; i < N; i += b)

int main(){
	long long N;
	cin >> N;

	long long val = 0;
	for(long long i = floor(sqrt(N)) + 1; i > 0; i--){
		if (N % i == 0){
			val = i;
			break ;
		}
	}
	cout << val + (N / val) - 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string S, T;
  cin>>S>>T;

  Int ans = 0;
  Int N = S.size();
  for(Int i=0;i<N;i++) ans += S[i] != T[i];
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3804
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//V,P(大文字)使用不可

const ll INF=1000000000000000000;

signed main(){
    int a,b,c,x;
    cin>>a>>b>>c>>x;
    int ans=0;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(500*i+100*j+50*k==x) ans++;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

enum Loc{
	Left,
	Right,
	Top,
	Bottom,
};

struct Info{
	int x,y;
};

int N,unite_count;
int* boss,*height;

int get_boss(int id){
	if(boss[id] == id)return id;
	else{
		return boss[id] = get_boss(boss[id]);
	}
}

int isSame(int x,int y){
	return get_boss(x) == get_boss(y);
}

void unite(int x,int y){
	x = get_boss(x);
	y = get_boss(y);

	if(x == y)return;

	if(height[x] > height[y]){

		boss[y] = x;

	}else if(height[x] < height[y]){

		boss[x] = y;

	}else{ //height[x] == height[y]

		boss[y] = x;
		height[x]++;
	}

	unite_count++;
}

int main(){

	int N,W,H;
	scanf("%d %d %d",&N,&W,&H);

	boss = new int[N];
	height = new int[N];

	for(int i = 0; i < N; i++){
		boss[i] = i;
		height[i] = 0;
	}

	Info* info = (Info*)malloc(sizeof(Info)*(N));
	vector<int> X[W+1],Y[H+1];

	for(int id = 0; id < N; id++){
		scanf("%d %d",&info[id].x,&info[id].y);
		X[info[id].x].push_back(id);
		Y[info[id].y].push_back(id);
	}

	for(int i = 1; i <= W;i++){

		if(X[i].size() <= 1)continue;
		for(int k = 0; k < X[i].size()-1;k++){
			for(int p = k+1; p < X[i].size();p++){
				unite(X[i][k],X[i][p]);
			}
		}
	}

	for(int i = 1; i <= H; i++){

		if(Y[i].size() <= 1)continue;
		for(int k = 0; k < Y[i].size()-1;k++){
			for(int p = k+1; p < Y[i].size();p++){
				unite(Y[i][k],Y[i][p]);
			}
		}
	}

	stack<int> GroupID;

	int group_num = 0;
	for(int i = 0; i < N; i++){
		if(boss[i] == i){
			group_num++;
			GroupID.push(i);
		}
	}

	int Loc_num[4] = {0,0,0,0},id;
	bool check[4];

	while(!GroupID.empty()){
		id = GroupID.top();
		GroupID.pop();

		for(int i = 0; i < 4; i++)check[i] = false;

		for(int i = 0; i < N; i++){
			if(boss[i] == id){
				if(info[i].x == 1){
					check[Left] = true;
				}else if(info[i].x == W){
					check[Right] = true;
				}

				if(info[i].y == 1){
					check[Top] = true;
				}else if(info[i].y == H){
					check[Bottom] = true;
				}
			}
		}

		for(int i = 0; i < 4; i++){
			if(check[i]){
				Loc_num[i]++;
			}
		}
	}

	int max_kabe = 0,tmp;

	for(int i = 0; i < 4; i++)max_kabe = max(max_kabe,Loc_num[i]);

	int ans = unite_count;

	if(group_num != 1){
		tmp = group_num-max_kabe;

		ans += tmp + group_num-1;
	}

	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 10256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int W = input.nextInt();

		int[] weights = new int[N];
		int[] values = new int[N];

		for(int i = 0; i < N; i++){
			weights[i] = input.nextInt();
			values[i] = input.nextInt();
		}

		long[][] memo = new long[N+1][W+1];

		for(int i = 1; i < N+1; i++){
			for(int j = 0; j <= W; j++){
				if(weights[i-1] <= j) memo[i][j] = Math.max(memo[i-1][j], memo[i-1][j-weights[i-1]] + values[i-1]);
				else memo[i][j] = memo[i-1][j];
			}
		}

		System.out.println(memo[N][W]);
	}
}

Measured memory_bytes: 127572
#include<stdio.h>
#include<stdlib.h>
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define min(x,y) ((x)<(y)?(x):(y))
#define N 10000000
#define INF 99999999
typedef struct{
    int pos;
    int rest;
}Data;
Data queue[N];
int head,num;
void enqueue(int pos,int rest){
    if(num<N){
        queue[(head+num)%N].pos=pos;
        queue[(head+num)%N].rest=rest;
        num++;
    }else{
        printf("エラー\n");
        exit(1);
    }
}
Data dequeue(int cost[110][110]){
    int idx=head;
    int min=cost[queue[head].pos][queue[head].rest];
    for(int i=head+1;i<head+num;i++){
        if(min>cost[queue[i%N].pos][queue[i%N].rest]){
            min=cost[queue[i%N].pos][queue[i%N].rest];
            idx=i%N;
        }
    }
    Data tmp=queue[head]; queue[head]=queue[idx]; queue[idx]=tmp;
    Data d={-1,-1};
    if(num>0){
        d=queue[head];
        head=(head+1)%N;
        num--;
    }
    return d;
}
int main(void){
    while(1){
        int n,m,l,k,a,h;
        scanf("%d%d%d%d%d%d",&n,&m,&l,&k,&a,&h);
        if(n==0) break;
        int cool[110]={0};
        int dist[110][110];
        int cost[110][110];
        rep(i,110) rep(j,110) dist[i][j]=0,cost[i][j]=INF;
        int x;
        rep(i,l) scanf("%d",&x),cool[x]=1;
        //rep(i,n) printf("%d ",cool[i]); puts("");
        rep(i,k){
            int a,b,t;
            scanf("%d%d%d",&a,&b,&t);
            dist[a][b]=dist[b][a]=t;
        }
        head=num=0;
        cost[a][m]=0;
        enqueue(a,m);
        while(1){
            Data tmp=dequeue(cost);
            int pos=tmp.pos,rest=tmp.rest;
            if(pos==h) continue;
            if(pos==-1) break;
            for(int i=0;i<n;i++){
                if(pos==i) continue;
                if(dist[pos][i]==0) continue;
                if(cool[pos]){
                    for(int j=0;j<=m;j++){
                        if(rest+j>m) break;
                        if(rest-dist[pos][i]+j<0) continue;
                        if(cost[i][rest-dist[pos][i]+j]>
                           cost[pos][rest]+dist[pos][i]+j){
                           cost[i][rest-dist[pos][i]+j]=
                            cost[pos][rest]+dist[pos][i]+j;
                            enqueue(i,rest-dist[pos][i]+j);
                        }
                    }
                }else{
                    if(rest-dist[pos][i]<0)continue;
                    if(cost[i][rest-dist[pos][i]]>
                       cost[pos][rest]+dist[pos][i]){
                        cost[i][rest-dist[pos][i]]=
                        cost[pos][rest]+dist[pos][i];
                        enqueue(i,rest-dist[pos][i]);
                    }
                }
            }
        }
        /*rep(i,n){
            rep(j,m+1){
                printf("%8d ",cost[i][j]);
            }puts("");
        }puts("");*/
        int ans=INF;
        rep(i,m+1) ans=min(ans,cost[h][i]);
        if(ans==INF) printf("Help!\n");
        else printf("%d\n",ans);
    }
}



Measured memory_bytes: 2108
INF = int(1e10)

N = int(input())
H = list(map(int, input().split()))
H.insert(0, -1)

DP = [INF] * (N + 1)
DP[1] = 0

for i in range(1, N):
    if i + 1 <= N:
        DP[i + 1] = min(DP[i + 1], DP[i] + abs(H[i] - H[i + 1]))
    if i + 2 <= N:
        DP[i + 2] = min(DP[i + 2], DP[i] + abs(H[i] - H[i + 2]))

print(DP[N])

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

long long int dp[100005],ar[100005];
long long int solve(long long int i, long long int n, long long int m)
{
    if(i==(n-1))
        return 0;
    if(i>=n)
        return INT_MAX;
    if(dp[i]!=-1)
        return dp[i];
    long long int mn=INT_MAX;
    for(long long int j=1;j<=m;j++)
    {
        mn=min(mn,abs(ar[i+j]-ar[i])+solve(i+j,n,m));
    }
    return dp[i]=mn;
}

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

    long long int 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;

    cin>>n>>m;
    for(i=0;i<n;i++)
    {
        cin>>ar[i];
        dp[i]=-1;
    }
    cout<<solve(0,n,m)<<"\n";
    return 0;


}


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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  string s;
  cin >> s;

  int result = 0;
  if (s == "SUN") {
    result = 7;
  } else if (s == "MON") {
    result = 6;
  } else if (s == "TUE") {
    result = 5;
  } else if (s == "WED") {
    result = 4;
  } else if (s == "THU") {
    result = 3;
  } else if (s == "FRI") {
    result = 2;
  } else if (s == "SAT") {
    result = 1;
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
ll lcm(ll a, ll b) {return ((a*b)/gcd(a,b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;
const int N = 1e6 + 10;

long long modpow(long long n, long long k, long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}

void solve(){
   int n,m;
   cin >> n >> m;
   int maxi = m/n;
   for(int i = maxi;i>=1;i--){
    if(m%i==0){
        cout << i;
        break;
    }
   }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>

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


ll fact(ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        res = (res * n) % mod;
        --n;
    }
    return res;
}

int main() {
    int task = 1;
//    cin >> task;
    while (task--) {
        int a, b, c;
        cin >> a >> b >> c;
        cout << a + b + c - max(a, max(b, c)) << "\n";
    }

    return 0;
}

Measured memory_bytes: 256