akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
 
// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
 
 
/*
--------------------------------------------
 
	type
 
--------------------------------------------
*/
using LL = long long;
using ULL = unsigned long long;
//using pair<T1, T2> = p12;
 
/*
--------------------------------------------
 
	container
 
--------------------------------------------
*/
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
 
/*
--------------------------------------------
 
	repetition
 
--------------------------------------------
*/
#define MAX(a,b) (a>b)?a:b
#define MIN(a,b) (a>b)?b:a
#define REP(n) for(int i=0; i<n; i++)
#define REPj(n) for(int j=0; j<n; j++)
#define REPS(i,n) for(int i=0; i<(n); i++)
#define REPinit(a,n) for(int i=a; i<(n); i++)
#define REPinitj(a,n) for(int j=a; j<n; j++)
 
//algorithm
//#define SORT(c) sort((c).begin(),(c).end())
 
/*
--------------------------------------------
 
	constant
 
--------------------------------------------
*/
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
/*
 
	Optimizer
 
*/
//#pragma GCC optimize("Ofast")


/*
 
	Utility Algorithm
 
*/
template <typename T>
void swapAlgorithm(T& a, T& b) {
    T tmp = a;
    a = b;
    b = tmp;
}

LL euclideanAlgorithm(LL a, LL b) {
    LL a_tmp = a;
    LL b_tmp = b;

    if (a_tmp > b_tmp) {
        swapAlgorithm<LL>(a_tmp, b_tmp);
    }

    LL r = a_tmp % b_tmp;
    while (r != 0) {
        a_tmp = b_tmp;
        b_tmp = r;
        r = a_tmp % b_tmp;
    }
    return b_tmp;    
}

LL getLCM(LL a, LL b) {
    return (a * b)/(euclideanAlgorithm(a, b));
}

/*
  Code
*/

double eauclidDistance(pair<double, double>& x1, pair<double, double>& x2) {
  return sqrt((x1.first - x2.first) * (x1.first - x2.first) + (x1.second - x2.second) * (x1.second - x2.second));
}

void swap(int& a, int& b) {
  int tmp;
  tmp = a;
  a = b;
  b = tmp;
}

int main(int argc, char const *argv[])
{
  int X;
  cin >> X;

  vector<bool> expo(X+1);

  expo[1] = 1;
  for(int b=2;b<=X;b++){
    int v = b*b;
    while(v<=X){
      expo[v] = 1;
      v *= b;
    }
  }

  for(int i=X; i>=1; i--) {
    if(expo[i]) {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
import math

def read():
    A, B = list(map(int, input().strip().split()))
    return A, B

def solve(A, B, INF= 100000000):
    min_v = INF
    for i in range(1, 1000000):
        a = math.floor(i * 0.08)
        b = math.floor(i * 0.10)
        if a == A and b == B:
            return i
    return -1


if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int main() {
  string A, B;
  cin >> A>> B;
  ll K;
  cin >> K;
  ll n = A.size();
  ll m = B.size();
  if (A.size() < B.size()) {
    A = string(m-n, '0') + A;
  } else {
    B = string(n-m, '0') + B;
  }
  n = max(n, m);
  ll ans = -(1LL<<50);
  for (ll i=0; i<min(K,n); ++i) {
    string perm = string(n-i-1, '0') + string(i+1, '1');
    do {
      ll borrow = 0;
      ll hoge = 1;
      ll tmp = 0;
      for (ll i=n-1; i>=0; --i) {
	ll a = A[i]-'0';
	ll b = B[i]-'0';
	ll C;
	if (a-borrow>=b) {
	  C = a-borrow-b;
	  borrow = 0;
	} else {
	  C = a-borrow+10-b;
	  borrow = 1;
	}
	if (perm[i] == '1') {
	  borrow = 0;
	}
	tmp += hoge*C;
	hoge *= 10;
      }
      ans = max(ans, tmp);
    }while(next_permutation(ALL(perm)));
  }
  cout << ans << endl;

}

Measured memory_bytes: 0
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< long long > vll;
typedef pair< int,int > ii;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define mp  make_pair
#define mod 1000000007
#define mod2 998244353
#define all(c) c.begin(),c.end()
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(all(c),x) != c.end())
#define rep(i, a, b) for (int i = (a); i <= int(b); i++)
#define fo(i,n) for(ll i=0;i<n;i++)
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
#define nl "\n"
ll gcd (ll a, ll b) {
    if (b == 0)
        return a;
    else
        return gcd (b, a % b);
}

unsigned long long factorial[1000004]; 
    /*factorial[0] = 1; 
    for (int i = 1; i <= n; i++) {
        factorial[i] = (factorial[i - 1] * i) % mod3; 
    }*/




unsigned long long power(unsigned long long x, 
                         int y, int p) 
{ 
    unsigned long long res = 1; // Initialize result 
  
    x = x % p; // Update x if it is more than or 
    // equal to p 
  
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res; 
} 



  
// Returns n^(-1) mod p 
unsigned long long modInverse(unsigned long long n, int p) 
{ 
    return power(n, p - 2, p); 
} 
unsigned long long nc(unsigned long long n, 
                                 int r, int p) 
{ 
    // Base case 
    if (r == 0) 
        return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
 
  
    return (factorial[n]* modInverse(factorial[r], p) % p * modInverse(factorial[n - r], p) % p) % p; 
} 



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

    int d,t,s;
    cin>>d>>t>>s;
    if(s*t >=d){
        Yes;
    }
    else{
        No;
    }
    

    


	return 0;
}


Measured memory_bytes: 3652
#include"iostream"
#include"cstdio"
#include"cmath"
#include"cstring"
#include"algorithm"
#include"stack"
#include"queue"
using namespace std;

#define read(x) scanf("%d",&x)
#define readl(x) scanf("%lld",&x)
#define ll long long 
#define ull unsigned long long
#define MAXN 1000005 

ll n,k,d;

int main()
{
	cin>>n>>k>>d;
	if(n>=0)
	{
		ll op=n/d;
		if(k<=op){cout<<n-k*d<<endl;return 0;}
		k-=op;
		if(k%2==0){cout<<n-op*d<<endl;return 0;}
		else{cout<<op*d+d-n<<endl;return 0;}
	}
	else
	{
		ll op=-n/d;
		if(k<=op){cout<<-(n+k*d)<<endl;return 0;}
		k-=op;
		if(k%2==0){cout<<-(n+op*d)<<endl;return 0;}
		else{cout<<op*d+d+n<<endl;return 0;}
	}
	return 0;
} 

Measured memory_bytes: 3672
#include<stdio.h>

int main(){
	char a,b;
	
	scanf("%c %c",&a,&b);
	
	if(a=='H' && b=='H'){
		printf("H\n");
	}
	else if(a=='D' && b=='D'){
		printf("H\n");
	}
	else printf("D\n");
	
	return 0;
}

Measured memory_bytes: 128
//Catchharsh
#include<bits/stdc++.h>
#define ll long long int 
#define ld long double
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define see(x) cout<<#x<<" = "<<x<<endl
const ll MOD = 1e9+7;
const ll INF = 1011111111;
const ll LLINF = 1000111000111000111LL;
const ld EPS = 1e-10;
const ld PI = 3.14159265358979323;
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
inline ll add(ll a,ll b){a+=b;if(a>=MOD)a-=MOD;return a;}
inline ll sub(ll a,ll b){a-=b;if(a<0)a+=MOD;return a;}
inline ll mul(ll a,ll b){return (a*1ll*b)%MOD;}
ll power (ll base,ll exponent)
{
    ll ans=1;
    //base%=MOD;
    //exponent%=(MOD-1);
    while(exponent!=0)
    {
      if(exponent&1) ans=(1LL*ans*base);
      base=(1LL*base*base);
      exponent>>=1;
    }
    return ans;
}

int32_t main()
{   
     IOS;
     
     ll n,m,i,j,k;
     map<ll,ll> mp;
     cin>>n>>k;
     k++;
     vector<ll> vv(n+1);
     vector<ll> v;
     for(i=1;i<=n;i++) cin>>vv[i];
     ll start=1;
     v.pb(1);
     ll id=-1;
     mp[1]=0;
     j=1;
     while(1)
     {
        ll to=vv[start];
        if(mp.count(to))
        {
            id=mp[to];
            break;
        }
        v.pb(to);
        mp[to]=j++;
        start=to;
     }
     // cout<<id<<endl;
     // for(i=0;i<(ll)v.size();i++) cout<<v[i]<<" ";cout<<endl;
     ll cnt=id;
     // cout<<cnt<<" "<<v.size()<<endl;
     if(k<=cnt)
     {
        cout<<v[k-1];
        return 0;
     }
     ll cycle=v.size()-cnt;
     k-=cnt;
     vector<ll> cy;
     for(i=id;i<(ll)v.size();i++) {cy.pb(v[i]);}
     k%=cycle;
     if(k==0) k=cycle;
     // cout<<k<<endl;
     cout<<cy[k-1];
     
     cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';             
}

Measured memory_bytes: 18984
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) throws Exception {
	    Scanner sc = new Scanner(System.in);   
	    int N = sc.nextInt();
	    
	    if (N == 1) {
	    	System.out.println(1);
	    	return;
	    }
	    
	    int[] map = new int[1001];
	    map[1] = 1;
	    for (int i = 2; i <= N; i++) {
	    	int tmp = 2;
	    	int iCopy = i;
	    	while(iCopy != 1) {
	    		if (iCopy % tmp == 0) {
	    			map[tmp]++;
	    			iCopy /= tmp;
	    		} else {
	    			tmp++;
	    		}
	    	}
	    }
	    
	    long ans = 1;
	    for (int i = 2; i < map.length; i++) {
	    	ans *= (map[i] + 1);
	    	ans %= 1_000_000_007;
	    }
	    
	    System.out.println(ans);
	}    
}	

Measured memory_bytes: 22996
#include<stdio.h>

int main(){
    int N;
    scanf("%d", &N);
    int A[N];
    for(int i = 0; i < N; i++){
        scanf("%d", &A[i]);
    }
    int sum = abs(A[0]);
    for(int i = 0; i < N - 1; i++){
        sum = sum + abs(A[i + 1] - A[i]);
    }
    sum = sum + abs(A[N - 1]);
    int B[N];
    B[0] = sum - abs(A[0]) - abs(A[1] - A[0]) + abs(A[1]);
    for(int i = 1; i < N - 1; i++){
        B[i] = sum - abs(A[i] - A[i-1]) - abs(A[i + 1] - A[i]) + abs(A[i + 1] - A[i - 1]);
    }
    B[N - 1] = sum - abs(A[N - 1] - A[N - 2]) - abs(A[N - 1]) + abs(A[N - 2]);
    for (int i = 0; i < N; i++){
        printf("%d\n", B[i]);
    }
    return 0;
}

Measured memory_bytes: 1920
n,x,m = map(int, input().split())

dp=[False]*m
flag = True

res=[]
for i in range(n):
    res.append(x % m) 
    if dp[x] != False:
        flag = False
        break
    dp[x] = i 
    x = (x*x) % m
    if x ==0:
        print(sum(res))
        exit()
    if x==1:
        print(sum(res)+n-i-1)
        exit()

if flag:
    print(sum(res))
    exit()

r_sum = sum(res[dp[x]:i])
r_kaisu = (n-dp[x]) // (i-dp[x])
r_amari = (n-dp[x]) % (i-dp[x])

amari_st = sum(res[:dp[x]])
amari_en = sum(res[dp[x]:dp[x]+r_amari])

print(r_sum*r_kaisu+amari_st+amari_en)

Measured memory_bytes: 13712
#include <stdio.h>

char map[8][9];

void bomb(int x,int y){
	int i;
	
	map[y-1][x-1] = '0';
	
	for(i = 1;i <= 3;i++){
		if(x+i<9){
			if(map[y-1][x+i-1] == '1') bomb(x+i,y);
		}
		if(x-i>0){
			if(map[y-1][x-i-1] == '1') bomb(x-i,y);
		}
		if(y+i<9){
			if(map[y+i-1][x-1] == '1') bomb(x,y+i);
		}
		if(y-i>0){
			if(map[y-i-1][x-1] == '1') bomb(x,y-i);
		}
	}
}

int main(void) {
	int i,j,n,x,y;
	
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		printf("Data %d:\n",i+1);
		for(j = 0;j < 8;j++){
			scanf("%s",map[j]);
		}
		scanf("%d %d",&x,&y);
		bomb(x,y);
		for(j = 0;j < 8;j++){
			printf("%s\n",map[j]);
		}
	}
	
	return 0;
}

Measured memory_bytes: 608
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeMap;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.Map.Entry;
import java.io.BufferedReader;
import java.util.SortedMap;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author HossamDoma
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {

            int n = in.nextInt();
            int[] a = new int[n];
            TreeMap<Integer, Integer> hs = new TreeMap<>();
            for (int i = 0; i < n; ++i) {
                a[i] = in.nextInt();
                hs.merge(a[i], 1, Integer::sum);
            }

            long bst = 1;
            int cnt = 0;

            for (Map.Entry<Integer, Integer> entry : hs.descendingMap().entrySet()) {

                if (entry.getValue() >= 4 && cnt == 0) {
                    bst *= entry.getKey();
                    bst *= entry.getKey();
                    cnt = 2;
                    break;
                } else if (entry.getValue() >= 2) {
                    bst *= entry.getKey();
                    cnt++;
                }

                if (cnt == 2)
                    break;
            }

            if (cnt != 2)
                bst = 0;

            out.println(bst);

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 49048
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<functional>
#include<cmath>
#include<vector>
//using namespace std;
using std::min;
using std::max;
using std::swap;
using std::sort;
using std::reverse;
using std::random_shuffle;
using std::lower_bound;
using std::upper_bound;
using std::unique;
using std::vector;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
void open(const char *s){
#ifndef ONLINE_JUDGE
    char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
int rd(){int s=0,c,b=0;while(((c=getchar())<'0'||c>'9')&&c!='-');if(c=='-'){c=getchar();b=1;}do{s=s*10+c-'0';}while((c=getchar())>='0'&&c<='9');return b?-s:s;}
void put(int x){if(!x){putchar('0');return;}static int c[20];int t=0;while(x){c[++t]=x%10;x/=10;}while(t)putchar(c[t--]+'0');}
int upmin(int &a,int b){if(b<a){a=b;return 1;}return 0;}
int upmax(int &a,int b){if(b>a){a=b;return 1;}return 0;}
const ll p=1000000007;
const int N=100010;
int cmp(pii a,pii b)
{
    if(a.first!=b.first)
        return a.first<b.first;
    return a.second>b.second;
}
int n,m,t,t2;
int a[N],b[N],d[N];
pii c[N];
ll e[N];
ll add(ll a,ll b)
{
    a+=b;
    return a>=p?a-p:a;
}
void add(int x,ll v)
{
    for(;x<=t2;x+=x&-x)
        e[x]=add(e[x],v);
}
ll sum(int x)
{
    ll s=0;
    for(;x;x-=x&-x)
        s=add(s,e[x]);
    return s;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=m;i++)
        scanf("%d",&b[i]);
    for(int i=1;i<=n;i++)
        if(a[i]>b[1]&&a[i]<b[m])
        {
            int x=lower_bound(b+1,b+m+1,a[i])-b;
            if(b[x]==a[i])
                continue;
            c[++t]=pii(a[i]-b[x-1],b[x]-a[i]);
            d[++t2]=b[x]-a[i];
        }
    sort(d+1,d+t2+1);
    t2=unique(d+1,d+t2+1)-d-1;
    for(int i=1;i<=t;i++)
        c[i].second=lower_bound(d+1,d+t2+1,c[i].second)-d;
    sort(c+1,c+t+1,cmp);
    t=unique(c+1,c+t+1)-c-1;
    ll ans=1;
    for(int i=1;i<=t;i++)
    {
        ll s=sum(c[i].second-1)+1;
        ans+=s;
        add(c[i].second,s);
    }
    ans%=p;
    printf("%lld\n",ans);
    return 0;
}

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

long long int search(long long int a, long long int num, long long int m, long long int time){
	long long int next = (a *num) % m;
	if (next == 1) return time;
	else return search(a, next, m, time + 1);
}

long long int gcd(long long a, long long int b){

	long long int v0 = a, v1 = b, v2 = a % b;
	while (v2 != 0) {
		v0 = v1;
		v1 = v2;
		v2 = v0 % v1;
	};
	return v1;
}

int main(void){

	long long int a1, m1, a2, m2, a3, m3;
	while (cin >> a1 >> m1 >> a2 >> m2 >> a3 >> m3, a1, m1, a2, m2, a3, m3){
		long long int num1 = search(a1, 1, m1, 1);
		long long int num2 = search(a2, 1, m2, 1);
		long long int num3 = search(a3, 1, m3, 1);

		long long int g1 = gcd(num1, num2);
		long long int g2 = gcd(num1 * num2 / g1, num3);

		cout << num1 * num2 * num3 / (g1 * g2) << endl;

	}

	return 0;
}

Measured memory_bytes: 1156
while True:
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    if op=="?":break

    if op=="+":
        print(a+b)
    elif op=="-":
        print(a-b)
    elif op=="*":
        print(a*b)
    else:
        print(int(a/b))


Measured memory_bytes: 5596
D, E = {}, {}
A, B = [], []
S = input()
T = input()
for i in range(len(S)):
  if S[i] in D:
    D[S[i]].append(i)
  else:
    D[S[i]] = [i]
  if T[i] in E:
    E[T[i]].append(i)
  else:
    E[T[i]] = [i]
for i in D:
  A.append(D[i])
for i in E:
  B.append(E[i])
A.sort()
B.sort()
if A == B:
  print('Yes')
else:
  print('No')

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

int main() {
  int N, A;
  int i;
  int count, count_place, count_min;
  
  cin >> N;
  
  for (i = 0; i < N; i++) {
    
    cin >> A;
    count = 0;
	while ( A % 2 == 0) {
      A /= 2;
      count++;
    }
    if (count == 0) {
      count_min = 0;
      break;
    }
    if (i != 0) {
      if (count_place < count) {
        count_min = count_place;
      } else {
        count_min = count;
      }
    }
    count_place = count;
  }
  
  cout << count_min << endl;
}


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

int main(){
    string s, t;
    cin >> s;
    t = s;
    reverse(t.begin(), t.end());
    for(int i=0; i<(int)t.length(); i++){
        if(t[i]=='b') t[i]='d';
        else if(t[i]=='d') t[i]='b';
        else if(t[i]=='p') t[i]='q';
        else t[i]='p';
    }
    if(s==t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int cmpstr(const void *a,const void *b){
    const char *x = a, *y = b;
    //return strcmp(a,b) --> funciona também
    return strcmp(x,y);
    return 0;
}
int main(){
    int n,l,i;
    scanf("%d %d\n",&n,&l);
    char s[n][l+1];
    for(i=0;i<n;i++){
        scanf("%s\n",s[i]);
    }
    //ordenar as strings
    qsort(s,n,sizeof(s[0]),cmpstr);
    for(i=0;i<n;i++){
        printf("%s",s[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))
num = 30
list_a = [[0]*num for i in range(n)]
list_ans = []
for i in range(n):
    count = 0
    j = a[i]
    while j>0:
        list_a[i][count]=j%2
        j = j//2
        count+=1
list_sum = []
for i in range(num):
    su = 0
    for j in range(n):
        su+=list_a[j][i]
    list_sum.append(su%2+2)
for i in range(n):
    ans = 0
    for j in range(num):
        k = list_sum[j]
        list_a[i][j] -=list_sum[j]
        list_a[i][j]%=2
for i in range(n):
    wa = 0
    for j in range(num):
        wa+= (list_a[i][j]*pow(2,j))
    list_ans.append(wa)
print(" ".join(map(str,list_ans)))


Measured memory_bytes: 185396
#include<iostream>

using namespace std;
int W,H;
char map[101][101];
int dir[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
void dfs(int x,int y,char ch){
  map[x][y] = '.';
  int newx,newy;
  for(int i = 0 ; i < 4 ; i ++){
    newx = dir[i][0]+x;
    newy = dir[i][1]+y;
    if(newx>=0&&newy>=0&&newx<H&&newy<W&&map[newx][newy]==ch)
      dfs(newx,newy,ch);
  }
}
int main(void){
  int cnt ;
  char ch;
  while(cin>>H>>W&&W+H){
    cnt = 0;
    for(int i = 0 ; i < H ; i ++)
      for(int j = 0 ; j < W ; j ++)
        cin>>map[i][j];
    for(int i = 0 ; i < H ; i ++)
      for(int j = 0 ; j < W ; j ++){
        ch=map[i][j];
        if(ch!='.'){
          cnt++;
          dfs(i,j,ch);
        }
      }
    cout<<cnt<<endl;
  }
  

}

Measured memory_bytes: 1632
//ysh_gpta
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
typedef long long ll;
#define vb vector<bool>
#define vi vector<ll>
#define vvi vector<vi>
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define mkp make_pair
#define pb push_back
#define INF 1000000000000000
#define MOD 1000000007
#define ff first
#define ss second
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//ll gcd( ll a, ll b ){if(b==0) return a; else return gcd( b, a%b );}
//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}
void printArray(vi &v){for(int i=0;i<v.size();i++) cout<<v[i]<<" "; cout<<endl; }
int main(){
   FastIO
   ll n;
   cin>>n;
   vi v(n);
   for(int i=0;i<n;i++)
   cin>>v[i];
   vi dp(n);
   dp[0]=0;
   dp[1] = abs(v[1]-v[0]);
   for(int i=2;i<n;i++){
       dp[i] = min(abs(v[i]-v[i-1])+dp[i-1],abs(v[i]-v[i-2])+dp[i-2]);
   }
//    printArray(dp);
   cout<<dp[n-1];
   return 0;
}

Measured memory_bytes: 1792
def GCD(x,y):
    if y==0:
        return x
    return GCD(y,x%y)
def LCM(x,y):
    return x*y // GCD(x,y)
N, M = map(int,input().split())
A = list(map(int,input().split()))
ans = 1
for i in A:
    i //= 2
    ans = LCM(ans,i)
    if (ans//i)%2 == 0:
        print(0)
        exit()
    if ans > M:
        print(0)
        exit()
print(M//ans-M//(ans*2))


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

int main(){
  
  int N;
  cin >> N;
  pair<pair<string, int>, int> shop[110];
  vector<string> S(N);
  vector<int> P(N);
  for(int i=0; i<N; i++) {
    cin >> S[i] >> P[i];
    shop[i] = make_pair(make_pair(S[i], -P[i]),i+1);
  }
  std::sort(shop, shop+N);
  for(int i=0; i<N; i++){
    cout << shop[i].second << endl;
  }
}
  
  
  
  



Measured memory_bytes: 256
n, k = [int(i) for i in input().split()]

prob = num_of_heads =  0
for i in range(n, 0, -1):
    while i * 2 ** num_of_heads < k:
        num_of_heads += 1
    prob += (1/n) * (1/2)**num_of_heads

print(prob)


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

    ll n,a,b;
    cin>>n>>a>>b;
    ll ans,d;

    if((b-a)%2==0)  ans=(b-a)/2;
    else {
        if(n-b<a) {
            d=n-b+1;
            ans=(n-(a+d))/2+d;
        }
        else {
            d=a;
            ans=(b-d-1)/2+d;
        }
    }
    
    cout<<ans<<endl;

 return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        int n;
        long total = 0;
        //????°???????Constraints????????§?????§?????????
        int min = 1000000;
        //min??¨????§?
        int max = -1000000;
    	//?¨??????\??????????????????????????§????????????
		Scanner scanner = new Scanner(System.in);
		n = scanner.nextInt();
		int a[] = new int[n];
		
		for(int i = 0;i < n;i++){
			a[i] = scanner.nextInt();
			total += a[i];
			
			if(min > a[i]){
				min = a[i];
			}
			
			if(max < a[i]){
				max = a[i];
			}
		}
		
		System.out.println(min+" "+max+" "+total);
    	scanner.close();
    }
}

Measured memory_bytes: 42296
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#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 For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    Int(n);
    vi data(n);
    rep(i, n) {
        cin >> data[i];
    }

    int ans = 0;
    rep(i, n) {
        Rep(j, n-i) {
            if (data[j-1] > data[j]) {
                ans++;
                swap(data[j-1], data[j]);
            }
        }
    }

    rep(i, n-1) cout << data[i] << " ";
    cout << data[n-1] << endl;
    cout << ans << endl;






    return 0;
}

Measured memory_bytes: 3148
#include<iostream>
using namespace std;
int main(void){
  int a, b, c;
  cin >> a >> b >>c;
  int d = 3;
  if (a == b) d--;
  if (b == c) d--;
  if (c == a) d--;
  if(d!=0)
  cout << d << endl;
  else
  cout <<"1"<<endl;
  return 0;
}


Measured memory_bytes: 256
def main():

    H, W = map(int, input().split())
    s = []
    for _ in range(H):
        t = list(input())
        s.append(t)

    dp = [[float('inf') for _ in range(W+1)] for _ in range(H+1)]

    for i in range(H):
        for j in range(W):
            if i == 0 and j == 0:
                if s[i][j] == "#":
                    dp[i+1][j+1] = 1
                else:
                    dp[i+1][j+1] = 0
            elif i == 0:
                if s[i][j] == s[i][j-1]:
                    dp[i+1][j+1] = dp[i+1][j]
                else:
                    dp[i+1][j+1] = dp[i+1][j] + (s[i][j] == '#')
            elif j == 0:
                if s[i][j] == s[i-1][j]:
                    dp[i+1][j+1] = dp[i][j+1]
                else:
                    dp[i+1][j+1] = dp[i][j+1] + (s[i][j] == '#')
            else:
                if s[i][j] == s[i][j-1]:
                    dp[i+1][j+1] = dp[i+1][j]
                else:
                    dp[i+1][j+1] = dp[i+1][j] + (s[i][j] == '#')
                if s[i][j] == s[i-1][j]:
                    dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j+1])
                else:
                    dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j+1] + (s[i][j] == '#'))
    # print(dp)
    return dp[H][W]



if __name__ == '__main__':
    print(main())

Measured memory_bytes: 43888
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include<cstdio>
#define MOD 1000000007
#define MOD2 1000000014000000049LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef long long ll;

template<int N, int M>
struct ModFact {
    int inv[N+1];
    int fact[N+1];
    int ifact[N+1];
    constexpr ModFact() : fact(), ifact() {
        ll f = 1;
        fact[0] = f;
        for (int i = 0; i < N; i++) {
            f = f*(i+1)%M;
            fact[i+1] = f;
        }
        f = power(f, M-2);
        ifact[N] = f;
        for (int i = N-1; i >= 0; i--) {
            f = f*(i+1)%M;
            ifact[i] = f;
        }
        for (int i = 0; i < N; i++) {
            f = ll(fact[i])*ll(ifact[i+1])%M;
            inv[i] = f;
        }
    }
    constexpr ll power(ll a, ll b) {
        ll r = 1;
        while (b>0) {
            if((b&1)!=0) r = (r*a)%M;
            a = (a*a)%M;
            b >>= 1;
        }
        return r;
    }
	int operator[](int n) {
		return inv[n];
	}
};

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}

inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

ModFact<100000, MOD> fact;

int main() {
    ll ans = 0, d;
    int a, N, prev, now;
    N = getint();
    prev = getint();
    REP(i, N-1) {
        now = getint();
        d = now - prev;
        prev = now;
        a = (a + fact[i]) % MOD;
        // ans += a * d % MOD;
        ans += a * d;
        if(ans > MOD2) ans -= MOD2;
    }
    printf("%lld\n", ((ans%MOD)*fact.fact[N-1])%MOD);
	return 0;
}


Measured memory_bytes: 1408
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

allenemy = sum(A)
for i in range(N):
    A[i] -= B[i]
    if A[i] < 0:
        A[i+1] += A[i]
        A[i] = 0
        if A[i+1] < 0:
            A[i+1] = 0
print(allenemy - sum(A))

Measured memory_bytes: 97476
sx,sy,tx,ty=map(int,input().split())
x=tx-sx
y=ty-sy
s=""
if tx!=sx and ty!=sy:
  #内回り計算
  s+="R"*x
  s+="U"*y
  s+="L"*x
  s+="D"*y
  #外回り
  s+="L"
  s+="U"*(y+1)
  s+="R"*(x+1)
  s+="D"
  s+="R"
  s+="D"*(y+1)
  s+="L"*(x+1)
  s+="U"
"""
elif tx==sx:
  s+="R"*x
  
  s+="D"+"L"*x+"U"
  
  s+="U"+"R"*x+"D"

  s+="R"
  s+="U"*2
  s+="L"*(x+2)
  s+="D"*2
  s+="R"
elif ty==sy:
  s+="U"*x
  s+="R"+"D"*x+"L"
  s+="L"+"U"*x+"R"
  s+="U"
  s+="R"*2
  s+="D"*(y+2)
  s+="L"*2
  s+="U"
"""
print(s)
  

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

int main() {
	int x,y;
	cin>>x>>y;
	if((y-2*x)%2==0 && (4*x-y)%2==0 && y>=2*x && 4*x>=y){
	    cout<<"Yes";
	}
	else{
	    cout<<"No";
	}
	return 0;
}


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

#define MAXN 200005
#define INF 0x3f3f3f3f

typedef long long lint;

using namespace std;

struct data {
	int next, to;
	data(int next = 0, int to = 0):next(next), to(to) {}
}edge[MAXN << 1];

struct node {
	int maxd, state;
	node(int maxd = 0, int state = 0):maxd(maxd), state(state) {}

	bool operator < (const node b) const {
		return maxd < b.maxd;
	}
};

int n; 
int fa[MAXN], state[MAXN], maxd[MAXN], maxu[MAXN], se[MAXN], semaxd[MAXN];
int stated[MAXN], stateu[MAXN], target[MAXN], times[MAXN], deg[MAXN];
int head[MAXN], cnt;
lint ans = 0;

void connect(int u, int v) {
	edge[++cnt] = data(head[u], v);
	head[u] = cnt;
}

void DFS1(int u, int pre) {
	fa[u] = pre;
	times[u] = stated[u] = state[u];
	for (int i = head[u]; i; i = edge[i].next) {
		int v = edge[i].to;
		++deg[u];
		if (v == pre)
			continue;
		DFS1(v, u);
		stated[u] |= stated[v];
		if (stated[v]) {
			++times[u];
			target[u] = v;
		}
		if (maxd[v] + 1 > maxd[u]) {
			semaxd[u] = maxd[u];
			maxd[u] = maxd[v] + 1;
		}
		else if (maxd[v] + 1 > semaxd[u]) 
			semaxd[u] = maxd[v] + 1;
	}
}

void DFS2(int u, int pre) {
	if (u != 1) {
		if (maxd[fa[u]] == maxd[u] + 1)
			maxu[u] = semaxd[fa[u]] + 1;
		else 
			maxu[u] = maxd[fa[u]] + 1;
		maxu[u] = max(maxu[u], maxu[fa[u]] + 1);
		if ((stated[fa[u]] && times[fa[u]] > 1) || (stated[fa[u]] && !stated[u]) || stateu[fa[u]])
			stateu[u] = 1;
	}
	for (int i = head[u]; i; i = edge[i].next) {
		int v = edge[i].to;
		if (v == pre)
			continue;
		DFS2(v, u);
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		connect(u, v);
		connect(v, u);
	}
	for (int i = 1; i <= n; ++i)
		scanf("%1d", &state[i]);
	DFS1(1, 0);
	DFS2(1, 0);
	for (int u = 1; u <= n; ++u) {
		if ((maxd[u] < maxu[u] - 1 && stated[u]) || (maxd[u] > maxu[u] - 1 && stateu[u]) || (maxd[u] == maxu[u] - 1 && (stateu[u] || stated[u]))) {
			++ans;
			// cout << u << " type1\n";
		}
		int up = 0;
		if (maxu[u] > maxd[u])
			up = maxd[u];
		else 
			up = max(maxu[u], semaxd[u]);
		if (state[u]) {
			ans += up + 1;
			// cout << u << " type2\n";
		}
		else {
			int down = stateu[u] ? maxu[u] : INF;
			for (int i = head[u]; i; i = edge[i].next) {
				int v = edge[i].to;
				if (v == fa[u])
					continue;
				if (stated[v])
					down = min(down, maxd[v] + 1);
			}
			// cout << u << " type3\n";
			ans += max(0, up - down + 1);
		}
		// cout  << deg[u] << " " << maxd[u] << " " << maxu[u] << endl;
	}
	printf("%lld\n", ans);
}

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

int main() {
	string s;
	cin >> s;
	if(s.length() == 2)
	{
		cout << s;
	}
	else
	{
		cout << s.at(2) << s.at(1) << s.at(0);
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);

		double x0 = sc.nextDouble();
		double y0 = sc.nextDouble();
		double x1 = sc.nextDouble();
		double y1 = sc.nextDouble();

		double xr = Math.abs(x1 - x0);
		double yr = Math.abs(y1 - y0);

		double ans = Math.sqrt(xr * xr + yr * yr);

		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 28112
#include <stdio.h>

#define MAX 100
#define NIL -1
#define INF (1 << 21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

void dijkstra();

int n;
int G[MAX][MAX];

int main() {
  int k, c, u, v, i, j;

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      G[i][j] = INF;
    }
  }
  for (i = 0; i < n; i++) {
    scanf("%d%d", &u, &k);
    for (j = 0; j < k; j++) {
      scanf("%d%d", &v, &c);
      G[u][v] = c;
    }
  }
  dijkstra();

  return 0;
}

void dijkstra() {
  int u, mincost, i, v;
  int d[MAX], color[MAX];

  for (i = 0; i < n; i++) {
    d[i] = INF;
    color[i] = WHITE;
  }
  d[0] = 0;
  color[0] = GRAY;
  while (1) {
    mincost = INF;
    u = NIL;
    for (i = 0; i < n; i++) {
      if (color[i] != BLACK && d[i] < mincost) {
	mincost = d[i];
	u = i;
      }
    }
    if (u == NIL) {
      break;
    }
    color[u] = BLACK;
    for (v = 0; v < n; v++) {
      if (color[v] != BLACK && G[u][v] != INF) {
	if (d[v] > d[u] + G[u][v]) {
	  d[v] = d[u] + G[u][v];
	  color[v] = GRAY;
	}
      }
    }
  }
  for (i = 0; i < n; i++) {
    if (d[i] != INF) {
      printf("%d %d\n", i, d[i]);
    } else {
      printf("%d -1\n", i);
    }
  }
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using st = string;
using P = pair<int, int>;
#define mrep(i, m, n) for(int i = m; i < n; i++)
#define rep(i, n) mrep(i, 0, n)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

const int mod = (int) (1e9 + 7);

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);
    vector<ll> b(n + 1, 0);
    rep(i, n){
        b.at(i + 1) = b.at(i) + a.at(i);
    }
    ll ans = 0;
    rep(i, n){
        ll sum = (b.at(n) - b.at(i + 1)) % mod; // A[i] + ... + A[N - 1] = B[N] - B[i]
        ans += (a.at(i) * sum) % mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5624
using System;

namespace _153232
{
    class Program
    {
        static void Main(string[] args)
        {
            string s= Console.ReadLine();
            string a;
            if (s == "Sunny") { a = "Cloudy"; }
            else if (s == "Cloudy") { a = "Rainy"; }
            else { a = "Sunny"; }
            Console.WriteLine(a);
        }
    }
}


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

struct Node{
  int key;
  Node *p, *l, *r;
};


Node *NIL, *root;

void preorder(Node *u){
  if(u == NIL) return;
  cout << ' ' << u->key;
  preorder(u->l);
  preorder(u->r);
}

void inorder(Node *u){
  if(u == NIL) return;
  inorder(u->l);
  cout << ' ' << u->key;
  inorder(u->r);
}

/*void Postorder(int u){
  if(u == -1) return;
  Postorder(T[u].l);
  Postorder(T[u].r);
  cout << ' ' << u;
}
*/

void insert(int k){
  Node *y = NIL;
  Node *x = root;

  Node *z;

  z = new Node[1];

  z->key = k;
  z->p = NIL;
  z->r = NIL;
  z->l = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->l;
    else x = x->r;
  }

  z->p = y;

  if(y == NIL){
    root = z;
  }
  else if(z->key < y->key) y->l = z;
  else y->r = z;
}

void find(int k){
  Node *x = root;
  while(x != NIL){
    if(k == x->key) break;
    else if(k > x->key) x = x->r;
    else x = x->l;
  }

  if(x == NIL) cout << "no" << endl;
  else cout << "yes" << endl;
}

Node *getMinimum(Node *x){
  while(x->l != NIL){
    x = x->l;
  }
  return x;
}

Node *getsuccessor(Node *x){
  if(x->r != NIL) return getMinimum(x->r);

  Node *y = x->p;
  while(y != NIL && x == y->r){
    x = y;
    y = y->p;
  }
  return y;
}


void deletex(int k){
  Node *z = root;
  while(z->key != k){
    if(k > z->key) z = z->r;
    else z = z->l;
  }
  Node *y;

  if(z->l == NIL || z->r == NIL) y = z;
  else y = getsuccessor(z);

  Node *x;

  if(y->l != NIL) x = y->l;
  else x = y->r;

  if(x != NIL) x->p = y->p;

  if(y->p == NIL) root = x;
  else if(y == y->p->l) y->p->l = x;
  else y->p->r = x;

  if(y != z) z->key = y->key;
}

void maxheapify(int *A, int x, int n){
  int largest, t;

  if(2 * x <= n && A[x] < A[2 * x]){
    largest = 2 * x;
  }
  else{
    largest = x;
  }
  if(2 * x + 1 <= n && A[largest] < A[2 * x + 1]){
    largest = 2 * x + 1;
  }

  if(x != largest){
    t = A[x];
    A[x] = A[largest];
    A[largest] = t;
    maxheapify(A, largest, n);
  }
}

void buildmaxheap(int *A, int n){
  for(int i = n / 2; i >= 1; i--){
    maxheapify(A, i, n);
  }
}





int main(){

  int n;

  cin >> n;

  int *A = new int[n + 1];

  for(int i = 1; i <= n; i++){
    cin >> A[i];
  }

  buildmaxheap(A, n);

  for(int i = 1; i <= n; i++){
    cout << " " << A[i];
  }
  cout << endl;

/*
  for(int i = 1; i <= n; i++){
    cout << "node " << i << ": key = " << A[i] << ", ";
    if(i / 2 >= 1){
      cout << "parent key = " << A[i / 2] << ", ";
    }
    if(i * 2 <= n){
      cout << "left key = " << A[i * 2] << ", ";
    }
    if(i * 2 + 1 <= n){
      cout << "right key = " << A[i * 2 + 1] << ", ";
    }
    cout << endl;
  }
*/



/*  for(int k = 0; k < n; k++){

    cin >> x;

    for(int i = 0; i < 2; i++){
      cin >> y;
      T[y].parent = x;
      if(i == 0){
      T[x].l = y;
      }
      else{
        T[x].r = y;
      }
    }
  }

/*
  cout << "Inorder" << endl;
  Inorder(r);
  cout << endl;


  cout << "Preorder" << endl;
  Preparse(r);
  cout << endl;


  cout << "Postorder" << endl;
  Postorder(r);
  cout << endl;
*/

  return 0;
}



Measured memory_bytes: 5040
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define memset(x,y) memset(x,y,sizeof(x))
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
using namespace std;
const int N =1e6+5;
ll s[N];
int main(){
	ios::sync_with_stdio(false);
	string a;
	cin>>a;
	memset(s,0);
	for(int i=0;i<a.size();i++){
		s[i]=a[a.size()-i-1]-'0';
	}
	ll ans=0;
	for(int i=0;i<a.size()+1;i++){
		if(s[i]<5) 
			ans+=s[i];
		else if(s[i]>5){
			ans=ans+10-s[i];
			s[i+1]++;
		}
		else{
			if(s[i+1]>=5){
				ans+=5;
				s[i+1]++;
			}
			else ans+=5;
		}
	} 
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 9116
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
    long n,m,x;
    cin >> n >> m >> x;

    vector<long> c(n,0);
    vector<vector<long>> a(n,vector<long>(m,0));
    

    for(long i=0; i<n; i++){
        cin >> c[i];
        for(long j=0; j<m; j++){
            cin >> a[i][j];
        }
    }

    long min = -1;

    for(long bit = 0; bit < (1<<n); bit++){
        vector<long> u(m,0);
        long sum=0;
        bool flg=true;
        for(long i=0; i<n; i++){
            if(bit & (1<<i)){
                sum+=c[i];
                for(long j=0; j<m; j++){
                    u[j]+=a[i][j];
                }
            }
        }

        for(long j=0; j<m; j++){
            if(u[j]<x){
                flg=false;
            }
        }
        if(flg){
            if(sum < min || min == -1){
                min=sum;
            }
        }
    }

    cout << min << endl;

    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < n; i++)
using namespace std;
using Graph = vector<vector<ll>>;

void dfs(Graph &G, vector<bool> &seen, vector<ll> &count, ll p){
  seen[p] = true;
  for (auto next_p : G[p]){
    if (seen[next_p]) continue;
    count[next_p] += count[p];
    dfs(G, seen, count, next_p);
  }
}

int main(){
  ll n, q;
  cin >> n >> q;
  Graph tree(n);
  vector<ll> count(n, 0);
  vector<bool> seen(n, false);
  rep(i, n-1){
    ll a, b;
    cin >> a >> b;
    a--; b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  rep(i, q){
    ll p, x;
    cin >> p >> x;
    p--;
    count[p] += x;
  }
  dfs(tree, seen, count, 0);
  rep(i, n) cout << count[i] << ' ';
  
  return 0;
}

Measured memory_bytes: 30592
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>

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

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
struct edge{ int to, time, cost; };
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;
const double infd = (double)1e+9;

double max = -infd, min = infd;

int main(){
	double d;
	while (std::cin >> d){
		if(d > max)max = d;
		if(d < min)min = d;
	}
	printf("%lf\n", max - min);
	return 0;
}

Measured memory_bytes: 1232
x,y,a,b,c = map(int,input().split())
p_list = list(map(int,input().split()))
q_list = list(map(int,input().split()))
r_list = list(map(int,input().split()))
p_list.sort(reverse = True)
q_list.sort(reverse = True)
p_list = p_list[:x]
q_list = q_list[:y]
all_list = p_list + q_list + r_list
all_list.sort(reverse = True)
print(sum(all_list[:x+y]))

Measured memory_bytes: 23328
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <cmath>

using ll = long long;

int main()
{
    int N, K;
    std::cin >> N >> K;
    std::string S;
    std::cin >> S;

    std::vector<int>A;

    char now = '1';

    int cnt = 0;
    for (int i = 0; i < N; i++)
    {
        if (S[i] == now)cnt++;
        else
        {
            now = '1' - now + '0';
            A.emplace_back(cnt);
            cnt = 1;
        }
    }
    if (cnt != 0)A.emplace_back(cnt);
    if (A.size() % 2 == 0)A.emplace_back(0);

    int k = std::min(2 * K + 1, N);
    int left = 0;
    int right = 0;
    int size = A.size();
    int sum = 0;
    int max = sum;

    for (int i = 0; i < A.size(); i += 2)
    {
        int nextLeft = i;
        int nextRight = std::min(i + k, size);
        while (left < nextLeft)
        {
            sum -= A[left];
            left++;
        }
        while (right < nextRight)
        {
            sum += A[right];
            right++;
        }
        max = std::max(max, sum);
    }

    std::cout << max << std::endl;

    return 0;
}

Measured memory_bytes: 1020
n = gets.chomp.to_i
b = gets.chomp.split(" ").map(&:to_i)

a = Array.new(n, 0)
a[0] = 10 ** 6
b.each_with_index do |v, i|
    a[i] = v  if a[i] > v
    a[i + 1] = v
end

puts a.inject(:+)


Measured memory_bytes: 1788
N = int(input())
s = []
m = [0, 0, 0, 0]

for i in range(N):
    s.append(input())

for i in range(N):
    if s[i] == 'AC':
        m[0] += 1
    if s[i] == 'WA':
        m[1] += 1
    if s[i] == 'TLE':
        m[2] += 1
    if s[i] == 'RE':
        m[3] += 1

print('AC x ' + str(m[0]))
print('WA x ' + str(m[1]))
print('TLE x ' + str(m[2]))
print('RE x ' + str(m[3]))


Measured memory_bytes: 79124
object Main extends App {
  override def main(args: Array[String]): Unit = {
    val lines = io.Source.stdin.getLines().toStream
    println(solve(lines))
  }

  def solve(lines: Seq[String]): Int = {
    val Array(a, p) = lines.head.split(" ").map(_.toInt)
    (a*3+p)/2
  }

  private def debug(x: Any): Unit = {
    if (System.getenv("LOCAL_DEBUG") != null) println(x)
  }
}

Measured memory_bytes: 27336
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
type Pi = (i32, i32);
fn pri<T: std::fmt::Display>(x: T) {
    println!("{}", x);
}

fn main() {
    input!{
        s: String,
    }
    let s = s.as_bytes();
    let mut ans = 0;
    for i in 1..s.len() {
        if s[i-1] != s[i] {ans += 1;}
    }
    pri(ans);
}

Measured memory_bytes: 4352
#include <fstream>
#include <iostream>
#define nmax 105
using namespace std;
long long l[nmax];
int n, i;

int main()
{
    cin >> n;
    l[0] = 2;
    l[1] = 1;
    for (i = 2; i <= n ; i++)
        l[i] = l[i-1] + l[i-2];
    cout << l[n] <<'\n';

    return 0;
}


Measured memory_bytes: 256
N=int(input())
import itertools
import bisect
L=list(i for i in range(1,N+1))
L1=[]
S1=tuple(map(int,input().split()))
S2=tuple(map(int,input().split()))
for v in itertools.permutations(L,N):
    L1.append(v)
print(abs(bisect.bisect(L1,S1)-bisect.bisect(L1,S2)))


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll X;
ll C;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>X;
	C=100;
	ll ret=0;
	while(C<X) {
		ret++;
		C+=C/100;
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3672
ans = "No"
length = gets

values = Array.new
while line = $stdin.gets
  values << line.chomp.split(' ')
end

count = 0
values.each do |v|
  if v[0] == v[1]
    count += 1

   if count >= 3
     ans = "Yes"
     break
   end
  else
    count = 0
  end
end

puts ans

Measured memory_bytes: 14376