akhauriyash/Code-Regression huggingface dataset:
#include <climits>
#include <cmath>
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
using namespace std;
int main(int, char**)
{
	string S, T;
	cin >> S >> T;
	int count = 0;
	for (int i = 0; i < 3; ++i)
	{
		count += S[i] == T[i];
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define pii pair<int,int>

using namespace std;

const int mod = 1e9 + 7;
const int nax = 2e5+5;
ll a[nax];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll sum = 0;
    int n; cin>>n;
    ll ans =0 ;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        sum += a[i];
    }
    sum %= mod;
    sum -= a[1];
    if(sum < 0) sum += mod;
    for(int i=1;i<n;i++)
    {
        ans += sum * a[i];
        ans %= mod;
        sum -= a[i + 1];
        if(sum < 0) sum += mod;
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 5192
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  
  int ma=max(a,max(b,c));
  if(ma==a) cout<<"A"<<endl;
  else if(ma==b) cout<<"B"<<endl;
  else cout<<"C"<<endl;

  return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>

using namespace std;
typedef long long ll;
ll N;

int main(){

    ll N;
    cin >> N;
    vector<ll > a(N,0);
    ll ans = 0;
    for(ll i = 0; i < N; i++){
        ll t = 0;
        cin >> t;
        //あまりは0~t-1までしか出ない
        a[i] = t - 1;
        ans += t - 1;
    }

    cout << ans << endl;

    /* 
    sort(a.begin(), a.end());

    ll center = (a[0] + a[a.size()-1]) / 2;

    ll divide = 11451419191919;

    for(ll i = 0; i < N; i++){
        if(abs(center - a[i]) < divide){
            divide = a[i];
        }
    }

    ll ans = 0;

    for(ll i = 0; i < N; i++){
        ans += divide / a[i];
    }

    cout << ans << endl;
    */


} 

Measured memory_bytes: 256
n = int(input())
rule = []
w = input()
rule.append(w)
now = w[-1]
for i in range(n - 1):
    w = input()
    if w in rule:
        print("No")
        exit()
    elif now != w[0]:
        print("No")
        exit()
    else:
        rule.append(w)
        now = w[-1]
print("Yes")

Measured memory_bytes: 9188
import java.util.Scanner;
import java.util.ArrayList;


public class Main {
	
	static String change(String str){
		StringBuffer sb = new StringBuffer(str);
		str = sb.reverse().toString();
		return str;
	}
	
	public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			int m = sc.nextInt();
			for(int i=0;i<m;i++) {
				String tomas = sc.next();
				ArrayList<String> pettern = new ArrayList<>();
				
				String s = "";
				
				for(int j=0;j<tomas.length()-1;j++) {
					for(int k=0;k<8;k++) {
						switch(k) {
						case 0:
							s = change(tomas.substring(0,j+1)) + change(tomas.substring(j+1,tomas.length()));
							pettern.add(s);
							break;
							
						case 1:
							s = change(tomas.substring(0,j+1)) + tomas.substring(j+1,tomas.length());
							pettern.add(s);
							break;
								
							
						case 2:
							s = tomas.substring(0,j+1) + change(tomas.substring(j+1,tomas.length()));
							pettern.add(s);
							break;
							
						case 3:
							s = tomas.substring(0,j+1) + tomas.substring(j+1,tomas.length());
							pettern.add(s);
							break;
							
						case 4:
							s = change(tomas.substring(j+1,tomas.length())) +  change(tomas.substring(0,j+1)) ;
							pettern.add(s);
							break;
							
						case 5:
							s = tomas.substring(j+1,tomas.length()) + change(tomas.substring(0,j+1)) ;
							pettern.add(s);
							break;
								
							
						case 6:
							s =  change(tomas.substring(j+1,tomas.length())) + tomas.substring(0,j+1) ;
							pettern.add(s);
							break;
							
						case 7:
							s = tomas.substring(j+1,tomas.length()) + tomas.substring(0,j+1) ;
							pettern.add(s);
							break;
							
						}
					}
				}
				//System.out.print(pettern);
				
				for(int l=0;l<pettern.size()-1;l++) {
					for(int n=l+1;n<pettern.size();n++) {
						if(pettern.get(l).equals(pettern.get(n))) pettern.set(n,"A");
					}
				}
				
				int count=0;
				for(int l=0;l<pettern.size();l++) {
				    if(!pettern.get(l).equals("A")) count++;
				}
				
				System.out.println(count);
				
			}
		}

	}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;
long long int n,cnt=0,ans=0,a,b,c,d,cmp[4],cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
  
       cin.tie(0);
    ios::sync_with_stdio(false);
      
      cin>>cmp[0]>>cmp[1]>>cmp[2];
      sort(cmp,cmp+3);
      a=cmp[0];b=cmp[1];c=cmp[2];
      ans=a+c*10+b;
      Cout(ans);
    
       
return 0;
}


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

int main() {
  
  int a, b;
  
  cin >> a >> b;
  
  int x = (a * b) % 2;
  
  	if ( x == 0 ) {
    
    	cout << "Even" << endl;
    
  	} else {
    
    	cout << "Odd" << endl;
    }
}

Measured memory_bytes: 256
import std.stdio; // ??\????????????????????????
import std.string; // chomp????????????????????????(?????????????????????)
import std.conv; // to????????????????????????
import std.array; // split?????????????????????
import std.algorithm; // map?????????????????????

void main() {
    int S = readln.chomp.to!int;
    int h = S / 3600;
    S = S - h * 3600;
    int m = S / 60;
    S = S - m * 60;
    writeln(h, ":", m, ":", S);
}

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

int main() {
  int A,B;
  cin >>A>>B;
  
  for (int i=0; i<1255; i++)
  {
    if (floor(i*0.08) == A && floor(i*0.1) == B)
    {
      cout << i << endl;
      return 0;
    }
  }  
  cout << -1 <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();


int main(){
  int n; cin>>n;
  bool flag = true;
  vector<int> a(n);
  REP(i, n)
      cin >> a[i];
      sort(ALL(a));

      FOR(i,1,a.size() )
      {
        if(a[i]==a[i-1]){
          flag = false;
          break;
        }
  }

 if(flag)
  cout << "YES" << endl;
  else
   cout << "NO" << endl;
}


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

#define SIZE 8
int q[SIZE], x[SIZE], data;

int cnt = 0;

bool can_set(int n, int j)
{
    if(n == 0) return true;
    for(int i = 0; i < n; i++){
        if(q[x[i]] == j || x[i] + q[x[i]] == x[n] + j || x[i] - q[x[i]] == x[n] - j){ return false; }
	}
    return true;
}

bool set_queen()
{
    int n, j, s;
    n = data, s = 0;

    cnt = 0;
    while((n < SIZE) && (n >= 0)){
        cnt++; if(cnt > 10000) break;
        for(j = s; j < SIZE; j++){
            if(can_set(n, j)){
                //cout << "(x[n], j) = (" << x[n] << ", " << j << ")" << endl;
                q[x[n]] = j; n++; s = 0; break;
            }
        }
        if(j == SIZE){ n--; if(n >= 0){ s = q[x[n]] + 1; } }
    };
    if(n == SIZE) return true;
    return false;
}

void show_queen()
{
    for(int i = 0; i < SIZE; i++){
        for(int j = 0; j < SIZE; j++){
            (q[i] == j ? printf("Q") : printf(".") );
        }
        printf("\n");
    }
}

int main()
{
    scanf("%d", &data);
    int i, j;
    int a = (1 << 8) - 1;

    for(int k = 0; k < data; k++){
        scanf("%d %d", &i, &j);
        x[k] = i; a = a & ~(1 << i); q[i] = j; }
    i = 0;
    for(int k = 0; k < SIZE; k++){
        if(!!(a & (1 << k))){
            x[data + i] = k; i++; }
    }

    if(set_queen()) show_queen();

    return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;


template <typename T>  bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template <typename T>  bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}


const int INF = 1000000000;

int main()
{
    int N;
    cin >> N;
    vi A(N),B(N);
    in(N,A);in(N,B);
    
    ve<vi> dp((1<<N),vi(51,INF));
    dp[0][0] = 0;
    
    rep(i,1<<N){
        int c = __builtin_popcount(i);
        for (int j = 0; j <= 50; j++) {
            if(dp[i][j] == INF) continue;
            int cost = 0;
            for (int k = 0; k < N; k++) {
                if(i & (1<<k)) continue;
                int next = (abs(c-k)%2==0 ? A[k]:B[k]);
                if(j <= next) chmin(dp[i|(1<<k)][next], dp[i][j]+cost);
                cost++;
            }
        }
    }
    
    int ans = INF;
    rep(i,51) chmin(ans,dp[(1<<N)-1][i]);
    if(ans == INF) out(-1);
    else out(ans);
    
    return 0;
}


Measured memory_bytes: 63872
def main():
    n = int(input())
    x = [int(xn) for xn in input().split()]
    x_sorted = sorted(x)
    idx_median = n // 2
    median_low = x_sorted[idx_median - 1]
    median_high = x_sorted[idx_median]
    for xn in x:
        print(median_high if xn <= median_low else median_low)


if __name__ == '__main__':
    main()


Measured memory_bytes: 30656
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main(void) {
    double A,B,ans=0;
    cin >> A >> B;

    double tmp1,tmp2;

    for(int i=0; i<1200; i++){
      tmp1 = floor(i*0.08);
      tmp2 = floor(i*0.10);
      if(tmp1==A && tmp2==B){
        ans = i;
        break;
      }
    }
    if(ans!=0)
      cout << ans << endl;
    else
      cout<<"-1" <<endl;

    return 0;
}


Measured memory_bytes: 256
import unittest


class TestC(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think([3, 5, 2], [4, 5]), 9)

    def test_2(self):
        self.assertEqual(think([5, 6, 3, 8], [5, 100, 8]), 22)

    def test_3(self):
        self.assertEqual(think([100, 1, 1], [1, 100]), 3)


def solve():
    a, b = read()
    result = think(a, b)
    write(result)


def read():
    n = read_int(1)[0]
    a = read_int(n + 1)
    b = read_int(n)
    return a, b


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a, b):
    count = 0
    for index, value in enumerate(b):
        if a[index] + a[index + 1] <= value:
            count += a[index] + a[index + 1]
            a[index] = 0
            a[index + 1] = 0
        else:
            if a[index] <= value:
                count += a[index]
                value -= a[index]
                a[index] = 0
                if value > 0:
                    count += value
                    a[index + 1] -= value
            else:
                count += value
                a[index] -= value
    return count


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 22080
#include <iostream>

using namespace std;
typedef long long ll;
ll gcd(ll a, ll b){
	if(a<b) swap(a,b);
	if(b==0) return a;
	return gcd(a%b,b);
}
ll a[100010];
int main(){
	ll i,n,m,x = -1;
	cin >> n >> m;
	for(i=0;i<n;i++){
		cin >> a[i]; a[i] /= 2;
		if(x==-1){
			x = a[i];
		}else{
			ll y = gcd(x,a[i]);
			x = (x*a[i])/y;
		}
		if(x>m){
			cout << 0 << endl;
			return 0;
		}
	}
	for(i=0;i<n;i++){
		if((x/a[i])%2==0){
			cout << 0 << endl;
			return 0;
		}
	}
	cout << (m/x + 1)/2 << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define DEC(i, a, b) for (int i = (a); i > (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int A, B;
  cin >> A >> B;
  int ans = 0;
  if (A >= 13) ans = B;
  else if (A >= 6) ans = B/2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){

  int n,m[1000],i,j,k,blank,a,b;
  double up,down,result=0;

  scanf("%d",&n);

  for(i = 0; i < n; i++) scanf("%d",&m[i]);

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

    for(j = 0; j < n-1; j++){

      if(m[j]>m[j+1]){

	blank=m[j];
	m[j]=m[j+1];
	m[j+1]=blank;

      }

    }

  }

  //for(i = 0; i < n; i++) printf("%d\n",m[i]);

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

    down=m[i+1]-m[i];
    a=m[i];
    b=m[i+1];
    m[i]=0;
    m[i+1]=0;
    //    printf("%f\n",down);
    
    for(j = n-4; j < n-1; j++){
      
      for(k = j+1; k < n; k++){
	
	up=(m[j]+m[k])/down;
	if(m[j] == 0 || m[k] == 0) continue;
	if(up > result){
	  
	  result=up;
	  
	}
	
      }
    
    }

    m[i]=a;
    m[i+1]=b;

  }

  printf("%f\n",result);
  
  return 0;

}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i < (b); ++i)
#define rrep(i,a,b) for(int i = b; i --> (a);)
#define all(v) v.begin(),v.end()
#define trav(x,v) for(auto &x : v)
#define sz(v) (int)(v).size()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	vi as(n);
	trav(x, as) cin >> x;
	deque<int> bs;
	rep(i,0,n){
		if(i%2 == 0) bs.push_back(as[i]);
		else bs.push_front(as[i]);
	}
	if(n % 2 == 1) reverse(all(bs));
	trav(x, bs) cout << x << ' ';
	cout << endl;
}

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    deque<ll> l;
    ll a;
    for (int i = 1; i <= N; i++)
    {
        cin >> a;
        if(i%2 == 0) l.push_front(a);
        else l.push_back(a);
    }
    if(N%2 == 0) {
        for (int i = 0; i < N; i++)
        {
            if(i) cout << " ";
            cout << l.front();
            l.pop_front(); 
        }
        
    }
    else {
        for (int i = 0; i < N; i++)
        {
            if(i) cout << " ";
            cout << l.back();
            l.pop_back(); 
        }
    }
    cout << endl;
}


Measured memory_bytes: 3840
#include<iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <algorithm>

using namespace std;
int main()
{
	int i, j, N, B, tmp;
	char A[100];

	cin >> N;

	for (i = 0; i < N; i++) {
		cin >> A[i];
	}

	tmp = 0;

	for (j = 0; j < N; j++) {

		if (A[j] == 89) {
			tmp = 1;
		}
	}

	if (tmp == 1) cout << "Four";
	else cout << "Three";

	return 0;
}

Measured memory_bytes: 256
a, b = map(int, input().split())
list_a = []
list_b = []

for i in range(a):
    list_a.append(str(b))

for i in range(b):
    list_b.append(str(a))
    
A = ''.join(list_a)
B = ''.join(list_b)

if a >= b:
    print(A)
else:
    print(B)

Measured memory_bytes: 61836
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
  int q;
  cin>>q;
  int cnt[2]={};
  for(int i=0;i<q;i++){
    int p,n;
    char c;
    cin>>p>>c>>n;
    cnt[c=='(']+=n;
    if(cnt[0]==cnt[1])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}



Measured memory_bytes: 3092
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  string s;
  vi a(3);
  cin>>a[0]>>a[1]>>a[2];
  sort(all(a));
  cout<<a[0]+a[1]<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <iterator>
#include <iomanip>
#include <queue>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

int main(){
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;
    ll ans = 0;
    if(N > K){
        int temp = N - K;
        for(int i = 0; i < temp; i++){
            ans += Y;
        }
        N = K;
    }
    for(int i = 0; i < N; i++){
        ans += X;
    }
    cout << ans << endl;
    
}

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>
using namespace std;

int main() {
	int N, M;
	cin >> N >> M;

	vector<int> edge(N);

	for ( int i = 0 ; i < M ; i++ ) {
		int a, b;
		cin >> a >> b;
		edge.at(a - 1) += 1;
		edge.at(b - 1) += 1;
	}

	for ( int i = 0 ; i < N ; i++ ) {
		cout << edge.at(i) << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
int main() {
    int A, B;
    cin >> A >> B;
    cout << max(A + B, max(A - B, A * B)) << endl;
    return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			d = scanner.nextInt();
			n = scanner.nextInt();
			if ((d | n) == 0)
				break;
			a = new int[n];
			e = new int[n];
			r = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = scanner.nextInt();
				e[i] = scanner.nextInt();
				r[i] = scanner.nextInt();
			}
			memo = new int[d + 1][101];
			for (int[] m : memo)
				Arrays.fill(m, -1);
			int ans = rec(d, 0);
			System.out.println(ans == INF ? "NA" : ans);
		}

	}

	private int rec(int hp, int exp) {
		if (hp == 0)
			return 0;
		if (memo[hp][exp] >= 0)
			return memo[hp][exp];
		int res = INF;
		for (int i = 0; i < n; i++) {
			if (exp >= r[i]) {
				int nhp = Math.max(0, hp - a[i]);
				int nexp = Math.min(100, exp + e[i]);
				if (hp == nhp && exp == nexp)
					continue;
				res = Math.min(res, rec(nhp, nexp) + 1);
			}
		}

		return memo[hp][exp] = res;
	}

	int d, n;
	int[] a, e, r;
	int[][] memo;
	int INF = 1 << 30;
}

Measured memory_bytes: 40156
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    n, m, q = intin()
    lrlist = intinl(m)
    qlist = intinl(q)

    tsum = defaultdict(lambda: defaultdict(int))
    for l, r in lrlist:
        tsum[l][r] += 1

    ans = defaultdict(lambda: defaultdict(int))
    for span in range(0, n):
        for i in range(1, n + 1):
            if i + span > n:
                continue
            if span == 0:
                ans[i][i] = tsum[i][i]
                continue
            ans[i][i+span] = ans[i][i+span-1] + ans[i+1][i+span] - ans[i+1][i+span-1] + tsum[i][i+span]

    for p, q in qlist:
        print(ans[p][q])


if __name__ == '__main__':
    main()


Measured memory_bytes: 56488
#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() {
  long double N, M;
  cin >> N >> M;
  long double x = (100*(N-M)+1900*M);
  int temp = M;
  while(temp--) {
    x *= 2.0l;
  }
  cout << (int) x << endl;
  return 0;
}


Measured memory_bytes: 3704
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;

int gcd(int x, int y){
    if(y > x){
        swap(y, x);
    }
    while(y>0){
        int t = x;
        x = y;
        y = t%y;
    }
    return x;
}


void diviser(int g, vector<int> &ans){
    int i;
    for(i=1; i*i<g; i++){
        if(g%i==0){
            ans.push_back(i);
            ans.push_back(g/i);
        }
    }
    if(i*i==g){
        ans.push_back(i);
    }
}

int main(){
    int a, b, k;
    scanf("%d%d%d", &a, &b, &k);
    int g = gcd(a, b);
    vector<int> divs;
    diviser(g, divs);
    sort(divs.begin(), divs.end());
    int n = divs.size();
    printf("%d", divs[n-k]);
    return 0;
}



Measured memory_bytes: 256
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;


macro_rules! max {($ a : expr $ (, ) * ) => {{$ a } } ; ($ a : expr , $ b : expr $ (, ) * ) => {{std :: cmp :: max ($ a , $ b ) } } ; ($ a : expr , $ ($ rest : expr ) ,+ $ (, ) * ) => {{std :: cmp :: max ($ a , max ! ($ ($ rest ) ,+ ) ) } } ; }
macro_rules! chmax {($ base : expr , $ ($ cmps : expr ) ,+ $ (, ) * ) => {{let cmp_max = max ! ($ ($ cmps ) ,+ ) ; if $ base < cmp_max {$ base = cmp_max ; true } else {false } } } ; }

struct Scanner<'a> {
    cin : StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin : StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main(){
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    loop {
        let n: usize = sc.read();
        let m: usize = sc.read();
        if n == 0 { break; };
        let mut a: Vec<usize> = Vec::new();
        for _ in 0..n {
            a.push(sc.read());
        }
        a.sort();
        let mut ans = 0;
        let mut idx = n-1;
        for i in 0..n {
            while idx > 1 && a[i] + a[idx] > m {
                idx -= 1;
            }
            if idx <= i || a[idx] + a[i] > m { break; };
            chmax!(ans, a[i] + a[idx]);
        }
        if ans > 0 {
            println!("{}", ans);
        } else {
            println!("NONE");
        }
    }
}



Measured memory_bytes: 5048
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{

    public static void Main( )
    {
        string S = Console.ReadLine( );
        string T = Console.ReadLine( );

        int ans = 0;
        for ( int i = 0; i < S.Length; i++ )
        {
            if ( S[i] != T[i] )
            {
                ans++;
            }
        }
        Console.WriteLine(ans);
    }
}


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

ans = 0
for i in range(K):
    scorer = 0
    prev = ''
    for j in range(i, N, K):
        if T[j] == "r":
            if prev != 'p':
                scorer += P
                prev = 'p'
            else:
                prev = ''
        elif T[j] == "s":
            if prev != 'r':
                scorer += R
                prev = 'r'
            else:
                prev = ''
        elif T[j] == "p":
            if prev != 's':
                scorer += S
                prev = 's'
            else:
                prev = ''
    ans += scorer

print(ans)

Measured memory_bytes: 4084
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

N = int(input())
summary = 0

i = 0
while summary < N:
    i += 1
    summary += i

print(i)

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

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

    if (N.at(0)==N.at(1)|| N.at(1) == N.at(2)|| N.at(2) == N.at(3)) {
        cout << "Bad" << endl;
    }
    else {
        cout << "Good" << endl;
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

ll const MOD = 1e9 + 7;
const ll MAX = 1e6 + 4; // modification needed.

ll fac[MAX], finv[MAX], inv[MAX];

void cominit(){

    fac[0]  = fac[1]  = 1;
    finv[0] = finv[1] = 1;
    inv[1]  = 1;

    for(ll i=2; i<MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

ll com(ll n, ll k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}




int main(){

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

    ll x, y; cin >> x >> y;

    cominit();

    if( (x + y) % 3 != 0){
        cout << 0;
        return 0;
    }
    else if( min(x, y) < (x + y) / 3){
        cout << 0;
        return 0;
    }

    ll n = (x + y) / 3;
    ll k = x - (x + y) / 3;

    cout << com(n, k);

    return 0;
}

Measured memory_bytes: 23808
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] count = new int[n+1];
        for(int i=1; i<n; i++) {
            a[i] = sc.nextInt();
            count[a[i]] += 1;
        }

        for(int i=1; i<n+1; i++) {
            System.out.println(count[i]);
        }

        
    }
}


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

typedef pair<int, int> ii;

int r, c, n;
vector<ii> v;

int main() {
    ios::sync_with_stdio(false);
    cin >> r >> c >> n;
    for (int i = 0; i < n; ++i) {
        int x[2], y[2], z[2];
        cin >> x[0] >> y[0] >> x[1] >> y[1];
        z[0] = z[1] = -1;
        for (int j = 0; j < 2; ++j) {
            if (x[j] == 0) {
                z[j] = y[j];
            }
            else if (x[j] == r) {
                z[j] = r + c + c - y[j];
            }
            else if (y[j] == 0) {
                z[j] = r + c + c + r - x[j];
            }
            else if (y[j] == c) {
                z[j] = c + x[j];
            }
        }
        if (z[0] != -1 && z[1] != -1) {
            if (z[0] > z[1]) swap(z[0], z[1]);
            //cout << z[0] << ' ' << z[1] << '\n';
            v.push_back(ii(z[0], z[1]));
        }
    }
    sort(v.begin(), v.end());
    set<int> s;
    for (int i = 0; i < v.size(); ++i) {
        if (s.lower_bound(v[i].first) != s.lower_bound(v[i].second)) {
            cout << "NO"; return 0;
        }
        s.insert(v[i].second);
    }
    cout << "YES";
}


Measured memory_bytes: 5748
#include <iostream>

int main(int argc, char **argv){
    int r, g, b;
    std::cin >> r;
    std::cin >> g;
    std::cin >> b;

    int value = r * 100 + g * 10 + b;

    if(value % 4 == 0){
        std::cout << "YES" << std::endl;
    }else{
        std::cout << "NO" << std::endl;
    }
    
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

const int mod = 1e9 + 7;

signed main() {
  int r = read();
  print(3 * r * r);
}


Measured memory_bytes: 764
import itertools as it
import collections as col
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n,x=map(int,input().split())
P=list(map(int,input().split()))

if(n==1):
    print(abs(P[0]-x))
    exit(0)

P.sort()
D=[0]
for i in range(n):
    D.append(abs(P[i]-x))
print(gcd_list(D))



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

int main(){
    int  n, m; cin >> n >> m;
    
    vector<bool> stairs(n+1, true);
    for(int i=0; i<m; i++){
        int a; cin >> a;
        stairs[a] = false;
    }

    vector<ll> dp(n+1);
    dp[0]=1;
    for(int i=0; i<n; i++){
        int MIN = min(n, i+2);
        for(int j=i+1; j<=MIN; j++){
            if(stairs[j]){
                dp[j]+=dp[i];
                dp[j]%=mod;
            }
        }
    }

    cout << dp[n] << endl;

    return 0;
}   

Measured memory_bytes: 4060
// B

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

int main(){
  int N[4];
  for (int i(0);i<4;i++) cin>>N[i];
  sort(N,N+4);
  if (N[0] == 1 && N[1] == 4 && N[2] == 7 && N[3] == 9){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n, a, b;
  scanf("%lld%lld%lld", &n, &a, &b);
  ll ans = n/(a+b);
  ll r = min(a,n%(a+b));
  printf("%lld\n", ans*a+min(r,n));
  return 0;
}


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

int main(){
	int N;
	cin >> N;
	int a[N];
	for(int i = 0; i < N; i++) cin >> a[i];
	int res = 0;
	for(int i = 0; i < N; i++) res += (a[i]-1);
	cout << res << endl;
}


Measured memory_bytes: 256
/*Lower_Rating*/
/*Ex*/
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<stack>
#include<vector>
#include<queue>
#include<bitset>
#include<set>
using namespace std;

#define LL long long
#define DB double
#define MOD 1000000007
#define Pr pair<int,int>
#define X first
#define Y second
#define MAXN 200
#define eps 1e-10
#define INF 1000000000
#define mem(x,p) memset(x,p,sizeof(x))

LL read(){
  LL x=0,F=1;char c=getchar();
  while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
  while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
  return x*F;
}
int add(int a,int b){return (a+b>=MOD)?a+b-MOD:a+b;}
int dec(int a,int b){return (a-b<0)?a-b+MOD:a-b;}
int mul(LL a,int b){return a*b%MOD;}
int fst_pow(int a,int b){
    int res=1;
    while(b){
        if(b&1)res=mul(res,a);
        a=mul(a,a);
        b>>=1;
    }return res;
}

int n,a[MAXN+5];

Pr solve(int l,int r,int c){
    if(l>r)return Pr(1,0);
    int mh=INF;
    for(int i=l;i<=r;i++)mh=min(mh,a[i]);
    vector<int> pos;
    pos.push_back(l-1);
    for(int i=l;i<=r;i++)
    if(a[i]==mh)pos.push_back(i);
    pos.push_back(r+1);
    int w=pos.size()-2;
    Pr tmp,v;tmp=Pr(1,1);
    for(int i=0;i<pos.size()-1;i++){
        v=solve(pos[i]+1,pos[i+1]-1,mh);
        tmp.X=mul(tmp.X,v.X);
        tmp.Y=mul(tmp.Y,add(v.X,v.Y));
    }
    return Pr(mul(tmp.X,fst_pow(2,mh-c)),add(mul(tmp.X,dec(fst_pow(2,mh-c),2)),mul(tmp.Y,fst_pow(2,w))));
}

int main(){
    n=read();
    for(int i=1;i<=n;i++)a[i]=read();
    printf("%d",solve(1,n,0).Y);
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    n, m = LI()
    sc = LIR(m)
    ans = []
    for i in range(10000):
        if len(str(i)) == n:
            ans.append(i)
    for s, c in sc:
        s -= 1
        res = []
        for a in ans:
            if str(a)[s] == str(c):
                res.append(a)
        ans = res[::1]
    if ans:
        ans.sort()
        print(ans[0])
        return
    print(-1)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 39152
/*author : Yashvardhan
Saturday, April 04, 2020
6:16 PM
*/

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define rev(Y) reverse(all(Y))
#define printArr(name,from,to) for(int x = from; x < to; x++) cout << name[x] << " ";


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

int takemod(int a){return ((a%mod)+mod)%mod;}

int pow(int a, int b, int m)
{
	int ans = 1;
	a %= m;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

int modinv(int a){return takemod( pow( takemod(a), mod-2,mod ) );}

vi tmp;
int done = 0;
const int MX = 1e6;

void makelunlun(string s, int rem){
	if(rem == 0){
		tmp.pb(stoll(s));
		done++;
		return;
	}
	if(done > MX) return;
	int n = s.size();
	int prev = s[n-1] - '0';
	if(prev == 9){
		makelunlun(s + '8',rem - 1);
	}
	else if(prev == 0){
		makelunlun(s + '1',rem - 1);
	}
	else{
		char c1 = (prev - 1) + '0';
		char c2 = (prev + 1) + '0';
		makelunlun(s + c1,rem - 1);
		makelunlun(s + c2,rem - 1);
	}
	char sm = s[n-1];
	makelunlun(s + sm,rem - 1);
}
signed main()
{

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

	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	int k;
	cin >> k;

	for(int j = 1; j <= 10; j++){
		for(int i = 1; i <= 9; i++) makelunlun(to_string(i),j - 1);
	}

	sort(all(tmp));
	cout << tmp[k - 1] << endl;
	

	t2 = clock();
	cerr << endl << t2-t1 << endl;
	
	return 0;
}



Measured memory_bytes: 2420
N = int(input())
K = int(input())

#桁DP
string = str(N)
digits = len(string)

#dp[i][j][k]=と同じ桁数の整数で上からi桁目までで0でない数字がj個あるものの個数
#k=0: i桁目まで見てN未満が確定, k=1: 未確定
dp = [[[0]*2 for _ in range(K+1)] for __ in range(digits+1)]
#初期状態
dp[0][0][1] = 1

for i in range(digits):
    d = int(string[i])
    ni = i+1
    for j in range(K+1):
        for k in range(2):
            for nd in range(10):
                nk = 1 if k == 1 and nd == d else 0
                if k == 1 and nd > d: break

                nj = j + (1 if nd != 0 else 0)
                if nj > K: continue

                dp[ni][nj][nk] += dp[i][j][k]

print(dp[digits][K][0] + dp[digits][K][1])


Measured memory_bytes: 41328
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1000010

int dp[SIZE][2];

int main() {
  char S[SIZE];

  scanf("%s", S);
  int N = strlen(S);

  for (int i = 0; i <= N; i++)
    dp[i][0] = dp[i][1] = INF;

  dp[0][0] = 0;
  dp[0][1] = 1;

  for (int i = 0; i < N; i++) {
    int p = S[i] - '0';

    dp[i + 1][0] = min(dp[i + 1][0], dp[i][0] + p);
    dp[i + 1][0] = min(dp[i + 1][0], dp[i][1] + 10 - p);

    dp[i + 1][1] = min(dp[i + 1][1], dp[i][0] + p + 1);
    dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + 10 - p - 1);
  }

  cout << dp[N][0] << endl;

  return 0;
}


Measured memory_bytes: 9088
import sys
input = sys.stdin.buffer.readline
from collections import defaultdict

def main():

    N = int(input())
    a = list(map(int,input().split()))
    pl = defaultdict(int)
    ans = 0
    for i,num in enumerate(a):
        s = num+i
        t = num-i
        ans += pl[-t]
        pl[s] += 1

    print(ans)
    
if __name__ == "__main__":
    main()
    


Measured memory_bytes: 141072
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    char a,b,c,d;
    int ans = 0;
    rep(i,4){
        cin >> a;
        if(a=='+'){
            ans++;
        }else{
            ans--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

int main(){
	string S;
	cin >> S;
	for(int i=0; i<S.size(); i++){
		for(int j=i+1; j<S.size(); j++){
			if(S[i] == S[j]){
				cout << "no" << endl;
				return 0;
			}
		}
	}
	cout << "yes" << endl;
}

Measured memory_bytes: 256
n = int(input())
s = input()

before = [[-1] * 10]

for i in range(n):
  c = s[i]
  num = int(c)
  hoge = before[-1][::]
  hoge[num] = i
  before.append(hoge)
ans = 0
for i in range(10):
  now = before[-1][i]
  if now == -1:
    continue
  for j in range(10):
    now2 = before[now][j]
    if now2 == -1:
      continue
    for k in range(10):
      now3 = before[now2][k]
      if now3 == -1:
        continue
      ans += 1
print(ans)

Measured memory_bytes: 8932
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int a = sc.nextInt();
    int b = sc.nextInt();
    int ans = Math.max(Math.max(a + b, a - b), a * b);
    os.println(ans);
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
const int Maxn=1e5+5;
const int inf=1<<30;
inline int R()
{
	char c;int sign=1,res=0;
	while((c=getchar())>'9'||c<'0') if(c=='-') sign=-1;
	res+=c-'0';
	while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
	return res*sign;	
}
struct range
{
	int l,r;
}a[Maxn],st[Maxn];
int n,top;
bool cmp(range x,range y)
{
	return x.r<y.r;
}
int main()
{
	n=R();int x,len;
	for(int i=1;i<=n;i++)
	{
		x=R();len=R();
		a[i].l=x-len;
		a[i].r=x+len;
	}
	sort(a+1,a+1+n,cmp);
	int M=-inf,pre=-inf;
	for(int i=1;i<=n;i++)
	{
		if(a[i].l>=M)
		{
			M=a[i].r;
			st[++top]=a[i];
		}
	}
	printf("%d\n",top);
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c,d;
    cin  >> a >> b >> c ;
    while(1){
            if(a<=b&&b<=c&&a<=c)break;
        if(a>b){
            d=a;
            a=b;
            b=d;
        }
        if(b>c){
            d=b;
            b=c;
            c=d;
        }
        if(a>c){
            d=a;
            a=c;
            c=d;
        }
    }
    cout<<a<<' '<<b<<' '<<c<<endl;


return 0;
}

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

int main(){
  long N, A, B;
  cin >> N >> A >> B;
  vector<long> X(N);
  for(int i=0; i<N; i++){
    cin >> X[i];
  }
  vector<long> D(N-1);
  for(int i=0; i<N-1; i++){
    D[i] = X[i+1]-X[i];
  }
  long ans=0;
  for(int i=0; i<N-1; i++){
    if(A*D[i]>=B){
      ans+=B;
    }else{
      ans+=A*D[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int main(){
    int n, num[105];
    while(cin >> n){
        rep(i,n){
            cin >> num[i];
        }
        for(int i = n - 1; i >= 0; i--){
            if(i != n - 1) cout << ' ';
             cout << num[i];
        }
        cout << endl;
    }
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int x = 0; 
		boolean flag = true;
		
		for(int i = 0; i < n; i++){
			x = scan.nextInt();
			if(x%2 == 0)
				if(x%3 != 0 && x%5 != 0)
					flag = false;
		}
		
		System.out.println(flag?"APPROVED":"DENIED");
		
	}
}

Measured memory_bytes: 21972
while True:
    H, W = [int(x) for x in input().split()]
    if H == W == 0:
        break
    for i in range(H):
        if i == 0 or i == H - 1:
            print('#'*W)
        else:
            print(''.join(['#' if c == 0 or c == W - 1 else '.' for c in range(W)]))
    print()

Measured memory_bytes: 7668
#include <stdio.h>

int main(void) {
  int A, B, C, max, cnt = 0;
  scanf("%d %d %d", &A, &B, &C);

  max = (A > B) ? ((A > C) ? A : C) : ((C > B) ? C : B);
  if (max - A >= 2) {
    cnt += (max - A) / 2;
    A += ((max - A) / 2) * 2;
  }
  if (max - B >= 2) {
    cnt += (max - B) / 2;
    B += ((max - B) / 2) * 2;
  }
  if (max - C >= 2) {
    cnt += (max - C) / 2;
    C += ((max - C) / 2) * 2;
  }
  switch ((max - A == 1) + (max - B == 1) + (max - C == 1)) {
  case 0:
    break;
  case 1:
    cnt += 2;
    break;
  case 2:
    cnt += 1;
    break;
  }
  printf("%d\n", cnt);

  return 0;
}

Measured memory_bytes: 128