akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
int main()
{
	int n,m,p[101],i,j,t;
	for(;scanf("%d%d",&n,&m),n;)
	{
		memset(p,0,m*4);
		for(i=0;i<n;i++)
		{
			for(j=0;j<m;p[j++]+=t)
				scanf("%d",&t);
		}
		for(i=0;i<m;i++,printf("%d%s",t+1,i==m?"\n":" "),p[t]=-1)
			for(j=t=0;j<m;j++)
				if(p[j]>p[t])
					t=j;
	}
	return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
int dp[3300][3300];
int C(int x,int y){
	if(x < y)return 0;
	if(x == y || y == 0)return 1;
	if(dp[x][y] != -1)return dp[x][y];
	return dp[x][y] = C(x-1,y-1) + C(x-1,y);
}

signed main(){
	int n,a,b;cin >> n >> a >> b;
	rep(i,3300)rep(j,3300)dp[i][j] = -1;
	vector<int> v(n);
	rep(i,n)cin >> v[i];
	sort(v.rbegin(),v.rend());
	int ret = 0;
	rep(i,a)ret += v[i];
	printf("%lf\n",(double)ret/a);
	int ans = 0;
	int cnt_a = 0,cnt_all = 0;
	
	rep(i,n){
		if(i < a)cnt_a += (v[i] == v[a-1]);
		cnt_all += (v[i] == v[a-1]);
	}
	// trace(cnt_a,cnt_all);
	if(v[0] != v[a-1])cout << C(cnt_all,cnt_a) << endl;
	else{
		int ans = 0;
		for(int i = a;i <= b;i++)ans = (ans + C(cnt_all,i));
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 88872
#include <stdio.h>
#include <math.h>
 
using namespace std;
 
int main(){
    double x1,x2,x3,y1,y2,y3,xp,yp;
    double calc1,calc2,calc3;
 
    while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp)!=EOF){
        calc1 = (x2-x1)*(yp-y1)-(y2-y1)*(xp-x1);
        calc2 = (x3-x2)*(yp-y2)-(y3-y2)*(xp-x2);
        calc3 = (x1-x3)*(yp-y3)-(y1-y3)*(xp-x3);
 
        if((calc1>0&&calc2>0&&calc3>0) || (calc1<0&&calc2<0&&calc3<0)){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2760
#include<bits/stdc++.h>
#ifndef LOCAL_PROJECT
#define cerr if(0)cerr
#endif
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
const int mn=2e5+10;
int main(){
	#ifdef LOCAL_PROJECT
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#else
		cin.tie(0);
		cin.sync_with_stdio(0);
	#endif
	int x;
	cin>>x;
	cout<<360/gcd((unsigned int)x,360);
}

Measured memory_bytes: 3636
#include<stdio.h>

int main(){

  int n;
  int sum=0;
  char* result="";
  scanf("%d",&n);
  int num=n;

  for(int i=100000000;i>0;i=i/10){
    if(n>=i){
      sum=sum+(num/i);
      num=num-(i*(num/i));
    }
  }

  if(n%sum==0) result="Yes";
  else result="No";

  printf("%s\n",result);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
using namespace std;
using v = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}

int main(int argc, char *argv[]){
    int a, b, c; cin >> a >> b >> c;
    // if((a+b+c)%3 == 0) cout << "Yes" << endl;
    // else cout << "No" << endl;
    // if((a == b and b == c) or (a == b and a == c) or (b ==))
    string res;
    // if(a == b or b == c or c == a) res = "Yes";
    if((a == b+c) or (b == c+a) or (c == a+b)) res = "Yes";
    else res ="No";
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#define inf 1000000000

using namespace std;
typedef pair<int, int> P;

struct edge{
	int toi, toj, cost;
	edge(int a, int b, int c){
		toi = a, toj = b, cost = c;
	}
};

int N, M, L;
vector<edge> G[105][105];
int dist[105][105];
priority_queue< P, vector<P>, greater<P> > Q;

void dijkstra()
{
	for(int i = 0; i <= L; i++){
		for(int j = 1; j <= N; j++){
			dist[i][j] = inf;
		}
	}
	dist[0][1] = 0;
	Q.push( make_pair(0, 1) );
	
	int ui, uj, vi, vj, d;
	while(Q.size()){
		ui = Q.top().second / 1000;
		uj = Q.top().second % 1000;
		d = Q.top().first;
		Q.pop();
		if(d > dist[ui][uj]) continue;
		for(int i = 0; i < G[ui][uj].size(); i++){
			vi = G[ui][uj][i].toi;
			vj = G[ui][uj][i].toj;
			if(dist[vi][vj] > dist[ui][uj] + G[ui][uj][i].cost){
				dist[vi][vj] = dist[ui][uj] + G[ui][uj][i].cost;
				Q.push(make_pair(dist[vi][vj], vi * 1000 + vj));
			}
		}
	}
}

int main(void)
{
	while(1){
		cin >> N >> M >> L;
		
		int a, b, d, e;
		if(N == 0 && M == 0 && L == 0) break;
		
		for(int i = 0; i <= L; i++){
			for(int j = 1; j <= N; j++){
				G[i][j].clear();
			}
		}
		
		for(int m = 0; m < M; m++){
			cin >> a >> b >> d >> e;
			for(int i = 0; i <= L; i++){
				G[i][a].push_back(edge(i, b, e));
				G[i][b].push_back(edge(i, a, e));
				if(i + d <= L){
					G[i][a].push_back(edge(i+d, b, 0));
					G[i][b].push_back(edge(i+d, a, 0));
				}
			}
		}
		
		dijkstra();
		
		int ans = inf;
		for(int i = 0; i <= L; i++) ans = min(ans, dist[i][N]);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 12532
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<62)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin>>n;
    vl a(n);
    cin>>a;
    
    rep(i,n){
        if(a[i]%2==0){
            if(a[i]%3==0||a[i]%5==0){
                continue;
            }else{
                puta("DENIED");
                return 0;
            }
        }
    }
    
    
    puta("APPROVED");
}

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

char c[50][50];
int h,w;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w;
    rep(i,h) {
        rep(j,w) {
            cin >> c[i][j];
        }
    }
    const int dh[]={-1,1,0,0};
    const int dw[]={0,0,-1,1};
    rep(i,h) {
        rep(j,w) {
            if(c[i][j]=='#') {
                bool f=false;
                rep(k,4) {
                    const int a=i+dh[k];
                    const int b=j+dw[k];
                    if(a>=0&&a<h&&b>=0&&b<w) {
                        if(c[a][b]=='#') {
                            f=true;
                            break;
                        }
                    }
                }
                if(!f) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>

long factorial(int);

int main(){
    
    int n;
    long ans;
    scanf("%d",&n);
    ans = factorial(n);
    printf("%ld\n",ans);
    
    return 0;
    
}


long factorial(int x){
    if(x == 0)
        return 1;
    else
        return x*factorial(x-1);
}

Measured memory_bytes: 588
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
 
int main() {
  int64_t N,K;
  cin>>N>>K;
  vector<int>a(N);
  vector<int>b(N);
  vector<int64_t>k(100005);
  for(int i=0;i<N;i++){
    cin>>a[i]>>b[i];
    k[a[i]]+=b[i];
  }
  for(int i=0;i<100005;i++){
   if(K<=k[i]){cout<<i<<endl;return 0;}
   else{K-=k[i];}
  }
  return 0;
}

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

int max(int a,int b){
   int r=a%b;
  if(a<b){
    swap(a,b);
  }
  while(r!=0){
    a=b;
    b=r;
    r=a%b;
  }
  return b;
}

int main(){
  int a,b,k,r,i,j;
  cin >> a >> b >> k;
  j=max(a,b);
  for(i=0;i<k;i++){
    for(;1<j;j--)if(a%j==0 && b%j==0)break;
    j--;
  }
  cout << j+1 << endl;
}

Measured memory_bytes: 256
n,k,q = list(map(int, input().split()))
a = [int(input()) for _ in range(q)]

from collections import Counter

c = Counter(a)
score = [0] + [k-q] * n

# 正解した分加点する
for player, point in c.items():
    score[player] += point

for p in score[1:]:
    if p <= 0:
        print('No')
    else:
        print('Yes')

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

int main(){
   int n;
   cin >> n;
   vector<int> p(n);
   vector<int> q(n);
   for(int i=0; i<n; i++){
      cin >> p.at(i);
   }
   for(int i=0; i<n; i++){
      cin >> q.at(i);
   }

   vector<int> m;
    for (int i=1; i<=n; i++) {
        m.emplace_back(i);
    }

    int a = 0;
    int b = 0; 
    int i=0;
    do {
        if(m == p) a=i;
       if(m == q) b=i;
       i++;
     } while (next_permutation(m.begin(), m.end()));
   cout << abs(a-b) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

int main(){
    string S; cin>>S;
    int N=S.length();

    for (int i = 0; i < N - 1; ++i) {
        if(S[i]==S[i+1]){
            cout<<i+1<<" "<<i+2<<endl;
            return 0;
        }if(i<N-2&&S[i]==S[i+2]){
            cout<<i+1<<" "<<i+3<<endl;
            return 0;
        }
    }
    cout<<"-1 -1"<<endl;
    return 0;
}

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

int mid(int a,int b,int c){
  return a+b+c-max(max(a,b),c)-min(min(a,b),c);
}
int samecount(string S){
    int A = 0;
    for(int i = 0;i < S.size();i++){
        int QA = 1;
        for(int j = i ;j < S.size() - 1;j++){
           if(S.at(j) == S.at(j + 1)){
               QA++ ;
           }
           if(S.at(j) != S.at(j + 1)){
               break;
           }
           
        }
        A = max(QA,A);
    }
    return A;
}
int main(){
    int K,X;
    cin >> K >> X;
    
        for(int i = -1000000;i < 1000001 ;i++){
            if(X - K + 1 <= i && X + K - 1 >= i){
                cout << i << endl;
            }
        }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MOD int(1e9+7)
using namespace std;
int main(int argc, char const *argv[]) {
    //Parparosa
    //Shawi Algorithm

    int n;
    cin >> n;
    set<int>a, b;
    vector<pair<int, int>>a1(n);
    for(int i = 0; i < n; i++) {
        cin >> a1[i].first >> a1[i].second;

    }
    map<pair<int, int>, int>m;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            if(i != j) {
                m[ {a1[i].first - a1[j].first, a1[i].second - a1[j].second}]++;
            }
        }
    }
    int ans = 0;
    for(auto x : m) {
        ans = max(ans, x.second);
    }
    cout << n - ans << endl;
    return 0;
}

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

#include<math.h>

//#define pi 3.14159265358979323846
#define pi acos(-1.0)
using namespace std;

int main()
{



    int r;

    cin>>r;

    double a=2*pi*r;

    printf("%.20lf",a);//cout<<a<<endl;

    return 0;


}


Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  if(!a)
    cout<<1;
  else if(!b)
    cout<<2;
  else if(!c)
    cout<<3;
  else if(!d)
    cout<<4;
  else
    cout<<5;}

Measured memory_bytes: 3644
s = input()
k = int(input())
alp = list(set(s))
alp.sort()
moji = []

for a in alp:
    for i, si in enumerate(s):
        if si == a:
            moji.append(s[i:i+1])
            moji.append(s[i:i+2])
            moji.append(s[i:i+3])
            moji.append(s[i:i+4])
            moji.append(s[i:i+5])
            moji = set(moji)
            moji = list(moji)

    if len(moji) > k-1:
        break
    
moji.sort()
print(moji[k-1])

Measured memory_bytes: 3188
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

from functools import lru_cache

def main(): 
    N = II()
    h = LI()

    # @lru_cache()
    # def min_cost(x):
    #     if x == 0: return 0
    #     elif x == 1: return abs(h[1] - h[0])
    #     else: return min(min_cost(x-1) + abs(h[x] - h[x-1]), min_cost(x-2) + abs(h[x] - h[x-2]))

    min_cost = [0 for _ in range(N)]
    min_cost[0] = 0
    min_cost[1] = abs(h[1] - h[0])
    for x in range(2, N):
        min_cost[x] = min(min_cost[x-1] + abs(h[x] - h[x-1]), min_cost[x-2] + abs(h[x] - h[x-2]))

    print(min_cost[N-1])

main()

Measured memory_bytes: 14088
#include<stdio.h>

int counter(int n) {
  int sum = 0;
  while (n != 0) {
    sum += n & 1;
    n = n >> 1;
  }
  return sum;
}

void solve() {
  int n, a[20], ans = 0; scanf("%d", &n);
  int x[20][20], y[20][20], alp = 1 << n;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    for (int j = 0; j < a[i]; j++) {
      scanf("%d%d", &x[i][j], &y[i][j]);
    }
  }
  for (int i = 0; i < alp; i++) {
    int is_able = 1;
    for (int j = 0; j < n; j++) {
      if ((i & (1 << j))) {
        for (int k = 0; k < a[j]; k++) {
          if (((i >> (x[j][k] - 1)) & 1) != y[j][k])is_able = 0;
        }
      }
    }
    if (is_able) {
      int sum = counter(i);
      if (ans < sum)ans = sum;
    }
  }
  printf("%d\n", ans);
}

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


Measured memory_bytes: 128
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=list(input())

ans=0

for j in range(len(T)):
    if j<K:
        if T[j]=='r':
            ans+=P
        elif T[j]=='s':
            ans+=R
        else:
            ans+=S
    elif j>=K and T[j]!=T[j-K]:
        if T[j]=='r':
            ans+=P
        elif T[j]=='s':
            ans+=R
        else:
            ans+=S
    else:
        T[j]=''
print(ans)
        

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

typedef long long ll;

int main(){
    int N, M;
    cin >> N >> M;
    vector<string> A(N), B(M);
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<M; i++) cin >> B[i];
    
    bool flag=true, F=false;
    for(int i=0; i<=N-M; i++){
        for(int j=0; j<=N-M; j++){
            flag=true;
            for(int k=0; k<M; k++){
                if(A[i+k].substr(j,M) != B[k])
                    flag = false;
            }
            if(flag) F=true;
        }
    }
    
    cout << (F?"Yes":"No") << endl;
}


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

int main(){
    int n, i, sum = 0;
    cin >> n;
    int a[n], b[n], c[n];
    for(i=0; i<n; i++) cin >> a[i];
    for(i=0; i<n; i++) cin >> b[i];
    for(i=0; i<n; i++) cin >> c[i];
    for(i=0; i<n; i++){
        sum += b[a[i]-1];
        if(i>0 && a[i]-a[i-1] == 1){
            sum += c[a[i-1]-1];
        }
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
import sys
from math import gcd
input = sys.stdin.readline

K = int(input())
ans = 0

for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            if i == j and k == i:
                ans += gcd(gcd(i, j), k)
            elif i == j or k == i or j == k:
                ans += 3 * gcd(gcd(i, j), k)
            else:
                ans += 6 * gcd(gcd(i, j), k)

print(ans)


Measured memory_bytes: 68108
import fractions

def main():
    n = int(input())  #nは入力回数
    t = [int(input()) for _ in range(n)]

    if not (1 <= n and n <= 100 and isinstance(n, int)):
        return
    for i in t:
        if not (1 <= i and i <= 10**18 and isinstance(i, int)):
            return

    k = t[0]
    for i in range(1, n):
        k = k * t[i] // fractions.gcd(k, t[i])

    if k <= 10**18:
        print(k)

if __name__ == "__main__":
    main()

Measured memory_bytes: 5560
import java.util.Scanner;

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

		int ans = n * (n - 1) / 2 + m * (m - 1) / 2;
		System.out.println(ans);
		sc.close();
	}
}

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


int main()
{
    int n;
    scanf("%d",&n);

    vector<long long> arr(n);
    vector<long long > distance(n,INT_MAX);

    for(int i = 0; i < n; i++)
        cin >> arr[i];


    distance[0] = 0ll;

    for(int i = 0; i < n; i++)
    {
        if(i + 1 < n)
            distance[i+1] = min(distance[i+1], distance[i] + abs(arr[i+1] - arr[i]));

        if(i + 2 < n)
            distance[i+2] = min(distance[i+2], distance[i] + abs(arr[i+2] - arr[i]));            
    }

    cout <<  distance[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<double, long long> pdl;

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007

int n, x, y;
vector<int> g[1<<20];
vector<long double> A(1<<20);
vector<long double> B(1<<20);

long double dfs(int s, int p) {
	if(g[s].size() == 1 and g[s][0] == p) {
		return 1;
	}

	long double sum = 0;
	for(auto &x : g[s]) {
		if(x == p) continue;
		sum += dfs(x, s);
	}

	A[s] = sum;
	if(p == -1) return sum/(g[s].size());
	return 1 + sum/(g[s].size()-1);
}

void modify(int s, int p) {
	if(p != -1 and g[s].size() == 1 and g[p].size() == 1) {
		A[s] = 1;
		return;
	}

	if(p != -1 and g[s].size() != 1 and g[p].size() == 1) {
		A[s] += 1;
	}

	if(p != -1 and g[s].size() == 1 and g[p].size() != 1) {
		A[s] += 1+(A[p]-1)/(g[p].size()-1);
		return;
	}

	if(p != -1 and g[s].size() != 1 and g[p].size() != 1) {
		A[s] += 1+(A[p]-(A[s]/(g[s].size()-1))-1)/(g[p].size()-1);
	}

	for(auto &x : g[s]) {
		if(x == p) continue;
		modify(x, s);
	}
}

int main() {
  	//freopen("input.in","r",stdin);
  	//freopen("output.out","w",stdout);
	cin>>n;
	rep(i, n-1) {
		cin>>x>>y;
		g[x].pb(y);
		g[y].pb(x);
	}

	if(n == 1) {
		cout<<"0"<<endl; return 0;
	}

	dfs(1, -1);
	modify(1, -1);
	rep(i, n) printf("%.12Lf\n", A[i+1]/g[i+1].size());

	return 0;
}


Measured memory_bytes: 69120
#include<bits/stdc++.h>
using namespace std;
int edge_num=-1;
struct edge
{
	int to,p,nxt;
}e[1000001];
int head[1000001];
void add_edge(int u,int v)
{
	e[++edge_num].to=v;
	e[edge_num].nxt=head[u];
	head[u]=edge_num;
}
int vis[1000001];
int out[1000001];
void dfs(int u,int fa)
{
	vis[u]=1;
	vector<int>v;
	for(int i=head[u];i!=-1;i=e[i].nxt)
	{
		int to=e[i].to;
		if(vis[to]==0)
		{
			v.push_back(i);
			dfs(to,u);
		}
		else if(e[i].p==0&&to!=fa)
		{
			e[i].p=1;
			e[i^1].p=-1;
			out[u]++;
		}
	}
	for(int i=0;i<v.size();i++)
	{
		int x=v[i];
		if(out[e[x].to]%2==1)
			e[x^1].p=1,e[x].p=-1;
		else
			e[x].p=1,e[x^1].p=-1,out[u]++;
	}
}
int main()
{
	memset(head,-1,sizeof(head));
	int n,m;
	scanf("%d%d",&n,&m);
	if(m%2==1)
	{
		printf("-1");
		return 0;
	}
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		add_edge(u,v);
		add_edge(v,u);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
		for(int j=head[i];j!=-1;j=e[j].nxt)
			if(e[j].p==1)
				printf("%d %d\n",i,e[j].to);
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; i++) cin >> v[i];

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

  double ans = v[0];
  for (int i = 1; i < N; i++) ans = (ans + v[i]) / 2;
  cout << ans << endl;
}


Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=1e5+5;
struct eg{int v,nx;}e[N<<1];int head[N],tot;
inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;}
int sg[N],n;
void dfs(int u,int fa){
	sg[u]=0;
	go(u)if(v!=fa)dfs(v,u),sg[u]^=sg[v]+1;
}
int main(){
	scanf("%d",&n);
	for(R int i=1,u,v;i<n;++i)scanf("%d%d",&u,&v),add(u,v),add(v,u);
	dfs(1,0);
	puts(sg[1]?"Alice":"Bob");
	return 0;
}

Measured memory_bytes: 7296
import sys
input = sys.stdin.readline

def main():
    N, K = [int(x) for x in input().split()]
    D = [int(x) for x in input().split()]

    Dset = set(D)

    for i in range(N, 1000000):
        for j in str(i):
            if int(j) in Dset:
                break
        else:
            print(i)
            return


    
    
    

if __name__ == '__main__':
    main()




Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int num[101]={};
  int e[4];
  for(int i=0;i<4;i++){
    cin>>e[i];
    num[e[i]]++;
  }
  for(int i=1;i<101;i++){
    if(num[i]%2==1){
      cout<<"no"<<endl;
      break;
    }
    if(i==100) cout<<"yes"<<endl;
  }
  return 0;
}
  



Measured memory_bytes: 3080
#include <stdio.h>

int main(void)
{
	int i, j, mt[10], co;
	
	for (i = 0; i < 10; i++) {
		scanf ("%d", &mt[i]);
	}
	for (i = 0; i < 10; i++){
		for (j = 0; j < 10; j++){
			if (mt[j] < mt[i]){
				co = mt[j];
				mt[j] = mt[i];
				mt[i] = co;
			}
		}
	}
		
	for (i = 0; i < 3; i++){
		printf("%d\n", mt[i]);
	}
	return(0);
}

Measured memory_bytes: 600
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long

ll n;
char name[20];
int len=0;

int main(){
  scanf("%lld",&n);
  while(n>0){
    ll tmp=n%26;
    char c;
    if(tmp==0){
      c='z';}
    else{
      c='a'+tmp-1;}
    name[len]=c;
    len++;
    n = (n-1)/26;}
  
  for(int i=len-1;i>=0;i--){
    printf("%c",name[i]);}
  printf("\n");
  
  return 0;
}


Measured memory_bytes: 1664
# -*- coding: utf-8 -*-
n = int(input())

tmp = pow(10, 13)
for i in range(1, int(pow(n, 0.5)) + 1):
    if n % i == 0 and abs(n // i - i) < tmp:
        tmp = abs(n // i - i)
        ans1 = n // i
        ans2 = i
#print(tmp, ans1, ans2)
print(ans1 + ans2 - 2)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main()
{
    int P,Q,R;
    cin>>P>>Q>>R;
if(P>=1&&Q>=1&&R>=1&&P<=100&&Q<=100&&R<=100){
    if(P+Q<=Q+R && P+Q<=P+R){
        cout<<P+Q;
    }
    else if(Q+R<P+R && Q+R<P+Q){
        cout<<Q+R;
    }
    else {
        cout<<P+R;
    }
}

    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define mod (int)(998244353)
#define PI 3.14159265358979323846264338327950L
#define debug(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << "[ " << *it << " = " << a << " ] ";
    err(++it, args...);
}

signed main(){

    fastIO

    int t = 1;
    // cin >> t;
    while (t--){
   		int n, k;
   		cin >> n >> k;
   		vector<int> v(n);
   		for (int &i : v) {
   			cin >> i;
   		}
   		sort(all(v));
   		int sum = 0;
   		for (int i = 0; i < k; i++) {
   			sum += v[i];
   		}
   		cout << sum << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main() {
	int a, b,ans;
	char op;
	scanf("%d %c %d", &a, &op, &b);
	if (op == '+')
		ans = a + b;
	else
		ans = a - b;
	printf("%d", ans);
	return 0;
}

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

int main(){
    int K;
    string S;
    cin>>K>>S;
    if(S.size()<=K){
        cout<<S<<endl;
    }else{
        for(int i=0;i<K;i++){
            cout<<S.at(i);
        }
        cout<<"..."<<endl;
    }
}

Measured memory_bytes: 3632
#include<stdio.h>
int main()
{
    int A[100],N,sum=0;
    int num=1,tum=0,a;
    scanf("%d",&N);
    for(a=0;a<N;a++)
    {
        scanf("%d",&A[a]);
    }
while(num==1){
    num=0;
    for(a=N-1;a>=1;a--)
    {
        if(A[a]<A[a-1])
        {
            tum=A[a];
            A[a]=A[a-1];
            A[a-1]=tum;
            sum++;
            num=1;
            
        }
    }
}
    for(a=0;a<N-1;a++)
    {
        printf("%d ",A[a]);
        
    }
    printf("%d\n",A[a]);
 printf("%d\n",sum);
 
    return 0;
}




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

int main()
{
    int n;
    cin>>n;
    int y;
    bool flag=0;
    for(int i=1;i<=n;i++){
        cin>>y;
        if(y&1) continue ;
        if(y%3&&y%5) flag=1;
    }
    if(flag) cout<<"DENIED"<<endl;
    else cout<<"APPROVED"<<endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;
const long long MOD = 1000000007;
long long A[10000];
long long power(long long m, long long n){
    long long res = 1;
    while(n > 0){
        if(n & 1) {
            res = (res * m) % MOD;
        }
        m = (m * m) % MOD;
        n >>= 1;
    }
    return res;
}

long long inverse(long long a){
    return power(a, MOD - 2);
}
map <int, int> mult_counts;
int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    for(int i = 0; i < N; i++){
        map <int, int> tmp_counts;
        int tmp = A[i];
        for(int j = 2; j < sqrt(A[i]) + 1; j++){
            if(tmp % j == 0){
                tmp_counts[j] = 0;
                while(tmp % j == 0){
                    tmp /= j;
                    tmp_counts[j] ++;
                }
            }
        }
        if(tmp != 1){
            tmp_counts[tmp] = 1;
        }
        for(auto it = tmp_counts.begin(); it != tmp_counts.end(); it++){
            //cout << i << " " << it->first << " " << it->second << endl;
            if(mult_counts.find(it->first) == mult_counts.end() || mult_counts[it->first] < it->second){
                mult_counts[it->first] = it->second;
            }
        }
    }
    long long prod = 1;
    for(auto it = mult_counts.begin(); it != mult_counts.end(); it++){
        prod = (prod * power(it->first, it->second)) % MOD;
    }
    //cout << prod << endl;
    long long ans = 0;
    for(int i = 0; i < N; i++){
        ans = (ans + (prod * inverse(A[i])) % MOD) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
import java.util.*;    
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a>b){
          for(int i=1;i<=a;i++){
            System.out.print(b);
            }
          }else{
			for(int i=1;i<=b;i++){
            System.out.print(a);
            }
		}
	}
}

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

int main() {
  int N;
  cin >> N;
  
  vector <int64_t> l(N);
  int i=0;
  while(i < N) {
    if (i == 0) l.at(i) = 1;
    if (i == 1) l.at(i) = 3;
    if (2 <= i) {
      l.at(i) = l.at(i-1) + l.at(i-2);
    }
   	i++;
  }
  cout << l.at(N-1) << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int[][] input = new int[N][D];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				input[i][j] = sc.nextInt();
			}
		}
		Integer[] square = new Integer[130];
		for (int i = 1; i <= 130; i++) {
			square[i - 1] = i * i;
		}
		int res = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(input[i][k] - input[j][k], 2);
				}
				if (Arrays.asList(square).contains(Integer.valueOf(sum))) {
					res += 1;
				}
			}
		}
		System.out.print(res);
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <algorithm>

const int N = 2e5 + 7;
long long a[N], n, k;

int main() {
    scanf("%lld%lld", &n, &k);
    for (int i = 1; i <= n; i++) a[i % k]++;
    long long ans = 0;
    ans = a[0] * a[0] * a[0];
    if (!(k % 2)) ans += a[k / 2] * a[k / 2] * a[k / 2];
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(void)
{
	double weight;
	
	while(cin >> weight){
		if(weight <= 48.00) 
		  cout << "light fly" << endl;
		else if(weight > 48.00 && weight <= 51.00)
		  cout << "fly" << endl;
		else if(weight > 51.00 && weight <= 54.00)
		  cout << "bantam" << endl;
		else if(weight > 54.00 && weight <= 57.00)
		  cout << "feather" << endl;
		else if(weight > 57.00 && weight <= 60.00)
		  cout << "light" << endl;
		else if(weight > 60.00 && weight <= 64.00)
		  cout << "light welter" << endl;
		else if(weight > 64.00 && weight <= 69.00)
		  cout << "welter" << endl;
		else if(weight > 69.00 && weight <= 75.00)
		  cout << "light middle" << endl;
		else if(weight > 75.00 && weight <= 81.00)
		  cout << "middle" << endl;
		else if(weight > 81.00 && weight <= 91.00)
		  cout << "light heavy" << endl;
		else if(weight > 91.00)
		  cout << "heavy" << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include <stdio.h>
 
int main(void) {
	int n,a,b,s;
	scanf("%d%d%d",&n,&a,&b);
	if(n*a<b){
		printf("%d",n*a);
	}else{
		printf("%d",b);
	}
 
	// your code goes here
	return 0;
}

Measured memory_bytes: 128
/*

	TRY_TO_BE8T_ME

*/
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define FIO ios::sync_with_stdio(0);
ll gcd(ll a,ll b){while(a&&b)a>b?a%=b:b%=a;return a+b;}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}
int main() 
{
	FIO;
	ll i,j,k,c=0,n,m,d=0,e=0;
	cin>>n>>m;
	c=n+m;
	d=n-m;
	e=n*m;
	cout<<max(max(c,d),e);
	return 0;
}

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

int N, M;
int A[305][305];
int top[305];
int event[305];
int event_closed[305];

bool check(int K) {
    memset(event, 0, sizeof(event));
    memset(event_closed, 0, sizeof(event_closed));
    memset(top, 0, sizeof(top));
    for (int i = 0; i < N; i++) {
        int ev = A[i][top[i]];
        event[ev]++;
    }
    
    int flag = 1;
    while (flag) {
        flag = 0;
        
        for (int i = 0; i < M; i++) {
            if (event[i] <= K) continue;
            flag = 1;
            event[i] = 0;
            event_closed[i] = 1;
            for (int j = 0; j < N; j++) {
                if (event_closed[A[j][top[j]]] == 0) continue; 
                while (top[j] != M && event_closed[A[j][top[j]]]) {
                    top[j]++;
                }
                if (top[j] == M) return false;
                event[A[j][top[j]]]++;
            }
        }
    }
    return true;
}

int main(void){
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            cin >> A[i][j];
            A[i][j]--;
        }
    }
    
    int ng = 0;
    int ok = N;
    while (abs(ok - ng) > 1) {
        int mid = (ng + ok) / 2;
        if (check(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<vector>
const int N=605;
double dp[N][2],f[N];
int n,m;
std::vector<int> g[N];
int main() {
    scanf("%d%d",&n,&m);
    for(int u,v;m--;) {
        scanf("%d%d",&u,&v);
        g[u].push_back(v);
    }
    dp[n][0]=dp[n][1]=0;
    for(int i=n-1;i;i--) {
        dp[i][0]=0;
        double mx=0;
        for(int v:g[i]) {
            dp[i][0]+=dp[v][0];
            mx=std::max(mx,dp[v][0]);
        }
        if(g[i].size()>1) {
            dp[i][1]=1+(dp[i][0]-mx)/(g[i].size()-1);
        }
        dp[i][0]=dp[i][0]/g[i].size()+1;
    }
    double ans=dp[1][0],res=0;
    f[1]=1;
    for(int i=2;i<=n;i++) f[i]=0;
    for(int i=1;i<n;i++) {
        for(int v:g[i]) f[v]+=f[i]/g[i].size();
        if(g[i].size()>1) res=std::max(res,f[i]*(dp[i][0]-dp[i][1]));
    }
    printf("%.10f",ans-res);
    return 0;
}


Measured memory_bytes: 1408
k = gets.chomp.to_i
b = []

k.times do |i|
a = gets.chomp.split(" ").map(&:to_i)
b << a
end
#b.reverse!
gbg = 0

for i in 0..k-1
  j = k-1 - i
  b[j][0] += gbg
  #while b[j][0] % b[j][1] != 0
  
    stb = b[j][1]-b[j][0] % b[j][1] #1
    stb = 0 if stb == b[j][1]
    b[j][0] +=stb
    gbg += stb #b[j][0] % b[j][1] #1
  #end
end
p gbg




Measured memory_bytes: 9468
#include<stdio.h>//////////AOJ0037
                               int
i,j,w[5][5];char*p,b[1<<7];;   int
F(int(v)){scanf("%s",b);for(   p=b
;*p;++p                 ){w[   p-b
+1-v][j   +v]|=((w[p-   b][j   ]|=
(*p==49   )<<3-v)&8>>   v)>>   2;}
return(   j+=v          );/*   */}
main(){   for(   ;4-F   (0);   F(1
));for(   p=b,   i=j=   (*b=   3)^
3;i+=""   "BA"          "BC"   [*b
]-66,j=   (*b)["ABCB"]-66+j,   *++
p="ULDR   "[*b],i+j;)for((*    b+=
1)&=~4;                        !(w
[i][j]&(1<<*b));(*b+=3)&=3);return
!puts(b+1);}/*May2018,tw:@siikya*/



Measured memory_bytes: 2512
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;
//set<int>::iterator it;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	string s;
	cin>>s;
	int y,m,d;
	y=(s[0]-'0')*1000+(s[1]-'0')*100+(s[2]-'0')*10+(s[3]-'0');
	m=(s[5]-'0')*10+s[6]-'0';
	d=(s[8]-'0')*10+(s[9]-'0');
	if(y<2019)cout<<"Heisei"<<endl;
	else if(y>2019)cout<<"TBD"<<endl;
	else if(m<=4)cout<<"Heisei"<<endl;
	else if(m>4)cout<<"TBD"<<endl;
//	else if(d==30||d==31)cout<<"Heisei"<<endl;
//	else cout<<"TBD"<<endl;
	
	
	
	
	
	return 0;
}


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

int main(){
    ll D;
    cin >> D;
    vector<ll> c(26), t(D), last(26, -1);
    vector< vector<ll> > s(365, vector<ll> (26));
    rep(i, 0, 26) cin >> c[i];
    rep(i, 0, D){
        rep(j, 0, 26) cin >> s[i][j];
    }
    rep(i, 0, D){
        cin >> t[i];
        t[i]--;
    }
    ll M;
    cin >> M;
    vector<ll> d(M), q(M), rec(26, 0);
    rep(i, 0, M){
        cin >> d[i] >> q[i];
        d[i]--; q[i]--;
    }
    ll res = 0;
    rep(d, 0, D){
        res += s[d][t[d]];
        last[t[d]] = d;
        rep(j, 0, 26) {
            res -= c[j] * (d - last[j]);
            rec[j] += c[j] * (d - last[j]);
        }
    }
    // t[d[m]] := 0 - 25
    rep(m, 0, M){
        res -= s[d[m]][t[d[m]]];
        res += s[d[m]][q[m]];
        res += rec[t[d[m]]];
        res += rec[q[m]];
        rec[t[d[m]]] = 0;
        rec[q[m]] = 0;
        ll lst = -1;
        rep(i, 0, D){
            if(i != d[m] && t[i] == t[d[m]]){
                lst = i;
            }
            res -= c[t[d[m]]] * (i - lst);
            rec[t[d[m]]] +=  c[t[d[m]]] * (i - lst);
        }
        lst = -1;
        rep(i, 0, D){
            if(i == d[m] || t[i] == q[m]){
                lst = i;
            }
            res -= c[q[m]] * (i - lst);
            rec[q[m]] += c[q[m]] * (i - lst);
        }
        t[d[m]] = q[m];
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 4688
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

#define int long long

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  int tmp = 0;
  REP(i, N) {
    if(A[i] % 2 == 1) { tmp++; }
  }
  if(tmp % 2 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
vector<int>x[1002],v[1002];int n,m,s,t,a[10001],b[10001];
int r1[1002],r2[1002],dist[1002];
void bfs(int y){
	queue<int>Q;
	for(int i=1;i<=n;i++)dist[i]=99999;
	dist[y]=0;Q.push(y);
	while(!Q.empty()){
		int a1=Q.front();Q.pop();
		for(int i=0;i<(int)x[a1].size();i++){
			if(dist[x[a1][i]]>dist[a1]+1){
				dist[x[a1][i]]=dist[a1]+1;
				Q.push(x[a1][i]);
			}
		}
	}
}
void bfs2(int y){
	queue<int>Q;
	for(int i=1;i<=n;i++)dist[i]=99999;
	dist[y]=0;Q.push(y);
	while(!Q.empty()){
		int a1=Q.front();Q.pop();
		for(int i=0;i<(int)v[a1].size();i++){
			if(dist[v[a1][i]]>dist[a1]+1){
				dist[v[a1][i]]=dist[a1]+1;
				Q.push(v[a1][i]);
			}
		}
	}
}
int main(){
	while(true){
		cin>>n;if(n==0)break;cin>>s>>t>>m;
		for(int i=1;i<=n;i++){x[i].clear();v[i].clear();}
		for(int i=0;i<m;i++){
			scanf("%d%d",&a[i],&b[i]);
			x[a[i]].push_back(b[i]);
			v[b[i]].push_back(a[i]);
		}
		bfs(s);for(int i=1;i<=n;i++)r1[i]=dist[i];
		bfs2(t);for(int i=1;i<=n;i++)r2[i]=dist[i];
		int maxn=r1[t],maxid=0;
		for(int i=0;i<m;i++){
			int H=r1[b[i]]+r2[a[i]]+1;
			if(maxn>H){maxn=H;maxid=i+1;}
		}
		cout<<maxn<<' '<<maxid<<endl;
	}
	return 0;
}

Measured memory_bytes: 3408
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <string>
#include <fstream>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LL long long
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int main(){
  int N;
  int F[100][10];
  int P[100][11];
  cin>>N;
  FOR(i,0,N){
    FOR(j,0,10){
      cin>>F[i][j];
    }
  }
  FOR(i,0,N){
    FOR(j,0,11){
      cin>>P[i][j];
    }
  }
  int res=-INF;
  FOR(i,1,(1<<10)){
    int cc=0;
    FOR(j,0,N){
      int c=0;
      FOR(k,0,10){
        if((i>>k&1)&&F[j][k]){
          c++;
        }
      }
      cc+=P[j][c];
    }
    res=max(res,cc);
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256
import numpy as np

N, K = map(int, input().split())
S = np.array(list(input()))
S = (S == 'L') * 1
inner01 = 0
outer10 = 0
happy = 0
for i in range(N - 1):
    if S[i] == S[i + 1]:
        happy += 1
    elif S[i] - S[i + 1] == 1:
        outer10 += 1
    else:
        inner01 += 1
up = min(inner01, min(K, outer10))
happy += 2 * up
if K - up >= 1 and outer10 - up >= 1 and S[0] == 1:
    happy += 1
if K - up >= 2 and outer10 - up >= 2 and S[-1] == 0:
    happy += 1
if K - up >= 1 and inner01 - up >= 1 and S[0] == 0:
    happy += 1
if K - up >= 2 and inner01 - up >= 2 and S[-1] == 1:
    happy += 1
print(happy)

Measured memory_bytes: 13900
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   cin>>n;
   vector<int>v;
   for(int i=0;i<n;i++)
   {
       int x;
       cin>>x;
       v.push_back(x);
   }
   double ans=0;
   double devide=0;
   for(int i=0;i<n;i++)
   {
       devide=devide+(1/(double)v[i]);
       ans=1/devide;
   }
   cout<<ans<<endl;


    return 0;
}



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

int main(){
  string num;
  char a;
  int sum = 0;
  cin >> num;
  for(int i = 0; i < num.size(); i++){
    a = num[i];
    sum += ((int)a - (int)'0');
  }
  if(stoi(num) % sum == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define INF = numeric_limits<long long>::max();
#define intf int_fast64_t

int main(){
    int A, B, K;
    cin >> K >> A >> B;
    string can = "NG";
    // if ((A % K) + (B % K) > K || B - A >= K-1 || A % K == 0 || B % K == 0 ){
        if (A / K != B / K || A % K == 0 || B % K == 0){
            can = "OK";
        }
    cout << can << endl;
}

Measured memory_bytes: 3624
package main

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

var sc *bufio.Scanner

const BufferSize = 1024

func nextInt() int {
	if !sc.Scan() {
		panic(nil)
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	s := make([]int, n)

	ans := 0
	for i := range s {
		s[i] = nextInt()
		if i > 1 {
			if s[i] > s[i-1] && s[i-1] >= s[i-2] {
				ans++
			}
			if s[i] <= s[i-1] && s[i-1] < s[i-2] {
				ans++
			}
		}
	}

	_, _ = fmt.Fprintf(writer, "%d", ans)
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 640
N=int(input())
L=[int(i) for i in input().split()]
cnt=0
if N<3:print(0)
else:
	for i in range(N):
		for j in range(i):
			for k in range(j):
				if (L[i]-L[j])*(L[j]-L[k])*(L[k]-L[i])!=0:
					if (L[i]+L[j]-L[k])>0 and  (L[j]+L[k]-L[i])>0 and  (L[i]+L[k]-L[j])>0:cnt+=1

	print(cnt)

Measured memory_bytes: 73816
#include <iostream>
  #include <complex>
  #include <vector>
  #include <string>
  #include <algorithm>
  #include <cstdio>
  #include <numeric>
  #include <cstring>
  #include <ctime>
  #include <cstdlib>
  #include <set>
  #include <map>
  #include <unordered_map>
  #include <unordered_set>
  #include <list>
  #include <cmath>
  #include <bitset>
  #include <cassert>
  #include <queue>
  #include <stack>
  #include <deque>
 #include <iomanip>

  using namespace std;
   

//abcdefghijklmnopqrstuvwxyz
//ABCDEFGHIJKLMNOPQRSTUVWXYZ
  typedef long long ll;
  typedef long double lld;
  typedef string str;
  typedef unsigned long long ull;
  int INF = INT_MAX;
  ll mod = 1e9+7;
  lld PI = 3.141592653;
 



  int main()
  {
      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     
    int a, b;
    cin>>a>>b;
    cout<<a*b<<"\n";

}



Measured memory_bytes: 3204
from itertools import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

L = input()
N = len(L)
dp =[[0]*2 for i in range(N+1)]
dp[0][0] = 1
for i in range(N):
    bit = int(L[i])
    dp[i+1][0] = (dp[i][0]*(1+bit)) % mod
    dp[i+1][1] = (dp[i][0]*(bit)+dp[i][1]*3)%mod

print(sum(dp[-1])%mod)


Measured memory_bytes: 54364
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, T;
  cin >> S >> T;
  
  int s_size = S.length();
  
  for(int i = 0; s_size; i++){
    if(S[i] != T[i]){
      cout << "No";
      break;
    }else if (i == s_size - 1){
	  cout << "Yes";
      break;
    }
  }
}

Measured memory_bytes: 3616