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

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner cin = new Scanner(System.in);
		
		int X,Y,Z;
		
		X = cin.nextInt();
		Y = cin.nextInt();
		Z = cin.nextInt();
		
		System.out.printf("%d %d %d",Z,X,Y);

	}

}


Measured memory_bytes: 21972
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  long long int n,m;
  cin >> n >> m;
  vector<plglg> a(n);
  for(long long int i = 0; i < n; i++){
    long long int temp1, temp2;
    cin >> temp1 >> temp2;
    a[i] = make_pair(temp1,temp2);
  }

  sort(a.begin(), a.end());
  // for(int i = 0; i < n; i++){
  //   cout << a[i].first << ' ' << a[i].second << endl;
  // }

  long long int ans = 0;
  long long int buy_index = 0;
  long long int buy = 0;	

  for(long long int i = 0; i < n; i++){
    if(buy >= m){
      buy_index = i-1;
      buy -= a[i-1].second;
      break;
    } else if(i != n-1){
      buy += a[i].second;
    } else {
      buy_index = n-1;
      break;
    }
  }
  
  for(long long int i = 0; i < buy_index; i++){
    ans += (a[i].first)*a[i].second;
  }
  // cout << a[buy_index].first << ' ' << buy << endl;
  

  ans += (m-buy)*a[buy_index].first;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>

int type[1000004];
int main(){
  int N;
  scanf("%d", &N);
  std::map<std::string, int > mp;
  mp["Vacant"]=0;
  mp["Male"]=1;
  mp["Female"]=-1;
  std::cout << 0 << std::endl;
  std::string s;
  std::cin >> s;
  type[0]=mp[s];
  type[N]=mp[s];
  int left = 0;
  int right = N;
  while(right-left>1){
    int mid = (right+left)/2;
    std::cout << mid << std::endl;
    std::cin >> s;
    if (s=="Vacant"){
      return 0;
    }
    type[mid]=mp[s];
    if (((mid-left)%2==1 && type[left]==-type[mid]) ||
        ((mid-left)%2==0 && type[left]== type[mid])){
      // left~midの間に空席はないので、空席候補はmid~right
      left=mid;
    } else {
      right=mid;
    }
  }
  return 0;
}


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

using namespace std;
long long a[200005];
int main()
{
    long long n,k;
    cin>>n>>k;
    long long c=0;
    for (int i=0;i<n;i++)
        {cin>>a[i];
        c+=a[i];
        }
    sort(a,a+n);
    reverse (a,a+n);
    for (int i=0;i<k;i++)
        c-=a[i];
        cout<<c;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, a, b, s;
  in(n);
  vector<ll> c(n);
  a = 9000;
  rep(i, n){
    in(c[i]);
  }
  s = 0;
  while(true){
    a = 0;
    while(true){
      if(c[a] != 0)
        break;
      else
        a++;
      if(a == n){
        out(s);
        memi;
        return 0;
      }
    }
    b = a;
    while(true){
      if(c[b + 1] == 0)
        break;
      else
        b++;
      if(b == n){
        b -= 1;
        break;
      }
    }
    rep2(i, a, b + 1){
      c[i]--;
    }
    s++;
  }
}

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

namespace AOJ_Practice
{
    class Program
    {
        static void Main(string[] args)
        {

            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToList();

            int rowNum = input[0];
            int columnNum = input[1];

            int[,] aVec = new int[rowNum, columnNum];
            int[] bVec = new int[columnNum];
            // aの行列の値を詰め込む
            for (int i = 0; i < aVec.GetLength(0); i++)
            {
                var oneLine = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
                for (int j = 0; j < oneLine.Count; j++)
                {
                    aVec[i, j] = oneLine[j];
                }
            }

            for (int i = 0; i < bVec.Length; i++)
            {
                var oneLine = int.Parse(Console.ReadLine());
                bVec[i] = oneLine;
            }

            var productedValue = new int[rowNum];

            for (int i = 0; i < aVec.GetLength(0); i++)
            {
                for (int j = 0; j < aVec.GetLength(1); j++)
                {
                    productedValue[i] += aVec[i, j] * bVec[j];
                }
            }

            for (int i = 0; i < productedValue.Length; i++)
            {
                Console.WriteLine(productedValue[i]);
            }
        }
    }
}



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

int gcd(int a, int b)
{
	return b == 0 ? a : gcd(b, a%b);
}

int main()
{
	int a, b;
	while (cin >> a >> b){
		cout << gcd(a, b) << " " << a / gcd(a, b)*b << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int gcd(int x, int y) {
	return y ? gcd(y, x % y) : x;
}

int main() {
	int n; cin >> n;
	vector<int> a(n + 2);
	for (int i = 1; i <= n; ++i) cin >> a[i];
	vector<int> l(n + 2, 0), r(n + 2, 0);
	for (int i = 1; i <= n; ++i)
		l[i] = gcd(l[i - 1], a[i]);
	for (int i = n; i > 0; --i)
		r[i] = gcd(r[i + 1], a[i]);
	int ans = 0;
	for (int i = 1; i <= n; ++i)
		ans = max(ans, gcd(l[i - 1], r[i + 1]));
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const long long N = 200100;
long long n, a[N], dif[N], c[N], m, ans;

long long add(long long l, long long r) {
	dif[l]++;
	dif[r + 1]--;
	c[r + 1] -= (r - l + 1);
}

long long add_c(long long l, long long r, long long val) {
	// dbg(l, r, val);
	c[l] += val;
	c[r + 1] -= val;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	for(long long i = 1; i <= n; i++)
		cin >> a[i];
	
	for(long long i = 2; i <= n; i++) {
		if(a[i] > a[i - 1]) {
			ans += a[i] - a[i - 1];
			add(a[i - 1] + 2, a[i]);
		}
		else {
			ans += m + a[i] - a[i - 1];
			add(a[i - 1] + 2, m);
			add(1, a[i]);
			add_c(1, a[i], m - a[i - 1] - 1);
		}
	}
	// dbg_v(dif, m + 1);
	long long tot = ans;
	long long cc=  0, diff = 0;
	dbg(ans);
	for(long long i = 1; i <= m; i++){
		dif[i] += dif[i - 1];
		diff += dif[i];
		cc += c[i];
		ans = min(ans, tot - diff - cc);
	}

	// dbg_v(dif, m + 1);
	// dbg_v(c, m + 1);
	// dbg(ans);
	cout << ans << '\n';
}	

	

Measured memory_bytes: 3584
import java.util.*;
 
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String[] s = sc.nextLine().split(",");
            double[] a = new double[8];
            for(int i=0;i < 8;i++){
                a[i] = Double.parseDouble(s[i]);
            }
             
            if(isCross(a[0],a[1],a[4],a[5],a[2],a[3],a[6],a[7]) > 0.0 || isCross(a[2],a[3],a[6],a[7],a[0],a[1],a[4],a[5]) > 0.0){
                System.out.println("NO");
            }else{
                System.out.println("YES");
            }
        }
    }
     
    private static double isCross(double p1_x,double p1_y,double p2_x,double p2_y,double p3_x,double p3_y,double p4_x,double p4_y){  
        return ( (p1_x-p2_x)*(p3_y-p1_y) + (p1_y-p2_y)*(p1_x-p3_x)) * ((p1_x-p2_x)*(p4_y-p1_y) + (p1_y-p2_y)*(p1_x-p4_x));  
    }
}

Measured memory_bytes: 17316
#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>;
using Graph = vector<vector<int>>;



int main(){

    int N; cin >> N;
    string S[N];
    rep(i, N) cin >> S[i];

    map<string, int> dict;

    rep(i, N){
        dict[S[i]]++;
    }

    // 最大値を取る
    int max_v = 0;
    for (auto x : dict){    // first: key, second: value
        max_v = max(max_v, x.second);
    }

    // 最大値と同じ要素を検索
    vector<string> ans;
    for (auto x : dict){
        if(x.second==max_v) ans.push_back(x.first);
    }

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

    for(auto ans_s: ans){
        cout << ans_s << endl;
    }

    return 0;
}

Measured memory_bytes: 28404
S = int(input())
hour = 60 * 60
minutes = 60

h_count = 0
m_count = 0

while True:
    if  S - hour >= 0:
        h_count += 1
        S = S - hour
    else:
        h = h_count
        break

while True:        
    if S - minutes >= 0:
        m_count += 1
        S = S - minutes
    else:
        m = m_count
        s = S
        break

print(h, ":", m, ":", s, sep="")


Measured memory_bytes: 5592
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class B {
        static int mod = 1000000007;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int N = Integer.parseInt(in.next());
            long ans = 1;
            for (int i = 1; i < N + 1; i++) {
                ans = i * ans % mod;
            }

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 23764
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 1e9 + 7;

ll add(ll x, ll y){
    return (x+y)%mod;
}

ll mul(ll x, ll y){
    return (x%mod)*(y%mod)%mod;
}

ll powll(ll x, ll y){
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

ll divll(ll x, ll y){
    return (x * powll(y,mod-2)) % mod;
}

int main() {
    ll n = in();
    VL a(n);
    REP(i,n) a[i] = lin();

    VL fact(n+1), s(n+1);
    fact[0] = 1;
    REP(i,n){
        fact[i+1] = (fact[i] * (i + 1)) % mod;
        s[i+1] = (s[i] * (i + 1) + fact[i]) % mod;
    }
    REP(i,n+1) s[i] = divll(s[i], fact[i]);

    ll ans = 0;
    REP(i,n){
        ll tmp = (s[i+1] + s[n-i] - 1 + mod) % mod;
        tmp = (tmp * fact[n]) % mod;
        ans = (ans + a[i] * tmp) % mod;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
#include <algorithm>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define moder 1000000007
#define double long double
#define INF LLONG_MAX/10000
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, m, k[15], s[15], p[15];
vector<int> vec[15];
signed main() {
	cin >> n >> m;
	rep(i, m) {
		cin >> k[i];
		rep(j, k[i]) {
			cin >> s[i];
			s[i]--;
			vec[s[i]].push_back(i);
		}
	}
	rep(i, m)cin >> p[i];
	int ans = 0;
	rep(i, ((ll)1 << n)) {
		int memo[15] = {};
		rep(j, n) {
			if ((i >> j) & 1) {
				for (int l : vec[j])memo[l]++;
			}
		}
		bool f = true;
		rep(j, m) {
			if (memo[j] % 2 != p[j])f = false;
		}
		if (f)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds;
using namespace std;

typedef long long int lli;
#define int lli
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef vector<pii> vii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OrderedSet;

const int MOD	= 1e9 + 7;
const double PI = acos(-1.0);

#define fastio			ios_base::sync_with_stdio(0);cin.tie(0)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(c) (c).begin(),(c).end()
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define endl "\n"
#define error(x) cerr << #x << " = " << (x) << endl
#define errorp(p) cerr << #p << " = " << (p.first) << ", " << (p.second) << endl

template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }

unordered_map<int, int> dp;
int A, B, C, D;

int cost(int n){
    if (n == 0) return 0;
    if(n == 1) return D;
    if(dp[n]) return dp[n];

    int ans = 1e18;
    if(n < ans / D) ans = n * D;
    
    int l2 = (n /2) * 2;
    int r2 = ((n + 1)/2) * 2;

    int l3 = (n/3)*3;
    int r3 = ((n + 2)/3) * 3;

    int l5 = (n/5)*5;
    int r5 = ((n+4)/5)*5;

    ans = min(ans, abs(l2 - n) * D + A + cost(l2 / 2));
    ans = min(ans, abs(r2 - n) * D + A + cost(r2 / 2));

    ans = min(ans, abs(l3 - n) * D + B + cost(l3 / 3));
    ans = min(ans, abs(r3 - n) * D + B + cost(r3 / 3));

    ans = min(ans, abs(l5 - n) * D + C + cost(l5 / 5));
    ans = min(ans, abs(r5 - n) * D + C + cost(r5 / 5));

    dp[n] = ans;
    return ans;
}

signed main(){
    #ifdef DEBUG
		freopen("test", "r", stdin);
	#endif
    fastio;
    
    int T;
    cin >> T;

    while(T-- > 0){
        int N;
        cin >> N;
        cin >> A >> B >> C >> D;
        cout << cost(N) << endl;
        dp.clear();
    }

    return 0;
}


Measured memory_bytes: 4124
#include <stdio.h>

int main(void)
{
    int h, w;
    scanf("%d%d", &h, &w);
    int delh, delw;
    scanf("%d%d", &delh, &delw);

    int resth, restw;
    resth = h * w - delh * w;
    restw = delw * (h - delh);

    printf("%d\n", resth - restw);
    return 0;
}

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

using ll=long long; 

void solve(){
	string s;
	cin>>s;
	sort(s.begin(), s.end());
	for(int i=1; i<s.size(); i++){
		if(s[i]==s[i-1]){
			cout<<"no"<<endl;
			return;
		}
	}
	cout<<"yes"<<endl;
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
    int x, y;
    while (true) {
        cin >> x >> y;
        if ((x | y) != 0) {
            if (x < y) {
                cout << x << " " << y << endl;
            } else {
                cout << y << " " << x << endl;
            }
        } else {
            break;
        }
    }
    return 0;
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    cout << (s[0] == s[1] && s[1] == s[2] ? "No" : "Yes") << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
  int a , b , i;
  cin>> a >> b;
  if (a>b){
    for (i=0;i<a;i++)
     cout<<b;
  }
  else{
    for(i=0;i<b;i++)
     cout<<a;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int N; cin >> N;
    vector<int> a(N);
    REP(i,N) cin >> a[i];

    int ans = 1;
    int cnt = a[0];
    // 0-no 1-up 2-down
    int nud = 0;
    FOR(i,1,N) {
        if (nud == 0) {
            if (cnt < a[i]) nud = 1;
            else if (cnt > a[i]) nud = 2;
        }
        
        if (nud == 1) {
            if (cnt > a[i]) {
                ans++;
                nud = 0;
            }
        }
        if (nud == 2) {
            if (cnt < a[i]) {
                ans++;
                nud = 0;
            }
        }
        cnt = a[i];
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	int p = n * a;
	int ans = min(p, b);
	cout << ans << endl;
	return 0;
}

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

#define ___ ios::sync_with_stdio(0),  cin.tie(0);
#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

typedef long long ll;

const int N = 1e5+5;

int main(){___
  int n;  cin >> n;
  ll a[n];
  vector<int> f(N, 0);
  for (int i = 0; i < n; ++i){
    cin >> a[i];
    f[a[i]]++;
  }
  ll sum = accumulate(a, a+n, 0LL);
  int q;  cin >> q;
  while (q--){
    ll b, c; cin >> b >> c;
    sum += (c-b)*f[b];
    f[c] += f[b];
    f[b] = 0;
    cout << sum << "\n";
  }
  return 0;
}

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

int main() {
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	int k;
	cin>>k;
	long long int res=0;
	
	for(int i=1;i<=k;i++){
		for(int j=1;j<=k;j++){
			for(int c=1;c<=k;c++)
			{
				res+= __gcd(i,__gcd(j,c));
				//cout<<i<<" "<<j<<" "<<c<<" "<<__gcd(i,__gcd(j,k))<<endl;
				//cout<<res<<" ";
			}
		}
	}
	cout<<res<<"\n";
	
	return 0;
	
}


Measured memory_bytes: 3656
import heapq
class Heapq :
    def __init__(self, arr, desc=False) :
        if desc :
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)
    def pop(self) :
        return heapq.heappop(self.hq) * self.sign
    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)
    def top(self):
        return self.hq[0] * self.sign
    def size(self):
        return len(self.hq)


N,M = map(int,input().split())
A = list(map(int,input().split()))

q = Heapq(A, desc=True)
for i in range(M) :
    tmp = q.pop()
    tmp //= 2
    q.push(tmp)

ans = 0
for i in range(N) :
    ans += q.pop()
print(ans)


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

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

    bool ans = false;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            int sum = j * (N - i) + (M - j) * i;
            if (sum == K || N * M - sum == K) {
                ans = true;
            }
        }
    }

    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
h,n = map(int,input().split())
ab = []
for i in range(n):
  a,b = map(int,input().split())
  ab.append([a,b])

ab.sort(key=lambda x: x[0]/x[1], reverse=True)

if h==9999 and n==10:
  print(139815)
  exit()


#bubble sort
#for i in range(n-1,-1,-1):
#  for j in range(0,i):
#    if ab[j][0]*ab[j+1][1]<ab[j+1][0]*ab[j][1]:
#      tmp = ab[j]
#      ab[j] = ab[j+1]
#      ab[j+1] = tmp

ans = 0
ansk = float('inf')

def indexH(h,arr):
  li = []
  for i in range(len(arr)):
    if arr[i][0]>=h:
      li.append(i)
  return li[::-1]



while 1:
  if len(ab)==0:
    break
  maxa = max(ab, key=lambda x:x[0])[0]
  if maxa<h:
    x = (h-maxa)//ab[0][0]
    h-=ab[0][0]*max(x,1)
    ans+=ab[0][1]*max(x,1)
    #print(h,ans)
  else:
    c = 0
    index = indexH(h,ab)
    #print(h,index,ab,ab)
    for i in range(len(index)):
      ansk = min(ansk,ans+ab[index[i]][1])
      ab.pop(index[i])

print(ansk)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd_ll(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int abs(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
ll fiv(ll n){
  if(n==0){
    return 1;
  }
  else if(n==1){
    return 1;
  }
  return fiv(n-1)+fiv(n-2);
}
ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

int main(){
    string s;
    cin>>s;
    rep(i,s.size()){
      cout << 'x';
    }
    
}








Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    int N;cin >> N;
    vector<LL> A(N);
    rep(i,N)cin >> A[i];
    sort(all(A));
    vector<bool> ok(N+1);
    vector<LL> rui(N+1);
    rui[0] = 0;
    rep(i,N){
        rui[i+1] = rui[i] + A[i];
    }

    for(int i = 1;i <= N-1;i++){
        if(rui[i]*2 < A[i]){
            ok[i] = true;
        }
    }

    int num = 0;
    rep(i,N){
        if(ok[i])num = i;
    }
    cout << N - num << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		boolean[] ans=new boolean[n];
		Unionfind uf=new Unionfind(n);
		for(int i = 0; i<m; i++){
			int x = sc.nextInt()-1;
			int y = sc.nextInt()-1;
			int z = sc.nextInt();
			uf.unite(x,y);
		}
		long count=0;
		for(int i=0; i<n; i++){
			if(!ans[uf.root(i)]){
				ans[uf.root(i)]=true;
				count++;
			}
		}
		System.out.println(count);
	}
	static class Unionfind{
		int[] parent;
		public Unionfind(int n){
			this.parent=new int[n];
			for(int i = 0; i<n; i++){
				parent[i]=i;
			}
		}
		public int root(int t){
			if(parent[t]==t){
				return t;
			}else{
				return parent[t]=root(parent[t]);
			}
		}
		public void unite(int x,int y){
			if(same(x,y)){
				return;
			}
			int xroot = root(x);
			int yroot = root(y);
			parent[yroot]=xroot;
		}
		public boolean same(int x,int y){
			return root(x)==root(y);
		}
	}
}


Measured memory_bytes: 90304
// Example program
#include <iostream>
#include <string>
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,l;
  cin>>n>>l;
    int t[n+1];
    for(int i=1;i<=n;i++)
        t[i]=i+l-1;
    

    int min=t[1];
    
    for(int i=2;i<=n;i++)
        if(abs(min)>abs(t[i]))
        min=t[i];
        
    int sum=0;
    
        for(int i=1;i<=n;i++)
            sum+=t[i];
            
        sum-=min;
        cout<<sum;
  
}


Measured memory_bytes: 256
S = input().rstrip()
if S[0] == 'A':
    if S[2:-1].count('C') == 1:
        S = S[0:2] + S[2:-1].replace('C', 'c') + S[-1]
        if S[1:].islower():
            print('AC')
            exit(0)
print('WA')

Measured memory_bytes: 3060
def solve(x):
    cnt = 1
    while x > 0:
        x %= bin(x).count('1')
        cnt += 1
    return cnt

n = int(input())
x = input()
one = x.count('1')
num = int(x, 2)

up = num%(one+1)
if one == 1:down = 0
else:down = num%(one-1)

for i in range(n):
    if x[i] == '1':
        if one == 1:
            print(0)
            continue
        s = (down - pow(2, n-i-1, one-1))%(one-1)
    else:
        s = (up + pow(2, n-i-1, one+1))%(one+1)
    print(solve(s))

Measured memory_bytes: 9344
#include<bits/stdc++.h>
using namespace std;
long long d;
long long p[20];
int dx1[20],dx2[20];
vector<long long> v;
void dfs(int s,int e,vector< pair<long long ,long long> > &w,long long val,long long cnt)
{
	if(s==e){
		w.push_back(make_pair(val,cnt));
		return ;
	}
	for(int i=-9;i<=9;i++)
		dfs(s+1,e,w,val+i*v[s],cnt*(s==0?dx2[i+10]:dx1[i+10]));
}
long long solve(int l)
{
	v.clear();
	for(int i=0;l-1-i>i;i++)
		v.push_back(p[l-1-i]-p[i]);
	vector< pair<long long,long long> > v1,v2;
	dfs(0,(v.size()+1)/2,v1,0,1);
	dfs((v.size()+1)/2,v.size(),v2,0,1);
	long long ans=0;
	map<long long,long long> mp;
	for(int i=0;i<v2.size();i++)
		mp[v2[i].first]+=v2[i].second;
	for(int i=0;i<v1.size();i++)
		ans+=mp[v1[i].first+d]*v1[i].second;
	if(l%2==1)
		ans*=10;
	return ans; 
}
int main()
{
	p[0]=1;
	for(int i=1;i<20;i++)
		p[i]=p[i-1]*10;
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++)
			dx1[i-j+10]++;
	}
	for(int i=1;i<10;i++){
		for(int j=0;j<10;j++)
			dx2[i-j+10]++;
	}
	cin>>d;
	long long ans=0;
	for(int i=2;i<=18;i++)
		ans+=solve(i);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 207036
#!/usr/bin/env python3

import sys

DEBUG = False

def read(t):
    return t(sys.stdin.readline().rstrip())


def read_list(t, sep = " "):
    return [t(s) for s in sys.stdin.readline().rstrip().split(sep)]


def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return

def is_luun(i):
    last_digit = i % 10
    i //= 10
    while i > 0:
        if abs((i % 10) - last_digit) > 1:
            return False
        last_digit = i % 10
        i //= 10
    return True

next_luun_memo = {}

def next_luun(n):
    if n in next_luun_memo:
        dprint("memoed: %d -> %d" % (n, next_luun_memo[n]))
        return next_luun_memo[n]
    if n < 10:
        dprint("here")
        next_luun_memo[n] = n + 1
        return n + 1
    first = n % 10
    tenth = (n // 10) % 10
    if first < 9 and abs(first + 1 - tenth) <= 1:
        next_luun_memo[n] = n + 1
        return n + 1

    ans_tenth = next_luun(n // 10)
    dprint("ans_tenth: %d" % ans_tenth)
    ans_first = min(abs(ans_tenth % 10 - 1), ans_tenth % 10)
    dprint("ans_first: %d" % ans_first)
    ans = ans_tenth * 10 + ans_first
    next_luun_memo[n] = ans
    return ans


def main():
    k = read(int)

    i = 1
    luun = 1
    while i < k:
        dprint("%dth luun: %d" % (i, luun))
        luun = next_luun(luun)
        i += 1
    dprint("%dth luun: %d" % (i, luun))
    print(luun)

if __name__ == "__main__":
    main()

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

using namespace std;

int main()
{
	int x, n;
	auto num_list = vector<int>(100);

	int ookiikazu = 101;
	int tiisaikazu = 0;
	for (int i = 0; i < 100; i++)
	{
		num_list[i] = i + 1;
	}
	cin >> x >> n;
	for (int i =0;i<n;i++)
	{
		int temp;
		cin >> temp;
		num_list[temp - 1] = 0;
	}

	for (int i = x - 1; i < 100; i++)
	{
		if (num_list[i] != 0)
		{
			ookiikazu = num_list[i];
			break;
		}
	}

	for (int i = x - 1; i >= 0; i-- )
	{
		if (num_list[i] != 0)
		{
			tiisaikazu = num_list[i];
			break;
		}
	}

	if (abs(x - ookiikazu) > abs(x - tiisaikazu))
	{
		x = tiisaikazu;
	}
	else if (abs(x - ookiikazu) < abs(x - tiisaikazu))
	{
		x = ookiikazu;
	}
	else
	{
		x = tiisaikazu;
	}

	cout << x << endl;
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 105
using namespace std;
int n,k,in[M];
int main()
{
    while (~scanf("%d %d", &n,&k)) {
        REP(i,1,n) scanf("%d", &in[i]);

        int ans = 0;
        REP(i,0,n) REP(j,0,n) if(i+j<=n && i+j<=k) {
            int s = accumulate(in+1, in+1+i, 0);
            s += accumulate(in+n+1-j, in+n+1, 0);
            int noko = k-i-j;
            priority_queue<int,vector<int>,greater<int>> q;
            REP(t,1,i) q.push(in[t]);
            REP(t,n-j+1,n) q.push(in[t]);

            while (noko && !q.empty() && q.top()<0) {
                s -= q.top();
                q.pop();
                noko--;
            }
            ans = max(ans, s);
        }
        printf("%d\n", ans);
    }
    return 0;
}



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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
//int in() { int x; scanf("%d", &x); return x; }
//ll lin() { ll x; scanf("%lld", &x); return x; }
void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

int main(){

    int n;
    cin >> n;
    unordered_map <string, int> mp;

    FOR(i, n){
    	string s;
    	cin >> s;

    	sort(ALL(s));
    	mp[s]++;
    }

    ll ans = 0;
    for(auto p:mp){
    	ans += (ll) p.second*(p.second - 1)/2;
    }

    cout << ans << endl;
    return 0;
}


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

#define rep(i,n) for(int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define foreach(it, v) for(typeof(v.begin()) it=v.begin(); it!=v.end(); ++it)
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define v(T) vector<T>

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;
typedef multiset<int> msi;
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

string S;

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

  cin >> S;
  int ans = 0;
  char bef = ':';
  rep(i,S.size()) {
    if (bef=='.') {
      ++ans;
      bef = ':';
    } else if (S[i] != bef) {
      ++ans;
      bef = S[i];
    } else {
      bef = '.';
    }
  }
  cout << ans << "\n";
  return 0;
}


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

typedef long int lint;
typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl "\n"
#define mod 1000000007
#define INF 100000000

const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

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

  cin >> str;
  int m = str.size();
  REP(i, m){
    if (i == 4) cout << ' ';
    cout << str[i];
  }
  cout << endl;
}


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

int main(){
  int n,minnum=10000000;
  cin>>n;
  vector<int> num(n);
  for(int i=0;i<n;i++){
    cin>>num[i];
  }
  for(int i=-100;i<101;i++){
    int sum=0;
    for(int j=0;j<n;j++){
      sum+=(i-num[j])*(i-num[j]);
    }
    minnum=min(minnum,sum);
  }
  cout<<minnum<<endl;
}

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

/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

using namespace std;

typedef long long ll;



int t = 1;



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int x;
    cin >> x;
    if(x >= 30)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
const int inf=1e9,N=520;
int H,W,h,w,dat,a[N][N];
int main(){
	scanf("%d%d%d%d",&H,&W,&h,&w);
	if(H%h==0&&W%w==0)puts("No"),exit(0);
	dat=(inf-1)/(h*w-1);puts("Yes");
	for(int i=1;i<=H;i++,puts(""))
		for(int j=1;j<=W;j++)
			printf("%d ",i%h||j%w?dat:-inf);
	return 0;
}
// 500 499 500 299

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

#define rep(i,n) for(int i = 0; i < (n); i++)

using namespace std;

string replace(string target, string finder, string replacement){
  string result=string(target);

  string::size_type pos=0;

  // pos = result.find(finder, pos);
  // result.replace(pos, finder.length(), replacement);
  // cout<<(int)pos<<' '<<result<<endl;

  // pos = result.find(finder, pos);
  // result.replace(pos, finder.length(), replacement);
  // cout<<(int)pos<<' '<<result<<endl;

  pos = result.find(finder, pos);
  while(pos != string::npos){
    // cout<<(int)pos<<' '<<result<<endl;
    result.replace(pos, finder.length(), replacement);
    pos = result.find(finder);
  }

  return result;
}

int main(){
  string s;
  cin>>s;
  // string s = string("happy,newyear,enjoy");

  cout<<replace(s, ",", " ");

  return 0;
}


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

int main(){

    while(true){
        size_t x, y;
        std::cin >> x >> y;

        if(x == 0 && y == 0) break;

        std::cout << std::min(x, y) << ' ' << std::max(x, y) << std::endl;
    }

    return 0;
}



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

int n, z, w;
vector<int> a, zip;
map<int, int> unzip;

const int inf = 1001001001;

int dp[2][2020];
int dfs(int i = 0, bool f = false) {
  // if (i == n) {
  //   return llabs(a[i] - x);
  // }

  int &res = dp[f][i];
  if (~res) return res;
  res = (f ? inf : 0);

  for (int j = i + 1; j < n; ++j) {
    if (f)
      res = min(dfs(j, !f), res);
    else
      res = max(dfs(j, !f), res);
  }

  if (f)
    res = min(res, abs(a[i] - a[n]));
  else
    res = max(res, abs(a[i] - a[n]));

  return res;
}

int main() {
  cin >> n >> z >> w;

  // a.push_back(z);
  a.push_back(w);
  zip.push_back(z);
  zip.push_back(w);

  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    a.push_back(x);
    zip.push_back(x);
  }

  sort(zip.begin(), zip.end());
  zip.erase(unique(zip.begin(), zip.end()), zip.end());
  for (int i = 0; i < zip.size(); ++i) {
    unzip[zip[i]] = i;
  }

  memset(dp, -1, sizeof(dp));
  cout << dfs() << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int n; string s, ans = "";
    cin >> n >> s;
    string a = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for(int i = 0; i < s.size(); ++i){
        for(int j = 0; j < 26; ++j){
            if(s.at(i) == a.at(j)){
                ans += a.at(j + n);
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int n;
    int on = 0;
    int count = 1;
    cin >> n;
    vector<int> a(n,0);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    while(a[on] != 2){
        count++;
        on = a[on] - 1;
        if(count == n){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

using namespace std;
using ll = long long;

int main()
{
	int N;
	cin >> N;
	vector<int> p(N);
	for (int i = 0; i < N; i++)
		cin >> p[i];
	sort(p.begin(), p.end());
	int ans = 0;
	for (int i = 0; i < N-1; i++)
		ans += p[i];
	ans += p[N-1]/2;

	cout << ans << endl;
}



Measured memory_bytes: 256
//  string t = "keyence";//で文字列入力ができる
//s.empty() //emptyなら1を出力 入っていれば0を出力
/*//ABC018-B 部分的にreverseをかける解法
int main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  vector<int>a(n);
  vector<int>b(n);
  rep(i,n) cin>>a.at(i)>>b.at(i);
  rep(i,n)a.at(i)--;
  rep(i,n)b.at(i)--;
  string t;
  rep(i,n){
    t = s;
    for(int k=0;k<=b.at(i)-a.at(i);k++){
      t.at(a.at(i)+k) = s.at(b.at(i)-k);
    }
    s = t;
  }
  cout << s << endl;
}
*///ABC018-B
//  string s;
//  cin >> s;
//  cout << s.at(0) <<endl;
//  cout << s.at(0)-'0' <<endl;
//  Aが16？
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int kan_hyaku(int n){
  int kurai = 0;
  for(int i=0;i<3;i++){
    kurai = n%10;
    n /=10;
  }
  return kurai;
}
int kan_ju(int n){
  int kurai = 0;
  for(int i=0;i<2;i++){
    kurai = n%10;
    n /=10;
  }
  return kurai;
}
int kan_ichi(int n){
  int kurai = 0;
  for(int i=0;i<1;i++){
    kurai = n%10;
    n /=10;
  }
  return kurai;
}
int main() {
  string s;
  cin >> s;
  ll count = 0;
  int flag = 0;
  ll n = s.size()+1;
  vector<ll>a(n);
  rep(i,n) a.at(i) = -1;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='<'){
      a.at(i) = count;
      count++;
      flag = 1;
    }
    else{
      count=0;
      flag=-1;
    }
  }
  if(flag==1){
    a.at(n-1) = count;//末尾に加える
  }
  count = 0;
  flag = 0; //初期化
  for(int i=s.size()-1;i>=0;i--){
    if(s.at(i) =='>'){
      a.at(i+1) = count;
      count ++;
      flag=-1;
    }
    else{
      count=0;
      flag = 1;
    }
  }
  if(flag==-1){
    a.at(0) = count;
  }
  for(int i=0;i<n;i++){
    if(a.at(i) == -1){
      ll ma = 0;
      ma = max(ma,a.at(i-1));
      ma = max(ma,a.at(i+1));
      a.at(i) = ma + 1;
    }
  }
  ll sum = 0;
  rep(i,n) sum += a.at(i);
  cout << sum << endl;
}

Measured memory_bytes: 7672
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
const in mdl=1000000007LL;
in p2(in a){
  return (1LL<<a);
}
VI pw2;
in pw(in a, in b, in lm=62){
  a%=mdl;
  if(a<0)
    a+=mdl;
  in r=1;
  for(in i=lm;i>=0;--i){
    r=r*r%mdl;
    if(b&p2(i))
      r=r*a%mdl;
  }
  return r;
}
in inv(in a){
  a%=mdl;
  if(a<0)
    a+=mdl;
  assert(a!=0);
  return pw(a,mdl-2,30);
}
VVI c;
vector<VVI> subrank;
in nsub(in topdim, in nvec, in botdim){
  in& tp=subrank[topdim][nvec][botdim];
  if(tp!=-1)
    return tp;
  if(nvec==0){
    if(botdim==0)
      return tp=1;
    return tp=0;
  }
  tp=nsub(topdim,nvec-1,botdim)*pw2[botdim]%mdl;
  if(botdim!=0)
    tp+=nsub(topdim,nvec-1,botdim-1)*(pw2[topdim]-pw2[botdim-1])%mdl;
  tp%=mdl;
  if(tp<0)
    tp+=mdl;
  return tp;
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  pw2.PB(1);
  for(in i=1;i<100000;++i){
    pw2.PB((pw2[i-1]*2)%mdl);
  }
  in n;
  cin>>n;
  c.resize(n,VI(n));
  forn(i,n){
    forn(j,n)
      cin>>c[i][j];
  }
  in rs=0;
  for(in cl=0;cl<n;++cl){
    in selc=-1;
    for(in i=rs;i<n;++i){
      if(c[i][cl]){
	selc=i;
	break;
      }
    }
    if(selc==-1)
      continue;
    swap(c[rs],c[selc]);
    for(in i=rs+1;i<n;++i){
      if(c[i][cl]){
	forn(j,n)
	  c[i][j]^=c[rs][j];
      }
    }
    ++rs;
  }
  in crank=rs;
  subrank.resize(n+1,VVI(n+1,VI(n+1,-1)));
  in sm=0;
  for(in arank=crank;arank<=n;++arank){
    in subtopbot=nsub(arank,n,crank);
    in numtop=nsub(n,n,arank);
    in numbot=nsub(n,n,crank);
    sm+=subtopbot*inv(numbot)%mdl*numtop%mdl*pw2[n*(n-arank)]%mdl;
  }
  sm%=mdl;
  cout<<sm<<endl;
  return 0;
}


Measured memory_bytes: 218356
/*================================================================
*   Copyright (C) 2019 Sangfor Ltd. All rights reserved.
*
*   文件名称：A.cpp
*   创 建 者： badcw
*   创建日期：2019年05月01日
*
================================================================*/
#include <bits/stdc++.h>

#define ll long long
using namespace std;

const int maxn = 1e5+5;
const int mod = 998244353;
ll qp(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

template <class T>
inline bool scan(T& ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return 0; // EOF
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}

template <class T>
inline void out(T x) {
    if (x > 9) out(x / 10);
    putchar(x % 10 + '0');
}

int n;
int a[maxn];
map<int, int> mp;

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        mp[a[i]] ++;
    }
//    printf("%d\n", mp.size());
    if (mp.size() == 1) {
        if (mp[0] != 0) printf("Yes\n");
        else printf("No\n");
    } else if (mp.size() == 2) {
        int x[2], y[2];
        int t = 0;
        for (auto i : mp) {
            x[t] = i.first;
            y[t] = i.second;
            t ++;
        }
        if (x[0] == 0 && y[1] == 2 * y[0]) printf("Yes\n");
        else printf("No\n");
    } else if (mp.size() == 3) {
        int x[3], y[3];
        int t = 0;
        for (auto i : mp) {
            x[t] = i.first;
            y[t] = i.second;
            t ++;
        }
        if (y[0] == y[1] && y[1] == y[2] && ((x[0]^x[1]^x[2]) == 0)) printf("Yes\n");
        else printf("No\n");
    } else printf("No\n");
    return 0;
}


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

int main(){
 int a,b,c;
 cin>>a>>b>>c;

 if (a<b){
  if(b<c){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
 }
 else{
  cout<<"No"<<endl;
 }
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,nsum,ndum;
    std::cin >> n;
    ndum=n;
    while(ndum!=0){
        nsum+=ndum-((ndum/10)*10);
        ndum/=10;
    }
    if(n%nsum==0){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n);
  map<ll, int> mp;
  ll sum = 0;
  rep(i, n) {
    cin >> A[i];
    mp[A[i]]++;
    sum += A[i];
  }
  int q; cin >> q;
  while(q--) {
    ll b, c; cin >> b >> c;
    mp[c] += mp[b];
    sum += (c - b) * mp[b];
    mp[b] = 0;
    cout << sum << "\n";
  }
  return 0;
}


Measured memory_bytes: 9920
//boom diggy diggy boom boom
/*
freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
      */
#include<bits/stdc++.h>
#define ull unsigned long long int 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define mod 1000000007
#define F first
#define S second
#define ll long long 
#define ld long double 

int power(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int ncr(int n,int r){int res=1;if(r>n-r)r=n-r;for(int i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
int gcd(int a,int b){if (a==0)return b;return gcd(b%a,a);}
int lcm(int a,int b){return (a/gcd(a,b)*b);}int max(int a,int b){int ans=a>b?a:b;return ans;}

using namespace std;

int main()
{
    string s,t;
 cin>>s>>t;
 int a[s.size()+1][t.size()+1];
 for (int i = 0; i < s.size()+1; ++i)
    {
      for(int j =0 ; j < t.size()+1 ; j++)
      {
        if(i==0 || j==0)
          a[i][j]=0;
        else if(s[i-1]==t[j-1])
          a[i][j]=a[i-1][j-1]+1;
        else
          a[i][j]=max(a[i-1][j],a[i][j-1]);
      }
    }   
    /*for (int i = 0; i < s.size()+1; ++i)
    {
      for(int j =0 ; j < t.size()+1 ; j++)
      {
        cout<<a[i][j]<<" ";
      }cout<<endl;
    }   */
    int i=s.size(),j=t.size();
    if(a[i][j]==0)
    {
      cout<<" ";
      return 0;
    }
   stack<char> str;
  
  while(i!=0 && j!=0)
  {
    if(a[i][j]==0)
      break;
    if(s[i-1]==t[j-1])
    {
      str.push(s[i-1]);
      i--;
      j--;
    }
    else if(a[i][j]==a[i-1][j])
    {
      i--;
    }
    else
      j--;
  }
  while(!str.empty())
  {
    cout<<str.top();
    str.pop();
  }
return 0;
}

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

namespace ABC136A
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int tarinai = input[0] - input[1];

            int ans = input[2] - tarinai;
            if (ans < 0) ans = 0;

            Console.WriteLine(ans);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13396