akhauriyash/Code-Regression huggingface dataset:
import math
a,b,x = map(int,input().split())
s = (2*a**2*b-2*x)/a**3
t = 2*x/(a*(b**2))
if x >= a**2*b//2:
  ans = math.degrees(math.atan(s))
else:
  ans = 90-math.degrees(math.atan(t))
print(ans)




Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;	// 998244353
using ll = long long;
using namespace std;

int main(){
	ll n; cin >> n;
	if( n == 1 ){
		cout << 0 << endl;
		return 0;
	}
	map<ll, int> pf;
	ll t = n;
	ll letzte = -1;
	for( ll k = 2; k*k <= n; ++k ){
		while( t%k == 0 ){
			t /= k;
			++pf[k];
			letzte = k;
		}
	}
	if( letzte == -1 ){
		cout << 1 << endl;
		return 0;
	}
	if( t != 1 ){
		++pf[t];
		letzte = t;
	}
	int cnt = 0;
	for( auto a : pf ){
		int k = a.second;
		int sum = 0, i = 1;
		while( true ){
			sum += i;
			if( sum > k ){
				--i;
				break;
			}
			++i;
		}
		cnt += i;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3632
n,p,i,a[51];
main(){
	for(;~scanf("%d", &n),n;) {
		for(a[n]=p=i=0;i<n;i++)scanf("%d",&a[i]);
		for(i=0;i<n;i++){
			if(a[i]+1!=a[i+1]) {
				if(i-p)printf(n-i-1?"%d-%d ":"%d-%d\n",a[p],a[i]);
				else printf(n-i-1?"%d ":"%d\n",a[p]);
				p=i+1;
			}
		}
	}
	exit(0);
}

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

using namespace std;

int main()
{
    long x;
    cin >> x;
    
    long five;
    five = x / 500;
    long amari = x % 500;
    long fi = amari / 5;
    long ama = amari % 5;

    long ans = five * 1000 + fi * 5;

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


Measured memory_bytes: 256
x=int(input())
import math
import sys
A=[math.pow(i,5) for i in range(-1000,1000,1)]
B=[math.pow(i,5) for i in range(-1000,1000,1)]
for n in A:
  for m in B:
    if n-m==x:
      print(-1000+A.index(n),-1000+B.index(m))
      sys.exit()
    

Measured memory_bytes: 9468
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> A;
    map<ll, ll> M;

    for (int i = 0; i < N; i++)
    {
        ll temp;
        cin >> temp;
        M[temp] += 1;
    }
    if(M.size() <= K){
        cout << 0 << endl;
    }
    else{
        ll ans = 0;
        for(int i = 0; i < M.size();i++)
        {
                A.push_back(M[i]);
        }
        sort(A.begin(), A.end());
        for (int i = 0; i < M.size() - K;i++)
        {
            ans += A[i];
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 13944
// sync

#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 3e3 + 33, P = 1e9 + 7, div2 = (P + 1) / 2;

int n, m, x, y, a[N], b[N], dp[N][N], tmp[N][N], ans, pw2 = 1;
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) scanf("%d", a + i), b[i] = a[i];
	std::sort(b + 1, b + n + 1);
	for (int i = 1; i <= n; i++) a[i] = std::lower_bound(b + 1, b + n + 1, a[i]) - b;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++) dp[i][j] = a[i] > a[j];
	for (int i = 1; i <= m; i++) {
		scanf("%d%d", &x, &y);
		for (int j = 1, u, v; j <= n; j++)
			if (j != x && j != y) {
				u = 1ll * (dp[j][x] + dp[j][y]) * div2 % P;
				v = 1ll * (dp[y][j] + dp[x][j]) * div2 % P;
				dp[j][x] = u, dp[j][y] = u;
				dp[x][j] = v, dp[y][j] = v;
			}
		int u = 1ll * (dp[x][y] + dp[y][x]) * div2 % P;
		dp[x][y] = dp[y][x] = u;
		pw2 = pw2 * 2 % P;
	}
	for (int i = 1; i < n; i++)
		for (int j = i + 1; j <= n; j++) ans = (ans + dp[i][j]) % P;
	printf("%lld", 1ll * ans * pw2 % P);
}

Measured memory_bytes: 36992
#include<iostream>
using namespace std;
int main(){
	int a=0;
	char b[101];
	cin>>b;
	for(int i=0;i<101;i++){
		if(b[i]=='C'){
			a=1;
		}
		if(b[i]=='F'&&a){
			a=2;
			break;
		}
	}
	if(a==2){
		cout<<"Yes"<<endl;	
	}else{
		cout<<"No"<<endl;
	}
	
return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);

	if(a < b) 
	{
		if(a==1 & b==13)
			printf("Alice");
		else 
			printf("Bob");
	} else if(a > b)
	{
		if(a==13 & b ==1)
			printf("Bob");
		else
			printf("Alice");
	} 
	else printf("Draw");

   	return 0;
}

Measured memory_bytes: 2112
#include <stdio.h>

int main(void)
{
  int R;
  scanf("%d", &R);
  if(R < 1200){
    printf("ABC\n");
  } else if(R < 2800){
    printf("ARC\n");
  } else {
    printf("AGC\n");
  }
  return 0;
}


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

int main()
{
    int N, M, X;
    int cnta = 0, cntb = 0;
    cin >> N >> M >> X;
    for ( int i = 0; i < M; i++ ) {
        int A;
        cin >> A;
        if ( A < X ) {
            cnta++;
        } else {
            cntb++;
        }
    }
    cout << min(cnta, cntb) << endl;
    return ( 0 );
}


Measured memory_bytes: 256
a, b, c, d = gets.split.map(&:to_i)
x = c * d
e = c
f = d
if c < d
  c,d = d,c
end
r = c % d
while r != 0
  c = d
  d = r
  r = c % d
end

lcm = x/d

puts b - (a-1) - ((b/e + b/f - b/lcm) - ((a-1)/e + (a-1)/f - (a-1)/lcm))

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

int main() {
  int n;cin>>n;
  long h;cin>>h;
  long a[n],b[n];
  rep(i,n){
    cin>>a[i]>>b[i];
  }
  sort(a,a+n);
  sort(b,b+n);
  reverse(b,b+n);
  
  long cnt=0,res=h;
  rep(i,n) {
    if (res<=0) break;
    if (b[i] < a[n-1]) break;
    cnt++;
    res-= b[i];
  }
  if (res>0) {
    long nd = floor((res-1) / a[n-1])+1;
    cnt += nd;
  }
  cout<<cnt;
}


Measured memory_bytes: 1792
from collections import deque

t = input()
s = deque()
for i in range(len(t)): s.append(t[i])
q = int(input())
flg = False
for i in range(q):
    query = input()
    if query[0] == '1': flg = not flg
    else:
        t,f,c = query.split()
        if flg:
            s.appendleft(c) if f=='2' else s.append(c)
        else:
            s.appendleft(c) if f=='1' else s.append(c)
if flg: s = reversed(s)
print(''.join(s))

Measured memory_bytes: 8692
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

#define endl '\n'
#define ll long long
const ll mod = 1000000007;

using namespace std;

ll sigma(ll n)
{
	return (n * (n + 1) / 2);
}

ll rsigma(ll n, ll k)
{
	return (sigma(n) - sigma(n - k));
}

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

	ll n, k;
	cin >> n >> k;

	ll cnt = 1;
	for (ll i = k; i < n + 1; i++)
	{
		ll mn = sigma(i - 1);
		ll mx = rsigma(n, i);
		cnt += (mx - mn + 1) % mod;
	}

	cout << cnt % mod << endl;

	return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back

const int maxm = 1000000000 + 7;


using namespace std;


int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin>>n;

	ll a[n];

	loop(i,n)
	{
		cin>>a[i];
	}

	int ans=0;
	int max_ans=0;

   loop(i,n)
   {
   	  if(a[i+1] <= a[i])
   	  {
   	  	 ans++;
   	  }

   	  else
   	  {
   	  	if(max_ans < ans)
   	  	{
   	  		max_ans = ans;
   	  		
   	  	}

   	  	ans=0;
   	  }
   }

   if(max_ans < ans)
   {
   	  max_ans = ans;
   }

  cout<<max_ans<<endl;





}

Measured memory_bytes: 4380
eval"K,*X,j=#{`tr ' 
' ,`}l=1
x,y,*s=X.map &:abs
d=x+y
x,y=y,x if f=x<y
K%2<d%2&&p(-1)+exit
d!=K&&(l+=[~-d/K,1].max
l+=1&d-K*l
v=K>(t=K*l-d>>1)?0:t-t=K
a=K-t
2.upto(l){s<<(u=f ?-t:a)<<a-t-u
a+=q=[x+v-a,K].min
t-=K-q})
p l,*s.map{_1.*X[j^=1]<=>0.1}+X"
####################################################################################################

Measured memory_bytes: 29888
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1
#define pb push_back

using namespace std;

class Team
{
private:
  int m_id;
  int m_solved;
  int m_penalty;
  int m_incorrect[10];
public:
  void setID(int id);
  void incSolved();
  void setPenalty(int penalty);
  void incIncor(int pid);
  int getID();
  int getSolved();
  int getPenalty();
  int getIncor(int pid);
  Team(int id) {
    setID(id);
    m_solved = 0;
    m_penalty = 0;
    for (int i = 0; i < 10; i++) {
      m_incorrect[i] = 0;
    }
  }
};

void Team::setID(int id) {
  m_id = id;
}

void Team::incSolved() {
  m_solved++;
}

void Team::setPenalty(int penalty) {
  m_penalty += penalty;
}

void Team::incIncor(int pid) {
  m_incorrect[pid-1]++;
}

int Team::getID() {
  return m_id;
}

int Team::getSolved() {
  return m_solved;
}

int Team::getPenalty() {
  return m_penalty;
}

int Team::getIncor(int pid) {
  return m_incorrect[pid-1];
}

int main() {
  int T, P, R, tid, pid, time;
  string message;
  while (cin >> T >> P >> R, T | P | R) {
    vector<Team> teams;
    for (int i = 0; i <= T; i++) {
      teams.pb(Team(i));
    }
    while (R--) {
      cin >> tid >> pid >> time >> message;
      if (message == "CORRECT") {
        teams[tid].incSolved();
        teams[tid].setPenalty(teams[tid].getIncor(pid)*1200 + time);
      } else {
        teams[tid].incIncor(pid);
      }
    }
    for (int i = 0; i <= T ; i++) {
      for (int j = i+1; j <= T; j++) {
        if ((teams[i].getSolved() < teams[j].getSolved()) || ((teams[i].getSolved() == teams[j].getSolved()) && (teams[i].getPenalty() > teams[j].getPenalty())) || ((teams[i].getSolved() == teams[j].getSolved()) && (teams[i].getPenalty() == teams[j].getPenalty()) && teams[i].getID() > teams[j].getID())) {
          swap(teams[i], teams[j]);
        }
      }
    }
    for (int i = 0; i <= T; i++) {
      if (teams[i].getID() == 0) continue;
      cout << teams[i].getID() << " " << teams[i].getSolved() << " " << teams[i].getPenalty() << el;
    }
  }
}

Measured memory_bytes: 1220
N, M = map(int, input().split())
ans = ["0"] * (N)
Flag = True

for i in range(M):
  s, c = map(int, input().split())
  if ans[s-1] == "0":
    ans[s-1] = c
  elif ans[s-1] == c:
    continue
  else:
    Flag = False

if N > 1:
  if ans[0] == 0:
    Flag = False
  elif ans[0] == "0":
    ans[0] = 1

if Flag:
  print(int("".join([str(i) for i in ans])))
else:
  print(-1)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
    int n,m,x=-2,y=-1;
    cin>>n>>m;
    char arr[n+1][m],brr[n*2+1][m];
    for (int i=1;i<=n;i++){
        for (int j=0;j<m;j++){
            cin>>arr[i][j];
        }
    }
    for (int i=1;i<=n*2;i++){
        for (int j=0;j<m;j++){
            brr[i][j]=arr[(i+1)/2][j];
        }
    }

    for (int i=1;i<=n*2;i++){
        for (int j=0;j<m;j++){
            cout<<brr[i][j];
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
using namespace std;
int main(){
    string s;
    cin >> s;
    rep(i,3){
        if(s[i]=='1'){
            s[i]='9';
        }else if(s[i]=='9'){
            s[i]='1';
        }
    }
    cout << s << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var gakusei = new List<Tuple<long, long>>();
            for (var i = 0; i < N; ++i)
            {
                var ab = Sarray();
                gakusei.Add(new Tuple<long, long>(ab[0], ab[1]));
            }
            var gpos = new Tuple<long, long>[N];//pos, dst
            for (var i = 0; i < N; ++i)
                gpos[i] = new Tuple<long, long>(-1, Mod);
            for (var i = 0; i < M; ++i)
            {
                var ab = Sarray();
                for (var j = 0; j < N; ++j)
                {
                    var dst = Abs(gakusei[j].Item1 - ab[0]) + Abs(gakusei[j].Item2 - ab[1]);
                    if (dst < gpos[j].Item2)
                        gpos[j] = new Tuple<long, long>(i + 1, dst);
                }

            }
            foreach (var gp in gpos)
                WriteLine(gp.Item1);
            //Out.Flush();
        }
    }
}

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

#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
//#define pdd pair<double,double>
#define pll pair<LL,LL>
#define pb(x) push_back(x)
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define mii map<int,int>
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi 3.14159265359
#define INF 0x7fffffff
#define next Next
using namespace std;
typedef long long LL;
int main(){
	string s;
	cin>>s;
	int x,y;
	cin>>x>>y;
	int a[2][8005];
	MEM(a);
	int now=0;
	int it=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='F'){
			a[now][it]++;
		}
		else{
			it+=now;
			now^=1;
		}
	}
	x-=a[0][0];
	int dp[8005];
	MEM(dp);
	dp[0]=1;
	int sum=0;
	for(int i=1;i<=it;i++){
		for(int j=sum;j>=0;j--){
			if(dp[j])
			dp[j+a[0][i]]=1;
		}
		sum+=a[0][i];
	}
	if((sum-x)%2==1){
		printf("No\n");
		return 0;
	}
	if(sum-x<0||dp[(sum-x)/2]==0){
		printf("No\n");
		return 0;
	} 
	MEM(dp);
	dp[0]=1;
	sum=0;
	for(int i=0;i<=it;i++){
		for(int j=sum;j>=0;j--){
			if(dp[j])
			dp[j+a[1][i]]=1; 
		}
		sum+=a[1][i];
	}
//	printf("%d",sum);
	if((sum-y)%2==1){
		printf("No\n");
		return 0;
	}
	if(sum-y<0||dp[(sum-y)/2]==0){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define sc scanf
#define pr printf
#define pb push_back
#define ll long long int
#define rp
int main()
{
 int a,ans=1,i=2;
 cin>>a;
 while(1)
 {
     bool f=1;
     for(int j=2;pow(i,j)<=a;j++)
     {
         ans=max((int)pow(i,j),ans);
         f=0;
     }
     if(f)
        break;
     i++;
 }
 cout<<ans<<endl;

    return 0;
}



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

int main(){
    int N,D,X,ans;
    cin >> N >> D >> X;
    vector<int> vec(N);
    ans=X+N;
    for(int i=0;i<N;i++){
        cin >> vec[i];
    }
    for(int i=1;i<D;i++){
        for(int j=0;j<N;j++){
            if(i%vec[j]==0)
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a[6],b=0,c=0,d=0,i;
while(1){
scanf("%d\n",&a[0]);
if(a[0]==0){
break;
}
else{
if(a[0]==1){
b++;
}
else if(a[0]==2){
c++;
}
else{
d++;
}
for(i=1;i<5;i++){
scanf("%d\n",&a[i]);
if(a[i]==1){
b++;
}
else if(a[i]==2){
c++;
}
else{
d++;
}
}
if((d>0 && b>0 && c>0) || d==5 || b==5 || c==5){
for(i=0;i<5;i++){
printf("3\n");
}
}
else if(b==0){
for(i=0;i<5;i++){
if(a[i]==2){
printf("1\n");
}
else{
printf("2\n");
}
}
}
else if(c==0){
for(i=0;i<5;i++){
if(a[i]==1){
printf("2\n");
}
else{
printf("1\n");
}
}
}
else if(d==0){
for(i=0;i<5;i++){
if(a[i]==1){
printf("1\n");
}
else{
printf("2\n");
}
}
}
}
b=0,c=0,d=0;
}
return 0;
}






Measured memory_bytes: 2040
/*input
4 5
0 5
-2 4
3 4
4 -4
*/

#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>




#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define fill(a)  memset(a, 0, sizeof (a))
#define mp make_pair
#define pb push_back
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define pdd pair<double, double>
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define forstl(i,v) for(auto &i: v)
#define dbg(x) cout << #x << " = " << x << '\n'
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl(v) cout<<#v<<" = \n"; { int c=0; forstl(it,v) \
cout<<"    "<<#v<<"["<< ++c <<"] = "<<it<<endl;} cerr<<endl
#define dbgstlp(v) cout<<#v<<" = \n"; { int c=0; forstl(it,v) \
cout<<"    "<<#v<<"["<< ++c <<"] = "<<it.f<<" , "<<it.s<<endl;} cerr<<endl
#define PI           3.14159265358979323846

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define pdd pair<double, double>
#define in(v,n) vll v(n);rep(i,n) cin>>v[i]


using namespace std;


int main(){
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    cin.exceptions(cin.failbit);
    int T;
	// cout<<std::fixed<<std::setprecision(35);
	// cin>>T;while(T--)
	{
		ll t,n,i,j,x,y,m,l,d,k;
		cin>>n>>d;
		d=d*d;
		ll ans=0;
		rep(i,n){
			cin>>x>>y;
			if(x*x+y*y<=d) ans++;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define N (1<<17)

using namespace std;

char d[10][10];

int main() {
	cin.tie(0); 
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	for(int i=0; i<3; i++) {
		for(int j=0; j<3; j++)
			cin >> d[j][i];
	}
	cout << d[0][0]<<d[1][1]<<d[2][2];
}

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

using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  int j;
  double S;
  double ans=0.0;
  for(int i=1;n>=i;++i){
    j = i;
    S = 1.0/n;
    while(j<k){
      j = j*2;
      S = S/2.0;
    }
    ans += S;
  }
  cout << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const int mod = 1e9+7;

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

  string S; cin >> S;
  int N = S.size();
  ll sum = 0;
  int cnt = 0;
  rep(i, N) {
    if (S.at(i) == 'W') {
      sum += i;
      cnt++;
    }
  }

  ll sum2 = 0;
  rep(i, cnt) {
    sum2 += i;
  }
  cout << sum - sum2 << endl;
}

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

int main(){
  int R,G,B,N,sum=0;
  cin>>R>>G>>B>>N;
  for(int i=0;i<=N/R;i++){
    for(int j=0;j<=(N-i*R)/G;j++){
      if((N-i*R-j*G)%B==0)sum++;
    }
  }
  cout<<sum<<endl;
    
}

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

#include <cmath>
#include <cstdlib>
#include <climits>

//#include <stdio.h>
//#include <stdlib.h>


using namespace std;

#define debug false

int main(int argc, char *argv[]){

  int N; // 枚数
  int Y; // 総額
  cin >> N >> Y;
  int YY = Y / 10000;
  int yukichi, ichiyo, souseki;
  yukichi = ichiyo = souseki = -1;

  if(N*1000 <= Y and Y <= N*10000){
    for(int x = 0; x <= N and x <= YY; x++){
      if((Y/1000 - 9*x - N) % 4 == 0){
        yukichi = x;
        ichiyo = (Y/1000 - 9*x - N) / 4;
        souseki = N - yukichi - ichiyo;
        //printf("%d %d %d\n", yukichi, ichiyo, souseki);

        if(ichiyo >= 0 and souseki >= 0) break;
        else yukichi = ichiyo = souseki = -1;
      }

    }
  }
  printf("%d %d %d\n", yukichi, ichiyo, souseki);



  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int m = scanner.nextInt();
    int n = scanner.nextInt();
    ArrayList arrayList=new ArrayList();
    for (int i = 0; i <m; i++) {
        arrayList.add(scanner.nextInt());
    }
    Collections.sort(arrayList);
    Collections.reverse(arrayList);
    int sum=0;
    for (int i = 0; i <n; i++) {
        int arr= (int) arrayList.get(i);
        sum+=arr;
    }
//    System.out.println(sum);

    System.out.println(sum);
}
}

Measured memory_bytes: 22996
N = int(input())
AB = [tuple(int(_) for _ in input().split()) for i in range(N)]
CD = [tuple(int(_) for _ in input().split()) for i in range(N)]

AB.sort(key=lambda xy:xy[1], reverse=True)
CD.sort()
for c, d in CD:
    for a, b in AB:
        if a < c and b < d:
            AB.remove((a, b))
            break

print(N - len(AB))


Measured memory_bytes: 3064
import Foundation

let inputLine = readLine()!.components(separatedBy: " ").map({Int($0)!})
let N = inputLine[0]
let K = inputLine[1]

var ans = N

func swapAbs() {
    if abs(ans-K)>ans{
        return
    }
    ans = abs(ans-K)
    swapAbs()
}

let div = N/K
ans = N-K*div
swapAbs()
print(ans)


Measured memory_bytes: 14176
import java.util.Scanner;
public class Main {

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

		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		int[] a = new int[m];
		
		for(int i = 0; i < m; ++i) {
			a[i] = sc.nextInt();
			
			if(x < a[i]) {
				if(i < m/2) {
					System.out.println(i);
					return;
				}else {
					System.out.print(m-i);
					return;
				}
			}
		}		
		sc.close();
	}
}

Measured memory_bytes: 23124
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long N;
	cin >> N;
	vector<long long>D(N);
	for (long long i = 0; i < N; i++) {
		cin >> D.at(i);
	}
	long long M;
	cin >> M;
	vector<long long>T(M);
	for (long long i = 0; i < M; i++) {
		cin >> T.at(i);
	}
	sort(D.begin(), D.end());
	sort(T.begin(), T.end());
	long long k = 0;
	for (long long i = 0; i < N; i++) {
		if (k == M) {
			cout << "YES" << endl;
			return 0;
		}
		if (D.at(i) == T.at(k)) {
			k++;
		}
	}
	if (k == M) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 3328
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (A, P) = read!(usize, usize);
    println!("{}", (A * 3 + P) / 2)
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
int main()
{
	int n,k=0;
	std::vector<int> a;
	std::cin>>n;
	a.resize(n);
	for(int i=0;i<n;i++){
		std::cin>>a[i];
		if(a[i]!=i+1){
			k++;
		}
	}
	if(k==0||k==2){
		std::cout<<"YES"<<"\n";
	}else{
		std::cout<<"NO"<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main(){
	var ans,m int
	var n string
	fmt.Scan(&n)
	for i:=0;i<3;i++ {
		if n[i] == 'R' {
			ans++
		} else {
			if m < ans {
				m = ans
			}
			ans = 0
		}
	}
	if m < ans {
		m = ans
	}
	fmt.Println(m)
}


Measured memory_bytes: 1772
#include <bits/stdc++.h>
using namespace std;
int A[105],B[105],in=0,flg=1;
void f(int l,int r){
	if(l>=r) return;
	int c = A[in++];
	int m = B[c];
	f(l,m);
	f(m+1,r);
	if(flg) cout<<c,flg = 0;
	else cout<<' '<<c;
}
int main()
{
	int n,u; cin>>n;
	for(int i=0;i<n;i++) cin>>A[i];
	for(int i=0;i<n;i++){
		cin>>u;
		B[u] = i;
	}
	f(0,n);
	cout<<endl;
	return 0;
}



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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;

void Main(){
    const int Y = 2019;
	string s;
	cin >> s;
	int n = s.size();
	
	reverse(all(s));
	
	// r[i] = i 文字目以降を Y で割った余り
	vi r(n);
	r[0] = s[0] - '0';
	vi cnt(Y, 0);
	cnt[0]++;
	
	int tn = 10;
	rep(i, n){
	    r[i+1] = (r[i] + (s[i+1] - '0') * tn) % Y;
	    cnt[r[i]]++;
	    tn = tn * 10 % Y;
	    // cout << i << ": " << r[i] << endl;
	}
	
	ll ans = 0;
	rep(i, Y){
	    // if(cnt[i] != 0) cout << i << ":" << cnt[i] << endl;
	    ans += cnt[i] * (cnt[i] - 1) / 2;
	}
	cout << ans << endl;
	return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 4344
from bisect import bisect_left, bisect_right
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]
A.sort()
B.sort()
C.sort()
ans = 0
for b in B:
    ltB = bisect_left(A, b)
    gtC = N - bisect_right(C, b)
    ans += ltB*gtC
print(ans)

Measured memory_bytes: 23232
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll h, w, k;
    cin >> h >> w >> k;
    ll x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    --x1, --y1, --x2, --y2;
    vector<string> c(h);
    rep(i, h) cin >> c[i];

    vvll d(h, vll(w, INFL));
    d[x1][y1] = 0;

    queue<pll> q;
    q.push(make_pair(x1, y1));
    ll dx[] = {1, -1, 0, 0};
    ll dy[] = {0, 0, 1, -1};
    while(!q.empty()) {
        pll p = q.front();
        q.pop();
        for(ll i = 0; i < 4; i++) {
            for(ll j = 1; j <= k; j++) {
                ll x = p.first + j * dx[i];
                if(x < 0 || x >= h) break;
                ll y = p.second + j * dy[i];
                if(y < 0 || y >= w) break;
                if(c[x][y] == '@') break;
                if(d[x][y] <= d[p.first][p.second]) break;
                else if(d[x][y] <= d[p.first][p.second] + 1) continue;
                d[x][y] = d[p.first][p.second] + 1;
                q.push(make_pair(x, y));
            }
        }
    }
    ll ans = d[x2][y2];
    if(ans == INFL) ans = -1;
    cout << ans << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 19804
#include<stdio.h>

struct Process
{
    char name[11];
    int tim;
};

struct Process dequeue(struct Process *Q,int *head)
{
    *head = *head + 1;
    return Q[*head - 1];
}

void enqueue(struct Process x,struct Process *Q,int *tail)
{
    Q[*tail] = x;
    *tail +=1;
}


int main()
{
    int n,c,cnt=0,box=0,ksn=0;
    scanf("%d %d",&n,&c);
    int tail=n,head=0;
    char nmtmp[11],tmp;
    struct Process p[n+1];
    for(int i=0;i<n;i++)
    {
        scanf("%s", p[i].name);
        scanf("%d", &p[i].tim);
    }
    while(head!=tail)
    {
        if(tail > n) tail = 0;
        struct Process x = dequeue(p,&head);
        if(head > n) head =0;
        if(x.tim < c)
        {
            ksn += x.tim;
            x.tim = 0;
        }
        else 
        {
            ksn += c;
            x.tim -= c;
        }
        if(x.tim == 0)
        {
            printf("%s %d\n", x.name,ksn);
        }
        else
        {
            enqueue(x,p,&tail);
        }
    }
    return 0;
}


Measured memory_bytes: 2576
import sys

K = int(input())
X, Y = map(int, input().split())
dest = (X, Y)
ans = 0
path = []


def sign(i):
    return 2*(i > 0)-1


def dist(p1, p2):
    return abs(p1[0]-p2[0])+abs(p1[1]-p2[1])


curpos = [0, 0]
if dist(curpos, dest) == K:
    print(1)
    print(X, Y)
    sys.exit()

while dist(curpos, dest) > 2*K:
    ans += 1
    xdiff = abs(curpos[0] - dest[0])
    curpos[0] += min(K, xdiff) * sign(dest[0] - curpos[0])
    curpos[1] += max(0, K - xdiff) * sign(dest[1] - curpos[1])
    path.append((curpos[0], curpos[1]))

if dist(curpos, dest) % 2 == 1:
    if K % 2 == 0:
        print(-1)
        sys.exit()
    ans += 1
    xdiff = abs(curpos[0] - dest[0])
    curpos[0] += min(K, xdiff) * sign(dest[0] - curpos[0])
    curpos[1] += max(0, K - xdiff) * sign(dest[1] - curpos[1])
    path.append((curpos[0], curpos[1]))
d = dist(curpos, dest)
rest = (2*K-d)//2
ans += 1
xdiff = abs(curpos[0] - dest[0])
if xdiff+rest >= K:
    curpos[0] += (K - rest) * sign(dest[0] - curpos[0])
    curpos[1] -= rest * sign(dest[1] - curpos[1])
else:
    curpos[0] += (xdiff+rest) * sign(dest[0]-curpos[0])
    curpos[1] += (K-(xdiff+rest)) * sign(dest[1] - curpos[1])
path.append((curpos[0], curpos[1]))
path.append(dest)
ans += 1
print(ans)
for p in path:
    print(p[0], p[1])


Measured memory_bytes: 86272
#include<stdio.h>

int main(){
  int h[100000];
  int w[100000];
  int count = 0;
  while(true){
    scanf("%d %d", &h[count], &w[count]);
    if(h[count] == 0 && w[count] == 0) break;
    count ++;
  }

  for(int i=0; i < count; i++){
    for(int tate=0; tate < h[i]; tate++){
      for(int yoko=0; yoko < w[i]; yoko++){
	if(tate%2 == 0){
	  if(yoko%2 == 0)printf("#");else printf(".");
	}else{
	  if(yoko%2 == 1)printf("#");else printf(".");
	}
      }
      printf("\n");
    }
    printf("\n");
  }
  
  return 0;
}



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

#define int long long
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 a[100010];

signed main(){
	int n;
	cin >> n;

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

	int ans = a[0] > 0 ? 0 : 1-a[0];
	int wa = a[0] > 0 ? a[0] : 1; 
	for(int i = 1;i < n;i++){
		int nxt = abs(wa)+1;
		if(wa < 0){
			if(nxt > a[i]){
				ans += nxt-a[i];
				wa += nxt;
			}else{
				wa += a[i];
			}
		}else{
			nxt *= -1;
			if(nxt < a[i]){
				ans += a[i]-nxt;
				wa += nxt;
			}else{
				wa += a[i];
			}
		}
	}

	int ans2 = a[0] < 0 ? 0 : a[0]+1;
	wa = a[0] < 0 ? a[0] : -1;
	for(int i = 1;i < n;i++){
		int nxt = abs(wa)+1;
		if(wa < 0){
			if(nxt > a[i]){
				ans2 += nxt-a[i];
				wa += nxt;
			}else{
				wa += a[i];
			}
		}else{
			nxt *= -1;
			if(nxt < a[i]){
				ans2 += a[i]-nxt;
				wa += nxt;
			}else{
				wa += a[i];
			}
		}
	}
	cout << min(ans, ans2) << endl;

	return 0;
}


Measured memory_bytes: 4364
#include <iostream>
using namespace std;
using uint = unsigned int;

int main() {
	uint M1, D1, M2, D2;
	cin >> M1 >> D1 >> M2 >> D2;

	if(M1 != M2) {
		cout << 1;
	} else {
		cout << 0;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define endl "\n";
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	ll a[4],best=-1000000000000000000;
	for(int i=0;i<4;i++){
		cin>>a[i];
	}
	for(int i=0;i<2;i++){
		for(int j=2;j<4;j++){
			best=max(best,a[i]*a[j]);
		}
	}
	cout<<best;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n, f[10][10];
ll ans;
int main() {
	scanf("%d", &n);
	for(int i=1; i<=n; ++i){
		int x=i;
		while(x>=10) x/=10;
		++f[x][i%10];
	}
	for(int i=1; i<=n; ++i){
		int x=i;
		while(x>=10) x/=10;
		ans+=f[i%10][x];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
long long s[510000];
long long t[510000];
deque<pair<double,int> >Q;
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		scanf("%lld%lld",s+i,t+i);
	}
	long long tot=0;
	double toJ=0;
	for(int i=0;i<a;i++){
		double J=0;
		long long cur=0;
		J+=(double)s[i]*t[i];
		cur+=t[i];
		while(Q.size()&&Q.front().first>=J/cur){
			J+=Q.front().first*Q.front().second;
			cur+=Q.front().second;
			Q.pop_front();
		}
		
	//	printf("%.12f %lld\n",J/cur,cur);
		Q.push_front(make_pair(J/cur,cur));
		toJ+=(double)s[i]*t[i];
		tot+=t[i];
		while(tot>b){
			pair<double,int> tmp=Q.back();
			Q.pop_back();
			if(tmp.second<=(tot-b)){
				toJ-=tmp.second*tmp.first;
				tot-=tmp.second;
			}else{
				Q.push_back(make_pair(tmp.first,tmp.second-(tot-b)));
				toJ-=(tot-b)*tmp.first;
				tot-=(tot-b);
			}
		}
		printf("%.12f\n",toJ/b);
		if(i<a-1){
			while(tot>b-t[i+1]){
				pair<double,int> tmp=Q.back();
				Q.pop_back();
				if(tmp.second<=(tot-b+t[i+1])){
					toJ-=tmp.second*tmp.first;
					tot-=tmp.second;
				}else{
					Q.push_back(make_pair(tmp.first,tmp.second-(tot-b+t[i+1])));
					toJ-=(tot-b+t[i+1])*tmp.first;
					tot-=(tot-b+t[i+1]);
				}
			}
		}
	}
}


Measured memory_bytes: 27540
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >>n;
  vector<int>a(3*n);
  for(int i=0;i<3*n;i++)cin>>a[i];
  sort(a.rbegin(),a.rend());
  long long sum=0;
  for(int i=1;i<=2*n;i=i+2){
    sum+=a[i];
  }
  cout << sum << endl;
}

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

using namespace std;

int main(){
    int N,M,S,T;
    cin >> N >> M;
    vector<vector<int>> graph(N);
    vector<long long int> len(3*N,-1);

    for(int i=0;i<M;i++){
        int u,v;
        cin >> u >> v;
        u--;
        v--;
        graph[u].push_back(v);
    }

    cin >> S >> T;

    S--;
    T--;

    queue<int> Q;
    Q.push(3*S);
    len[3*S] = 0;

    while(!Q.empty()){
        int now = Q.front();
        Q.pop();
        for(int i=0;i<graph[now/3].size();i++){
            if(len[3*graph[now/3][i] + (now%3+1)%3]==-1){
                len[3*graph[now/3][i]+(now%3+1)%3] = len[now] + 1;
                Q.push(3*graph[now/3][i]+(now%3+1)%3);
            }
        }
    }

    if(len[3*T]==-1){
        cout << -1 << endl;
    }else{
        cout << len[3*T]/3 << endl;
    }
}

Measured memory_bytes: 8064
let N = Int(readLine()!)!
let A: [Int] = readLine()!.split(separator: " ").map { Int($0)! }.sorted()

var dp: [Bool] = Array(repeating: true, count: 3*Int(1e6))
var x: Int = -1
for a in A {
    if x == a { continue }
    x = a
    while x <= A[N-1] {
        x += a
        dp[x] = false
    }
    x = a
}

var res: Int = 0
for (i, a) in A.enumerated() {
    if i > 0 && a == A[i-1] { continue }
    if i < N-1 && a == A[i+1] { continue }
    if dp[a] { res += 1 }
}
print(res)  // (๑•ૅㅁ•๑)

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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

long long INF=numeric_limits<long long>::max();

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    ll n,m,ans(0);
    cin >> n >> m;
    ll mod[m],same[100001],smod[m];
    memset(mod,0,sizeof(mod));
    memset(smod,0,sizeof(smod));
    memset(same,0,sizeof(same));
    vector< ll > x(n);
    for(ll i = 0; i < n; i++)
    {
        cin >> x[i];
        same[x[i]]++;
    }
    for(ll i = 1; i <= 100000; i++)
    {
        ll a = i%m;
        mod[a]+=same[i];
        smod[a]+=same[i]/2;
    }
    ans += mod[0]/2;
    if(m%2==0)ans += mod[m/2]/2;
    for(ll i = 1; i < (m+1)/2; i++)
    {
        ll j = m-i;
        //cout << mod[i] << " " << mod[j] << endl;
        if(mod[i]==mod[j])
        {
            ans += mod[i];
        }
        else if(mod[i]>mod[j])
        {
            ans += mod[j];
            ll left = mod[i] - mod[j];
            //cout << left/2 << " " << smod[i] << endl;
            left = min(left/2,smod[i]);
            ans += left;
        }
        else
        {
            ans += mod[i];
            ll left = mod[j] - mod[i];
            left = min(left/2,smod[j]);
            ans += left;
        }
    }
    cout << ans << endl;
}

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

signed main()
{

  while(true){
    int N; cin>>N;
    if(N==0) break;

    vector<int> x(N),y(N);
    set<pair<int,int>> st;
    for(int i=0;i<N;i++){
      cin>>x[i]>>y[i];
      st.insert({x[i],y[i]});
    }

    int ans=0;
    for(int i=0;i<N-1;i++) for(int j=i+1;j<N;j++){
      int dx=x[j]-x[i];
      int dy=y[j]-y[i];

      swap(dx,dy);
      dx*=-1;
      int x1=x[j]+dx;
      int y1=y[j]+dy;

      swap(dx,dy);
      dx*=-1;
      int x2=x1+dx;
      int y2=y1+dy;

      if(st.count({x1,y1}) and st.count({x2,y2})){
        ans=max(ans,dx*dx+dy*dy);
      }
    }
    cout<<ans<<endl;
  }

  return 0;
}



Measured memory_bytes: 3316
(function() {
function Main(input) {
  lines = input.split("\n")[0]
  j = 0
  for (i=0; i < lines.length; i++) {
    if (lines[i] == 'x') j++
  }
  if (j >= 8) {
    console.log('NO')
  } else {
    console.log('YES')
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
}())


Measured memory_bytes: 7372
#include <bits/stdc++.h>
#include <ctime>
#include <sstream>
#define weewoo ios::sync_with_stdio(false);cin.tie(0)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ld long double
#define ll long long
#define se second
#define fi first
#define ctoi(x) (x-'0')
#define pi (acos(-1))
#define llputin(a,n) for(int i=0;i<n;i++){ll x;cin >> x;a.push_back(x);}
#define iputin(a,n) for(int i=0;i<n;i++){int x;cin >> x;a.push_back(x);}

#define MOD ((ll) 1e9 + (ll) 7)
using namespace std;

ll pw(ll x,ll a){
    if(a==0)
        return 1;
    ll t = pw(x,a/2);
    if(a%2==0)
        return (t*t);
    else
        return (t*t*x);
}

bool prime(int x)
{
    if(x < 2) return false;
        for(int i=2; i<= sqrt(x); i++) {
            if ((x%i) == 0) return false;
        }
    return true;
}



int main()
{
    weewoo;
    vector<int>a;
    iputin(a,3);
    sort(a.begin(),a.end());
    if(a[0]==a[1]){
        if(a[1]!=a[2])
            return cout << "Yes" << endl,0;
    }
    if(a[1]==a[2]&&a[1]!=a[0])
        return cout << "Yes" << endl,0;
    cout << "No" << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ld PI = acos(-1.0);
const ll LINF = (ll)1e18 + 5;
const int INF = (int)1e9 + 5;

template<class T>
T sqr(T x) { return x * x; }

template<class T>
T abs(T x) { return x < 0 ? -x : x; }

template<class T>
ll round(T x) { return x < 0 ? x - 0.5 : x + 0.5; }

template<class T>
bool chmin(T & x, const T & y) {
	if (y < x) {
		x = y;
		return true;
	}
	return false;
}

template<class T>
bool chmax(T & x, const T & y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}


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

template<class T>
ostream & operator <<(ostream & os, const vector<T> & v) {
	bool was = false;
	os << "{";
	for (typename vector<T>::const_iterator it = v.begin(); it != v.end(); it++) {
		if (was) {
			os << ", ";
		}
		else {
			was = true;
		}
		os << *it;
	}
	os << "}";
	return os;
}

template<class T>
ostream & operator <<(ostream & os, const set<T> & v) {
	bool was = false;
	os << "{";
	for (typename set<T>::const_iterator it = v.begin(); it != v.end(); it++) {
		if (was) {
			os << ", ";
		}
		else {
			was = true;
		}
		os << *it;
	}
	os << "}";
	return os;
}

template<class T>
ostream & operator <<(ostream & os, const multiset<T> & v) {
	bool was = false;
	os << "{";
	for (typename multiset<T>::const_iterator it = v.begin(); it != v.end(); it++) {
		if (was) {
			os << ", ";
		}
		else {
			was = true;
		}
		os << *it;
	}
	os << "}";
	return os;
}

template<class P, class Q>
ostream & operator <<(ostream & os, const map<P, Q> & v) {
	bool was = false;
	os << "{";
	for (typename map<P, Q>::const_iterator it = v.begin(); it != v.end(); it++) {
		if (was) {
			os << ", ";
		}
		else {
			was = true;
		}
		os << *it;
	}
	os << "}";
	return os;
}

#define all(x) (x).begin(), (x).end()

template<class T>
T nextInt() {
	ll x = 0;
	bool p = false;
	char c;
	do {
		c = getchar();
	} while (c <= 32);
	if (c == '-') {
		p = true;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		x = x * 10 + c - '0';
		c = getchar();
	}
	return (p ? -x : x);
}

void tak() {
	puts("Possible");
	exit(0);
}

void nie() {
	puts("Impossible");
	exit(0);
}

void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int & x : a) {
		cin >> x;
	}
	sort(all(a));
	int diam = a.back();
	if (a[(int)a.size() - 2] != diam) {
		nie();
	}
	int z = (diam + 1) / 2;
	if (a[0] != z) {
		nie();
	}
	if (diam % 2 == 0) {
		if (a[1] == z) {
			nie();
		}
	}
	else {
		if (a[1] != z) {
			nie();
		}
		if (2 < (int)a.size() && a[2] == z) {
			nie();
		}
	}
	for (int i = 0; i + 1 < (int)a.size(); i++) {
		if (a[i + 1] - a[i] > 1) nie();
	}
	tak();
}

int main() {
	srand(time(0));

#ifdef LOCAL
	//gen();
	freopen("input.txt", "r", stdin);
#else
	
#endif

	int t = 1;
	//scanf("%d", &t);
	while (t--) solve();
	
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		char[] arr = sc.next().toCharArray();
		arr[k - 1] = (char)(arr[k - 1] - ('A' - 'a'));
		System.out.println(arr);
	}
}


Measured memory_bytes: 22996
package main

import (
	"fmt"
	"sort"
)

type shop struct {
	a int // 値段
	b int // 在庫
}

type byPrice []shop

func (s byPrice) Len() int           { return len(s) }
func (s byPrice) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s byPrice) Less(i, j int) bool { return s[i].a < s[j].a }

func main() {
	n, m := 0, 0
	fmt.Scan(&n, &m)

	s := make([]shop, n)
	for i := range s {
		fmt.Scan(&s[i].a, &s[i].b)
	}

	sort.Sort(byPrice(s))

	count := 0
	price := 0
	for i := range s {
		count += s[i].b
		if count >= m {
			x := count - m
			price += s[i].a * (s[i].b - x)
			fmt.Println(price)
			return
		}
		price += s[i].a * s[i].b
	}
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t; cin>>s>>t;
    int dp[s.size()+1][t.size()+1];
    dp[0][0]=1;
    for (int i1=1;i1<=t.size();i1++)
        dp[0][i1]=0;
    for (int i2=1;i2<=s.size();i2++)
        dp[i2][0]=0;
    for (int i=1;i<=s.size();i++) {
        for (int j=1;j<=t.size();j++) {
            if (s[i -1]==t[j -1])
                dp[i][j]=1+dp[i-1][j-1]; //popoff from both
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]); //try both, choose max
        }
    }
    stack<char> lcs;
    int i,j; i=s.size(); j=t.size();
    while (i!=0 && j!=0) {
        if (dp[i][j]>max(dp[i-1][j],dp[i][j-1])) {
            lcs.push(s[i -1]);
            i--;j--;
        }
        else {
            if (dp[i][j-1]<=dp[i-1][j])
                i--; //dont push, just reach there and in next iteration it will be pushed
            else
                j--;
        }
    }
    while (!lcs.empty())
        cout<<lcs.top(), lcs.pop();
    return 0;
}

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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;

#define ull unsigned long long
#define ld long double

template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<V<V<T>>>;

#define rep2(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) rep2(i,0,n)
#define rep1(i, n) rep1(i,1,n+1)

// #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
// #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend() //

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO = "No";

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(15);
//    cout << std::setfill('0') << std::setw(2);

    long long A;
    std::cin >> A;
    long long B;
    std::cin >> B;
    long long C;
    std::cin >> C;

    if (A + B >= C) cout << YES << endl;
    else
        cout << NO << endl;

    return 0;
}


Measured memory_bytes: 256