akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        int[][] a = new int[3][3];
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++){
                a[i][j] = stdIn.nextInt();
            }
        }
        int n = stdIn.nextInt();
        int[] b = new int[n];
        for(int i = 0; i < n; i++){
            b[i] = stdIn.nextInt();
        }

        int[][] map = {{0,0,0}, {0,0,0}, {0,0,0}};

        for(int k = 0; k < n; k++){
            for(int i = 0; i < 3; i++){
                for(int j = 0; j < 3; j++){
                    if(a[i][j] == b[k]) map[i][j] = 1;           
                }
            }
        }
        boolean flag = false;
        if(map[0][0] == 1 && map[0][1] == 1 && map[0][2] == 1) flag = true;
        if(map[1][0] == 1 && map[1][1] == 1 && map[1][2] == 1) flag = true;
        if(map[2][0] == 1 && map[2][1] == 1 && map[2][2] == 1) flag = true;
        if(map[0][0] == 1 && map[1][0] == 1 && map[2][0] == 1) flag = true;
        if(map[0][1] == 1 && map[1][1] == 1 && map[2][1] == 1) flag = true;
        if(map[0][2] == 1 && map[1][2] == 1 && map[2][2] == 1) flag = true;
        if(map[0][0] == 1 && map[1][1] == 1 && map[2][2] == 1) flag = true;
        if(map[2][0] == 1 && map[1][1] == 1 && map[0][2] == 1) flag = true;
        if(flag == true){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

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

int main(){
    long long int n, t;
    cin >> n >> t;

    long long int bt;
    cin >> bt;

    long long int ans = 0;
    for(int i=1;i<n;++i){
        long long int tmp;
        cin >> tmp;
        ans += min(t, tmp - bt);
        bt = tmp;
    }
    ans += t;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

#n,*a = [int(i) for i in read().split()]
n = int(input())
a = [int(i) for i in input()]

n -= 1
d = [abs(i-j) for i,j in zip(a,a[1:])]

p2 = [0]
for i in range(1,n+2):
    r = p2[-1]
    while i&1==0:
        r += 1
        i >>= 1
    p2.append(r)    

def choose(n,k):
    if p2[n] > p2[k]+p2[n-k]: return 0
    else: return 1

#print([choose(n,k) for k in range(n+1)])

par = sum(choose(n-1,i)*di for i, di in enumerate(d))%2

if par == 1:
    print(1)
else:
    if 1 in d: print(0)
    else:
        d = [di>>1 for di in d]
        par = sum(choose(n-1,i)*di for i, di in enumerate(d))%2
        
        if par == 0:
            print(0)
        else:
            print(2)
        
        
        








Measured memory_bytes: 131676
// Probably getting a WA/Tle
// Still trying
// Apna time ayega

#include<bits/stdc++.h>
#define ll long long int
#define FastRead ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0);
using namespace std;
int main()
{
    ll n,l,a,b,m,k,i,j;
    cin>>a>>b;
    if(a>=b)cout<<min(a%b,b-(a%b))<<endl;
    else cout<<min((b-a),a)<<endl;


    return 0;
}


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

int main(){
	char str[100];
	int length;
	int i;
	scanf("%s",&str);
	length = strlen(str);
	for(i=length-1;i>=0;i--){
		printf("%c",str[i]);
	}
	printf("\n");
	return 0;
}

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

using namespace std;

const int maxn = 110;
int n,m,a[maxn],cnt,a1,a2;

bool cmp(int x,int y)
{
    if (x % 2 == 1 && y % 2 == 0)
        return true;
    return false;
}

int main()
{
    scanf("%d%d",&n,&m);
    for (int i = 1; i <= m; i++)
    {
        scanf("%d",&a[i]);
        if (a[i] % 2 == 1)
            cnt++;
    }
    if (cnt > 2)
    {
        puts("Impossible");
        return 0;
    }
    sort(a + 1,a + 1 + m,cmp);
    if (a[2] % 2 == 1)
        swap(a[2],a[m]);
    for (int i = 1; i <= m; i++)
        printf("%d ",a[i]);
    printf("\n");
    if (m == 1)
    {
        if (a[1] != 1)
        {
            printf("%d\n",2);
            printf("%d %d\n",a[1] - 1,1);
        }
        else
        {
            printf("%d\n",1);
            printf("%d\n",1);
        }
    }
    else
    {
        if (a[1] != 1)
        {
            printf("%d\n",m);
            printf("%d ",a[1] - 1);
            for (int i = 2; i < m; i++)
                printf("%d ",a[i]);
            printf("%d\n",a[m] + 1);
        }
        else
        {
            if (m != 2)
            {
                printf("%d\n",m - 1);
                printf("%d ",a[2]);
                for (int i = 3; i < m; i++)
                    printf("%d ",a[i]);
                printf("%d\n",a[m] + 1);
            }
            else
            {
                printf("%d\n",1);
                printf("%d\n",a[2] + 1);
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val S = readLine()!!
    val a = mutableListOf<Int>()
    for (i in 0 until S.length - 2) {
        a.add(Math.abs(S.substring(i, i + 3).toInt() - 753))
    }
    println(a.min())
}

Measured memory_bytes: 33532
#include <iostream>
#include <vector>

using namespace std;

const int NMAX = 100000 + 5;

int N, K;
int a[NMAX];

vector <int> graph[NMAX];

int h[NMAX];

int ans;
void dfs(int node) {
    for (auto it: graph[node]) {
        dfs(it);
        if (h[it] == K - 1)
            ans += (node > 1);
        else
            h[node] = max(h[node], 1 + h[it]);
    }
}

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

    cin >> N >> K;
    for (int i = 1; i <= N; ++ i)
        cin >> a[i];

    ans = (a[1] > 1);
    for (int i = 2; i <= N; ++ i)
        graph[a[i]].push_back(i);
    dfs(1);

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 11136
import sys
import math

n, m = [int(x) for x in sys.stdin.readline().rstrip().split()]
h = [int(x) for x in sys.stdin.readline().rstrip().split()]

ipt = sys.stdin.readlines()
dic = {str(x):True for x in range(1, n + 1)}

for x in ipt:
  a, b = [int(y) for y in x.split()]
  _a = h[a - 1]
  _b = h[b - 1]
  if _a  > _b:
    dic[str(b)] = False
  elif _a == _b:
    dic[str(a)] = False
    dic[str(b)] = False
  else:
    dic[str(a)] = False

li = list(dic.values())
print(li.count(True))

Measured memory_bytes: 34364
s = input()
s = list(s)
t = input()
ok_num = []
for i in range(len(s) - len(t) + 1):
  check = True
  s_part = s[i:i+len(t)]
  for j in range(len(t)):
    if s_part[j] != "?" and s_part[j] != t[j]:
      check = False
  if check == True:
    ok_num.append(i)  
if len(ok_num) == 0:
  print("UNRESTORABLE")
else:
  for i in range(len(t)):
    s[max(ok_num) + i] = t[i]
  for  j in range(len(s)):
    if s[j] == "?":
      s[j] = "a"
      
  print("".join(s))
  

  

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

UL N,M;
vector<UL> E[10000];
vector<UL> rE[10000];
UL I[10000];
UL rI[10000];
UL P[10000];
UL H[10000];
ULL ans = 0;

UL DFS1(UL p,UL i=0){
 for(UL e:E[p]){
  if(P[e]!=~0u) continue;
  P[e]=p;
  i = DFS1(e,i);
 }
 I[p]=i; rI[i]=p; ++i;
 return i;
}

void DFS2(UL p,UL s){
 if(rI[I[p]]!=p) return;
 H[p]=s;
 for(UL e:rE[p]){
  if(I[e]>I[s]) continue;
  if(H[e]!=~0u) continue;
  DFS2(e,s);
 }
}

int main(){
 scanf("%u%u",&N,&M);
 rep(i,M){
  UL u,v; scanf("%u%u",&u,&v);
  E[u].push_back(v);
  rE[v].push_back(u);
 }
 rep(i,N) P[i]=I[i]=H[i]=~0u;
 rep(i,N){
  if(P[i]!=~0u) continue;
  P[i]=i;
  UL Z = DFS1(i);
  for(UL i=Z-1; i!=~0u; i--) if(H[rI[i]]==~0u) DFS2(rI[i],rI[i]);
 }

 UL Q; scanf("%u",&Q);
 rep(q,Q){
  UL u,v; scanf("%u%u",&u,&v);
  if(H[u]==H[v]) printf("1\n");
  else printf("0\n");
 }

 return 0;
}



Measured memory_bytes: 4924
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int calc(string s){
    int res=0;
    rep(i,s.size()){
        res+=s[i]-'0';
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    
    int ans=calc(s);
    rep(i,s.size()){
        if(i==0){
            s[i]--;
        }else{
            s[i]='9';
        }
    }
    chmax(ans,calc(s));
    cout1(ans)
}

Measured memory_bytes: 768
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  int n;
  cin >> n;
  
  int dai=0;
  int ans;
  rep(i,n){
  int x,y;
  cin>>x>>y;
    if(dai<x) ans=x+y;
    dai=max(dai,x);
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <stdint.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string.h>
#include <set>
using namespace std;
 
#define int long long
 
 
int gcd(int a, int b){
	
	if(b==0){
		return a;
	}
	
	return gcd(b,a%b);
	
}
 
 int lcm(int a, int b)  
 {  
    return (a*b)/gcd(a, b);  
 }  
 
 
int f(int x){
	
	
	int res = 0;
	
	while( x%2 == 0){
		
		x/=2;
		res++;
	}
	
	return res;
	
}
int g[16][16];
 
int32_t main() {
 	
 
 	
 	int n;
 	
 	cin >> n;
 	
 	for(int i=0; i<n; i++){
 		
 		for(int j=0; j<n; j++){
 			
 			g[i][j] = -1;
 			
 			
 			
		}
 		
	 }
 		
 		
 		
 		
 	for(int i=0; i<n; i++){
 		
 		int m;
 		cin >> m;
 	 
 		for(int j=0; j<m; j++){	
		 	int x, y;		 
			cin >> x >> y;	
			x--;		
		 	g[i][x] = y;
		}
 		
	 }
 
 	 int ans =0 ;
	  
	  for(int i=0; i< 1<<n; i++ ){
	  	
	  	vector<int> d(n);
	  	
	  	for(int  j=0; j<n; j++){
	  		int f = 1 << j;
		  if(i & f) {
		  	d[j] = 1;
		  }	
	  		
		}
	  	
	  	bool ok =true;
	  	for(int j=0; j<n; j++){
	  		
	  		if(d[j]){
	  			
	  			for(int k=0; k<n; k++){
	  			
				  	if(g[j][k] == -1)
				  		continue;
	  				if(g[j][k] != d[k])
	  					ok = false;
				}
	  			
			}
		  	
		}
	  	
	  			  	
		  	if(ok){
		  		int tmp = __builtin_popcount(i);
			  	if(tmp > ans){
			  		ans = tmp;
				}
		  	 
		  	}
	  	 
	  } 
 	 
 	  	cout << ans << endl;
 	  
 	  
}
 
 
 

Measured memory_bytes: 3152
#include <iostream>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <map>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define setpre(n) fixed << setprecision(n)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  ll intCount=0;
  ll dp[100][100]={0};
  ll a[LIMIT2]={0};
  ld b;
  string s;
  
  cin >> n;
  rep(i,n){
    cin >> b;
	a[i] = (b*1000000000)+0.5;
    ll tmp=a[i];
    ll cnt2=0,cnt5=0;
    while(tmp%2==0){
      tmp/=2;
      cnt2++;
    }
    while(tmp%5==0){
      tmp/=5;
      cnt5++;
    }
    cnt2-=9;//
    cnt5-=9;//1e9(ABCD.000000000)
    for(j=0;j<60;j++){
      for(k=0;k<60;k++){
        if(j+cnt2>=15 && k+cnt5>=15) result += dp[j][k];
      }
    }
    dp[cnt2+15][cnt5+15]++;
    //cout << i << " " << cnt2 << " " << cnt5 << endl;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3840
#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use proconio::marker::{Isize1, Usize1, Bytes, Chars};

#[proconio::fastout]
fn main() {
    proconio::input!{
        x: u128, 
    }
    let mut z = 100;
    for y in 0.. {
        if x <= z {
            println!("{}", y);
            return;
        }
        z = ((z as f64) * 1.01f64).floor() as u128;
    }
}



Measured memory_bytes: 2696
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int S; cin >> S;
    cout << "0 0 ";
    int base = 1e9;
    int div = S / base + (S % base != 0);
    int dif = div * base - S;
    assert(dif >= 0 and dif <= base);
    cout << base << " " <<  dif;
    cout << " 1 " << div << endl;
    
    
}


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

using namespace std;

typedef long long ll;

ll com[70][70];

ll nCr(int n, int r){
        return com[n][r];
}

int main(){
        int N;
        cin>>N;
        for(int i=0;i<=66;i++){
                for(int j=0;j<=i;j++){
                        if(j==0||j==i){
                                com[i][j]=1LL;
                        }
                        else{
                                com[i][j]=com[i-1][j-1]+com[i-1][j];
                        }
                }
        }
        ll a, b;
        cin>>a>>b;
        vector <ll> v(N);
        for(int i=0;i<N;i++){
                cin>>v[i];
        }
        sort(v.begin(), v.end());
        reverse(v.begin(), v.end());
        ll sum=0;
        ll mi;
        for(int i=0;i<a;i++){
                sum+=v[i];
                if(i==a-1)mi=v[i];
        }
        cout<<setprecision(10)<<(double)sum/(double)(a)<<endl;
        bool update=true;
        for(int i=0;i<a;i++){
                if(v[i]!=mi)
                        update=false;
        }
        int cnta=0, cntb=0, cnt=0;
        for(int i=0;i<a;i++){
                if(v[i]==mi)
                        cnta++;
        }
        for(int i=0;i<b;i++){
                if(v[i]==mi)
                        cntb++;
        }
        for(int i=0;i<N;i++){
                if(v[i]==mi)
                        cnt++;
        }
        ll res=0;
        for(int i=cnta;i<=(update?cntb:cnta);i++){
                res+=nCr(cnt, i);
        }
        cout<<res<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int c1,c5,c10,c50,c100,c500,sum;
  scanf("%d %d %d %d %d %d",&c1,&c5,&c10,&c50,&c100,&c500);
  sum=c1*1+c5*5+c10*10+c50*50+c100*100+c500*500;
  if(sum>=1000)
    printf("1\n");
  else
    printf("0\n");
  return 0;
}

Measured memory_bytes: 1804
#include<stdio.h>
#include<string.h>
int max(int a,int b){
  if(a > b)return a;
  return b;
}
int min(int a,int b){
  if(a < b)return a;
  return b;
}
int zet(int a){
  if(a > 0)return a;
  return -a;
}
void swap(int *x,int *y) {
  int temp = *x;
  *x = *y;
  *y = temp;
}
int partition(int array[],int left,int right) {
  int i,j,pivot;
  i = left;
  j = right + 1;
  pivot = left;
  do{
    do{ i++; } while(array[i] < array[pivot]);
    do{ j--; } while(array[pivot] < array[j]);
    if(i < j)swap(&array[i],&array[j]);
  }while (i < j);
  swap(&array[pivot],&array[j]);
  return j;
}
void quick_sort(int array[],int left,int right) {
  int pivot;
  if(left < right) {
    pivot = partition(array,left,right);
    quick_sort(array,left,pivot-1);
    quick_sort(array,pivot+1,right);
  }
}
int main(void){
  int n,cnt = 0;
  scanf("%d",&n);
  int a[n],b,c;
  for(int i = 0;i < n;i++){
    scanf("%d",&a[i]);
  }
  for(int i = 0;i < n;i++){
    scanf("%d",&b);
    c = a[i] - b;
    if(c > 0){
      cnt += c;
    }
  }
  printf("%d\n",cnt);
  return 0;
}

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

 
int main() {
    int x,y,z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,ai,ans=0;
	cin >>n;
	map<int,int> mp[2];
	for(int i=0;i<n;++i){
		cin >>ai;
		++mp[i&1][ai];
	}
	pair<int,int> p1[2],p2[2];
	for(int i=0;i<2;++i){
		for(map<int,int>::iterator it=mp[i].begin();it!=mp[i].end();++it){
			pair<int,int> p={it->second,it->first};
			if(p>p1[i])
				swap(p,p1[i]);
			if(p>p2[i])
				swap(p,p2[i]);
		}
	}
	if(p1[0].second!=p1[1].second)
		ans=p1[0].first+p1[1].first;
	else
		ans=max(p1[0].first+p2[1].first,p2[0].first+p1[1].first);
	cout <<n-ans;
}


Measured memory_bytes: 8280
/*
 * じょえチャンネル
 * 高評価・チャンネル登録よろしくおねがいします！
 * https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
 */
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define inf (int)(3e18)
#define P pair<int,int>
#define mod (int)(1e9+7)
template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}

int N;
vector<int>dp[15][15];
vector<string>res;
void out(int x){
	string ans="";
	rep(i,N){
		ans.push_back((char)('a'+(x%10)));
		x/=10;
	}
	reverse(all(ans));
	res.push_back(ans);
}
signed main() {
	cin>>N;
	dp[1][0].push_back(0);
	REP(i,N){
		rep(j,i){
			rep(k,j+2){
				for(int l:dp[i][j]){
					dp[i+1][max(j,k)].push_back(l*10+k);
				}
			}
		}
	}
	rep(i,N){
		for(int j:dp[N][i]){
			out(j);
		}
	}
	sort(all(res));
	for(string s:res)cout<<s<<endl;
	cerr<<(int)res.size()<<endl;
}


Measured memory_bytes: 8964
import Data.Maybe
import Data.List

main :: IO ()
main = do
  input <- getContents
  putStrLn $ trim (solve (trim input))

--処理
solve :: String -> String
solve s | b - a == c - b = "YES"
        | otherwise      = "NO"
  where [a, b, c] = fmap read (words s) :: [Int]

trimHead :: String -> String
trimHead = dropWhile (\s -> isJust (elemIndex s [' ', '\t', '\n', '\r']))

trim :: String -> String
trim = reverse . trimHead . reverse . trimHead

Measured memory_bytes: 508
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;

int n;
int p[MAXN];

void run() {
	scanf("%d",&n); REP(i,n) scanf("%d",&p[i]),--p[i];
	int ret=0; bool prev=false;
	REP(i,n) {
		if(p[i]==i) {
			if(prev) prev=false; else ++ret,prev=true;
		} else {
			prev=false;
		}
	}
	printf("%d\n",ret);
}

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


Measured memory_bytes: 640
import numpy as np

n = int(input())
a = np.array(list(map(int,input().split())))
ans = np.array([])

max_num = max(a)
min_num = min(a)

for i in range(min_num,max_num+1):
  ans = np.append(ans, sum((a-i)**2))

print(int(min(ans)))

Measured memory_bytes: 12504
/*B - TAKOYAKI FESTIVAL 2019*/

#include <bits/stdc++.h>

using namespace std;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int ans = 0;
	int nums;
	cin >> nums;

	vector <int> arr(nums);

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

	for (int i = 0; i < nums; ++i)
		for (int j = i + 1; j < nums; ++j)
			if(i != j)
				ans+= (arr[i]*arr[j]);
				
	cout << ans;

	return 0;
}

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

typedef pair<int,int> PII;

int main(void){
  vector<PII> v;
  int p,s,q;
  char cmm; // to skip reading camma
  
  // regist
  while (cin >> p >> cmm >> s){
    if (p==0 && s==0) break;
    v.push_back(make_pair(s,p));
  }
  // sort by score (desc.)
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  // query
  while (cin >> q){
    int rnk=1;
    for (int i=0; i<v.size(); i++){
      if (i!=0 && v[i].first != v[i-1].first) rnk++;
      if (v[i].second == q){
        cout << rnk << endl;
        break;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3004
#include <algorithm>
#include <array>
#include <climits> // INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX
#include <cmath>
#include <cstdint>
#include <cstring> // memset
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
#define LOG(x) cout << #x << " = " << (x) << endl
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

int main() {
    int r, g;
    cin >> r >> g;
    double p = 2.0 * g - r;

    cout << p << endl;
        
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

int main() {
    int n;
    string s;
    cin>>n>>s;
    int sum=0;
    for(int i=0;i<s.size()-2;i++){
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
			sum++;
		}
	}
	cout<<sum<<endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int A,B,T;
  cin >> A >> B >> T;
  cout << T/A*B << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
from operator import itemgetter #sortedの対象を決めたい
from fractions import gcd #最大公約数求めたい
from math import ceil, floor, sqrt #小数点切り上げ、切り捨て、平方根求めたい
from copy import deepcopy #参照で影響されないコピーが作られる
from collections import Counter, deque #要素ごとの出現回数を数える。双方向アクセス可能データ型
import heapq
from functools import reduce
sys.setrecursionlimit(200000)

input = sys.stdin.readline
# template


n,q = map(int, input().split())

ct = [0] * (n+1)
o = [0] * (n+1)
g = [[] for _ in range(n+1)]

for i in range(n-1):
    a,b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

for i in range(q):
    p,x = map(int, input().split())
    o[p] += x

todo = [1]
seen = [False] * (n+1)
while todo:
    p = todo.pop(-1)
    ct[p] += o[p]
    seen[p] = True
    for i in g[p]:
        if seen[i]:
            ct[p] += ct[i]
        else:
            todo.append(i)

print(*ct[1:])




Measured memory_bytes: 64548
import math

N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(int(N))]
cnt = 0

for i in range(N):
    for j in range(i+1, N):
        length = 0
        for x_i, x_j in zip(X[i], X[j]):
            length += (x_i-x_j)**2
        length = math.sqrt(length)
        if length == int(length):
            cnt += 1

print(cnt)

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

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

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

    for (int i = 0; i < N; i++) {
        if (X[i] <= v[N / 2 - 1]) {
            cout << v[N / 2] << endl;
        } else {
            cout << v[N / 2 - 1] << endl;
        }
    }
}

Measured memory_bytes: 3712
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iostream>
#include <utility>
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
 
using namespace std;
using ll = long long;
using ld = long double;
using Vl = vector<ll>;
using pll = pair<ll, ll>;
using vb = vector<bool>;
using vs = vector<string>;

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

ll N;
int main() {
    cin >> N;
    cout << pow(N,3);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
using namespace std;

int main() {
	long long n, y;
	cin >> n >> y;

	for (int i = 0;i <= n;i++) {
		for (int j = 0;j <= n-i;j++) {
			long long k = 10000 * i + 5000 * j + 1000 * (n - i - j);
			if (k == y) {
				cout << i << " " << j << " " << n - i - j << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;

}

Measured memory_bytes: 3620
#include <iostream>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if (a < b)cout << "a < b" << endl;
  if (a > b)cout << "a > b" << endl;
  if (a == b)cout << "a == b" << endl;
  return 0;
}

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

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

	int n; cin >> n;
	set<string> s;
	string word;
	while(n){
		cin >> word;
		s.insert(word);
		n--;
	}	
	cout << s.size();
	

}


Measured memory_bytes: 19248
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map> 
#include<iostream>
#include<time.h>
using namespace std;
typedef long long ll;
const double pi=acos(-1.0);
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;
//ll begin_time=clock();
//ll end_time=clock();printf("time=%lldms\n",end_time-begin_time);

int z[2020];
char x[200005];
int main()
{
	z[0]=1;
	scanf("%s",x);
	ll a=strlen(x);
	ll sum=0,b=0,c=1;
	for(ll i=a-1;i>=0;i--)
	{
		sum=(sum+ll(x[i]-'0')*c)%2019;
		b+=z[sum]++;
		c=c*10%2019;
	}
	printf("%lld\n",b);
}

Measured memory_bytes: 4020
#include<iostream>
#include<iomanip>
#include<limits>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>


using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9)+7)

ll gcd(ll a,ll b)
{
//   ll x = a*b;
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
  ll r;
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}



int main()
{
   int k;
   cin >> k;
   ll sum = 0;
   for(int i = 1;i <= k;i++)
   {
       for(int j = 1;j <= k;j++)
       {
           for(int l = 1;l <= k;l++)
           {
            //    cout << i << " " << j << " " << l << endl;
                sum += (gcd(gcd(i,j),l));
                // cout << sum << endl;
           }
       }
   }
   cout << sum << endl;
}


Measured memory_bytes: 3620
N, M = list(map(int,input().split()))
K = []
A = []
for i in range(N):
    ls = list(map(int,input().split()))
    K.append(ls[0])
    A.append(ls[1:K[i] + 1])

cnt = [0 for i in range(M)]
for i in range(M):
    for j in range(N):
        if (i + 1) in A[j]:
            cnt[i] += 1
print(cnt.count(N))

Measured memory_bytes: 3064
#include <stdio.h>

int main(){
    int n,p,i,j,x,a[50];
    while(1){
        scanf("%d %d\n",&n,&p);
        if (n==0&&p==0) break;
        x=p;
        for (i=0;i<n;i++) {
        a[i]=0;
        }
        i=0;
        while (x!=1||a[i%n]!=p-1) {
            j=i%n;
            if (x==0) {
                x=a[j];
                a[j]=0;
            }
            else {
                x--;
                a[j]++;
            }
            i++;
        }
        printf("%d\n",i%n);
        
    }
    return 0;
}

Measured memory_bytes: 604
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
    static void Main()
    {
        FastScanner sc = new FastScanner(Console.OpenStandardInput());
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] p = sc.intArray(N);
        Array.Sort(p);
        Console.WriteLine(p.Take(K).Sum());
        return;
    }
}

// FastScanner start
public class FastScanner
{
    public readonly Stream str;
    private readonly byte[] buf = new byte[1024];
    private int len, ptr;
    public bool isEof = false;
    public FastScanner(Stream stream)
    {
        str = stream;
    }
    private T[] enumerate<T>(int n, Func<T> f)
    {
        var a = new T[n];
        for (int i = 0; i < n; ++i) a[i] = f();
        return a;
    }
    public char nextChar()
    {
        byte b = 0;
        do
        {
            b = read();
        }
        while ((b < 33 || 126 < b) && !isEof);
        return (char)b;
    }
    public int nextInt()
    {
        return (isEof) ? int.MinValue : (int)nextLong();
    }
    public long nextLong()
    {
        if (isEof)
        {
            return long.MinValue;
        }
        long ret = 0;
        byte b = 0;
        var ng = false;
        do
        {
            b = read();
        }
        while (b != '-' && (b < '0' || '9' < b));
        if (b == '-')
        {
            ng = true;
            b = read();
        }
        for (; true; b = read())
        {
            if (b < '0' || '9' < b)
            {
                return ng ? -ret : ret;
            }
            else ret = ret * 10 + b - '0';
        }
    }
    public int[] intArray(int n)
    {
        return enumerate(n, nextInt);
    }
    public long[] longArray(int n)
    {
        return enumerate(n, nextLong);
    }
    public char[] charArray(int n)
    {
        return enumerate(n, nextChar);
    }
    public string Scan()
    {
        var sb = new StringBuilder();
        for (var b = nextChar(); b >= 33 && b <= 126; b = (char)read())
        {
            sb.Append(b);
        }
        return sb.ToString();
    }
    private byte read()
    {
        if (isEof)
        {
            return 0;
        }
        if (ptr >= len)
        {
            ptr = 0;
            if ((len = str.Read(buf, 0, 1024)) <= 0)
            {
                isEof = true;
                return 0;
            }
        }
        return buf[ptr++];
    }
}
// FastScanner end

Measured memory_bytes: 26508
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iostream>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n)	 for(int i = 0; i < (n); i++)
#define all(a)		 begin(a), end(a)

typedef long long int		   ll;
typedef long long unsigned int llu;

void solve(ll N, vector <ll> a) {
	sort(all(a));
	int sum = 0;
	rep(i, N - 1) {
		sum += (a[i + 1] - a[i]);
	}
	printf("%d", sum);
}

int main() {
	ll N;
	scanf("%lld", &N);
	vector <ll> a(N - 1 + 1);
	for(int i = 0; i <= N - 1; i++) {
		scanf("%lld", &a[i]);
	}
	solve(N, a);
	return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

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

void Main() {
    ll a;
    string b;
    cin >> a >> b;
	int c = 100*(b[0]-'0') + 10*(b[2]-'0') + (b[3]-'0');	
  
    cout << a*c/100 << endl;
	return;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 3596
N, Q = gets.split.map(&:to_i)
S = gets.chomp
ls = Array.new(Q)
rs = Array.new(Q)
Q.times do |i|
  ls[i], rs[i] = gets.split.map(&:to_i)
end

sum_array = Array.new(S.length)
sum_array[0] = 0
sum = 0
(S.length - 1).times{|x|
  if S[x..(x+1)] == "AC"
    sum = sum + 1
  end
  sum_array[x+1] = sum
}

Q.times{|x|
  puts sum_array[rs[x]-1] - sum_array[ls[x]-1]
}


Measured memory_bytes: 4860
t = gets.to_i
t.times {
    n = gets.to_i
    a = gets.split.map &:to_i
    up = a.each_cons(2).map{|x, y| [y - x, 0].max}.max
    down = a.each_cons(2).map{|x, y| [x - y, 0].max}.max
    puts "#{up} #{down}"
}

Measured memory_bytes: 6120
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9+7, A = 1e3+5;

int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n;
	cin >> n;
	ll mn = 2e9;
	for (int i = 0; i < n; i++)
	{
		ll x, cnt = 0;
		cin >> x;
		while(x % 2 == 0)
			x /= 2, cnt++;
		mn = min(mn, cnt);
	}
	cout << mn;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <algorithm>
using namespace std;
int main()
{
	char num[40005];
	int  n;
	while(cin>>n)
	{
		stack <int> s;
		int a;
		if(n == 0)
		cout<<0<<endl;
		else
		{
			while(n!=0)
		{
		a = abs(n%(-2));
		s.push(a);
		n = (n-a) / (-2);
		}
		}
		while(!s.empty())
		{
			cout<<s.top();
			s.pop();
		}
		cout<<"\n";
	}
	return 0;
}


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

bool judge;
string s,tar;

void rec(int ind,int t_ind,int dis,int prev){
    if(ind == s.size()){judge = true; return;}
    if(t_ind == tar.size()) return;;
    if(s[ind] == tar[t_ind] && ind == 0) rec(ind+1,t_ind+1,dis,t_ind);
    if(s[ind] == tar[t_ind] && (ind == 1 || t_ind - prev == dis)){
        rec(ind+1,t_ind+1,t_ind - prev,t_ind);
    }
    return rec(ind,t_ind+1,dis,prev);
}

int main(){
    int n,ans = 0;
    cin >> n >> s;
    for(int i=0;i<n;i++){
        cin >> tar;
        rec(0,0,0,0);
        if(judge) ans++;
        judge = false;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1208
#include<stdio.h>
int color[10005]={0};
int main()
{
	int n;
	scanf("%d",&n);
	
	for(int i=0;i<n;i++)
	{
		scanf("%d",&color[i]);
	}
	int cnt=0;
	for(int i=0;i<n-1;i++)
	{
		if(color[i]==color[i+1])
		{
			color[i+1]=10002;
			cnt++;
		}
	}
	printf("%d",cnt);
}

Measured memory_bytes: 128
/*ex5_4 hightierra*/
#include <stdio.h>
#include <string.h> 
#define LIMIT 20

int main(void){
    char string[LIMIT];
    // 部分文字列の長さを入れる数字
    int length=0,counter=0;
    int i;

    scanf("%s",string);

    for(i=0; i<strlen(string); i++){
        if(string[i] == 'A' || string[i] == 'C' || string[i] == 'G' || string[i] == 'T'){
            // A,C,T,Gならcounterをインクリメント
            counter++;
        }
        // 部分列文字数がそれまでの部分文字列数よりも長かったら更新
        if(length < counter){
            length = counter;
        }
        // A,C,T,Gでなくなったら0に戻す
        if(string[i] != 'A' && string[i] != 'C' && string[i] != 'G' && string[i] != 'T'){
            counter = 0;
        }
    }
    
    printf("%d\n",length);
    
    return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int N,X;
  cin>>N>>X;
  
  vector<int> m(N);
  int sum=0;
  for(int i=0; i<N; i++){
    cin>>m[i];
    sum+=m[i];
  }
  int x=X-sum;
  sort(m.begin(),m.end());
  cout<<N+x/m[0]<<endl;
 
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/02/24  Problem: ABC 119 C / Link: http://abc119.contest.atcoder.jp/tasks/abc119_c  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL ans = 0LL;

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

	LL N, A, B, C; cin >> N >> A >> B >> C;
	VL a(N);
	FOR(i, 0, N) {
		cin >> a[i];
	}
	LL S = 1;
	FOR(i, 0, N)S *= 4;

	auto f = [](const VL& a, LL A) {
		if (SZ(a)) {
			return (SZ(a) - 1) * 10 + abs(A - accumulate(ALL(a), 0LL));
		}
		else {
			return LINF;
		}
	};
	ans = LINF;
	FOR(s, 0, S) {
		LL ss = s;
		VVL se(4);
		FOR(i, 0, N) {
			se[ss % 4].push_back(a[i]);
			ss /= 4;
		}
		LL ret = f(se[0], A) + f(se[1], B) + f(se[2], C);
		if (SZ(se[3]) != N)
			ans = min(ans,ret );
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict


def input():
    return sys.stdin.readline().rstrip()


def main():
    s = int(input())

    def f(y):
        if y % 2 == 0:
            a = y // 2
        else:
            a = 3 * y + 1
        return a

    ss = set()
    ss.add(s)

    for i in range(10 ** 8):
        s = f(s)
        if s in ss:
            print(i+2)
            exit()
        ss.add(s)



if __name__ == "__main__":
    main()


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

int main()
{
    int n;
    cin >> n;
    if(n%1000 == 0){
        cout << 0 << endl;
    }else{
        cout << 1000 - n%1000 << endl;
    }
    return 0;
}

Measured memory_bytes: 3564
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
using namespace std;
typedef long long LL;
int n,m;
int main(){
	scanf("%d%d",&n,&m);
	if(m>=n) printf("%d\n",n);
	else printf("%d\n",n-1);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://beta.atcoder.jp/contests/abc079/tasks/abc079_c

string abcd;
string op;

bool dfs(int sum, string o) {
    if (o.size() == 3) {
        op = o;
        return sum == 7;
    }

    if (dfs(sum + (abcd[o.size() + 1] - '0'), o + "+")) return true;

    if (dfs(sum - (abcd[o.size() + 1] - '0'), o + "-")) return true;

    return false;
}

int main() {
    cin >> abcd;

    if (dfs(abcd[0] - '0', "")) {
        printf("%c%c%c%c%c%c%c=7\n", abcd[0], op[0], abcd[1], op[1], abcd[2], op[2], abcd[3]);
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////





int main() {

	ll N;
	cin >> N;

	ll V[MAX], C[MAX];

	repn(i, N) cin >> V[i];
	repn(i, N) cin >> C[i];

	ll ans = 0;

	repn(i, N) {
		if (V[i] - C[i] > 0) { ans += V[i] - C[i]; }
	}

	cout << ans;

	system("PAUSE");
}

Measured memory_bytes: 2552
n = int(input())
P = list(map(int, input().split()))
num = 0
for i in range(1, n - 1):
    if P[i - 1] < P[i] < P[i + 1] or P[i + 1] < P[i] < P[i - 1]:
        num += 1
print(num)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define ff first
#define ss second
//#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  A.begin(), A.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))


#define forr(i,n) for(i=0; i<n; i++)
#define whilee(i,t) while(i!=t)
#define pb(x) push_back(x);

//sort(A.begin(),A.end());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//accumulate(A.begin(), A.end(), 0);
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());

//vector <int> A;
//deque <int> A;
//queue <int> A;
//stack <int> A;
//set <int> A;
//map <int,int> A;
//pair <int,int> A ;
//vector <pair <int,int>> A ;
//string S, T;
int i, j, k, a, b, c, d, l, m, n=3, p, q, r, s, t, x, y, z, cnt=0;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int A[n];
    forr(i,n)
    {
        cin>>A[i];
    }
    sort(A,A+n);

    cout<<((A[2]*10)+A[1])+A[0]<<endl;

    return 0;
}



Measured memory_bytes: 256
import math
 
s = list(map(str, input().split()))
s = s[0]
n = len(s)

now = 1
amari = []
for i in range(len(s)):
    amari.append(now)
    now = (now * 10) % 13

ans = [[0 for i in range(13)] for j in range(2)]
ans[0][0] = 1
ans[1][0] = 1

for i in range(len(s)):
    now = s[n-1-i]
    ans[(i+1)%2] = [0 for i in range(13)]
    if(now=="?"):
        for k in range(10):
            plus = (amari[i] * k)%13
            for j in range(13):
                ans[(i+1)%2][(j+plus)%13] += ans[i%2][j]
                ans[(i+1)%2][(j+plus)%13] %= 1000000007
    else:
        now = int(now)
        plus = (amari[i] * now)%13
        for j in range(13):
            ans[(i+1)%2][(j+plus)%13] = ans[i%2][j]
            
    last = (i+1)%2
            
print(ans[last][5])


Measured memory_bytes: 46064
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

template<class T, class Cond>
struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  bool operator()(T& a, const T& b) const {
    if(cond(a, b)) { a = b; return true; }
    return false;
  }
};
template<class T, class Cond>
chain<T, Cond> make_chain(Cond cond) { return chain<T, Cond>(cond); }

int main() {
  i64 N, M;
  cin >> N >> M;
  cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1e+9;
 
int main()
{
	int r, d, x = 0;
	cin >> r >> d >> x;
 
    int ans = 0;
	for (int i = 0; i < 10; i++)
    {  
        ans = r * x - d;
        cout << ans << "\n";

        x = ans;
    }

	return 0;
}

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

using namespace std;

#define int long long
#define pii pair<int, int>
#define pb push_back

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n, m;
    cin >> n >> m;
    int ans = 0;
    int a[n];
    int s = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        s += a[i];
    }
    for(int i = 0; i < n; i++) {
        ans += (4 * m * a[i] >= s);
    }
    cout << (ans >= m ? "Yes": "No");



    return 0;
}



Measured memory_bytes: 256