akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;
int n,m,i,Nr[100005],num,x,y,Viz[100005];
vector<int> V[100005];
vector<int>::iterator it;

void dfs(int nod)
{
    vector<int>::iterator it;
    Viz[nod]=1;
    for(it=V[nod].begin(); it!=V[nod].end(); it++)
        if(!Viz[*it])
            dfs(*it);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    cin>>n>>m;
	for(i=1; i<=m; i++)
	{
        cin>>x>>y;
        Nr[x]++;
        Nr[y]++;
        V[x].push_back(y);
        V[y].push_back(x);
	}
    for(i=1; i<=n; i++)
        if(Nr[i]%2)
        {
            cout<<"No\n";
            return 0;
        }
    for(i=1; i<=n; i++)
        if(Nr[i]>=6)
        {
            cout<<"Yes\n";
            return 0;
        }
    x=y=0;
    for(i=1; i<=n; i++)
        if(Nr[i]==4)
        {
            num++;
            if(x==0)
                x=i;
            else
                y=i;
        }
    if(num<=1)
    {
        cout<<"No\n";
        return 0;
    }
    if(num>=3)
    {
        cout<<"Yes\n";
        return 0;
    }
    Viz[y]=1;
    dfs(x);
    for(it=V[y].begin(); it!=V[y].end(); it++)
        if(!Viz[*it])
        {
            cout<<"Yes\n";
            return 0;
        }
    cout<<"No\n";
    return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3001;

char s[maxn], t[maxn], ans[maxn];
int dp[maxn][maxn];

int main()
{
#ifdef LOCAL
    freopen("data.txt", "r", stdin);
#endif
    scanf("%s%s", s + 1, t + 1);
    int m = strlen(s + 1), n = strlen(t + 1);
    for (int i = 1; i <= m; ++i)
        for (int j = 1; j <= n; ++j)
            if (s[i] == t[j])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else
                dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
    int i = m, j = n, p = dp[m][n];
    ans[p] = '\0';
    while (p) {
        if (j && dp[i][j] == dp[i][j - 1])
            --j;
        else if (i && dp[i][j] == dp[i - 1][j])
            --i;
        else if (dp[i][j] != dp[i - 1][j - 1])
            ans[--p] = s[i], --i, --j;
    }
    puts(ans);
}

Measured memory_bytes: 35456
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
using namespace std;
int main(){
    long long n,x;
    cin >> n >> x;
    long long ans=0;
    long long temp=0;
    for(long long i=0;i<n;i++){
        long long num;
        cin >> num;
        if(temp+num>x){
            ans+=num+temp-x;
            temp = num-(temp+num-x);
        }else{
            temp = num;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_b() {
	ll n, m;
	ll x, y;
	//ll a, b, c;
	ll k;
	string s, t;
	ll l_ans = 0;
	float f_ans = 0;
	string s_ans;

	cin >> s >> t;

	rep(i, s.size()) {
		if (s[i] != t[i]) l_ans++;
	}

	cout << l_ans << "\n";

}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed;
	cout << setprecision(7);

	solve_abc_b();

	return 0;
}


Measured memory_bytes: 3828
import sys
def input(): return sys.stdin.readline().rstrip()
from bisect import bisect
def main():
    n,k=map(int,input().split())
    X=list(map(int,input().split()))
    zero=bisect(X,0)
    ans=10**9
    for i in range(k+1):
        if zero-i<0 or zero+k-i-1>=n:
            continue
        if i==0:
            ans=min(ans,X[zero+k-i-1])
        elif i==k:
            ans=min(ans,-X[zero-i])
        else:
            kyori_m=2*-X[zero-i]+X[zero+k-i-1]
            kyori_p=-X[zero-i]+2*X[zero+k-i-1]
            ans=min(ans,kyori_m,kyori_p)  
    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 62576
#include<stdio.h>
int main()
{
	int a, b, c;
	int ans = 0;
	while(~scanf("%d %d %d", &a, &b, &c))
		{
	if(a != b && b != c && a != c)
		printf("3\n");
	else if(a == b && b == c)
		printf("1\n");
		else 
			printf("2\n");
		}
		return 0;


}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

int g[55][55];
int n,m;
int a[55],b[55];
int ans = 0;

void dfs(int x, vector<int> v) {
  bool visited[9] = {false};
  rep(i, v.size()) {
    visited[v[i]] = true;
  }
  bool flag = true;
  FOR(i, 1, n+1) if(!visited[i]) flag = false;
  if(flag) ans++;
  FOR(i, 1, n + 1) {
    if(g[x][i] && !visited[i]) {
      vector<int> vv = v;
      vv.push_back(i);
      dfs(i, vv);
    }
  }
}

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

  cin>>n>>m;
  rep(i,55) {
    rep(j,55) g[i][j] = 0;
  }
  rep(i,m) {
    cin>>a[i]>>b[i];
    g[a[i]][b[i]] = 1;
    g[b[i]][a[i]] = 1;
  }
  vector<int> al;
  al.push_back(1);
  dfs(1, al);
  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <bitset>

using namespace std;
typedef long long ll;
bool check(int a,int b,int c){
    // If a==b==c return false, else return true;
    if(a==b&&b==c) return false;
    else return true;
}

int main(){
    int c[3][3],oc[3][3]; //c[i][j] = c_(i,j)
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> c[i][j];
            oc[i][j] = c[i][j]; 
        }
    }

    for(int j=0;j<3;j++){
            c[j][0] = oc[j][1]-oc[j][0]; 
    }
    for(int j=0;j<3;j++){
              c[j][1] = oc[j][2]-oc[j][0]; 
    }
    for(int j=0;j<3;j++){
              c[j][2] = oc[j][2]-oc[j][1]; 
    }
    if(check(c[0][0],c[1][0],c[2][0])||check(c[0][1],c[1][1],c[2][1])||check(c[0][2],c[1][2],c[2][2])){
        cout << "No" << endl;
        return 0;
    }
    //b3-b2,b3-b1,b2-b1
    if(c[0][1]-c[0][0]!=c[0][2]) cout << "No" << endl;
    else         cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let m: usize = itr.next().unwrap().parse().unwrap();
    let mut ab = Vec::new();
    for _ in 0..m {
        let a: usize = itr.next().unwrap().parse().unwrap();
        let b: usize = itr.next().unwrap().parse().unwrap();
        ab.push((b, a));
    }
    ab.sort();

    let mut ans = 0;
    let mut now = 0;
    for i in 0..m {
        let s = ab[i].1;
        let t = ab[i].0;
        if now <= s {
            ans += 1;
            now = t;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 10492
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	ll n;
	while(cin>>n,n){
		ll ans = INFL;
		for(ll i = 0; i*i*i <= n; i++){
			ll tmp = n - i*i*i;
			ll t = sqrt(tmp);
			reep(j, t-4,t+4){
				if(j<0) continue;
				if(j*j > tmp) continue;
				mins(ans, i+j+(tmp-j*j));
			}
		}
		cout<<ans<<endl;
	}
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

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

public class Main {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		String s;
		while(( s = reader.readLine())!=null){
			String[] line = s.split(" ");
			int a = Integer.parseInt(line[0]);
			int b = Integer.parseInt(line[1]);
			builder.append(String.valueOf(a+b).length()).append('\n');
			
		}
		System.out.print(builder);
		
	}
}

Measured memory_bytes: 16992
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  
  char g = 'A';
  
  
  for (int i = 0; i < 3; i++) {
    
    cin >> s;
    
    if (s.at(0) == 'A' && !(i == 1)) {
      
      continue;
      
    }
    else if (s.at(0) == 'C' && !(i == 1)) {
      
      continue; 
      
    }
    else {
      
      g = s.at(0);
      
      
      
      break;
      
    }
  }
  cout << "A"  << g << "C" <<endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n;
  string s;
  cin >> n >> s;
  ll ans=0;
  for(ll i=1;i<n;i++) {
    set<char> a,b;
    for(ll j=0;j<n;j++) {
      if(j<i) a.insert(s[j]);
      else b.insert(s[j]);
    }
    ll cnt=0;
    for(auto p:a) {
      if(b.count(p)) cnt++;
    }
    ans=max(ans,cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
   int a, b, c, tmp;
   scanf("%d %d %d",&a,&b,&c);
   if(a>b){
      tmp=a; a=b; b=tmp;
   }
   if(b>c){
      tmp=b; b=c; c=tmp;
      if(a>b){ tmp=a; a=b; b=tmp; }
   }
   printf("%d %d %d\n",a,b,c);
   return 0;
}

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

struct dot{
	int x;
	int y;
	int e;
}seq [100];

int cal(dot a, dot b){
	return max(a.e - abs(a.x-b.x)-abs(a.y-b.y), 0);
}

int main(){
	int num;
	cin>>num;
	int j,k,i,p;
	for( i=0; i<num; i++)	{
		cin>>seq[i].x>> seq[i].y>> seq[i].e;
		if (seq[i].e!=0) p=i;
	}

	dot a;
	for(i=0; i<=100; i++){
		for(j=0; j<=100; j++){
			int fla=1;
			a.x=i;
			a.y=j;
			a.e=seq[p].e+abs(a.x-seq[p].x)+abs(a.y-seq[p].y);
			for(k=0; k<num && fla==1; k++){
				if( cal(a, seq[k])!= seq[k].e && fla==1) {
					fla=0;
				}
			}
			
			if(fla==1) {
				cout<< a.x<<' '<<a.y<<' '<<a.e;
				return 0;
			}
		}
	}
	return 0;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    map<int,int> check;

    REP(i,0,N){
        cin >> A[i];
        check[A[i]]++;
    }
    ll ans=1;
    if(N%2==1){
        REP(i,0,N){
            if(i==0){
                if(check[i]!=1) goto failed;
            }else if(i%2==1){
                if(check[i]!=0) goto failed;
            }else{
                if(check[i]!=2) goto failed; 
            }
        }
        REP(i,0,(N-1)/2){
            ans*=2;
            ans=ans%MOD;
        }
    }else{
        REP(i,0,N){
            if(i==0){
                if(check[i]!=0) goto failed;
            }else if(i%2==1){
                if(check[i]!=2) goto failed;
            }else{
                if(check[i]!=0) goto failed; 
            }
        }
        REP(i,0,N/2){
            ans*=2;
            ans=ans%MOD;
        }
    }
    P(ans);
    return 0;

    failed:
    P(0);
    return 0;

}

Measured memory_bytes: 5376
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
# 約数列挙
def find_divisor(n):
    divisors=[]
    for i in range(1, int(sqrt(n)) + 1):
        if n % i == 0:
            divisors.append(i)
            if i*i!=n:
                divisors.append(n // i)
    return divisors


def main():
    N,M=MI() ##Mの倍数
    ans = 1
    for d in find_divisor(M):
        if(M//d >= N):
            ans = max(ans, d)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 64108
from itertools import permutations
from collections import deque

def main():
    N, M = map(int, input().split())
    edge = [[] for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        edge[a].append(b)
        edge[b].append(a)
    cnt = 0
    for patterns in permutations(range(1,N)):
        pattern = [0] + list(patterns)
        Q = deque(pattern)
        while Q:
            s = Q.popleft()
            if Q[0] in edge[s]:
                if len(Q) == 1:
                    Q.popleft()
                    break
                else:
                    continue
            else:
                break
        if not Q:
            cnt += 1
    
    print(cnt)
if __name__ == "__main__":
    main()

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

int main() {
	int N;
	cin >> N;
	char s;
	for (int i = 0;i < N;i ++) {
		cin >> s;
		if (s == 'Y') { // 四種類だった
			cout << "Four";
			return 0;
		}
	} // 四種類ではなかった
	cout << "Three";
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

黄色が入っていれば四種類、そうでなければ三種類ですね
*/

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

int n,k,s;
vector<vector<int>> edge;
map<pair<int,int>,long long int> cost;

const long long int INF=1e16;

long long int kwalk(const int org){
  int pre=-1;
  long long int res=-INF;
  for(int lop=0;lop<edge[org].size();lop++){
    int v=org;
    pre=v;
    v=edge[org][lop];
    long long int sum=cost[{pre,v}];   
    for(int i=0;i<k-2;i++){
      if(edge[v].size()<2){
	sum=-INF;
	break;
      }
      assert(edge[v].size()==2);
      int to=(edge[v][0]==pre ? edge[v][1] : edge[v][0]);
      if(to==org){
	sum=-INF;
	break;
      }
      sum+=cost[{v,to}];
      pre=v;
      v=to;
    }

    if(edge[v].size()==2){

      int to=(edge[v][0]==pre ? edge[v][1] : edge[v][0]);
      if(to==org){

	sum+=cost[{v,org}];
      }
    }
    res=max(res,sum);
  }
  
  return res;
}

int main(){
  while(cin>>n>>k>>s,n){
    vector<long long int> x(n),y(n),z(n);
    for(int i=0;i<n;i++){
      cin>>x[i]>>y[i]>>z[i];
    }
    if(k==1){
      cout<<s*s*6<<endl;
      continue;
    }
    edge.clear();
    cost.clear();
    edge.resize(n);
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	long long int p=s-abs(x[i]-x[j]);
	long long int q=s-abs(y[i]-y[j]);
	long long int r=s-abs(z[i]-z[j]);
	if(p>0 && q>0 && r>0){
	  long long int cst=2*(p*q+q*r+r*p);
	  edge[i].push_back(j);
	  cost[{i,j}]=cst;
	  edge[j].push_back(i);
	  cost[{j,i}]=cst;
	}
      }
    }
    
    long long int res=-INF;
   
    for(int i=0;i<n;i++){
      res=max(res,kwalk(i));
    }
    if(res<0){
      cout<<-1<<endl;
      continue;
    }
    res=6*s*s*k-res;
    cout<<res<<endl;
  }
  
  return 0;
}

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

class dsu {
  int N;
  vector<int> PS;
public:
  dsu() : N(0) {}
  dsu(int n) : N(n), PS(n, -1) {}
  int merge(int a, int b) {
    assert(0 <= a && a < N);
    assert(0 <= b && b < N);
    int x = leader(a), y = leader(b);
    if (x == y) return x;
    if (-PS.at(x) < -PS.at(y)) swap(x, y);
    PS.at(x) += PS.at(y);
    PS.at(y) = x;
    return x;
  }
  bool same(int a, int b) {
    assert(0 <= a && a < N);
    assert(0 <= b && b < N);
    return leader(a) == leader(b);
  }
  int leader(int a) {
    assert(0 <= a && a < N);
    if (PS.at(a) < 0) return a;
    return PS.at(a) = leader(PS.at(a));
  }
  int size(int a) {
    assert(0 <= a && a < N);
    return -PS.at(leader(a));
  }
  vector<vector<int>> groups() {
    vector<int> leader_buf(N), group_size(N);
    for (int i = 0; i < N; i++) {
      leader_buf.at(i) = leader(i);
      group_size.at(leader_buf.at(i))++;
    }
    vector<vector<int>> result(N);
    for (int i = 0; i < N; i++) {
      result.at(i).reserve(group_size.at(i));
    }
    for (int i = 0; i < N; i++) {
      result.at(leader_buf.at(i)).push_back(i);
    }
    result.erase(
      remove_if(result.begin(), result.end(), [&](const vector<int>& v) { return v.empty(); }),
      result.end()
    );
    return result;
  }
};

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int N, Q;
  cin >> N >> Q;
  dsu D(N);
  for (int i = 0; i < Q; i++) {
    int t, u, v;
    cin >> t >> u >> v;
    if (t)
      cout << D.same(u, v) << "\n";
    else
      D.merge(u, v);
  }
}

Measured memory_bytes: 3892
#include <iostream>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <cstdio>

#define LL long long
#define PI 3.14159265358979323846
#define E 2.71828182845904523536
#define pie 0.618
using namespace std;
const int maxn = 1e5+5;
//bool vis[maxn]={false};
int dp[maxn];
int arr[maxn]={0};

void init(int);

int main() {
    int n;
    cin>>n;
    for (int i = 1; i <= n; ++i) {
        cin>>arr[i];
    }
    init(n);
    cout<<dp[n];
    return 0;
}


void init(int n){
    dp[1]=0;
    dp[2]=dp[1]+abs(arr[2]-arr[1]);
    for(int i=3;i<=n;i++){
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    }
}


Measured memory_bytes: 1024
H,W=[int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(H)]
res = []
for h in range(H):
    for w in range(W-1):
        if a[h][w] % 2 is not 0:
            res += ["{0} {1} {2} {3}".format(h+1,w+1,h+1,w+2)]
            a[h][w+1] += 1
for h in range(H-1):
    w = W - 1
    if a[h][w] % 2 is not 0:
        res += ["{0} {1} {2} {3}".format(h+1,w+1,h+2,w+1)]
        a[h+1][w]+=1

print(len(res))
for t in res:
    print(t)


Measured memory_bytes: 16348
S = input()
T = input()
M = len(S)
N = len(T)

def strmap(s, c_from='?', c_to='a'):
    return "".join(map(lambda c: c_to if c == c_from else c, s))

keys = []
for first in range(M - N + 1):
    match = True
    for i in range(N):
        if S[first + i] != '?' and S[first + i] != T[i]:
            match = False
            break
    if match:
        keys.append(strmap(S[: first]) + T + strmap(S[first + N:]))

if keys:
    print(min(keys))
else:
    print("UNRESTORABLE")

Measured memory_bytes: 3064
import java.util.*;
import java.util.Map.Entry;
 
 
 class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
	 static List<ArrayList<Integer>>  list = new ArrayList<ArrayList<Integer>>();
	 static long[] kaijo;
	 static long[] kaiinv;
    public static void main(String[] args) {
    
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int cnt=0;
        
        while(X!=2*Y && 2*X!=Y) {
        	cnt++;
        	X=X-3;Y=Y-3;
        	if(X<0||Y<0) {
                System.out.println(0);      		
        		return;
        	}
        }
        
        int n=cnt*2+Math.min(X, Y);
        int r=cnt;
        
        
        
        kaijo = new long[n+1];;
        kaijo[0]=1;
        for(int i=1;i<n+1;i++) {
        	kaijo[i]=(kaijo[i-1]*i)%mod;
        }
        kaiinv = new long[n+1];
        kaiinv[0]=1;
        kaiinv[1]=1;
        for(int i=2;i<n+1;i++) {
        	kaiinv[i]=modinv(kaijo[i])%mod;
        }

        System.out.println(nCr(cnt*2+Math.min(X, Y),cnt));        	
                		
    }
	static long nCr(int n, int r) {
		if(n<r) {
			return 0;
		} else {
			return (kaijo[n]*(kaiinv[r]*kaiinv[n-r]%mod))%mod;
		}
	}

	public static long pow(long a,long n) {
	    long res=1;
	    while (n>0) {
	        if ((n-n/2*2)==1) {
	            res=(res*a)%mod;
	        }
	        a=(a*a)%mod;
	        n>>=1;
	    }
	    return res;
	}
 
	public static long modinv(long n) {
		return pow(n, mod-2);
	}

}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const ll MOD = (ll)(1e9 + 7);

/////////////////////////////////////////////////////////////
class CombinationModulo {
public:
  static const int MAX_N_LIB = (int)(2e5 + 100);
  static const ll MOD_LIB = (ll)(1e9 + 7);

  ll fact[MAX_N_LIB];
  ll inv[MAX_N_LIB];
  ll fact_inv[MAX_N_LIB];

  CombinationModulo(int n) {
    init(n);
  }

  void init(int n) {
    inv[1] = fact[0] = fact_inv[0] = 1;
    for (int i = 2; i <= n; i++) {
      inv[i] = (MOD_LIB - (MOD_LIB / i) * inv[MOD_LIB % i] % MOD_LIB) % MOD_LIB;
    }
    for (int i = 1; i <= n; i++) {
      fact[i] = fact[i - 1] * i % MOD_LIB;
    }
    for (int i = 1; i <= n; i++) {
      fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD_LIB;
    }
  }

  ll comb(int n, int r) {
    if (r > n) return 0;
  	return fact[n] * fact_inv[r] % MOD_LIB * fact_inv[n - r] % MOD_LIB;
  }
};
/////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////
class ModuloOperator {
public:
  ll mo_modulo;

  ModuloOperator(ll modulo) {
    mo_modulo = modulo;
  }

  ll add(ll a, ll b) {
    ll ret = a + b;
    ret %= mo_modulo;
    return ret;
  }

  ll sub(ll a, ll b) {
    ll ret = a - b;
    if (ret < 0) ret += mo_modulo;
    else ret %= mo_modulo;
    return ret;
  }

  ll mul(ll a, ll b) {
    ll ret = a * b;
    ret %= mo_modulo;
    return ret;
  }

  ll div(ll a, ll b) {
    return mul(a, pow(b, mo_modulo - 2));
  }

  ll pow(ll x, ll y) {
    ll res = 1LL;

    x %= mo_modulo;

    while (y > 0) {
      if (y & 1) {
        res = mul(res, x);
      }

      y = y >> 1;
      x = mul(x, x);
    }

    return res;
  }
};
/////////////////////////////////////////////////////////////

ll n, m, k;

ll ans;

ModuloOperator mo(MOD);

int main(void) {
  // Here your code !
  scanf("%lld %lld %lld", &n, &m, &k);

  int size = (int)(n * m + 3);
  CombinationModulo cm(size);

  ans = 0;

  ll base_comb = cm.comb((int)(n * m - 2), (int)(k - 2));

  for (ll i = 1; i <= n - 1; ++i) {
    ll slide_size = n - i;

    ll times = mo.mul(mo.mul(slide_size, mo.mul(m, m)), base_comb);
    ll commit = mo.mul(i, times);

    ans = mo.add(ans, commit);
  }

  for (ll i = 1; i <= m - 1; ++i) {
    ll slide_size = m - i;

    ll times = mo.mul(mo.mul(slide_size, mo.mul(n, n)), base_comb);
    ll commit = mo.mul(i, times);

    ans = mo.add(ans, commit);
  }

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

  return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	char t;
	ll ans;
	cin>>ans;
	while(cin>>t){
		if(t=='='){
			cout<<ans<<endl;
			return 0;
		}
		
		else if(t=='+'){
			ll tmp;
			cin>>tmp;
			ans+=tmp;
		}
		else if(t=='-'){
			ll tmp;
			cin>>tmp;
			ans-=tmp;
		}
		else if(t=='*'){
			ll tmp;
			cin>>tmp;
			ans*=tmp;
		}
		else if(t=='/'){
			ll tmp;
			cin>>tmp;
			ans/=tmp;
		}
	}
}

Measured memory_bytes: 1156
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX

#include <bits/stdc++.h>

using namespace std;

#define db(x) cout << (x) << '\n';
#define all(x) x.begin(),x.end()
#define UNIQUE(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define LB(v,x) lower_bound(all(v),x)
#define UB(v,x) upper_bound(all(v),x)
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define PF push_front
#define int long long
#define double long double
#define trick int m = (l+r)>>1,lc=n<<1,rc=lc|1

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

int dy[]={0,1,1,1,0,-1,-1,-1};
int dx[]={-1,-1,0,1,1,1,0,-1};
const int maxn = 1e5;
const int OO = 1e18;
const int mod = 1e9 + 7;
const double PI = acos(-1);

void maxself(int &a,int b)
{a=max(a,b);}
void minself(int &a,int b)
{a=min(a,b);}


int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);

    int t;
    t = 1;
    while(t--)
    {
        int n,x,k;
        cin >> n >> x >> k;
        int a = n/x;
        if(n%x)
            a++;
        cout << a* k;
    }

	return 0;
}



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


int N;
vector<int> vec;

int main(int argc, char **argv)
{
	cin >> N;
	vec.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> vec[i];

	int alice{0};
	int bob{0};

	for (int i = 0; i < N; ++i)
	{
		auto max_p = max_element(vec.begin(), vec.end());

		if (i % 2 == 0) alice += *max_p;
		else bob += *max_p;

		*max_p = 0;
	}

	std::cout << (alice - bob) << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

ll f(ll n) {
  ll b = (((n+1) / 2) % 2 == 0 ? 0 : 1);
  if((n+1) % 2 != 0) {
    b ^= n;
  }
  
  return b;
}

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  ll A, B;
  cin >> A >> B;
  if(A > 0) {
    fin(f(A - 1) ^ f(B));
  } else {
    fin(f(B));
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <string>
#include <map>
#include <iterator>
#include <set>
#include <queue>
#include <bitset>
#include <cassert>

using namespace std;


int enum_divisors(int N) {
    int res = 0;

    for (int i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res += 1;
            if (N / i != i) {
                res += 1;
            }
        }
    }
    return res;
}

int main() {

    int N;
    cin >> N;
    long res = 0;
    for (int c = 1; c < N; ++c) {
        res += enum_divisors(N - c);
    }

    cout << res << endl;

    return 0;

}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <limits>
#include <iomanip>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)

ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

int main() {
    ll n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    ll l = n*m/gcd(n, m);

    ll p = l/n;
    ll q = l/m;
    ll r = p*q/gcd(p, q);
    for(ll i = 0; i < l; i+=r) {
        if(!(s.at(i/p) == t.at(i/q))) {
            cout << -1 << endl;
            return 0;
        }
    }
    //
    cout << setprecision(20) << l << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
//    std::sort(a.begin(), a.end(), std::greater<int>() );
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    string hoge;
    cin>>hoge;
    cout<<hoge[0];
    cout<<hoge.size()-2;
    cout<<hoge[hoge.size()-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
data = input().split(" ")
x = int(data[0])
y = int(data[1])
g1 = [1,3,5,7,8,10,12]
g2 = [4,6,9,11]
if x in g1 and y in g1:
	print("Yes")
elif x in g2 and y in g2:
	print("Yes")
else:
	print("No")
	

Measured memory_bytes: 2940
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        if(s == 60 || s > 60){
            int m = s/60;
            if(m == 60 || m >60){
                int h = m/60;
                int mr = m-60*h;
                int sr = s-(3600*h+60*mr);
                System.out.println(h+":"+mr+":"+sr);
            }
            else{
                int sr = s-60*m;
                System.out.println("0:"+m+":"+sr);
                System.exit(0);
            }
        }
        else if(s != 0){
            System.out.println("0:0:"+s);
            System.exit(0);
        }
        else{
            System.out.println("0:0:0");
        }
    }
}


Measured memory_bytes: 26260
n=int(input())
A=[int(input()) for _ in range(n)]
m1, m2=0, 0
for a in A:
  if a >= m1:
    m1, m2 = a, m1
  elif a >= m2:
    m2=a
for a in A:
  if a==m1:
    print(m2)
  else:
    print(m1)

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

class Main {

	void solve() {

		out.println(inint() - inint() + 1);
		
	}
	
	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);
	
	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}
	
	public int inint() {
		return in.nextInt();
	}
	
	public String instr() {
		return in.next();
	}

	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}
	
	public char[] incharar() {
		return in.next().toCharArray();
	}
	
}

Measured memory_bytes: 23764
n = int(input())
ns = 0
ew = 0
meirei = list(input())
for i in range(n) :
    if 65 <= ord(meirei[i]) <= 77 :
        ns += 1
    elif 78 <= ord(meirei[i]) <= 90 :
        ns -= 1
    elif 97 <= ord(meirei[i]) <= 109 :
        ew += 1
    else :
        ew -= 1
print(abs(ns) + abs(ew))
if ns > 0 :
    print('A' * ns, sep='', end='')
elif ns < 0 :
    print('Z' * (-ns), sep='', end='')
if ew > 0 :
    print('a' * ew, sep='', end='')
elif ew < 0 :
    print('z' * (-ew), sep='', end='')
print()


Measured memory_bytes: 6508
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=1e6;
string s[maxn];
int main(){
	int n,A=0,B=0,AB=0,sum=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s[i];
		int len=s[i].size()-1;
		for(int j=1;j<=len;j++){
			if(s[i][j]=='B'&&s[i][j-1]=='A') sum++;
		}
		if(s[i][0]=='B'&&s[i][len]=='A'){
			AB++;continue;
		}
		if(s[i][0]=='B'){
			B++;continue;
		}
		if(s[i][len]=='A'){
			A++;continue;
		}
	}
	int ans=0;
	if(AB>0){
		if(A>0||B>0){
			A--; B--;
			ans+=2;AB--;			
		}
		else AB--;
	}
	ans+=min(A,B)+AB+sum;
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#define pb push_back
#define fi first
#define se second
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;

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

    cout << n*(n-1)/2;

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int dp[100010][3];
int N;
int p[100010][3];

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

	cin >> N;
	rep(i, 0, N)rep(j, 0, 3)cin >> p[i][j];

	rep(i, 0, N)
	{
		rep(j, 0, 3)
		{
			dp[i + 1][j] += p[i][j];
			int maxi = 0;
			rep(k, 0, 3)
			{
				if (j == k)continue;
				chmax(maxi, dp[i][k]);
			}
			dp[i + 1][j] += maxi;
		}
	}

	int ans = 0;
	rep(i, 0, 3)
	{
		chmax(ans, dp[N][i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
std::vector<ll> v;
std::vector<ll> v2;
ll digits(ll n)
{
  ll count=0;
  while(n>0)
  {
      n/=10;
      count++;
  }
  return count;
}

void function1(ll n)
{
  ll x;
  for(ll i=1;i<=sqrt(n);i++)
  {
    if(n%i==0)
    {
      if(n/i==0)
      {
        x=digits(i);
        v2.push_back(x);
      }
      else
      {
        x=digits(i);
        v.push_back(x);
        x=digits(n/i);
        v.push_back(x);
      }
    }
  }
}


int main()
{
  ll n;
  cin >> n;
  function1(n);
  ll x=1000000000,y;
  for(int i=0;i<v.size();i+=2)
  {
    y=max(v[i],v[i+1]);
    if(y<x)
      x=y;
  }
  for(int i=0;i<v2.size();i++)
  {
    y=v2[i];
    if(y<x)
      x=y;
  }
  cout << x << endl;
  return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  int sum = 0;
  for(int i=0; i<M; i++){
    int tmp=0;
    cin >> tmp;
    sum +=tmp;
  }
  if(sum>N){
    cout << -1 << endl;
    return 0;
  }
  else{
    cout << N - sum << endl;
  }
}

//cout << fixed << setprecision(10) << (long double)2*sum/(long double)N << endl;


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#define rep(i, a, b) for(int i = a; i < b; i++)
using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> v(h+2, vector<char>(w+2,'.'));
  rep(i, 1, h+1) {
    rep(j, 1, w+1) {
      cin >> v[i][j];
    }
  }
  rep(i, 1, h+1) {
    rep(j, 1, w+1) {
      if(v[i][j] == '#') {
        if(!(v[i-1][j] == '#' || v[i][j-1] == '#' || v[i+1][j] == '#' || v[i][j+1] == '#')) {
          cout << "No\n";
          return 0;
        }
      }
    }
  }
  cout << "Yes\n";
  return 0;
}

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

int main(){

int L, R, d;
cin >> L >> R >> d;

int m =0;
for(int i=L;i<=R;++i){

    if(i%d==0){
        m=m+1;
    }
}


cout << m;

return 0;

    
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 123456789012

int main(){
    ll n,a,b,c,i,j;
    cin>>n>>a>>b>>c;
    ll l[n];
    for(i=0;i<n;i++){
        cin>>l[i];
    }
    ll ans=INF;
    ll N=1<<(2*n);
    for(i=0;i<N;i++){
        ll k=i;
        ll tem=0;
        vector<ll> v(4,0);
        for(j=0;j<n;j++){
            if((k%4)<3&&v[k%4]>0) tem+=10;
            v[k%4]+=l[j];
            k=k/4;
        }
        if(v[0]==0||v[1]==0||v[2]==0) continue;
        ans=min(ans,tem+abs(v[0]-a)+abs(v[1]-b)+abs(v[2]-c));
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to)

int main() {
	int n;
	cin >> n;
	while(n--) {
		char s[10];
		cin >> s;
		sort(s,s+8);
		int min = atoi(s);
		sort(s,s+8,greater<int>());	
		int max = atoi(s);
		cout << max - min << endl;
	}
	return 0;
}

Measured memory_bytes: 1192
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
for x in a:
    d[x] += 1
b = [i for i in range(n)[::-1]]
if not all([d[i] == 2, d[i] == 1][n % 2 and i == 0] for i in b[::2]):
    print(0)
else:
    ans = 1
    for v in d.values():
        ans = ans * v % (10**9+7)
    print(ans)

Measured memory_bytes: 15200
#include <cstdio>
#include <cmath>
#include <algorithm>
 
using namespace std;
 
#define MAX 10
typedef long long ll;
 
ll d[MAX],v[MAX];
 
ll gcd(ll a,ll b){
  return __gcd(a,b);
}
 
ll lcm(ll a,ll b){
  return a * b / gcd(a,b);
}
 
int main(){
  int n;
 
  while(scanf("%d" ,&n) ,n){
    for(int i = 0 ; i < n ; i++){
      scanf("%lld %lld" ,&d[i] ,&v[i]);
      ll a = gcd(d[i],v[i]);
      d[i] /= a;
      v[i] /= a;
    }       
     
    ll T = d[0],V = v[0];
    for(int i = 1 ; i < n ; i++){
      T = lcm(T,d[i]);
      V = gcd(V,v[i]);
    }
     
    for(int i = 0 ; i < n ; i++){
      ll div = T / d[i];
      printf("%lld\n" ,div*v[i]/V);
    }
  }
   
  return 0;
}

Measured memory_bytes: 1032
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>
#include <math.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define RREP(i,n) for(int i=(n)-1; i>=0; --i)
#define SREP(i,s,n) for(int i=(s), i##_len=(n); i<i##_len; ++i)


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

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

bool comp(pair<ll, ll> a, pair<ll, ll> b) {
    return (a.first*a.first + a.second*a.second) > (b.first*b.first + b.second*b.second);
}

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    
    UnionFind(int n = 1) {
        init(n);
    }
    
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
        }
    }
    
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

#define MOD (1000000007)

ll d2(pair<ll, ll> p) {
    return p.first*p.first+p.second*p.second;
}

int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N;
    cin >> N;
    cout << N*N*N << endl;
    return 0;
}


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


int main()
{
	ll lef, rig;
	cin >> lef >> rig;
	if (lef <= 2019 && rig >= 2019)
	{
		cout << 0;
		return 0;
	}
	ll min = 2020;
	for (ll i = lef; i <= rig; i++)
	{
		if (i % 2019 == 0)
		{
			cout << 0;
			return 0;
		}
	}
	//
	for (ll i = lef; i <= rig; i++)
	{
		for (ll j = i + 1; j <= rig; j++)
		{
			if (((i*j) % 2019) < min)
				min = ((i*j) % 2019);
		}
	}
	cout << min;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <functional>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

void Main();

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(10);
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  Main();
#ifdef LOCAL
  cout << "\nTime: " << (int)ceil((double)1000 * clock() / CLOCKS_PER_SEC) << " ms";
#endif
}

const int N = 10'000'000 + 228;
int f[N];

void precalc() {
  for (int i = 1; i <= N; i++) {
    for (int j = i; j <= N; j += i) {
      f[j]++;
    }
  }
}

void Main() {
  precalc();
  int n;
  cin >> n;
  ll ans = 0;
  for (int k = 1; k <= n; k++) {
    ans += 1ll * k * f[k];
  }
  cout << ans << '\n';
}

Measured memory_bytes: 42696
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

template <class T = usize> class rep {
	const T f, l;

public:
	class itr {
		friend rep;
		T i;
		itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		T operator*() const noexcept { return i; }
		bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	rep(const T first, const T last) noexcept : f(first), l(last) {}
	itr begin() const noexcept { return itr(f); }
	itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
	const T f, l;

public:
	class itr {
		friend revrep;
		T i;
		itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		T operator*() const noexcept { return i; }
		bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	revrep(const T first, const T last) noexcept : f(first), l(last) {}
	itr begin() const noexcept { return itr(l - 1); }
	itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool maxi(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool mini(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool smaxi(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool smini(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }

#include <algorithm>
#include <iostream>
#include <utility>

int main() {
	usize n;
	::std::cin >> n;
	for (const auto i : rep<>(1, 1000)) {
		if (i*(i - 1) / 2 == n) {
			::std::cout << "Yes" << ::std::endl;
			::std::cout << i << ::std::endl;
			auto v = md_vec(i, 0, usize(0));
			usize cnt = 0;
			for (const auto j : rep<>(0, i)) {
				for (const auto k : rep<>(j+1,i)){
					v[j].push_back(++cnt);
					v[k].push_back(cnt);
				}
			}
			for (const auto& x : v) {
				::std::cout << x.size();
				for (const auto e : x) {
					::std::cout << " " << e;
				}
				::std::cout << ::std::endl;
			}
			return 0;
		}
	}

	::std::cout << "No" << ::std::endl;
	return 0;
}


Measured memory_bytes: 3200
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>
#include <string.h>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long

using namespace::std;

int jo(ll int jxo, ll int jyo){
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){
  return (toxbig-0x20);
}
char tolow(char toxlow){
  return (toxlow+0x20);
}
  


int main(){
  int a,b;
  cin>>a>>b;
  cout<<(b%a?(b-a):(b+a));
}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 256