akhauriyash/Code-Regression huggingface dataset:
from itertools import product

n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]

ans = -(10 ** 10)
for bit in product([0, 1], repeat=10):
    if sum(bit) == 0:
        continue
    gain = 0
    for pi, fi in zip(p, f):
        tmp = sum(bitj & fij for bitj, fij in zip(bit, fi))
        gain += pi[tmp]
    ans = max(ans, gain)
print(ans)


Measured memory_bytes: 74488
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  string s,ans;
  cin >> s;
  if(s.size()==2) {
    cout << s << endl;
  }
  else {
    cout << s[2] << s[1] << s[0] << endl;
  }
}


Measured memory_bytes: 256
n, m = map(int, raw_input().split())
A = {}
for i in range(n):
    temp = map(int, raw_input().split())
    for j in range(m):
        A[(i,j)] = temp[j]
b = {}
for j in range(m):
    b[(j)] = input()
c = {}
for i in range(n):
    c[(i)] = 0
    for j in range(m):
        c[(i)] += A[(i,j)] * b[(j)]

for i in range(n):
    print c[(i)]

Measured memory_bytes: 5800
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let 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")
    };
}

fn main() {
    input! {
        r: i32,
        g: i32,
        b: i32,
        n: i32,
    }
    let mut ans = 0;
    for i in 0..n / r + 1 {
        let mut balls = r * i;
        for j in 0..(n - balls) / g + 1 {
            balls = r * i + g * j;
            if balls + b * ((n - balls) / b) == n { ans += 1; }
        }
    }
    println!("{}", ans)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a[4] = {0,0,0,0};
    int b;
    cin >> b;
    string c;
    for(int i = 0; i<b;i++){
        cin >> c;
        switch(c[0]){
            case 'A':
                a[0] += 1;
                break;
            case 'W':
                a[1] += 1;
                break;
            case 'T':
                a[2] += 1;
                break;
            case 'R':
                a[3] += 1;
                break;
        }
    }
    cout << "AC x "<<a[0]<< endl;
    cout << "WA x "<<a[1]<< endl;
    cout << "TLE x "<<a[2]<< endl;
    cout << "RE x "<<a[3]<< endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
#include <cstdio>
using Int = long long;
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;
int main()
{
    int N, M; cin >> N >> M;
    vector<pair<int, int>> students(N), checkpoints(M);
    REP(i, N) {
        int a, b; cin >> a >> b;
        students[i] = make_pair(a, b);
    }
    REP(i, M) {
        int c, d; cin >> c >> d;
        checkpoints[i] = make_pair(c, d);
    }
    for(auto s : students) {
        int distance = numeric_limits<int>::max();
        int cp = 0;
        REP(i, checkpoints.size()) {
            int d = abs(s.first - checkpoints[i].first) + abs(s.second - checkpoints[i].second);
            if (distance > d) {
                distance = d;
                cp = i;
            }
        }
        cout << cp + 1 << endl;
    }
    return 0;
}

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

#define forn(i, a, b) for (int i = a; i <= b; ++i)
#define forr(i, a, b) for (int i = a; i >= b; --i)

using namespace std;

const int N = (int)2e5 + 7;
const int INF = 1e9 + 7;

typedef long long ll;
typedef long double ld;

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

int n, k, a[N];
set < int > st;
map < int, int > cnt;

bool cmp (int x, int y){
  return cnt[x] < cnt[y];
}

int main (){
  scanf ("%d %d", &n, &k);
  forn (i, 1, n) scanf ("%d", a + i), st.insert(a[i]), cnt[a[i]]++;
  int ans = 0;
  if ((int)st.size() > k){
    vector < int > v;
    for (auto i : st){
      v.push_back(i);
    }
    sort (v.begin(), v.end(), cmp);
    int sz = st.size();
    forn (i, 0, (int)v.size() - 1){
      ans += cnt[v[i]];
      sz--;
      if (sz == k) break;
    }
  }
  printf ("%d\n", ans);
  return 0;
}


Measured memory_bytes: 20988
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define f(i,n) for(int i=0; i<n; ++i)
#define fi(i,st,n) for(int i=st; i<=n; ++i)
#define veci vector<int>
#define vecp vector<pair<int,int> >
#define vecl vector<ll>
int prime[100000+10];

ll lcm(ll a, ll b) {
	return a*b/__gcd(a,b);
}

ll power(ll a, ll n, ll mod) {
	ll res = 1;
	while(n > 0) {
		if(n&1) {
			res = (res*a)%mod;
		}
		a = (a*a)%mod;
		n = n/2;
	}
	return res;
}

ll sum(int arr[], int n) {
	ll res = 0;
	f(i,n) {
		res += arr[i];
	}
	return res;
}

void seive() {
	prime[1] = 0;
	for(int i=2; i<=100000; i++) {
		prime[i] = 1;
	}
	for(ll i=2; i<=100000; i++) {
		if(prime[i]) {
			for(ll j=i*i; j<=100000; j+=i) {
				prime[j] = 0;
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int ans;
		if(n <= 599) ans = 8;
		else if(n <=799) ans = 7;
		else if(n <=999) ans = 6;
		else if(n <=1199) ans = 5;
		else if(n <=1399) ans = 4;
		else if(n <=1599) ans = 3;
		else if(n <=1799) ans = 2;
		else if(n <=1999) ans = 1;
		cout<<ans<<"\n";
 	}
 	return 0;
}


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

int main(){
  string a,b;
  cin>>a>>b;
  int ans = 0;
  for(int i=0;i<3;i++){
    if(a[i]==b[i]){
      ans++;
    }
  }
  cout<<ans<<endl;
}    


Measured memory_bytes: 256
#include <iostream>

int main(){
	int N;
	
	std::cin >> N;
	
	if(N < 10){
		std::cout << N << std::endl;
		return 0;
	}
	if(N < 100){
		std::cout << "9" << std::endl;
		return 0;
	}
	if(N < 1000){
		std::cout << N -90 << std::endl;
		return 0;
	}
	
	if(N < 10000){
		std::cout << "909" <<std::endl;
		return 0;
	}
	if(N < 100000){
		std::cout << N - 9000 -90 << std::endl;
		return 0;
	}
	std::cout << "90909"  <<std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long int lli;

int main() {
    int N;
    cin >> N;
    int min = (int)(N / 1.09);
    int max = (int)(1 + (N / 1.07));
    for (int i = min; i <= max; i++) {
        int val = i * 1.08;
        if (val == N) {
            cout << i << endl;
            break;
        }
        if (i == max) {
            cout << ":(" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3640
n, y = map(int, input().split())

for i in range(n+1):
    for j in range(n-i + 1):
        if i*10000 + j*5000 + (n - i - j)*1000 == y:
            print(i, j, n -i -j)
            exit()

print(-1, -1, -1)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <functional>
#include <array>

using namespace std;
constexpr int64_t INF = 1000000000000010;

int64_t Func(int64_t n){
    int64_t sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(){
    int64_t K;
    cin >> K;

    for(int i = 1; i <= min(9, int(K)); ++i){
        cout << i << endl;
    }
    K -= 9;
    int64_t num = 10;
    int64_t plus = 1;
    while(K > 0){
        int64_t ans = num + plus;
        for(int64_t i = 2; i <= 1000; ++i){
            int64_t po = num + i * plus;
            if(po * Func(ans) <= ans * Func(po)){
                ans = po;
            }
        }
        cout << ans << endl;
        while(plus <= ans / 10000){
            plus *= 10;
        }
        num = ans;
        --K;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int city, road;
  cin >> city >> road;
  vector<int> a(road);
  vector<int> b(road);
  int kosuu;
  for (int i = 0; i < road; i++) {
    cin >> a.at(i) >> b.at(i);
  }
  for (int j = 1; j <= city; j++) {
    kosuu = 0;
    for (int k = 0; k < road; k++) {
      if (a.at(k) == j) {
        kosuu++;
      }
      else if (b.at(k) == j) {
        kosuu++;
      }
    }
    cout << kosuu << endl;
  }
}

Measured memory_bytes: 256
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())

// code
// ------------------------------------------------
int main() {
  int a;
  cin >> a ;
  if(a > 999) cout << "ABD";
  else cout << "ABC";
  
  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;

	void run() {
		int MAX = 150;
		Scanner sc = new Scanner(System.in);
		ArrayList<Rec> l = new ArrayList<Rec>();
		for(int y=1;y<MAX;y++) for(int x=y+1;x<MAX;x++) l.add(new Rec(x, y));
		Rec[] recs = l.toArray(new Rec[]{});
		sort(recs);
		for(;;) {
			int h = sc.nextInt(), w = sc.nextInt();
			if( (h|w) == 0 ) break;
			int ans = 0;
			for(ans=0;;ans++) if(recs[ans].x == w && recs[ans].y == h) break;
			System.out.println(recs[ans+1].y + " " + recs[ans+1].x);
		}
	}
	
	class Rec implements Comparable<Rec>{
		int x, y;
		Rec(int x, int y) {
			this.x = x;
			this.y = y;
		}
		public int compareTo(Rec o) {
			// TODO 自動生成されたメソッド・スタブ
			if( x*x + y*y != o.x*o.x + o.y*o.y )
				return (x*x + y*y) - (o.x*o.x + o.y*o.y);
			return y - o.y;
		}
	}
	
	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 32256
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int n;
    cin >> n;
    vector<int> ans(n + 1);
    for (int x = 1; x < 100; x++) {
        for (int y = 1; y < 100; y++) {
            for (int z = 1; z < 100; z++) {
                int w = x * x + y * y + z * z + x * y + y * z + z * x;
                if (w <= n) ans[w] += 1;
                if (w > n) break;
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << ans[i] << endl;
    }
}


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


int main() {
    //input
    int n;
    cin >> n;

    string w;
    cin >> w;
    char c = w.at(w.size()-1);
    map<string,int> wmap;
    wmap[w]++;
    for(int i = 1;i<n;i++){
        cin >> w;
        if(++wmap[w] > 1 || w.at(0) != c ){
            cout << "No" << endl;
            return 0;
        }
        c = w.at(w.size()-1);
    }
    cout << "Yes" << endl;

    return 0;
}

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

using namespace std;

int main() {
    int N, L;
    string tmp;
    vector<string> v;
    cin >> N >> L;
    for (int i = 0; i < N; ++i) {
        cin >> tmp;
        v.push_back(tmp);
    }
    sort(v.begin(), v.end());
    for (int j = 0; j < N; ++j) {
        cout << v[j];
    }
}

Measured memory_bytes: 256
import sys
from collections import deque
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    h, w = map(int, input().split())
    c = 0
    for _ in range(h):
        a = list(input())
        c += a.count("#")
    print(("Possible" if c == h + w - 1 else "Impossible"))


if __name__ == '__main__':
    main()

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

using namespace std;
using ll = long long;

#define INF (1LL << 60)

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

int main()
{
    ll N, W;
    ll V = 1000;
    cin >> N >> W;
    vector<ll> w(N), v(N);
    REP(i,0,N) cin >> w[i] >> v[i];

    vector<vector<ll>> dp(N+1, vector<ll>(V*N+1, INF));

    dp[0][0] = 0;
    REP(i,0,N) {
        REP(j,0,V*N+1) {
            if (j - v[i] >= 0) dp[i+1][j] = MIN(dp[i+1][j],dp[i][j-v[i]]+w[i]);
            dp[i+1][j] = MIN(dp[i+1][j],dp[i][j]);
        }
    }

    ll M = 0;
    REP(i,0,V*N+1) {
        if (dp[N][i] <= W) M = i;
    }

    _PR(M);

    return 0;
}

/*



*/

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(b>=c){
    cout << "delicious" << endl;
  }
  else if(c-b<=a){
    cout << "safe" << endl;
  }
  else{
    cout << "dangerous" << endl;
  }
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	int r, g;
	cin >> r >> g;

	int ans = r + (g - r) * 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef pair<int,int> pi;
typedef long long int ll;

const int N = (int)1e5+5;
bool palindrome(string s) {
    for(int i=0,j=s.size()-1;i<j;i++,j--) {
        if (s[i]!=s[j]) return false;
    }
    return true;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    string s;
    cin>>s;
    int n = s.size();
    if(palindrome(s) && palindrome(s.substr(0,(n-1)/2)) && palindrome(s.substr((n+3)/2-1,n-(n+3)/2+1))) {
        cout<<"Yes";
    }
    else cout<<"No";
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

string s, t;

const int MAX_N = 3005;
int dp[MAX_N][MAX_N];
int tr[MAX_N][MAX_N];

int main2() {
  cin >> s >> t;
  CLR(dp, -1);
  CLR(tr, -1);
  REP(i, MAX_N) dp[i][0] = 0;
  REP(i, MAX_N) dp[0][i] = 0;
  int N = (int)s.size();
  int M = (int)t.size();
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      if (s[i-1] == t[j-1]) {
        if (dp[i][j] < dp[i-1][j-1] + 1) {
          dp[i][j] = dp[i-1][j-1] + 1;
          tr[i][j] = 3;
        }
      }
      if (dp[i][j] < dp[i-1][j]) {
        dp[i][j] = dp[i-1][j];
        tr[i][j] = 1;
      }
      if (dp[i][j] < dp[i][j-1]) {
        dp[i][j] = dp[i][j-1];
        tr[i][j] = 2;
      }
    }
  }
  string ans;
  int i = N;
  int j = M;
  for (;i > 0 && j > 0;) {
    if (tr[i][j] == 3) {
      i--;
      j--;
      ans += s[i];
    } else if (tr[i][j] == 2) {
      j--;
    } else if (tr[i][j] == 1) {
      i--;
    }
  }
  reverse(ALL(ans));
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 70784
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);while((a%b)!=0){a=b;b=a%b;}return b;}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};


int main(){
  int n; cin>>n;
  int k=1;
  vector<vector<ll>> p(9,vector<ll>(9,0));

  for(int i=1;i<=n;i++){
    if(i==k*10) k*=10;
    int a=i/k;
    int b=i%10;
    if(i<10) b=i;
    // cout<<i<<endl;
    // cout<<a<<" "<<b<<endl;
    a--;b--;
    if(b<0) continue;
    p[a][b]++;
  }
  ll ans=0;
  rep(i,9){
    rep(j,9){
      ans+=p[i][j]*p[j][i];
    }
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000*1000+10;
int n, a[MAX], dosort[MAX], pref[MAX], t[MAX];
long long sortowanie(int pocz, int kon)
{
    if(pocz == kon)
        return 0;
    int sr = (pocz + kon) / 2;
    long long wynik = sortowanie(pocz, sr) + sortowanie(sr + 1, kon);
    int i = pocz, j = sr + 1, k = pocz;
    while( i <= sr || j <= kon )
    {
        if(j > kon || (i <= sr && pref[i] <= pref[j]))
            t[k++] = pref[i++];
        else
            t[k++] = pref[j++], wynik += sr - i + 1;
    }
    for(int i = pocz; i <= kon; i++)
        pref[i] = t[i];
    return wynik;
}
bool ok(int x)
{
    for(int i = 1; i <= n; i++)
    {
        if(a[i] < x)
            pref[i] = pref[i - 1] - 1;
        else
            pref[i] = pref[i - 1] + 1;
    }
/*    for(int i = 1; i <= n; i++)
        cout << pref[i] << " " ;
    cout << "\n";
*/    bool xd = sortowanie(0, n) * 2 <= (long long)n * (n + 1) / 2;
/*    for(int i = 1; i <= n; i++)
        cout << pref[i] << " ";
*/
    return xd;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        dosort[i] = a[i];
    }
    sort(dosort + 1, dosort + n + 1);
    int m = unique(dosort + 1, dosort + n + 1) - dosort;
    int pocz = 0, kon = m - 1;
    while(pocz < kon)
    {
        int sr = (pocz + kon + 1) / 2;
        if(ok(dosort[sr]))
            pocz = sr;
        else
            kon = sr - 1;
    }
    cout << dosort[kon] << "\n";
}

Measured memory_bytes: 5180
def main():
	A, B, C = map(int,input().split())
	m = max(A, B)
	m = max(m, C)
	diff = 3*m - (A + B + C)
	ans = diff//2
	if diff % 2 == 1:
		ans += 2
	print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<long double,long double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int a,b,c,d;

int main(){
	cin>>a>>b>>c>>d;
	a+=b;
	c+=d;
	if(a>c) cout<<"Left"<<endl;
	else if(a<c) cout<<"Right"<<endl;
	else cout<<"Balanced"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int a[101],b[101];
    for(int i=0;i<101;++i){
        a[i]=-1;
        b[i]=-1;
    }
    int n,m;
    cin>>n>>m;
    int *day;
    day=new int[n];
    for(int i=0;i<n;++i){
        cin>>day[i];
    }
    int **c;
    c=new int*[m];
    for(int i=0;i<m;++i){
        c[i]=new int[3];
        for(int j=0;j<3;++j){
            cin>>c[i][j];
        }
        if(c[i][0]<=day[0]&&day[0]<=c[i][1]){
            a[c[i][2]]=0;
        }
    }
    for(int i=1;i<n;++i){
        for(int j=0;j<101;++j) {
            if(a[j]>-1){
                for(int k=0;k<m;++k) {
                    if(c[k][0]<=day[i]&&day[i]<=c[k][1]){
                        b[c[k][2]]=max(a[j]+abs(j-c[k][2]),b[c[k][2]]);
                    }
                }
            }
        }
        swap(a,b);
    }
    int ans=0;
    for(int i=0;i<101;++i){
        ans=max(ans,a[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3084
#include <stdio.h>

int main(void) {
	int i;
	int human[3][2][3];
	int sec[3];
	for(i = 0; 3 > i; i++){
		scanf("%d %d %d", &human[i][0][0], &human[i][0][1], &human[i][0][2]);
		scanf("%d %d %d", &human[i][1][0], &human[i][1][1], &human[i][1][2]);
		sec[i] = 3600*(human[i][1][0] - human[i][0][0]) + 60*(human[i][1][1] - human[i][0][1]) + human[i][1][2] - human[i][0][2];
	}
	for(i = 0; 3 > i; i++){
		printf("%d %d %d\n", sec[i]/3600, sec[i]%3600/60, sec[i]%60);
	}
	return 0;
}

Measured memory_bytes: 600
// AtCoder Beginner Contest 070
// D - Transit Tree Path
// https://atcoder.jp/contests/abc070/tasks/abc070_d
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }

typedef vector<vpii> graph;

int main()
{
    int N; cin >>N;
    graph g(N);
    rep(i, N-1) {
        int a, b, c; cin >> a >> b >> c; a--; b--;
        g[a].push_back(make_pair(b, c));
        g[b].push_back(make_pair(a, c));
    }

    int Q, K; cin >> Q >> K; K--;

    queue<int> q;
    vector<ll> dist(N, -1);
    dist[K] = 0;
    q.push(K);
    while (!q.empty()) {
        int v = q.front(); q.pop();
        for (int i = 0; i < g[v].size(); i++) {
            int w = g[v][i].first;
            if (dist[w] == -1) {
                dist[w] = dist[v] + g[v][i].second;
                q.push(w);
            }
        }        
    }

    rep(i, Q) {
        int x, y; cin >> x >> y; x--; y--;
        cout << (dist[x] + dist[y]) << endl;
    }
}


Measured memory_bytes: 8820
#include<stdio.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<string.h>
#include<stack> 
#include<set>
#include<map>
#include<iostream>
#include<assert.h>
//#define Min(a,b,c) min((a),min((b),(c)))
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pb(x) push_back(x)
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-11
#define pi 3.14159265359
typedef long long LL;
using namespace std;
const int mod = 1e9+7;
int main(){
	int n;
	int a[100005];
	LL sum=0;
	LL ans[100005];
	memset(ans,0,sizeof(ans));
	map<int,int> index;
	map<int,int> num; 
	num[0]=1;
	scanf("%d",&n);
	for(int i=0;i<n;i++){ 
		scanf("%d",&a[i]);
		if(index[a[i]]==0)
		index[a[i]]=i+1;
		num[a[i]]++;
		sum+=a[i];
	}
	int ium=1e9;
	for(map<int,int>::iterator it=num.end();;){
		it--;
	//	printf("%d\n",it->x);
		if(it->x==0)
		break;
		ium=min(ium,index[it->x]);
		map<int,int>::iterator it2=it;
		it2--;
		ans[ium]+=(long long)(it->x-it2->x)*it->y;
		it2->y+=it->y;
	} 
	for(int i=1;i<=n;i++)
	printf("%lld\n",ans[i]);
}

Measured memory_bytes: 11648
#include<iostream>
using namespace std;
int main() {
	int N;
	int count = 0;
	cin >> N;
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (N == i * j && count == 0) {
				cout << "Yes" << endl;
				count++;
			}
		}
	}
	if (count == 0) {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<vector>
#include<climits>
#define ll long long int
using namespace std;
int main(void) {
  int a[3];
  int k;
  cin>>a[0]>>a[1]>>a[2];
  cin>>k;
  sort(a, a+3);
  cout<<a[0]+a[1]+pow(2, k)*a[2]<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static int N;
    static int T;
    static int A;
    static int[] H;

    public static void Main(string[] args)
    {
        N = Input.NextInt();
        T = Input.NextInt();
        A = Input.NextInt();
        H = Input.LineInt();

        double currMin = double.MaxValue;
        int ans = -1;
        for (int i = 0; i < N; i++)
        {
            var h = H[i];
            var t = T - h * 0.006;
            var dif = Math.Abs(t - A);
            if (currMin > dif)
            {
                ans = i + 1;
                currMin = dif;
            }
        }
        Console.WriteLine(ans);
    }
}

public static class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

Measured memory_bytes: 13460
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#include<list>
#include<utility>
#include<tuple>
#include<cstdio>
#include<map>
#include<unordered_map>
#include<ios>
#include<iomanip>
using namespace std;
typedef long long llong;
llong gcd(llong a, llong b) {
	if (a < b) std::swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通
int N;
vector<int>A,B;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		A.push_back(a);
		B.push_back(a);
	}
	sort(A.begin(), A.end(), greater<int>());
	for (int i = 0; i < B.size(); i++) {
		if (B[i] == A[0]) {
			cout << A[1] << endl;
		}
		else {
			cout << A[0] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3436
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();

        int l = 0, r = s.length() - 1;

        int count = 0;
        while (l < r) {
            if (s.charAt(l) != s.charAt(r)) {
                count++;
            }

            l++; r--;
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 25300
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <utility>
#include <vector>

#define ll long long

using namespace std;

string s;
int j2, j3;

int judge2()
{
    for (int i = 0; i < s.size() - 1; i++) {
        if (s[i] == s[i + 1]) {
            return i + 1;
        }
    }
    return -1;
}

int judge3()
{
    for (int i = 0; i < s.size() - 2; i++) {
        if (s[i] == s[i + 2]) {
            return i + 1;
        }
    }
    return -1;
}


int main()
{
    cin >> s;

    j2 = judge2();
    if (j2 >= 0) {
        cout << j2 << " " << j2 + 1 << endl;
        return 0;
    }

    j3 = judge3();
    if (j3 >= 0) {
        cout << j3 << " " << j3 + 2 << endl;
        return 0;
    }

    cout << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 512
n,y = map(int, input().split())
isComplete = False

for ichiman in range(n + 1):
  for gosen in range(n + 1):
    sen = (y - (ichiman*10000) - (gosen*5000)) // 1000
    zero = y - (ichiman*10000) - (gosen*5000) - (sen*1000)
    if zero == 0 and ichiman + gosen + sen == n and sen >= 0:
      print(str(ichiman) + " " +  str(gosen) + " " + str(sen))
      isComplete = True
      break
  if isComplete:
    break

if isComplete == False:
  print("-1 -1 -1")

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

int main() {
  string N;
  int count;
  cin>>N;
  rep(i,3){
  if(N.at(i)=='7'){count++;}
  }
  if(count>=1){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  string result;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());
  if (t > s){
    result="Yes";
    }
  else{
    result="No";
    }
  
  cout << result << endl;
}





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

#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
using i32 = int32_t;
using i64 = int64_t;
using f32 = float;
using f64 = double;
using P   = pair<int, int>;

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

template <class T>
void dump_vector(const vector<T> &v) {
    auto len = v.size();
    rep(i, 0, len) {
        cout << v[i] << (i == (int)len - 1 ? "\n" : " ");
    }
}

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

//---------------------------------------------------------------------------------------------------
template <class T>
int bubble_sort(vector<T> &vec) {
    auto len = vec.size();
    int cnt  = 0;    // スワップ回数
    bool flg = true; // 逆の隣接要素が存在する
    while (flg) {
        flg = false;
        for (int i = len - 1; i >= 1; i--) {
            if (vec[i] < vec[i - 1]) {
                swap(vec[i], vec[i - 1]);
                flg = true;
                cnt++;
            }
        }
    }
    return cnt;
}
//---------------------------------------------------------------------------------------------------

signed main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, 0, N) {
        cin >> A[i];
    }

    auto ans = bubble_sort(A);
    dump_vector(A);
    cout << ans << "\n";
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll mod = 1000000007;

const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


int main() {
  ll h, w;
  cin >> h >> w;

  vector<vector<ll>> c(10, vector<ll>(10, 0));
  for (int i = 0; i < 10; ++i) {
    cin >> c[i];/* code */
  }

  vector<vector<ll>> a(h, vector<ll>(w, 0));

  for (int i = 0; i < h; ++i) {
    cin >> a[i];/* code */
  } 


  //warshall floyd
  for(int k = 0; k < 10; k++) {
    for(int i = 0; i < 10; i++) {
      for(int j = 0; j < 10; j++) {
        c[i][j] = min(c[i][j],c[i][k] + c[k][j]);
      }
    }
  }

  ll ans = 0;

  for (int i = 0; i < h; ++i) {
    for(int j=0;j<w;j++){
      if (a[i][j] == -1)continue;
      ans += c[a[i][j]][1];
    }
  }


  cout << ans <<endl;

}




















Measured memory_bytes: 512
import java.util.Scanner;

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

    int k = sc.nextInt();
    String s = sc.next();

    if (s.length() <= k) {
      System.out.println(s);
    } else {
      System.out.println(s.substring(0, k) + "...");
    }

  }
}


Measured memory_bytes: 27036
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    int k=0,l=0;
    while(n>499)
    {
        n=n-500;
        k++;
    }
    while(n>4)
    {
        n-=5;
        l++;
    }
    cout<<(1000*k)+l*5<<endl;
}


Measured memory_bytes: 256
from operator import itemgetter

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
      
n = int(input())
XY = [tuple(map(int, input().split())) for _ in range(n)]
L_to_R = sorted([(xy[0], xy[1], i) for i, xy in enumerate(XY)])
D_to_U = sorted([(xy[0], xy[1], i) for i, xy in enumerate(XY)], key=itemgetter(1))
dist = []
for i in range(n-1):
  x1, y1, num1 = L_to_R[i]
  x2, y2, num2 = L_to_R[i+1]
  d = min(abs(x1-x2), abs(y1-y2))
  dist.append((d, num1, num2))
for i in range(n-1):
  x1, y1, num1 = D_to_U[i]
  x2, y2, num2 = D_to_U[i+1]
  d = min(abs(x1-x2), abs(y1-y2))
  dist.append((d, num1, num2))
dist.sort(reverse=True)  
  
uf = UnionFind(n)
count = 0
ans = 0
while count < n-1:
  d, num1, num2 = dist.pop()
  if uf.same(num1, num2):
    continue
  count += 1
  ans += d
  uf.unite(num1, num2)
print(ans)

Measured memory_bytes: 62588
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
S = list(map(int,list(input())))


Ls = [10**10]*10
Rs = [-1]*10

for i,s in enumerate(S):
    Ls[s] = min(i,Ls[s])
    Rs[s] = max(i,Rs[s])


ans = 0
for l,Li in enumerate(Ls):
    if Li == 10**10:
        continue
    for r,Ri in enumerate(Rs):
        if Ri == -1 or Ri <= Li:
            continue
        # print(l,r,S[Li+1:Ri])
        ans += len(set(S[Li+1:Ri]))


print(ans)


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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

const int N = 200005;

int n;
char a[N];
int pre[N], suf[N];

int main() {
	n = readStr(a + 1);
	for (int i = 1; i <= n; ++i) {
		pre[i] = pre[i - 1] + (a[i] == '0');
	}
	for (int i = n; i; --i) {
		suf[i] = suf[i + 1] + (a[i] == '0');
	}
	bool flag = 1;
	long long ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (a[i] == '1') {
			ans += (pre[i] + 1 + (i & 1)) / 2 + (flag ? suf[i] : 0);
			flag ^= 1;
		} else {
			flag = 1;
		}
	}
	for (int i = 1; i < n - pre[n]; ++i) {
		ans += (n - pre[n] - i + 1) / 2;
	}
	print(ans);
}

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

using namespace std;

typedef long long ll;
#define _ ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

#define sll(x) scanf("%I64d",&x)
#define sd(x)  scanf("%d",&x)
#define pll(x) printf("%I64d",x)
#define pd(x)  printf("%d",x)

#define clr(x) memset(x,0,sizeof x)

#define mid    ((l+r)>>1)
#define Pi acos(-1)
#define EPS 1e-12
#define MOD  1000000007
#define MOD1 1000000009
#define INFL 10000000000000LL
#define INF  2000000000

#define N 100005

pair<int,int> ar[1000];
ll dp[110][N],n,W;
ll solve(int i, ll w){
if(w > W) return -1*INFL;
if(i == n) return 0;

if(dp[i][w] != -1) return dp[i][w];

ll c1 = -1*INFL,c2= -1*INFL;
c1 = solve(i+1,w+ar[i].first) +ar[i].second;
c2 = solve(i+1,w);
ll ret = max(c1,c2);

return dp[i][w] = ret;

}

int main()
{_
    memset(dp,-1,sizeof dp);
    cin >> n >> W;

    for(int i=0;i<n;i++){
        int wi,vi; cin >> wi >> vi;
        ar[i] = {wi,vi};
    }
    cout << solve(0,0);

    return 0;
}


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


public class MyProgram
{	
  
    public static void Main()
	{
        int N = int.Parse(Console.ReadLine());
        int[] items = new int[N];
    
        for(int i = 0 ; i < N ; i++)
        {
            items[i] = int.Parse(Console.ReadLine());
        }
        Array.Sort(items);
        int Sum = 0;
        for(int i = 0 ; i < N ;i++)
        {
            if(i == N-1) items[i] /= 2;
            Sum += items[i];
        }
        Console.WriteLine(Sum);
    }
    
}

Measured memory_bytes: 11092
s = input()
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        print(i+1, i+2)
        exit()
for i in range(len(s)-2):
    if s[i] == s[i+2]:
        print(i+1, i+3)
        exit()
print(-1, -1)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define rep1(i,n) for (int i=1; i<=(int)(n); i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define fst first
#define scd second
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll n, m; cin >> n >> m;
  ll ans = 0, M = 1e9+7;
  if (abs(n-m) <= 1) {
    ll a = 1, b = 1;
    rep1(i,n) a = (a * i) % M;
    rep1(i,m) b = (b * i) % M;
    if (n==m) ans = ((a*a % M) * 2) % M;
    else ans = (a * b) % M;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
    using namespace std;
     
    using ll = long long;
     
    int main() {
      int N, K;
      cin >> N >> K;
      int x[N], y[N];
      for (int i = 0; i < N; i++) cin >> x[i] >> y[i];
     
      ll ans = 1LL << 62;
      for (int i = 0; i < N; i++) { 
        for (int j = 0; j < N; j++) { 
          for (int k = 0; k < N; k++) { 
            for (int l = 0; l < N; l++) { 
              if (x[i] > x[j]) continue;
              if (y[k] > y[l]) continue;
              int cnt = 0;
              for (int m = 0; m < N; m++) {
                if (x[i] <= x[m] && x[m] <= x[j] && y[k] <= y[m] && y[m] <= y[l]) cnt++;
              }
     
              if (cnt >= K) ans = min(ans, 1LL * (x[j] - x[i]) * (y[l] - y[k]));
            }
          }
        }
      }
     
      cout << ans << endl;
     
      return 0;
    }

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// ABC116_A();
		ABC116_B();
		// ABC116_C();
		// ABC116_D();
	}

	private static void ABC116_A() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();
			lineBC = scanner.nextInt();
			lineCA = scanner.nextInt();

			int result = lineAB * lineBC / 2;
			System.out.println(result);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private static void ABC116_B() {
		Scanner scanner = null;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numS = scanner.nextInt();

			int wkResult = 0;

			List<Integer> wkList = new ArrayList<Integer>();
			int cnt = 0;
			while (true) {
				if (cnt != 0) {
					wkResult = isResultNum(wkList.get(cnt - 1));
					if (wkList.contains(wkResult)) {
						cnt++;
						break;
					}
					wkList.add(wkResult);
				} else {
					wkResult = numS;
					wkList.add(numS);
				}
				cnt++;
			}
			System.out.println(cnt);
		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private static int isResultNum(int numS) {
		if (numS % 2 == 0) {
			return numS / 2;
		} else {
			return 3 * numS + 1;
		}
	}

	private static void ABC116_C() {
		Scanner scanner = null;
		String numT = "";
		String numX = "";

		try {
			scanner = new Scanner(System.in);
			numT = scanner.next();
			numX = scanner.next();

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private static void ABC116_D() {
		Scanner scanner = null;
		String numT = "";
		String numX = "";

		try {
			scanner = new Scanner(System.in);
			numT = scanner.next();
			numX = scanner.next();

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 510000;
const int MOD = 1000000007;
//
int fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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;
    }
}
// 二項係数計算
int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
        signed main() {
            COMinit();
            int n,k;
            cin>>n>>k;
           int a[k];
           for(int i=0;i<k;i++)cin>>a[i];
           int dp[k][n+1];
           for(int i=0;i<=n;i++)dp[0][i]=(finv[i]*COM(n-i,a[0]-i))%MOD;
           for(int i=1;i<k;i++){
               for(int j=0;j<=n;j++){
                   dp[i][j]=0;
                   for(int jj=0;jj<=j;jj++){
                       dp[i][j]=(dp[i][j]+ ((dp[i-1][jj]*finv[j-jj])%MOD)*COM(n-(j-jj),a[i]-(j-jj))%MOD)%MOD;
                       
                   }
                  
               }
           }
           cout<<dp[k-1][n]*fac[n]%MOD<<endl;
         return 0;

        }


Measured memory_bytes: 12416
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,w;
    cin >> n >> w;
    ll wt[n],val[n];
    for(ll i = 0;i < n;i++){
    	cin >> wt[i] >> val[i];
    }
    ll dp[w+1][n];
    memset(dp,0,((w+1)*n)*sizeof(ll));
    for(ll i = 1;i <= w;i++){
    	if(i >= wt[0]){
    		dp[i][0] = val[0];
    	}
    	for(ll j = 1;j < n;j++){
    		if(i >= wt[j]){
    			dp[i][j] = max(dp[i-wt[j]][j-1]+val[j],dp[i][j-1]);
    		}
    		else{
    			dp[i][j] = dp[i][j-1];
    		}
    	}
    }
    cout << dp[w][n-1] << endl;
}


Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}
int main() {
    cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(20);
    ll N;
    cin >> N;
    auto res = prime_factorize(N);
    ll ans = 0;
    for(auto p : res) {
        ll cnt = 0;
        for(ll i = 1; i*(i+1) <= 2*p.second; i++) {
            cnt = i;
        }
        ans += cnt;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3644
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int p = Integer.parseInt(sc.next());
		sc.close();
		sc = null;
		System.out.println((a*3+p)/2);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll; //long longをllとして簡略

int main(){
  int h,a;
  cin >> h >> a;
  int ans=0;
  int temp;
  temp = a;
  do{
    ans++;
    a =temp*ans;
  }
  while(h>a);
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256