akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int makecombi(int i, int n, vector<int> &s, vector<vector<int>> &ss, int &counter) {

	if (i == n) {
		for (int j = 0; j < n; j++) {
//			cout << s[j];
			ss[counter][j] = s[j];
		}
//		cout << endl;
		counter++;
		return 0;
	}

	makecombi(i + 1, n, s, ss, counter);
	s[i] = 1;
	makecombi(i + 1, n, s, ss, counter);
	s[i] = 0;
	return 0;
}

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

	//組み合わせ作り
	vector<int> s(n, 0);
	vector<vector<int>> ss(pow(2, n), vector<int>(n, 0)); //組み合わせは2^n個ある
	int counter = 0;;

	makecombi(0, n, s, ss, counter);

	for (int i = 0; i < counter; i++) {
		for (int j = 0; j < n; j++) {
//			cout << ss[i][j];
		}
//		cout << endl;
	}

	vector<int> c(n + 1);
	vector<vector<int>> a(n + 1, vector<int>(m + 1));
	for (int i = 1; i <= n; i++) {
		cin >> c[i];
		for (int j = 1; j <= m; j++) {
			cin >> a[i][j];
		}
	}

	int minn = 10000000;
	for (int i = 0; i < counter; i++) {
		int sum = 0;
		vector<int> xx(m + 1,0);
		for (int j = 0; j < n; j++) {
			if (ss[i][j] == 1) {
				sum += c[j + 1];
				for (int k = 1; k <= m; k++) {
					xx[k] += a[j+1][k];
				}
			}
		}
		for (int k = 1; k <= m; k++) {
			if (xx[k] < x) {
				break;
			}
			if (k == m) {
				minn = min(minn, sum);
			}
		}
	}

	cout << (minn==10000000? -1 : minn) << endl;

	return 0;
}

Measured memory_bytes: 4352
N = int(input())
X = list(map(int, input().split()))
sum = 0
min_sum = 100000000
P = 1
while P <= 100:
  for n in X:
    sum = sum +(n-P)**2
  if sum <= min_sum:
    min_sum = sum
  P = P + 1
  sum = 0
print(min_sum)

Measured memory_bytes: 3060
#include <stdio.h>
#define N 100

int isLeft( double xy[ 2 ][ N ], int a, int b, int x ){
  double x1 = xy[ 0 ][ b ] - xy[ 0 ][ a ];
  double y1 = xy[ 1 ][ b ] - xy[ 1 ][ a ];
  double x2 = xy[ 0 ][ x ] - xy[ 0 ][ a ];
  double y2 = xy[ 1 ][ x ] - xy[ 1 ][ a ];

  return ( x1 * y2 - x2 * y1 > 0 ) ? 1 : 0;
}

int main( void ){
  int i, j, k, n;
  double xy[ 2 ][ N ]; // vertex
  int mostLeftIndex;
  int next[ N ]; // edge
  int cur, count;
  char hoge;

  while( 1 ){
    scanf( "%d", &n);
    if( !n ) break;

    for( i = 0; i < n; i++ ){
      scanf( "%lf%c%lf", &xy[ 0 ][ i ], &hoge, &xy[ 1 ][ i ] );
    }

    for( i = 0; i < n; i++ ){
      next[ i ] = -1; // null value
    }

    mostLeftIndex = 0;
    for( i = 1; i < n; i++ ){
      if( xy[ 0 ][ mostLeftIndex ] > xy[ 0 ][ i ] )
        mostLeftIndex = i;
    }

    i = mostLeftIndex;
    next[ i ] = (i+1)%n;
    for( j = 0; j < n; j++ ){
      if( j == i || j == next[ i ] ) continue;

      if( isLeft( xy, i, next[ i ], j ) ){
        next[ i ] = j;
      }
    }
    count = 1;
    i = next[ i ];

    while( i != mostLeftIndex ){
      next[ i ] = (i+1)%n;
      for( j = 0; j < n; j++ ){
        if( j == i || j == next[ i ] ) continue;

        if( isLeft( xy, i, next[ i ], j ) ){
          next[ i ] = j;
        }
      }
      count++;
      i = next[ i ];
    }

    printf( "%d\n", n - count );
  }

  return( 0 );
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define vsort(v) sort(v.begin(),v.end())
#define asort(a,n) sort(a, a + n)
#define vi vector<int>
#define vd vector<double>

//ここからAtCoder向けdefine
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    string str;
    cin >> str;
    int n = 0;
    rep(i, str.size()){
        if(str.at(i) == '1'){
            n++;
        }
    }

    cout << n << endl;

    return 0;
}

Measured memory_bytes: 256
// パナソニックプログラミングコンテスト2020 C.cpp

#include <iostream>
#include <boost/multiprecision/cpp_dec_float.hpp>

using namespace std;
namespace mp = boost::multiprecision;

int main()
{
	mp::cpp_dec_float_100 a, b, c;
	cin >> a >> b >> c;
	a = mp::sqrt(a);
	b = mp::sqrt(b);
	c = mp::sqrt(c);
	if ((a + b) < c) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

#define int long long
#define fi first
#define se second
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) ct(v[i])
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int n,a,b;

main() {
    cin >> n >> a >> b;
    if ((b-a)%2) ct("Borys")
    else ct("Alice")
}


Measured memory_bytes: 256
from collections import defaultdict
from re import finditer
from bisect import bisect_right

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


    str_dict = defaultdict(list)



    for char in set(t):
        c_iter = finditer(char, s)
        flag = True
        for j in c_iter:
            flag = False
            str_dict[char] += [j.start() + 1]
        if flag:
            return '-1'


    ans = 0
    for i in t:
        remain = ans % len(s)
        array = str_dict[i]
        str_ind = bisect_right(array, remain)
        if str_ind != len(array):
            ans += array[str_ind] - remain
        else:
            ans += len(s) - remain + array[0]
    return ans


print(main())

Measured memory_bytes: 56312
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define all(X) X.begin(),X.end()

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   str.substr (x) : returns a substring str[x],... end of string
   str.find(qtr) : returns the first occurenece of qtr in str */

const int M = (1<<20)+5;
const int md = 1e9+7;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	char a;
	cin >> a;
	cout << (char)(a-'a'+1+'a') << "\n";

}

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

int main() {
  string S;
  cin >> S;
  if(S=="SUN"){
    cout<<7<<endl;
  }
  if(S=="MON"){
    cout<<6<<endl;
  }
  if(S=="TUE"){
    cout<<5<<endl;
  }
  if(S=="WED"){
    cout<<4<<endl;
  }
  if(S=="THU"){
    cout<<3<<endl;
  }
  if(S=="FRI"){
    cout<<2<<endl;
  }
  if(S=="SAT"){
    cout<<1<<endl;
  }
}


Measured memory_bytes: 256
/*    FAILING IS AN ART
       AND 
     I HAVE MASTERED IT
*/
#include<bits/stdc++.h>
#define ll  long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
#define ld long double
using namespace std;

int main()
{ 

    fast;

    ll n,r;
    cin>>n>>r;

    if(n>=10)
        cout<<r<<endl;
    else
    {
        cout<< r+ 100*(10-n)<<endl;
    }



}


Measured memory_bytes: 256
use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();

    let mut three_iter = buf.split_whitespace()
        .into_iter()
        .map(|s| s.parse::<u32>().unwrap());
    let first = three_iter.next().unwrap();
    match three_iter.all(|elem| elem == first) {
        true => println!("Yes"),
        false => println!("No"),
    }
}


Measured memory_bytes: 4352
s=input()
former=int(s[:2])
latter=int(s[2:])

if former>0 and former<13:
    if latter>0 and latter<13:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if latter>0 and latter<13:
        print("YYMM")
    else:
        print("NA")

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

using namespace std;

using ll = long long;

const int MOD = 1e9 + 7;

template<typename T>
void min_self(T& a, T b)
{
    a = min(a,b);
}

template<typename T>
void max_self(T& a, T b)
{
    a = max(a,b);
}

const int Nax=1000 + 5;

char matrix[Nax][Nax];

int main() {
    
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int H, W;
    scanf("%d%d",&H,&W);
    
    for(int i=0; i<H; ++i)
    {
        scanf("%s",matrix[i]);
    }

    vector<vector<int>> dp(H,vector<int>(W));
    
    dp[0][0] = 1;
    
    vector<pair<int,int>> nn = {{0,1},{1,0}};

    for(int i=0; i<H; ++i)
    {
        for(int j=0; j<W; ++j)
        {
            if(matrix[i][j] != '.')  continue;
            
            for(auto& n: nn)
            {
                if(i+n.first < H && j+n.second < W && matrix[i+n.first][j+n.second] == '.')
                {
                    dp[i+n.first][j+n.second] += dp[i][j];
                    dp[i+n.first][j+n.second] %= MOD;
                }
            }
        }
    }
    
    cout << dp[H-1][W-1];
    
}


Measured memory_bytes: 5248
#include <iostream>
#include <algorithm>
#include <vector>
int main() {
	int r, c;
	std::cin >> r >> c;
	std::vector<int> rows(c);
	std::vector<std::vector<int>> a;
	for (size_t i = 0; i < r; ++i)
	{
		a.push_back(rows);
	}

	for (int i = 0;i < r;++i) {
		for (int j = 0; j < c; ++j) {
			std::cin >> a[i][j];
		}
	}

	for (int i = 0; i < r; ++i) {
		int sum = 0;
		for (int j = 0; j < c; ++j) {
			std::cout << a[i][j] << " ";
			sum += a[i][j];
		}
		std::cout << sum << std::endl;
	}

	int final = 0;
	for (int i = 0; i < c; ++i) {
		int sum = 0;
		for (int j = 0; j < r; ++j) {
			sum += a[j][i];
		}
		std::cout << sum << " ";
		final += sum;
	}

	std::cout << final << std::endl;

	return 0;
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
int main() {
  int X,Y;
  cin>>X>>Y;
  if(Y%2==1) cout<<"No";
  else if(Y<2*X||Y>4*X) cout<<"No";
  else cout<<"Yes";
}



Measured memory_bytes: 3632
def examC():
    NM = LI(); NM.sort()
    if NM[0]>=2:
        ans = (NM[0]-2)*(NM[1]-2)
    else:
        if NM[1]==1:
            ans = 1
        else:
            ans = max(0,NM[1]-2)
    print(ans)


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Measured memory_bytes: 38384
# -*- coding: utf-8 -*-

S = input()
N = len(S)

half = int((N-1)/2)

flg = True
for i in range(int((half-1)/2)):
    if S[i] != S[half-1-i]:
        flg = False
        break
if flg == True and S[:half] == S[half+1:]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
// 有點不耐煩會破壞偉大的計劃

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 1e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug() {
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

int main() {
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long long n, k; cin >> n >> k;

    vector<long long> p(n);

    for(long long i = 0; i < n; i++) {
        cin >> p[i];
    }

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

    long long ans = accumulate(p.begin(), p.begin() + k, 0);

    cout << ans;

    return 0;
}


Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();

		if (b - a == c - b) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 21844
#include<cstdio>
#include<algorithm>
#define MOD 924844033
#define MAXN 2006
using namespace std;
int fac[MAXN],vis[MAXN][2],cnt,ed[MAXN*2],d[MAXN*2][MAXN][2],f[MAXN];
long long ans;
int n,k;
int main()
{
	//freopen("captain.in","r",stdin);
	//freopen("captain.out","w",stdout);
	scanf("%d%d",&n,&k);
	fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=1ll*fac[i-1]*i%MOD;
	for(int i=1;i<=n;i++)
		for(int j=0;j<=1;j++)
			if(!vis[i][j])
			{
				int len=0;
				for(int x=i,y=j;x<=n;x+=k,y^=1)
					vis[x][y]=1,len++;
				cnt+=len;
				ed[cnt]=1;
			}
	ed[0]=1;
	d[0][0][0]=1;
	for(int i=0;i<2*n;i++)
		for(int j=0;j<=n;j++)
		{
			d[i+1][j][0]=(d[i][j][0]+d[i][j][1])%MOD;
			if(!ed[i]) d[i+1][j+1][1]=d[i][j][0];
		}
	for(int i=0;i<=n;i++)
		f[i]=(d[n*2][i][0]+d[n*2][i][1])%MOD;
	long long ans=0;
	for(int i=0,j=1;i<=n;j=-j,i++)
		ans=((ans+1ll*f[i]*fac[n-i]*j)%MOD+MOD)%MOD;
	printf("%lld",ans);
}

Measured memory_bytes: 62976
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
using namespace std;

int main() {
	long long int a, b, c, d, n, m;
	string str;
	cin >> str;
	if (str[5] == '1' || str[6] >= '5') {
		cout << "TBD";
	}
	else {
		cout << "Heisei";
	}
	

}


Measured memory_bytes: 256
n=int(input())
s=str(input())
a=s.count('W')
b=s.count('E')
count=0
if s[0]=='W':
    count=b
else:
    count=b-1
ans=[count]
for i in range(1,n):
    if s[i-1]=='W':
        count+=1
    if s[i]=='E':
        count-=1
    ans.append(count)
print(min(ans))
    

Measured memory_bytes: 15520
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<sstream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<bitset>
#include<set>
#include<stack>
#include<queue>
#include<iomanip>
#include<memory.h>
#include<complex>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tuple<int,int> tii;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
#define DIV int(1e9+7)
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

 /* Coding Space*/
int n;
string str;

void dfs(string s){
while(1){
  int ss = s.size();
  char c = s[ss-1];
  char cb = s[ss-2];
  if(ss == n){
    if((s[ss-1] == s[1] && ((s[0] == 'S' && str[0] == 'o')||(s[0]=='W' && str[0] == 'x'))) ||
       (s[ss-1] != s[1] && ((s[0] == 'W' && str[0] == 'o')||(s[0]=='S' && str[0] == 'x')))){ 
    if(cb!= s[0]){
      if((str[ss-1] == 'o' && c == 'W') || (str[ss-1] == 'x' && c == 'S')){
        cout << s << endl;
        
        exit(0);
        //return;
      }else
        return;
    }else{
      if((str[ss-1] == 'o' && c == 'S') || (str[ss-1] == 'x' && c == 'W')){
        cout << s << endl;
        exit(0);
       // return;
      }else
        return;
    }
    }else
      return;
  }
  if(c == 'S' && cb == 'W')
    s.pb((str[ss-1] == 'o')?'W':'S');
  else if(c == 'S' && cb == 'S')
    s.pb((str[ss-1] == 'o')?'S':'W');
  else if(c=='W' && cb == 'S')
    s.pb((str[ss-1] == 'o')?'W':'S');
  else if(c == 'W' && cb == 'W')
    s.pb((str[ss-1] == 'o')?'S':'W');

}
  return;
}

int main(){
  cin >> n >> str;
  dfs("SS");
  dfs("SW");
  dfs("WS");
  dfs("WW");
  cout << -1 << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

typedef   signed long long int slli;
typedef unsigned long long int ulli;
const slli MAX_SLLI = 0x7FFFFFFFFFFFFFFF;
const slli MIN_SLLI = 0x8000000000000000;
const ulli MAX_ULLI = 0xFFFFFFFFFFFFFFFF;
const ulli MIN_ULLI = 0x0000000000000000;

#define N_TIMES(i, n)     for (ulli i = 0;     i <  n; ++i)
#define N_TIMES_REV(i, n) for (slli i = n - 1; i >= 0; --i)

#ifdef __DEBUG__
template<typename T>
std::ostream& operator<<(std::ostream &os, const std::list<T> &list)
{
  const std::string delim = ", ";
  typename std::list<T>::const_iterator itr = list.begin();
  while (itr != list.end()) {
    os << *itr;
    ++itr;
    if(itr != list.end()) os << delim;
  }
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v)
{
  const std::string delim = ", ";
  for (unsigned n = 0; n < v.size(); ++n) {
    os << v[n];
    if((n + 1) < v.size()) os << delim;
  }
  return os;
}
#endif /* __DEBUG__ */

int main()
{
  long x, a, b;
  std::cin >> x >> a >> b;
  
  if (std::abs(x - a) < std::abs(x - b)) {
    std::cout << 'A' << std::endl;
  } else {
    std::cout << 'B' << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
from queue import PriorityQueue

def bfs(num, c):
    ans=0
    queue=PriorityQueue()
    for i in range(len(c[num])):
        if num != i:
            queue.put_nowait((c[num][i], i))


    while not queue.empty():
        node=queue.get_nowait()
        if node[1] == 1:
            return node[0]
        else:
            for num in range(len(c[node[1]])):
                if num != node[1]:
                    queue.put_nowait((node[0]+c[node[1]][num], num))

H, W=map(int, input().split())
c=[]
numList=[0 for i in range(10)]

for i in range(10):
    c.append([int(i) for i in input().split()])

for i in range(H):
    for n in input().split():
        num=int(n)
        if -1 != num and 1 != num:
            numList[num]+=1
ans=0
for i in range(len(numList)):
    if numList[i] != 0:
        ans+=bfs(i,c)*numList[i]

print(ans)


Measured memory_bytes: 5488
#include<bits/stdc++.h>
using namespace std ;
int main () {
	long long n , ans = 0 ;
	cin >> n ;
	for (long long i = 2 ; i*i <= n ; ++i) {
		if (n % i == 0) {
			long long div = i ;
			while(n % div == 0) {
				++ans ;
				n /= div ;
				div *= i ;
			}
		}
		if(n % i == 0) {
            while(n % i == 0) {
                n /= i ;
            }
        }
	}
	if (n > 1) {
		++ans ;
	}
	cout << ans ;
	return 0 ;
}

Measured memory_bytes: 3624
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

N = int(input())
a = [int(t) for t in input().split()]
assert len(a) == N

# 同じ値が何個並んでいるか
sslen = [1]  # a[0]
for i in range(1, len(a)):
    if a[i] == a[i-1]:
        sslen[-1] += 1
    else:
        sslen.append(1)

print(sum(l//2 for l in sslen))

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

using namespace std;

int main()
{
	string str;
	int val = 700;
	cin >> str;

	for (int i = 0; i < str.size(); i++) {
		if (str[i] == 'o')
			val += 100;
	}

	cout << val << endl;


    return 0;
}


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

int main(){
	int x;
	cin >> x;
	int a, b;
	a = x/100;
	b = x%100;
	if(0 < a && a <= 12){
		if(0 < b && b <= 12){
			cout << "AMBIGUOUS" << endl;
		}else{
			cout << "MMYY" << endl;
		}
	}else{
		if(0 < b && b <= 12){
			cout << "YYMM" << endl;
		}else{
			cout << "NA" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdio>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

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

	k = pow(2, k);

	int mx=1;
	if (a < b) {
		mx = 2;
	}
	if (b < c) {
		mx = 3;
	}

	switch (mx)
	{
	case 1:
		a *= k;
		break;
	case 2:
		b *= k;
		break;
	case 3:
		c *= k;
		break;
	}


	cout << a+b+c << endl;

	return 0;
}

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

int main() {
    string cards, temp,a;
    int num, change;
     cin >> cards >> num;
     int i=0, sum=0;
    while(i<100){
       
        if(cards=="-")
        break;
        i=0;
        sum=0;
        while(i<num){
            cin >> change;
            sum+=change;
            i++;
        }
        a=cards;
        cards.append(cards.substr(0,sum%cards.length()));
        cards.erase(0,sum%a.length());
        
        cout << cards << endl;
        cin >> cards >> num;
        
    }
    
}



Measured memory_bytes: 3204
#include <algorithm>
#include <cstdio>
#include <map>

using namespace std;

map<int, pair<int, int>> p;
map<int, int> d;

int main()
{
    int H, W, D;
    if (scanf("%d%d%d", &H, &W, &D) < 3) return 0;

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            int x;
            if (scanf("%d", &x) < 1) return 0;
            p[x] = {i, j};
        }
    }

    map<int, pair<int, int>>::reverse_iterator ri = p.rbegin();
    int mx = ri->first;

    while (ri != p.rend())
    {
        int key = ri->first;
        pair<int, int> nw = ri->second;

        if (key <= mx - D)
        {
            int nxkey = key + D;
            pair<int, int> nx = p[nxkey];

            // Manhattan distance
            d[key] = abs(nx.first - nw.first) + abs(nx.second - nw.second);
            // Next distance
            d[key] += d[nxkey];
        }
        else
        {
            d[key] = 0;
        }

        ri++;
    }

    int Q;
    if (scanf("%d", &Q) < 1) return 0;
    for (int i = 0; i < Q; i++)
    {
        int L, R;
        if (scanf("%d%d", &L, &R) < 2) return 0;
        printf("%d\n", d[L] - d[R]);
    }

    return 0;
}


Measured memory_bytes: 11008
#include <bits/stdc++.h>
using namespace std;
#define print(x) cout << (x) << '\n'

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(__null);
  
  int n; cin >> n;
  int p[n];
  for (int i = 0; i < n; ++i) cin >> p[i];
  
  sort(p, p + n);
  
  print(accumulate(p, p + n - 1, int()) + p[n - 1] / 2);
  
  return 0;
}

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

typedef long long ll;
const ll N = 2e5 + 77;

int main()
{
  int tt = 1;
  // scanf("%d", &tt);
  while (tt--)
  {
    ll a, b, v, w, t;
    cin >> a >> v >> b >> w >> t;
    ll d = abs(a - b), u = abs(w - v);
    if (w >= v)
    {
      puts("NO");
      return 0;
    }
    ll time = (d + u - 1) / u;
    if (time <= t)
    {
      puts("YES");
    }
    else
    {
      puts("NO");
    }
  }
  return 0;
}

Measured memory_bytes: 3636
/**
 *   
 *   Date: 31 March 2020
 *   Time: 11:44:36
**/
#pragma GCC optimize("O3")
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cmath>
#include <cstring>
#include<queue>
#include<stack>
#include<climits>
#include<iomanip>
#include<unordered_map>
#include<unordered_set>
#define endl "\n"
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vec;
typedef vector<vector<ll> > matrix;
ll const mod=1000000007;
ll dp[3002][3002];
int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll n,m,idx,idy;
	vector<char> v1;
	string st,pat;
	cin>>st;
	cin>>pat;
	n=st.length();
	m=pat.length();
	for(ll i=1;i<=n;i++)
	{
		for(ll j=1;j<=m;j++)
		{
			if(st[i-1] == pat[j-1])
				dp[i][j]=dp[i-1][j-1]+1;
			else
			{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	idx=n;
	idy=m;
	while(idx>0 && idy>0)
	{
		if(dp[idx][idy] == dp[idx][idy-1])
			idy-=1;
		else if(dp[idx-1][idy] == dp[idx][idy])
			idx-=1;
		else
		{
			idx-=1;
			idy-=1;
			v1.push_back(st[idx]);
		}
	}
	reverse(v1.begin(),v1.end());
	for(ll i=0;i<v1.size();i++)
		cout<<v1[i];

return 0;
}

Measured memory_bytes: 70656
N = int(input())
A = [[0]*2 for _ in range(N)]
C = [[0]*2 for _ in range(N)]
for i in range(N):
    A[i][0],A[i][1] = map(int,(input().split()))
for i in range(N):
    C[i][0],C[i][1] = map(int,(input().split()))
    
C.sort()
ans = 0
for i in range(N):
    nim = 100000
    for j in range(len(A)):
        if A[j][0] < C[i][0]:
            tmp = C[i][1] - A[j][1]
            if 0 < tmp < nim:
                nim = tmp
                sa = j
    if nim != 100000:
        del A[sa]
        ans += 1

print(ans)

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto &it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vl vector<long>
#define P pair<int,int>
using namespace std;

main()
{
        int x,y; cin>>x>>y;
        cout<<x+y/2<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

int cnt[3];

char ch[100100];

int main(){
	scanf("%s", ch);
	int N = strlen(ch);
	for(int i = 0; i < N; ++i){
		cnt[ch[i] - 'a']++;
	}
	sort(cnt, cnt + 3);
	if(cnt[2] - cnt[0] <= 1){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=1000000007;

int main() {
 ll n,a,b;
  cin >> n >> a >> b;
  if((n==1 && a!=b) || a>b){
    cout << 0 << endl;
    return 0;
  }
  cout << (b-a)*(n-2)+1 << endl;
}



Measured memory_bytes: 3572
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
using namespace std;
int main(){
	deque<int> x;
	int n,a,d,c;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a==0){
			cin>>d>>c;
			if(d==0) x.push_front(c);
			else x.push_back(c);
		}
		else if(a==1){
			cin>>c;
			cout<<x[c]<<endl;
		}else{
			cin>>d;
			if(d==0) x.pop_front();
			else x.pop_back();
		}
	}
	return 0;
}



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

int main(){
  int N, K;
  string S;
  cin >> N >> K >> S;
  
  if(S.at(K-1)=='A'){
    S.at(K-1) = 'a';
  }
  else if(S.at(K-1)=='B'){
    S.at(K-1) = 'b';
  }
  else{
    S.at(K-1) = 'c';
  }
  cout << S << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
//#define all(v) ((v).begin(),(v).end())
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main(){
    int w,a,b;
    cin>>w>>a>>b;
    if(a+w<b)cout<<b-a-w<<endl;
    else if(b+w<a)cout<<a-b-w<<endl;
    else cout<<0<<endl;


}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define nl '\n'
#define f(i, n) for (int i = 0; i < n; ++i)

using namespace std;
void solve() {
    int th, ts, ah, as;
    cin >> th >> ts >> ah >> as;

    bool turn = true;
    bool ans = false;
    while (true) {
        if (turn) {
            if (ts >= ah) {
                ans = true;
                break;
            }
            ah -= ts;
            turn = false;
        } else {
            if (as >= th) {
                ans = false;
                break;
            }
            th -= as;
            turn = true;
        }
    }
    cout << ((ans) ? "Yes" : "No") << nl;
}

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

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

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			Question.Exec();
		}
	}

	public static class Question
	{
		public static bool IsOdd(long n)
		{
			bool isOdd = n % 2 == 1;
			return isOdd;
		}

		public static void Exec()
		{
			string s = Console.ReadLine();
			string t = Console.ReadLine();
			if (s == t) {
				Console.WriteLine($"No");
				Console.ReadKey();
				return;
			}

			if (t.Contains(s) && s.Length < t.Length) {
				Console.WriteLine($"Yes");
				Console.ReadKey();
				return;
			}

			var slist = s.ToCharArray().ToList();
			slist.Sort();
			string ss = new string(slist.ToArray());

			var tlist = t.ToCharArray().ToList();
			tlist.Sort();
			tlist.Reverse();
			string tt = new string(tlist.ToArray());
			bool isOK = false;
			for (int i = 0; i < ss.Length && i < tt.Length; ++i) {
				if (ss[i] < tt[i]) {
					isOK = true;
					break;
				}
			}

			if (isOK){
				Console.WriteLine($"Yes");
			} else {
				Console.WriteLine($"No");
			}

			Console.ReadKey();
		}
	}
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>

#define mii map<int,int>
#define int long long
#define inf 2000000000000000000
#define re(i,x,n) for(i=x;i<=n;i++)
typedef long long ll;
using namespace std;
void c_p_c()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef  ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
struct edge
{
	int a;
	int b;
	int w;
};
edge ar[100000];
int par[10001];
bool comp(edge a, edge b)
{
	if (a.w < b.w)
		return true;
	else
		return false;
}
int find(int a)
{
	if (par[a] == -1)
		return a;
	else
		return par[a] = find(par[a]);
}
void merge(int a, int b)
{
	par[a] = b;
}
void Sieve(int  n)
{
	int i;
	bool primes[n + 1];
	memset(primes, true, sizeof(primes));
	int j;
	for (i = 2; i * i <= n; i++)
	{
		if (primes[i])
		{
			for (j = i * i; j <= n; j += i)
				primes[j] = false;
		}
	}
	int a[n + 1];
	int k = -1;
	for (i = 2; i <= n; i++)
		if (primes[i]) {
			//cout << i << " ";
			a[++k] = i;
		}
//	cout << endl;
	int count = 0;


	int r = 0;
	bool be = false;
	for (i = 6; i <= n; i++)
	{
		for (j = 0; j <= k; j++)
		{
			if (i % a[j] == 0)
				count++;
			if (count == 2) {

				be = true;
				break;
			}
		}
		if (be) {
			r++;

			be = false;
		}
		count = 0;
	}
	// cout << endl;
	cout << r << endl;

}

int32_t main()
{

	//c_p_c();
	int a;
	cin >> a;
	cout << a + a*a + a*a*a;

}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define lli long long int
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lli n,k,cnt=0,i;
    cin>>n>>k;
    lli a[n];
    for(i=0;i<n;i++)
    cin>>a[i];
    sort(a,a+n);
    for(i=n-1;i>=0;i--)
    {
        if(k>0)
        {
            k--;
            a[i]=0;
        }
        else
        {
            cnt+=a[i];
        }
    }
    cout<<cnt<<"\n";
}

Measured memory_bytes: 5188
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMax = 1e12 + 1;
constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll A, B, C;
  cin >> A >> B >> C;

  ll d = C - A - B;
  if (d > 0 && d * d > 4 * A * B) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int c = 1000000,f = -1000000;
  string s; cin >> s;
  int n = (int)s.size();
  for(int i = 0; i < n; ++i){
    if(s[i] == 'C'){
      c = i;break;
    }
  }
  for(int i = n-1; i >= 0; --i){
    if(s[i] == 'F'){
      f = i;break;
    }
  }
  cout << (c<f?"Yes":"No") << endl;
}

Measured memory_bytes: 3580
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();

        int[] t = new int[n];
        for (int i = 0; i < n; i++) {
            t[i] = sc.nextInt();
        }

        Arrays.sort(t);

        int ans = 1;
        int num_of_ride = 1;
        int time_limit = t[0] + k;

        for (int i = 1; i < n; i++) {
            if (num_of_ride >= c || t[i] > time_limit) {
                ans++;
                num_of_ride = 1;
                time_limit = t[i] + k;
            } else {
                num_of_ride++;
            }
        }

        System.out.println(ans);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

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

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

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

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

using namespace std;

int main()
{
	// 入力
	int K, X;
	cin >> K >> X;
	
	// X - K + 1, X - K + 2 ...  X + K -1
	// 黒がおかれる個数は2K - 1個
	for (int i = -K + 1; i <= K - 1; i++)
	{
		cout << X + i << " ";
	}
	cout << endl;
	
	return 0;
}

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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;


int32_t main()
{
	GO;
	int n;
	string s, t;
	cin >> n >> s >> t;
	for (int i = 0; i < n; i++) {
		cout << s[i] << t[i] ;
	}
	cout << endl;
	return 0;
}

//!

Measured memory_bytes: 3660
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Iterator;
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.AbstractSequentialList;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.LinkedList;
import java.util.Collections;
import java.io.InputStream;

/**
 * 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;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = in.nextIntArray(n);

            LinkedList<Integer> list = new LinkedList<>();
            for (int i = 0; i < n; i++) {
                if (i % 2 == 0) {
                    list.addLast(a[i]);
                } else {
                    list.addFirst(a[i]);
                }
            }

            if (n % 2 == 1) Collections.reverse(list);

            Iterator<Integer> iterator = list.iterator();
            if (iterator.hasNext()) {
                out.print(iterator.next());
            }
            while (iterator.hasNext()) {
                out.print(" " + iterator.next());
            }
            out.println();
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

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

        public int[] nextIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt();
            }
            return res;
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 74288
#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>

using namespace std;

int n, q;
vector<int> ve[200005];
int a[200005];
int ans[200005];
bool vv[200005];
queue<int> qu, ql;

int main()
{
    //freopen("input.txt", "r", stdin);
    scanf("%d%d", &n, &q);
    for(int i = 0; i < n - 1; i++)
    {
        int u, v;
        scanf("%d%d", &u, &v);
        ve[u].push_back(v);
        ve[v].push_back(u);
    }
    for(int i = 0; i < q; i++)
    {
        int t1, t2;
        scanf("%d%d", &t1, &t2);
        a[t1] += t2;
    }
    qu.push(1), ql.push(0);
    while(!qu.empty())
    {
        int t1 = qu.front();
        int t2 = ql.front();
        qu.pop(), ql.pop();
        if(vv[t1]) continue;
        vv[t1] = true;
        ans[t1] = t2 + a[t1];
        for(int i = 0; i < ve[t1].size(); i++)
        {
            if(vv[ve[t1][i]]) continue;
            qu.push(ve[t1][i]);
            ql.push(ans[t1]);
        }
    }
    for(int i = 1; i <= n; i++)
    {
        printf("%d ", ans[i]);
    }
    return 0;
}


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

int main()
{
    int n;
    string s[100];
    int p[100], sort[100], rank[100];
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> s[i] >> p[i];
        sort[i] = i + 1;
    }

    for (int i = 0; i < n; i++)
    {
        //cout << s[i] << " " << p[i] << endl;
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = n - 1; j > i; j--)
        {
            //cout << j << "-" << j - 1 << "|==>";
            if (s[j].compare(s[j - 1]) < 0)
            {
                swap(s[j], s[j - 1]);
                swap(p[j], p[j - 1]);

                swap(sort[j], sort[j - 1]);
            }
            else if (s[j].compare(s[j - 1]) == 0)
            {
                if (p[j] > p[j - 1])
                {
                    swap(s[j], s[j - 1]);
                    swap(p[j], p[j - 1]);

                    swap(sort[j], sort[j - 1]);
                }
            }
        }
    }

    for (int i = 0; i < n; i++)
    {
        //cout << s[i] << " " << p[i]<<" "<<sort[i] << endl;
        cout << sort[i] << endl;
    }

    // cout << (s[0].compare(s[1]) < 0);
    // cout << s[0];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
const LL INF = 1001001001001001;

int r, x[2], y[2];
LL grid[2][502][502];
bool done[2][502][502];
LL memo[2][500001];

struct P
{
	int g, x, y;
	
	bool operator < (const P& t) const {
		return grid[g][x][y] > grid[g][t.x][t.y];
	}
};

void search(int g)
{
	for (int i = 0; i < 502; i++){
		for (int j = 0; j < 502; j++){
			done[g][i][j] = false;
		}
	}
	for (int i = 0; i <= 5000; i++){
		memo[g][i] = INF;
	}
	memo[g][0] = 0;
	
	int num = 0;
	LL level = 0;
	LL mini = INF;
	priority_queue<P> que;
	que.push({g, x[g], y[g]});
	while (!que.empty()){
		P p = que.top(); que.pop();
		if (done[g][p.x][p.y]) continue;
		done[g][p.x][p.y] = true;
		
		//printf("%d %d %d\n", g, p.x, p.y);
		
		if (grid[g][p.x][p.y] <= level){
			num++;
			memo[g][num] = level;
		}
		else {
			//if (grid[g][p.x][p.y] == INF) break;
			level = grid[g][p.x][p.y];
			num++;
			memo[g][num] = level;
		}
		
		if (num >= r) return;
		
		for (int dir = 0; dir < 4; dir++){
			int tx = p.x + dx[dir];
			int ty = p.y + dy[dir];
			if (!done[g][tx][ty] && done[g][tx][ty] != INF){
				que.push({g, tx, ty});
			}
		}
	}
}

int main()
{
	while (scanf("%d", &r), r){
		for (int i = 0; i < 2; i++){
			for (int j = 0; j < 502; j++){
				for (int k = 0; k < 502; k++){
					grid[i][j][k] = INF;
				}
			}
			
			int h, w;
			scanf("%d %d %d %d", &w, &h, &y[i], &x[i]);
			for (int j = 1; j <= h; j++){
				for (int k = 1; k <= w; k++){
					scanf("%lld", &grid[i][j][k]);
				}
			}
		}
		
		for (int i = 0; i < 2; i++){
			search(i);
		}
		
		LL mini = INF;
		for (int i = 0; i <= r; i++){
			mini = min(mini, memo[0][i] + memo[1][r - i]);
		}
		printf("%lld\n", mini);
	}
	
	return 0;
}

Measured memory_bytes: 12820
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < array.length; i++) {
            array[i] = sc.nextInt();
        }
        for (int i = 1; i < array.length; i++) {
            System.out.println(Arrays.stream(array).mapToObj(String::valueOf).collect(Collectors.joining(" ")));
            int v = array[i];
            int j = i - 1;
            while (j >= 0 && array[j] > v) {
                array[j+1] = array[j];
                j--;
            }
            array[j+1] = v;
        }
        System.out.println(Arrays.stream(array).mapToObj(String::valueOf).collect(Collectors.joining(" ")));
    }
}


Measured memory_bytes: 33364
use std::io;
use std::cmp;

fn add_left(s: String) -> String {
    let mut cs = s.chars();
    let mut h = 0isize;
    let mut prefix = String::from("");

    for c in cs {
        match c {
            '(' => h += 1,
            ')' => h -= 1,
            _ => ()
        }
        if h < 0 {
            prefix = prefix + "(";
            h += 1;
        }
    }

    prefix + &s
}

fn add_right(s: String) -> String {
    let mut suffix = String::from("");
    {
        let mut cs = s.chars();
        let mut h = 0isize;
        for c in cs.rev() {
            match c {
                '(' => h += 1,
                ')' => h -= 1,
                _ => ()
            }
            if h > 0 {
                suffix = ")".to_string() + &suffix;
                h -= 1;
            }
        }
    }
    

    s + &suffix
}

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line);
    let N = line.trim().parse::<usize>().unwrap();
    
    let mut line = String::new();
    io::stdin().read_line(&mut line);
    let mut S = String::from(line.trim());

    let S = add_left(S);
    let S = add_right(S);

    println!("{}", S);
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

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


int main()
{
    int N;
    cin >> N;
    vector<string> S(N);
    REP(i, N) cin >> S[i];

    int max_appeared = 0;
    map<string, int> num_appeared;
    REP(i, N){
        ++num_appeared[S[i]];
        max_appeared = max(max_appeared, num_appeared[S[i]]);
    }
    
    for(auto p: num_appeared){
        if(p.second == max_appeared) cout << p.first << endl;
    }

    return 0;
}

Measured memory_bytes: 26752
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const list = input.trim().split('\n');
const n = Number(list[0]);
const A = list[1].trim().split(' ');
const q = Number(list[2]);
const mi = list[3].trim().split(' ');

const dp = {};
const memo = (i, sum) => {
   dp[sum] = true;
   if (i === n) {
     return;
   }
   memo(i + 1, sum);
   memo(i + 1, sum + Number(A[i]));
 }
 memo(0, 0);

 for (let i = 0; i < q; i++) {
   console.log(dp[mi[i]] ? 'yes' : 'no');
 }



Measured memory_bytes: 16844