akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <functional>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

long long N, a[300009], l[300009], r[300009];
priority_queue<long long, vector<long long>, less<long long>>Q;

int main() {
	cin >> N;
	for (int i = 1; i <= N * 3; i++) cin >> a[i];
	long long S = 0;
	for (int i = 1; i <= N; i++) { S += a[i]; Q.push(-a[i]); }
	l[N] = S;
	for (int i = N + 1; i <= N * 3; i++) {
		Q.push(-a[i]); S += a[i];
		long long P = -Q.top(); Q.pop(); S -= P;
		l[i] = S;
	}
	S = 0;
	for (int i = 2 * N + 1; i <= 3 * N; i++) { S += a[i]; Q.push(a[i]); }
	r[2 * N + 1] = S;
	for (int i = 2 * N; i >= 1; i--) {
		Q.push(a[i]); S += a[i];
		long long P = Q.top(); Q.pop(); S -= P;
		r[i] = S;
	}
	long long ans = -(1LL << 60);
	for (int i = N; i <= 2 * N; i++) {
		ans = max(ans, l[i] - r[i + 1]);
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
ll h, ans;

int main() {
    cin >> h;
    ll x = h, num = 1;
    while (x) {
        ans += num;
        x /= 2; num *= 2;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n;
vector<int>c;
ll s[200005];
int main(void){
    scanf("%lld",&n);
    for(int i=0;i<n;i++){
		ll x;
		scanf("%lld",&x);
		if(c.size()==0||c.back()!=x)c.PB(x);
	}
	n=c.size();
	s[c[0]]=1;
	for(int i=1;i<n;i++){
		ll x=c[i],y=c[i-1];
		s[x]=(s[x]+s[y])%M;
	}
	printf("%lld\n",s[c[n-1]]);
}

Measured memory_bytes: 2676
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
typedef long double ld;
using ll=long long;
using namespace std;
const int mod=1e9+7;
const ll inf = 1LL << 60;
const ld pi = (acos(-1));
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  int a,b,k; cin >> k >> a >> b;
  string ans ="NG";
  rep(i,a,b+1) if(i%k==0){ ans="OK"; break;}
  cout << ans << endl;
}

Measured memory_bytes: 3652
import collections
N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]

s_counter = collections.Counter(s)
t_counter = collections.Counter(t)

ans = 0
for i in s_counter:
    ans = max(ans, s_counter[i] - t_counter[i])
print(ans)  

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {
    string S;
    cin >> S;
    if (S == "RRR") {
        cout << 3 << endl;
    }
    else if (S == "RRS" || S == "SRR") {
        cout << 2 << endl;
    }
    else if (S == "RSR" || S == "SSR" || S == "RSS" || S == "SRS") {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 3620
n, m = gets.split.map(&:to_i)
drinks = []
n.times do
  drinks << gets.split.map(&:to_i)
end

sorted_drinks = drinks.sort_by(&:first)

sum_price = 0
rest_num = m

sorted_drinks.each do |price, num|
  buying = rest_num < num ? rest_num : num

  sum_price += price * buying
  rest_num -= buying

  break if rest_num.zero?
end

puts sum_price


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

#define ll long long int

ll f(vector<ll> &a,vector<ll> &b,vector<ll> &c,int n){

    ll dp[n+1][3];
    for(int z=0;z<3;z++) dp[0][z] = 0;

    for(int x=1;x<=n;x++){
        dp[x][0] = a[x] + max(dp[x-1][1],dp[x-1][2]);
        dp[x][1] = b[x] + max(dp[x-1][0],dp[x-1][2]);
        dp[x][2] = c[x] + max(dp[x-1][0],dp[x-1][1]);
    }

    return max(dp[n][0],max(dp[n][1],dp[n][2]));
}

int main() {

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

    int n;
    cin>>n;

    vector<ll> a(n+1);
    vector<ll> b(n+1);
    vector<ll> c(n+1);
    for(int z=1;z<=n;z++) cin>>a[z]>>b[z]>>c[z];

    cout<<f(a,b,c,n);

    return 0;
}

Measured memory_bytes: 4992
#include  <stdio.h>

int main()
{
    int a,b,c;
    scanf("%d %d %d", &a, &b, &c);
    
    if(a==b && b!=c){
        printf("Yes\n");
}
    else if(a==c && b!=a){
        printf("Yes\n");
}
    else if(b==c && a!=b){
        printf("Yes\n");
}
    else{
        printf("No\n");
}   
    return 0;
}

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

   int a,b;

   scanf("%d %d",&a,&b);

   if(a<b){
      printf("a < b\n");
   }
   else if(a>b){
      printf("a > b\n");
   }
   else {
      printf("a == b\n");
   }

   return 0;
}

Measured memory_bytes: 1012
#include <iostream>

using namespace std;
int main ()
{
    /*/
    int i = 0, j = 1;
    cout << i;
    int *ptr = &i;
    cout << i;

    i = 2;
    cout << i;
    *ptr = 3;
    ptr = &j;
    j = i;
    cout << i;
    *ptr = 4;
      /*/

    /*/
    int n , ctn=0 ,arr;
    cin >> n ;
    for (int i = 1; i <=n ; ++i) {
        cin >> arr;

        if ((i%2!=0)&&(arr%2!=0))ctn++;

    }
    cout<<ctn <<endl;

    cout << "Hello, world!"<<endl;
    cout << "Greetings from Illinois!" <<endl;
    /*/

    int n ,ac=0,wa=0,tle=0,re=0 ;
    string inp;
    cin >> n ;
    for (int i = 0; i < n ; ++i)
    {
        cin >> inp;
        if (inp =="AC") ac++;
        if (inp=="WA") wa++;
        if (inp=="TLE") tle++;
        if (inp=="RE") re++;

    }
    cout <<"AC x "<< ac <<endl;
    cout <<"WA x "<< wa <<endl;
    cout <<"TLE x "<< tle <<endl;
    cout <<"RE x "<< re <<endl;


    
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=500010;

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

    string s;
    cin>>s;
    ll n=s.length();
    if(n%2){cout<<"No";return 0;}
    int f=1;
    for(ll i=0;i<n;i+=2)
    {
        if(s[i]=='h'&&s[i+1]=='i'){}
        else{f=0;}
    }
    if(f){cout<<"Yes";}
    else{cout<<"No";}

	return(0);
}


Measured memory_bytes: 764
#include <iostream>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, m[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u) {
    color[u] = GRAY;
    d[u] = ++tt;
    for (int v = 0; v < n; v++) {
        if (m[u][v] == 0) {
            continue;
        }
        if (color[v] == WHITE) {
            dfs_visit(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++tt;
}

void dfs() {
    for (int u = 0; u < n; u++) color[u] = WHITE;
    tt = 0;

    for (int u = 0; u < n; u++) {
        if (color[u] == WHITE) {
            dfs_visit(u);
        }
    }
    for (int u = 0; u < n; u++) {
        cout << u + 1 << " " << d[u] << " " << f[u] << endl;
    }
}

int main() {
    int u, v, k;

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


    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            cin >> v;
            v--;
            m[u][v] = 1;
        }
    }

    dfs();
}



Measured memory_bytes: 3124
a,$,=:+,' '
puts [6484,a,0,1,3,:<,2,3,3]+[0,1].map{|x|[a,x,3,x]+(0..29).map{v=x+4;u=x*60+9+_1;[a,v,v,v,a,v,3,6,*[a,6,6,6]*(29-_1),:<,6,x,u,a,v,u,v]}}+(0..59).map{|t|[a,2,2,2]+(0...t).map{[a,8+t-_1,69+_1,5,:<,3,5,6,a,2,6,2]}}

Measured memory_bytes: 14780
n=int(input())
v=list(map(int,input().split()))
d1={}
d2={}
for i in range(n):
  if i%2==0:
    if v[i] not in d1:
      d1[v[i]]=1
    else:
      d1[v[i]]+=1
  else:
    if v[i] not in d2:
      d2[v[i]]=1
    else:
      d2[v[i]]+=1
nd1=sorted(d1.items(),key=lambda x:x[1],reverse=True)
nd2=sorted(d2.items(),key=lambda x:x[1],reverse=True)
nd1.append((0,0))
nd2.append((0,0))
if nd1[0][0]==nd2[0][0]:
  print(n-max(nd1[0][1]+nd2[1][1],nd1[1][1]+nd2[0][1]))
else:
  print(n-nd1[0][1]-nd2[0][1])

Measured memory_bytes: 20720
"""
左右の累積gcdをもたせて置く

i番目を除く(i=1)
R : acc[i-1]
L : racc[n-i-1] 
"""

n = int(input())
As = list(map(int, input().split()))

def gcd(n, m):
    a = max(n,m)
    b = min(n,m)
    while b:
        a, b = b, a % b
    return a


acc = [As[0]]
racc = [As[-1]] #(右から)i番目の累積gcd
for i in range(1,n):
    acc.append(gcd(acc[i-1],As[i]))
    racc.append(gcd(racc[i-1],As[-i-1]))

racc = racc[::-1] #i番目以降のgcd
ans = 0
for i in range(n):
    if i == 0:
        ans = max(ans, racc[i+1])
    elif i == n-1:
        ans = max(ans, acc[i-1])
    else:
        ans = max(ans, gcd(acc[i-1],racc[i+1]))
    
print(ans)

Measured memory_bytes: 14588
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

string grid[1009];
ll dp[1009][1009];
ll h, w;

int main()
{
    ll i, j;
    cin >> h >> w;
    for(i = 0; i < h; i++)
        cin >> grid[i];

    for(i = 1; i <= h; i++)
    {
        for(j = 1; j <= w; j++)
        {
            if(i == 1 && j == 1)
            {
                dp[i][j] = 1;
                continue;
            }

            if(grid[i-1][j-1] == '.')
                dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod;
        }
    }

    cout << dp[h][w];
}


Measured memory_bytes: 9216
//       Author: Mostafa Mounir Shehab
 
#include <bits/stdc++.h>
using namespace std;
 
#define PI  3.14159265  // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
#define SZ(v) (int)(v.size())
typedef long long ll;
typedef long double ld;
//template <class Type>
 
 
void Fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
}
 
inline int D(){
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}
 
 
ll MOD=1e9 + 7; 
const int N=1e5 + 5;
char arr[N];
int OO=1e6; 
 
ll n,m,k,cnt,SU,idx,len,MN,MX,T;
ll l,r,mid;
ll a,b,c,d;
vector<int> vec,v;
string str="BGR",s;
 
bool flage;
map<char,vector<int>> mp;
 
int valid(int i,int j){
	if(arr[i] == arr[j])
		return 0;
	int len=0;
	do{
		
		if(str[0] == arr[i] && str[1] == arr[j]){
			if(!SZ(mp[str[2]]))
				return 0;
			if(mp[str[2]].back()<=j)
				continue;
			len+=SZ(mp[str[2]]) - (lower_bound(mp[str[2]].begin(),mp[str[2]].end(),j) - mp[str[2]].begin());
			len-=(arr[j+j-i] == str[2]);
			
		}
	}while(next_permutation(str.begin(),str.end()));
	
//	cerr<<i<<" "<<j<<" "<<len<<endl;
	
	return len;
	
}
 
 
int main(){
	
	scanf("%lld",&n);
	scanf("%s",arr);
	
	for(int i=0;i<n;++i)
		mp[arr[i]].push_back(i);
 
	for(int i=0;i<n;++i)
		for(int j=i+1;j<n;++j)
			cnt+=valid(i,j);
	
	printf("%lld\n",cnt);
	
	
}
 
 
 
 
 
 
 
 

Measured memory_bytes: 3800
import sys

N, M = map(int, input().split())
if N >= M:
    print(0)
    sys.exit(0)

X = list(map(int, input().split()))
X.sort()

distance_list = [b - a for a, b in zip(X, X[1:])]
distance_list.sort()

if N != 1:
    print(sum(distance_list[:-N+1]))
else:
    print(sum(distance_list))


Measured memory_bytes: 13968
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://beta.atcoder.jp/contests/abc082/tasks/abc082_b

int main() {
    string s, t; cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    cout << (s<t?"Yes":"No") << "\n";

    return 0;
}


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

int main() {
	int n, r, p, c;
	while (cin >> n >> r , n != 0 || r != 0) {
		vector<int> deck = vector<int>(n);
		for (int i = 0; i < n; i++) {
			deck[i] = n - i;
		}

		for (int j = 0; j < r; j++) {
			cin >> p >> c;
			vector<int> tmp = vector<int>(c);
			for (int k = 0; k < c; k++) {
				tmp[k] = deck[p - 1 + k];
			}
			for (int k = 0; k < p - 1; k++) {
				deck[p + c - 2 - k] = deck[p - 2 - k];
			}
			for (int k = 0; k < c; k++) {
				deck[k] = tmp[k];
			}
		}
		cout << deck[0] << endl;
	}


}

Measured memory_bytes: 1196
N, M = map(int,input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
prev = [0] * N
to_list = [ [] for _ in range(N)]

for a,b in AB:
  to_list[a - 1].append(b - 1)
  to_list[b - 1].append(a - 1)

marked = {0}
que = [0]

for i in que:
    for j in to_list[i]:
        if j in marked: continue
        que.append(j)
        marked.add(j)
        prev[j] = i+1

print('Yes')
print(*prev[1:], sep='\n')

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

using namespace std;
typedef long long ll;

ll n, w;
ll dp[100+9][100000+9], maksio=-1;
vector<pair<ll, ll>>a;


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>w;
    a.resize(n);
    //for(int i=0; i<=n; i++) fill(dp[i]+1, dp[i]+w+1, -1);
    for(int i=0; i<n; i++) cin>>a[i].second>>a[i].first;
    sort(a.begin(), a.end());
    for(int i=1; i<=n; i++)
    {
        ll v=a[i-1].first, m=a[i-1].second;
        for(int j=0; j<m; j++) dp[i][j]=dp[i-1][j];
        for(int j=m; j<=w; j++)
        {
            dp[i][j]=max(dp[i-1][j], dp[i-1][j-m]+v);
            maksio=max(dp[i][j], maksio);
        }
    }
    //for(int i=0; i<=w; i++) maksio=max(maksio, dp[n][i]);
    cout<<maksio<<endl;
    return 0;
}


Measured memory_bytes: 79360
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
typedef long double ld;
const char sp = ' ';

using namespace boost::multiprecision;
using namespace std;

int main(void){
    string S,T;
    ll count=0;
    cin>>S>>T;
    rep(i, S.size()){
        if(S[i]!=T[i]) count++;
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 3920
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;



int main(){
  ios_base::sync_with_stdio(false);

  int x,y,z;
  int ans = 0;

  cin >> x >> y >> z;

  x -= z;
  y += z;
  ans = x / y;

  cout << ans << endl;

  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> v(n,0);
    for(int i = 0; i < n; i++){ 
        int z;
        cin >> z;
        z--;
        v[i] = z;
    }
    int now = 0, c = 0;
    for(;;){
        if(now == 1){
            cout << c << endl;
            break;
        }
        if(c >= n){
            cout << -1 << endl;
            break;
        }
        c++;
        now = v[now];
    }
}

Measured memory_bytes: 640
using System;

using System.Collections.Generic;
public class a{
 static void Main(){
  int a = int.Parse(Console.ReadLine());
  int b = int.Parse(Console.ReadLine());
  List<int> abc = new List<int>(){1,2,3};
  abc.Remove(a);
  abc.Remove(b);
   Console.WriteLine(abc[0]);
 }
}

Measured memory_bytes: 27516
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define N 100005

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

void make()
{
	fac[0] = fac[1] = 1;
	inv[1] = 1;
	finv[1] = finv[0] = 1;
	for(int i = 2; i < N; ++i)
	{
		fac[i] = i * fac[i - 1] % MOD;
		inv[i] = MOD - MOD/i * inv[MOD % i] % MOD;
		finv[i] = inv[i] * finv[i - 1] % MOD;
	}
}

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

ll gcd(ll a, ll b)
{
	if(b == 0)
		return a;
	return gcd(b, a % b);
}
#define N 100005
int n;
int h[N];
int dp[N];
int dpf(int i)
{
	if(i >= n)
		return 1e9;
	if(i == n - 1)
		return 0;
	if(dp[i] >= 0)
		return dp[i];
	return dp[i] = min(abs(h[i + 1] - h[i]) + dpf(i + 1), abs(h[i + 2] - h[i]) + dpf(i + 2));
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> h[i];
		dp[i] = -1;
	}
	dp[1] = abs(h[1] - h[0]);
	dp[0] = 0;
	for(int i = 2; i < n; ++i)
	{
		dp[i] = min(abs(h[i - 1] - h[i]) + dp[i-1], abs(h[i] - h[i - 2]) + dp[i - 2]);
	}
	int ans = dp[n - 1];
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <cfloat>
#include <cmath>
using namespace std;

double x[100];
double y[100];

double calcLength(int i, int j) {
  return sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
}

double calcGradient(int i, int j) {
  return (y[j]-y[i])/(x[j]-x[i]);
}

double calcCos(int i, int j, int k) {
  double t = (x[i]-x[j])*(x[k]-x[j]) + (y[i]-y[j])*(y[k]-y[j]);
  return t / (calcLength(i, j) * calcLength(j, k));
}

int main() {
  int n, v0, v1, v2, v3, vt, c;
  double m = DBL_MAX, t;
  while (1) {
    scanf("%d", &n);
    if (!n) break;
    for (int i=0; i<n; i++) {
      scanf("%lf,%lf", &x[i], &y[i]);
      if (x[i] < m) {
        m = x[i];
        v0 = i;
      }
    }
    v1 = v0;
    m = 0;
    for (int i=0; i<n; i++) {
      if (i==v0) continue;
      if (x[i]==x[v0]) {
        if (y[i]>y[v0]) {
          v2 = i;
          break;
        } else continue;
      } else {
        t = calcGradient(v0, i);
        if (t > m) {
          m = t;
          v2 = i;
        }
      }
    }

    c = 2;
    while (1) {
      m = 1.0;
      for (vt=0; vt<n; vt++) {
        if (vt==v1 || vt==v2) continue;
        t = calcCos(v1, v2, vt);
        if (t < m) {
          m = t;
          v3 = vt;
        }
      }
      if (v3 == v0) break;
      v1 = v2;
      v2 = v3;
      ++c;
    }
    printf("%d\n", n-c);
  }
  return 0;
}

Measured memory_bytes: 1068
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
    int K, S;
    cin >> K >> S;

    int ans = 0;

    for(int i = 0; i <= K; i++){
        for(int j = 0; j <= K; j++){
            if((S-i-j)>=0 && (S-i-j)<=K) ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
N, M = list(map(int, input().strip().split()))

key_prices = []
keys = []

for i in range(M):
	a, b = list(map(int, input().strip().split()))
	key_prices.append(a)
	bits = 0
	for c in input().strip().split():
		c = int(c) - 1
		bits += (2 ** c)
	keys.append(bits)

count = (2 ** N)
min_prices = [None] * count
min_prices[0] = 0

for price, key in zip(key_prices, keys):
	for bits in range(count):
		base_price = min_prices[bits]
		if base_price != None:
			new_bits = bits | key
			new_price = base_price + price
			old_price = min_prices[new_bits]
			if old_price == None or old_price > new_price:
				min_prices[new_bits] = new_price

min_price = min_prices[count - 1]
if min_price != None:
	print(min_price)
else:
	print("-1")


Measured memory_bytes: 3188
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

H, W = list(map(int, sys.stdin.readline().split()))

S = np.array([list(sys.stdin.readline().rstrip()) for _ in range(H)]) == '.'
ups = np.zeros((H, W), dtype=int)
downs = np.zeros((H, W), dtype=int)
rights = np.zeros((H, W), dtype=int)
lefts = np.zeros((H, W), dtype=int)

for h in range(1, H):
    ups[h] = (ups[h - 1] + 1) * S[h - 1]
for h in reversed(range(H - 1)):
    downs[h] = (downs[h + 1] + 1) * S[h + 1]
for w in range(1, W):
    lefts[:, w] = (lefts[:, w - 1] + 1) * S[:, w - 1]
for w in reversed(range(W - 1)):
    rights[:, w] = (rights[:, w + 1] + 1) * S[:, w + 1]
print(((ups + downs + lefts + rights) * S).max() + 1)


Measured memory_bytes: 226288
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;
int main(){
    while(1){
        lli n;
        cin >> n;
        if(n==0) break;

        lli s=0;
        if(n!=1) s=1;
        for(lli i=2; i*i<=n; i++){
            if(n%i == 0){
                s += i;
                s += n/i;
            }
            if(i*i == n) s -= i;
        }
        if(n == s){
            cout << "perfect number" << endl;
        }else if(n > s){
            cout << "deficient number" << endl;
        }else{
            cout << "abundant number" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3072
#coding:utf-8
s=raw_input()
l=list(s)
f=False
for i in range(len(l)):
    try:
        if l[i]==l[i+1]:
            print i+1,i+2
            f=True
            break
        if l[i]==l[i+2]:
            print i+1,i+3
            f=True
            break
    except:
        pass
if f==False:
    print -1,-1
            
        

Measured memory_bytes: 15600
/*  
    Talkin' to myself and feelin' old
    Sometimes I'd like to quit, nothin' ever seems to fit
    Hangin' around, nothin' to do but frown
    Rainy days and Mondays always get me down
    _________________________
    _________________________
    912 Hours of Solitude
    Quarantine_Day : 38
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int       ll;
typedef vector<int>         vi;
typedef vector<ll>          vl;
typedef pair<int, int>      pii;
typedef pair<ll, ll>		pll;

#define pb(n)           push_back(n)
#define GSORT(v)        sort(v.begin(), v.end(), greater<int>())
#define SORT(v)         sort(v.begin(), v.end());
#define REV(v)          reverse(v.begin(), v.end());
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define REP(i,n)        for(int i = (int)(0); i < (int)(n); i++)
#define FOR(i, a, b)    for(int i = (int)a; i <= (int)b; i++)    

#define MAX 50005

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

    int n, k;
    cin>>n>>k;

    int temp = 2;
    REP(i, n - 1){
        int m = min(temp + temp, temp + k);
        temp = m;
    }
    cout<<temp<<"\n";

    return 0;
}


Measured memory_bytes: 256
h,w = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(h)]
n = 0
ans = []
b = []
for i in range(h):
  for j in range(w):
    b.append((i,j if i%2==0 else w-j-1))
for i in range(h*w-1):
  y,x = b[i]
  if a[y][x]%2==0:
    continue
  a[y][x]-=1
  n+=1
  ny,nx = b[i+1]
  a[ny][nx]+=1
  ans.append("{} {} {} {}".format(str(y+1),str(x+1),str(ny+1),str(nx+1)))
print(n)
print("\n".join(ans))

Measured memory_bytes: 45752
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
#include <set>
using namespace std;

int main() {
    int n , k , b[10] = {} , d;
    cin >> n >> k;
    for ( int i = 0 ; i < k ; i++ ) {
        cin >> d;
        b[d] = 1;
    }
    for ( int i = n ; i < 100000 ; i++ ) {
        string a = to_string( i );
        bool c = 0;
        for ( int j = 0 ; j < a.length() ; j++ ) {
            if ( b[a[j] - '0' ] == 1 ) {
                c = 1;
                break;
            }
        }
        if ( c == 0 ) {
            cout << i;
            break;
        }
    }
}

Measured memory_bytes: 256
n, y = map(int, input().split())
y2 = y // 1000
for i in range(n+1):
    for j in range(n-i+1):
        if i * 10 + j * 5 + (n-i-j) == y2:
            print(i, j, n - i - j)
            quit()
print(-1, -1, -1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,m;
    cin >> n >> m;
    vi h(n);
    cin >> h;
    vvi v(n);
    rep(_,m) {
        int a,b;
        cin >> a >> b;
        a--; b--;
        v[a].pb(b);
        v[b].pb(a);
    }
    int ans = 0;
    rep(i,n) {
        bool ok = true;
        for(auto j : v[i]) {
            if(h[i] <= h[j]) ok = false;
        }
        if(ok) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 8744
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
 
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for (int i=a; i<b; i++)
// #define endl "\n"
const int mod = 1000000007;

ll power(ll x, ll y) 
{ 
    ll res = 1;     // Initialize result 
   
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = res*x; 
        res%=mod;
        // n must be even now 
        y = y>>1; // y = y/2 
        x = x*x;
        x%=mod;  // Change x to x^2 
    } 
    return res%mod; 
}

int main() {
    ios_base::sync_with_stdio(false);    //Fast I/O
    cin.tie(NULL);
 
    // freopen("input.txt", "r", stdin);    // Read and write from a file
    // freopen("output.txt", "w", stdout);
    string str;
    cin >> str;
    if(str=="SUN")
        cout << 7 << endl;
    else if(str=="SAT")
        cout << 1 << endl;
    if(str=="MON")
        cout << 6 << endl;
    if(str=="TUE")
        cout << 5 << endl;
    if(str=="WED")
        cout << 4 << endl;
    if(str=="THU")
        cout << 3 << endl;
    if(str=="FRI")
        cout << 2 << endl;

    return 0;
}

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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b[55],c,d;
int main()
{
    cin>>a>>c;
    for(int i=0;i<a;i++)
        cin>>b[i];
    sort(b,b+a);
    for(int i=a-c;i<a;i++)
        d+=b[i];
    cout<<d<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll N; cin >> N;
  ll result[N];

  if (N==3) { cout <<  "2 3 25" << endl; return 0; }
  else if (N==4) { cout <<  "2 3 5 20" << endl; return 0; }
  else if (N==5) { cout <<  "2 3 5 20 30" << endl; return 0; }
  else {
    rep(i,N) {
      if (i%4==0) result[i] = 6*(i/4) + 2;
      else if (i%4==1) result[i] = 6*(i/4) + 3;
      else if (i%4==2) result[i] = 6*(i/4) + 4;
      else if (i%4==3) result[i] = 6*(i/4) + 6;
    }
    if (N%8==1) result[N-1] += 4;
    else if (N%8==2) result[N-1] += 1;
    else if (N%8==3) result[N-2] += 3;
    else if (N%8==4) result[N-3] += 9;
    else if (N%8==5) result[N-4] += 7;
    else if (N%8==6) result[N-2] += 4;
  }
  debug(result,result+N);
  // cout << result << endl;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n;
  cin >> n;
  ll a[n];
  vector<P> ans;
  for(int i=0;i<n;i++){
    cin >> a[i];
    ans.push_back(P(a[i],i));
  }
  sort(ans.begin(),ans.end());
  for(int i=0;i<n;i++){
    cout << ans[i].second+1<<" ";
  }
  cout << endl;
}


Measured memory_bytes: 3312
def main():
    import sys
    input = sys.stdin.readline
    n,w = map(int,input().split())
    l = [list(map(int,input().split())) for i in range(n)]

    dp = [[0]*(w+1) for i in range(n+1)]
    for i in range(1,n+1):
        for j in range(w+1):
            if j-l[i-1][0] >= 0:
                dp[i][j] = max(dp[i-1][j],dp[i-1][j-l[i-1][0]]+l[i-1][1])
            else:
                dp[i][j] = dp[i-1][j]
    print(dp[n][w])
if __name__ == "__main__":
    main()

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

"""
参考：http://ferin-tech.hatenablog.com/entry/2017/10/28/231616
・愚直に3重ループでシミュレーション
"""

N = int(input())
tN = list(map(int, input().split()))
vN = list(map(int, input().split()))
# 終点の処理をしやすくするため追加
tN.append(0)
vN.append(0)

dist = 0
speed = 0
for i in range(N):
    keep = True
    plus = True
    # 小数刻みのfor文
    for j in [0.5*x for x in range(tN[i]*2)]:
        # 現在の最大スピードに達した
        if speed == vN[i]:
            plus = False
        rest = tN[i] - j
        # 今より先で、下げきれなくなる状況がないか確認
        for k in range(i+1, N+1):
            if vN[k] < vN[i] and rest <= speed - vN[k]:
                keep = False
                plus = False
            rest += tN[k]
        # フラグの状況に合わせて加速or維持or減速
        if plus:
            # ここでの数値の加減は進み方が0.5刻みなので注意する
            dist += speed/2
            speed += 0.5
            dist += 0.125
        elif keep:
            dist += speed/2
        else:
            speed -= 0.5
            dist += speed/2
            dist += 0.125
print(dist)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define init(a,i) for(int k=0;k<(i);k++)(a)[k]=0
#define in(a,i) for(int k=0;k<(i);k++)cin>>(a)[k]
#define all(a)  (a).begin(),(a).end()
#define el(a) (a).end()-(a).begin()
#define mod 1000000007
#define inf 2147483647
#define range(x,a,b) (a)<=x&&x<=(b)
int main(){
	int n;
	cin>>n;
	int a[n],b[n];
	in(a,n);
	in(b,n);
	int anum[200001],bnum[200001];
	init(anum,200001);
	init(bnum,200001);
	rep(i,n){
		anum[a[i]]++;
		bnum[b[i]]++;
	}
	rep(i,n)if(anum[i+1]+bnum[i+1]>n){
		cout<<"No";
		return 0;
	}
	cout<<"Yes"<<"\n";
	int find1=0;
	rep(i,n){
		if(a[i]>b[n-i-1]){
			find1=n-i-1;
			break;
		}
	}
	int div=find1+1;
	int j=0,num,count=0;
	rep(i,n){
		if(i+div<n){
			if(b[div+i]==a[i]){
				num=b[div+i];
				count++;
			}
			else cout<<b[div+i]<<" ";
		}
		else {
			cout<<b[j]<<" ";
			j++;
		}
	}
	while(count!=0){
		cout<<num<<" ";
		count--;
	}
	return 0;
}

Measured memory_bytes: 6772
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <math.h>
#include <string>
using namespace std;

int main()
{
//	freopen("input.txt","r",stdin);
  //  freopen("output.txt","w",stdout);
 	
 	string s;
 	int n;
 	string abc="ABC";
 	cin>>n>>s;
 	int j=0;int c=0;
 	for (int i = 0; i < n; ++i){
 		if(abc[j]==s[i]){
 			j++;
 		}else{
 			j=0;
 			if(abc[j]==s[i]){
 				j++;
 			}
 		}

 		if(j==3){
 			j=0;
 			c++;
 		}
 	}
 	printf("%d\n",c);
   

    return 0;
}
 

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

using namespace std;

#define R register
#define LL long long
const int inf = 0x3f3f3f3f;
const int MAXN = 2e5 + 10;
const int P = 1e9 + 7;
const int MAXM = 5e3 + 10;
const int D = 2e3 + 10;

inline int read() {
	char a = getchar(); int x = 0,f = 1;
	for(; a > '9' || a < '0'; a = getchar()) if(a == '-') f = -1;
	for(; a >= '0' && a <= '9' ;a = getchar()) x = x * 10 + a - '0';
	return x * f;
}

int n;
int a[MAXN], b[MAXN]; 
int f[MAXM][MAXM];
int fac[MAXM * 2], ifac[MAXM * 2];

inline int qpow(int x,int k) {
	int res = 1;
	while(k) {
		if ( k & 1 ) res = 1LL * res * x % P;
		x = 1LL * x * x % P;
		k >>= 1; 
	}
	return res;
}

inline int C(int x, int y) {
	return 1LL * fac[x] * ifac[y] % P * ifac[x - y] % P;
}

int main() {
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n = read(); 
	for(R int i = 1; i <= n ; i++) a[i] = read(), b[i] = read(); 
	for(R int i = 1; i <= n ; i++) f[D - a[i]][D - b[i]] ++;
	
	for(R int i = 1; i <= D * 2; i++) 
		for(R int j = 1; j <= D * 2; j++)
			f[i][j] += ( f[i - 1][j] + f[i][j - 1] ) % P, f[i][j] %= P;
			
	fac[0] = 1;
	for(R int i = 1; i <= D * 4; i++) fac[i] = 1LL * fac[i - 1] * i % P;
	ifac[D * 4] = qpow( fac[D * 4], P - 2 );
	for(R int i = D * 4 - 1; i >= 0 ; i--) 
		ifac[i] = 1LL * ifac[i + 1] * (i + 1) % P;
		
	int ans = 0;
	for ( R int i = 1; i <= n; i++) {
		ans = ( ans + f[D + a[i]][D + b[i]] ) % P;
		ans = ( ans - C ( a[i] * 2 + b[i] * 2, a[i] * 2 ) ) % P;
	}
	
	ans = ( ( ans % P ) + P ) % P;
	printf("%lld\n", 1LL * ans * qpow( 2, P - 2) % P );
	return 0;	
}

Measured memory_bytes: 83456
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  String s = sc.next();
  char[] a = s.toCharArray();
  int min = 1000;
  int n = s.length();
  for(int i = 0;i < n-2;i++){
    int b = (a[i] - '0')*100 + (a[i+1] - '0')*10 + a[i+2] - '0';
    int c = Math.abs(753-b);
    min = Math.min(min,c);
  }
  System.out.println(min);
}}

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

public class Main {
	
	public static void main(String args[]) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] parts;
		
		parts = br.readLine().split(" ");
		
		int a = Integer.parseInt(parts[0]);
		int b = Integer.parseInt(parts[1]);
		
		String s1 ="";
		for (int i = 0; i<a; i++) {
			s1+=parts[1];
		}
		
		String s2="";
		for (int i = 0; i<b; i++) {
			s2+=parts[0];
		}
		if(s1.compareTo(s2)<0) {
			System.out.println(s1);
			
		}else{
			System.out.println(s2);
		}
	}
	
}


Measured memory_bytes: 22612
a,b=(int(x) for x in input().split())
A=0
if a<b :
  n=10**b//10
  for i in range(b):
    A=A+a*n
    n=n//10
if b<a :
  n=10**a//10
  for i in range(a):
    A=A+b*n
    n=n//10
if a==b :
  n=10**a//10
  for i in range(a):
    A=A+b*n
    n=n//10
print(A)    
 


Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Main {

	static int n;
	static double[] x1, y1, x2, y2;
	static double sx, sy, gx, gy;
	static ArrayList<Integer>[] g;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		while (q-- > 0) {
			long x0, y0, x1, y1, x2, y2, x3, y3;
			x0 = sc.nextLong();
			y0 = sc.nextLong();
			x1 = sc.nextLong();
			y1 = sc.nextLong();
			x2 = sc.nextLong();
			y2 = sc.nextLong();
			x3 = sc.nextLong();
			y3 = sc.nextLong();
			Point p0 = new Point(x0, y0);
			Point p1 = new Point(x1, y1);
			Point p2 = new Point(x2, y2);
			Point p3 = new Point(x3, y3);
			if (linesIntersect(p0, p1, p2, p3)) {
				System.out.println(1);
			} else {
				System.out.println(0);
			}
		}

	}

	static class Point {
		long x, y;
		int id;

		public Point(long x, long y) {
			this.x = x;
			this.y = y;
		}

		long norm2() {
			return x * x + y * y;
		}
	}

	static boolean linesIntersect(Point s1, Point d1, Point s2, Point d2) {
		long prd1 = ccw(s1, d1, d2) * ccw(s1, d1, s2);
		long prd2 = ccw(s2, d2, s1) * crossProduct(s2, d2, s2, d1);
		return prd1 <= 0 && prd2 <= 0;
	}

	static long ccw(Point s, Point d, Point p) {
		long cp = crossProduct(s, d, s, p);
		if (cp != 0)
			return Long.compare(cp, 0);
		else {
			if (dotProduct(s, d, s, p) < 0)
				return -2;
			else if (dotProduct(d, s, d, p) < 0)
				return 2;
			else
				return 0;
		}
	}

	static long crossProduct(Point s1, Point d1, Point s2, Point d2) {
		return (d1.x - s1.x) * (d2.y - s2.y) - (d1.y - s1.y) * (d2.x - s2.x);
	}

	static long dotProduct(Point s1, Point d1, Point s2, Point d2) {
		return (d1.x - s1.x) * (d2.x - s2.x) + (d1.y - s1.y) * (d2.y - s2.y);
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 39992
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<b){
		printf("%d\n",(b-a));
	}
	else if(a==b){
		printf("%d\n",(a-b));
	}
	else{
		printf("%d\n",(a-b));
	}
	return 0;
}


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

int main(){ 
    int n;
    cin >> n;
    string s;
    cin >>s;
    int r=0,b=0;
    for(int i=0;i<n;i++){
        if(s.at(i) == 'R')r++;
        else b++;
    }
    if(r > b)cout << "Yes" << endl;
    else cout << "No" << endl;
 }

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

template <class Monoid>
class SegmentTree
{
public:
  using Func = function<Monoid(Monoid, Monoid)>;
  const Func F;
  const Monoid M1;
  int sz;
  vector<Monoid> seg;

  SegmentTree(int n,const Func fu, const Monoid &m1): F(fu) , M1(m1) {init(n);}
  void init(int n)
  {
      sz= 1;
      while (sz < n) sz *= 2;
      seg.assign(sz * 2, M1);
  }
  void update(int k,const Monoid &x)
  {
    k+=sz;
    seg[k]=x;
    while(k>>=1)
    {
      seg[k]=F(seg[k*2],seg[k*2+1]);
    }
  }
  Monoid query(int l,int r)
  {
    Monoid L=M1,R=M1;
    l+=sz;r+=sz;
    for(;l<r;l>>=1,r>>=1)
    {
      if(l&1)L=F(L,seg[l++]);
      if(r&1)R=F(seg[--r],R);
    }
    return F(L,R);
  }
};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  vector<ll>a(n);
  rep(i,n)cin>>a[i];
  ll ng=0,ok=1e9;
  auto check=[&](ll num){
    auto b=a;
    rep(i,n){
      if(a[i]<=num)b[i]=1;
      else b[i]=-1;
    }
    vector<ll>sb(n+1,0);
    sb[0]=n;
    rep(i,n)sb[i+1]=sb[i]+b[i];
    SegmentTree<ll> st(3*n,[](ll a,ll b){return a+b;},0LL);
    ll su=0;
    repi(i,0,n+1){
      //cout<<"sb "<<sb[i]<<endl;
      su+=st.query(0,sb[i]);
      st.update(sb[i],1+st.query(sb[i],sb[i]+1));
      //cout<<"su "<<su<<endl;

    }
  //  cout<<num<<endl;
  //  cout<<su<<" "<<n*(n+1)/4<<endl;
    return su>n*(n+1)/4;

  };
  while(ok-ng>1){
    ll nn=(ok+ng)/2;
    if(check(nn))ok=nn;
    else ng=nn;
  }
  cout<<ok<<endl;
  return 0;

}


Measured memory_bytes: 10876
n,d=map(int,input().split())

x=[list(map(int,input().split())) for i in range(n)]

lis=[False for i in range(16001)]
i=0
while(i*i<16000):
  lis[i*i]=True
  i+=1
  
ans=0
for i in range(n):
  for j in range(i):
    dis=sum([(x[i][k]-x[j][k])*(x[i][k]-x[j][k]) for k in range(d)])
 #   print(dis)
    if lis[dis]:
      ans += 1
print(ans)

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

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
ll mod = 1e9+7;
ll h,w;
ll dp[1009][10009];
char c[1009][1009];
ll fun(ll i,ll j){
    ll &ref = dp[i][j];
    if(ref!=-1)
        return ref;
    ref = 0;
    if(c[i][j]=='.' && i<=h && j<=w){
        ref += fun(i+1,j)%mod;
        ref += fun(i,j+1)%mod;
    }
    return ref%mod;
}
int main(){
    fast;
    cin>>h>>w;
    
    for(ll i=1;i<=h;++i){
        for(ll j=1;j<=w;++j){
            cin>>c[i][j];
        }
    }
    memset(dp,-1,sizeof(dp));
    dp[h][w] = 1;

    cout<<fun(1,1);
    /*for(ll i=h;i>=1;--i){
        for(ll j=w;j>=1;--j){
            if(c[i][j]=='.'){
                if(i==h && j==w){
                    dp[i][j] = 1;
                }
                else{
                    dp[i][j] = (dp[i][j+1]%mod + dp[i+1][j]%mod)%mod;
                }
            }
        }    
    }*/
    /*for(ll i=1;i<=h;++i){
        for(ll j=1;j<=w;++j){
            cout<<dp[i][j]<<" ";            
        }cout<<endl;
    }*/
    //cout<<dp[1][1];
    return 0;
}

Measured memory_bytes: 80256
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }


        public static long GCM(long x, long y)
        {
            var s = x;
            var t = y;
            if (x < y) GCM(y, x);
            while (y != 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return s / x * t;
        }



        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var n = Read();
            var x = Reads();
            var y = new long[n];
            Array.Copy(x, y, x.Length);
            Array.Sort(y);
            for (int i = 0; i < n; i++)
            {
                if (x[i] < y[n / 2]) Console.WriteLine(y[n / 2]);
                else Console.WriteLine(y[n / 2 - 1]);
            }
            

            Console.Out.Flush();
        }
    }
}




Measured memory_bytes: 40592
#include<bits/stdc++.h>
using namespace std;
signed main(){
int n;
int count=0;
string a;
char b={};
cin>>n;
cin>>a;
b=a[0];
for(int i=0;i<n;i++){
if(a[i]==b){
}else{
count++;
b=a[i];
}
}
cout<<count+1<<"\n";
return(0);
}

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

int main(){
	int ans[4] = {0};
	int n;
	char buf[80];
	string type;
	
	while (~scanf("%d,%s", &n, buf)) {
		type = string(buf);
		if (type == "A") {
			ans[0]++;
		}else if (type == "B") {
			ans[1]++;
		}else if (type == "AB") {
			ans[2]++;
		}else if (type == "O") {
			ans[3]++;
		}
	}
	for (int i = 0; i < 4; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include<iostream>
#include <math.h>//pow(x,y)=x^y 99999とかの場合+1するif文
#include <algorithm>//sort(a.begin(), a.end());reverse(a.begin(), a.end());
#define rep(init,i,n) for (int i=init; i <(n);i++)
#define ll long long
#define rev(s) reverse(s.begin(),s.end())
#define sor(v) sort(v.begin(),v.end())

using namespace std;


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

ll L = 7;
ll LmodK = L%K;

rep(1,i,K+1){
if(LmodK == 0){
cout<<i<<endl;return 0;
}
LmodK = LmodK*10+7;
LmodK %= K;
}

cout<<-1<<endl;

/*
ll K,L;
cin>>K;

if(K==7 || K==1){cout<<1<<endl;return 0;}


L = 9*K;


//cout<<"L="<<L<<endl;//

ll M = 70;

rep(0,i,K+1){

    //cout<<"M="<<M<<endl;//
    
    
    

    if(M%L==7){
        //cout<<"ans="<<i<<endl;return 0;
        cout<<i+1<<endl;return 0;
    }
    M = M%L*10+7;
}

cout<<"ans="<<-1<<endl;
*/

}


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

int main(){
  string fullname;
  cin >> fullname;
//  string nickname = fullname.at(1) + fullname.at(2) + fullname.at(3); //文字型にならない？
//  cout << nickname << endl;
  cout << fullname.at(0) << fullname.at(1) << fullname.at(2) << endl;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int N;
vector<int> P;

PII dp[100][50000];
bool cmp (const PII &l, const PII &r)
{
    if (l.first == r.first) return l.second > r.second;
    return l.first < r.first;
}


PII solve(int n, int x, int sum, int num)
{
    if (n == N) return PII(0, 0);
    if (dp[n][x].first != -1) return dp[n][x];

    PII res = PII(0, INF);

    // ????????????
    res = max(res, solve(n+1, x, sum, num), cmp);

    // ?°????????????£?????????
    {
        int kozeni = (P[n] + 500) % 1000;
        if (kozeni <= x) {
            PII tmp = solve(n+1, x-kozeni, sum+P[n], num+1);
            tmp.first++;
            tmp.second += P[n];
            res = max(res, tmp, cmp);
        }
    }
    
    // ?????????????????£?????????
    {
        int kozeni = (1000 - P[n]%1000)%1000;
        int get = 0;
        if (kozeni >= 500) {
            get = 1;
            kozeni -= 500;
        }

        PII tmp = solve(n+1, x+kozeni, sum+P[n], num+get);
        tmp.first += get;
        tmp.second += P[n];
        res = max(res, tmp, cmp);
    }

    return dp[n][x] = res;
}


int main()
{
    while (cin >> N, N) {
        fill(dp[0], dp[0]+100*50000, PII(-1, -1));
        P.resize(N);
        rep(i, N) cin >> P[i];

        PII ans = solve(0, 0, 0, 0);
        cout << ans.first << " " << ans.second << endl;
    }
}

Measured memory_bytes: 42140
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<ll, int> mp;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<ll> t(n);
	rep(i, n) cin >> t[i];
	ll ans = 1LL;
	for (int i = 0; i < n; i++) {
		ans = lcm(ans, t[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256